Advertisement
Rockhopper09

Advanced Register System Using Emails !

Nov 7th, 2014
1,161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.79 KB | None | 0 0
  1.  
  2. #include <a_samp>
  3. #include <YSI\y_ini>
  4.  
  5. #define MAILER_URL "phphoster09.comyr.com/mailer.php" // This has to be defined BEFORE you include mailer. CUSTOM
  6.  
  7. #include <mailer>
  8.  
  9. native WP_Hash(buffer[], len, const str[]);
  10.  
  11. #define DIALOG_REGISTER 1
  12. #define DIALOG_LOGIN 2
  13. #define DIALOG_SUCCESS_1 3
  14. #define DIALOG_SUCCESS_2 4
  15. #define DIALOG_PASS 5
  16. #define DIALOG_MAIL 6
  17.  
  18. #define PATH "/User/%s.ini"
  19.  
  20. #define COL_WHITE "{FFFFFF}"
  21. #define COL_RED "{F81414}"
  22. #define COL_GREEN "{00FF22}"
  23. #define COL_LIGHTBLUE "{00CED1}"
  24.  
  25. #define COLOR_RED 0xFF0000FF
  26.  
  27. #define SCM SendClientMessage
  28. #define SCMTA SendClientMessageToAll
  29.  
  30. enum pInfo
  31. {
  32.     pPass[129],
  33.     pCash,
  34.     pAdmin,
  35.     pKills,
  36.     pDeaths,
  37.     pScore,
  38.     pJailed,
  39.     pBanned,
  40.     pWarn,
  41.     pMail[300],
  42.     pSPass,
  43.     pCMail,
  44.  
  45. }
  46. new PlayerInfo[MAX_PLAYERS][pInfo];
  47.  
  48. forward LoadUser_data(playerid,name[],value[]);
  49. public LoadUser_data(playerid,name[],value[])
  50. {
  51.     INI_String("Password",PlayerInfo[playerid][pPass], 129);
  52.     INI_Int("Cash",PlayerInfo[playerid][pCash]);
  53.     INI_Int("Admin Level",PlayerInfo[playerid][pAdmin]);
  54.     INI_Int("Kills",PlayerInfo[playerid][pKills]);
  55.     INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
  56.     INI_Int("Score",PlayerInfo[playerid][pScore]);
  57.     INI_Int("IsJailed",PlayerInfo[playerid][pJailed]);
  58.     INI_Int("IsBanned",PlayerInfo[playerid][pBanned]);
  59.     INI_Int("Warnings",PlayerInfo[playerid][pWarn]);
  60.     INI_Int("SecondPass",PlayerInfo[playerid][pSPass]);
  61.     INI_String("Mail",PlayerInfo[playerid][pMail], 300);
  62.     INI_Int("Email Check",PlayerInfo[playerid][pCMail]);
  63.  
  64.     return 1;
  65. }
  66.  
  67. forward KickPublic(playerid);
  68. public KickPublic(playerid) { Kick(playerid); }
  69.  
  70. stock KickWithMessage(playerid, message[])
  71. {
  72.     SendClientMessage(playerid,COLOR_RED, message);
  73.     SetTimerEx("KickPublic", 1000, 0, "d", playerid);     //Delay of 1 second before kicking the player so he recieves the message
  74. }
  75.  
  76. stock UserPath(playerid)
  77. {
  78.     new string[128],playername[MAX_PLAYER_NAME];
  79.     GetPlayerName(playerid,playername,sizeof(playername));
  80.     format(string,sizeof(string),PATH,playername);
  81.     return string;
  82. }
  83.  
  84. stock AutoSave(playerid)
  85. {
  86. new INI:File = INI_Open(UserPath(playerid));
  87.     INI_SetTag(File,"PlayerData");
  88.     INI_WriteString(File, "Password", PlayerInfo[playerid][pPass]);
  89.     INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
  90.     INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
  91.     INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
  92.     INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
  93.     INI_WriteInt(File,"Score",GetPlayerScore(playerid));
  94.     INI_WriteInt(File,"IsJailed",PlayerInfo[playerid][pJailed]);
  95.     INI_WriteInt(File,"IsBanned",PlayerInfo[playerid][pBanned]);
  96.     INI_WriteInt(File,"Warnings",PlayerInfo[playerid][pWarn]);
  97.     INI_WriteInt(File,"SecondPass",PlayerInfo[playerid][pSPass]);
  98.     INI_WriteString(File, "Mail", PlayerInfo[playerid][pMail]);
  99.     INI_WriteInt(File,"Email Check",PlayerInfo[playerid][pCMail]);
  100.     INI_Close(File);
  101. return 1;
  102. }
  103.  
  104.  
  105. public OnFilterScriptInit()
  106. {
  107.     print("\n--------------------------------------");
  108.     print(" Advanced Register System By Rockhopper");
  109.     print("--------------------------------------\n");
  110.     return 1;
  111. }
  112.  
  113. public OnFilterScriptExit()
  114. {
  115.     return 1;
  116. }
  117.  
  118.  
  119. public OnGameModeInit()
  120. {
  121.     // Don't use these lines if it's a filterscript
  122.  
  123.     return 1;
  124. }
  125.  
  126. public OnGameModeExit()
  127. {
  128.     return 1;
  129. }
  130.  
  131. public OnPlayerRequestClass(playerid, classid)
  132. {
  133.  
  134.     return 1;
  135. }
  136.  
  137. public OnPlayerConnect(playerid)
  138. {
  139.     if(fexist(UserPath(playerid)))
  140.     {
  141.         INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
  142.         if(PlayerInfo[playerid][pBanned] >= 1)
  143.         {
  144.           KickWithMessage(playerid,"You are banned from the server!!");
  145.           return 0;
  146.          }
  147.         else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Forgot Pass");
  148.     }
  149.     else
  150.     {
  151.         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
  152.     }
  153.     return 1;
  154. }
  155.  
  156. public OnPlayerDisconnect(playerid, reason)
  157. {
  158.     new INI:File = INI_Open(UserPath(playerid));
  159.     INI_SetTag(File,"PlayerData");
  160.     INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
  161.     INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
  162.     INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
  163.     INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
  164.     INI_WriteInt(File,"Score",GetPlayerScore(playerid));
  165.     INI_WriteInt(File,"IsJailed",PlayerInfo[playerid][pJailed]);
  166.     INI_WriteInt(File,"IsBanned",PlayerInfo[playerid][pBanned]);
  167.     INI_WriteInt(File,"Warnings",PlayerInfo[playerid][pWarn]);
  168.     INI_WriteInt(File,"SecondPass",PlayerInfo[playerid][pSPass]);
  169.     INI_WriteString(File, "Mail", PlayerInfo[playerid][pMail]);
  170.     INI_WriteInt(File,"Email Check",PlayerInfo[playerid][pCMail]);
  171.     INI_Close(File);
  172.     return 1;
  173. }
  174.  
  175. public OnPlayerSpawn(playerid)
  176. {
  177.     return 1;
  178. }
  179.  
  180. public OnPlayerDeath(playerid, killerid, reason)
  181. {
  182.     PlayerInfo[killerid][pKills]++;
  183.     PlayerInfo[playerid][pDeaths]++;
  184.     return 1;
  185. }
  186.  
  187.  
  188. public OnPlayerUpdate(playerid)
  189. {
  190.     return 1;
  191. }
  192.  
  193. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  194. {
  195.     switch( dialogid )
  196.     {
  197.         case DIALOG_REGISTER:
  198.         {
  199.             if (!response) return Kick(playerid);
  200.             if(response)
  201.             {
  202.                 if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, ""COL_WHITE"Making your account ..",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
  203.                 new INI:File = INI_Open(UserPath(playerid));
  204.                 INI_SetTag(File,"PlayerData");
  205.                 new HashPass[129];
  206.                 WP_Hash(HashPass, sizeof(HashPass), inputtext);
  207.                 INI_WriteString(File, "Password", HashPass);
  208.                 INI_WriteInt(File,"Cash",0);
  209.                 INI_WriteInt(File,"Admin",-1);
  210.                 INI_WriteInt(File,"Kills",0);
  211.                 INI_WriteInt(File,"Deaths",0);
  212.                 INI_WriteInt(File,"Score",0);
  213.                 INI_WriteInt(File,"IsJailed",0);
  214.                 INI_WriteInt(File,"IsBanned",0);
  215.                 INI_WriteInt(File,"Warnings",0);
  216.                 PlayerInfo[playerid][pSPass] = 100*random(10) + random(10) + random(10);
  217.                 INI_Close(File);
  218.  
  219.                 ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Account created!",""COL_GREEN"You've created an account successfuly. ","Ok","");
  220.                 ShowPlayerDialog(playerid, DIALOG_MAIL, DIALOG_STYLE_INPUT, ""COL_WHITE"Setting up Mail",""COL_WHITE"Type your email ID for password recovery purposes \n You can't enter it later and if lost your password it \n can't be recovered ","Set","Abort");
  221.             }
  222.         }
  223.  
  224.         case DIALOG_LOGIN:
  225.         {
  226.             if ( !response ) {
  227.              if(PlayerInfo[playerid][pCMail] < 1)
  228.              {
  229.                 SCM(playerid,COLOR_RED,"You didn't set up your email now you can't login using the recovery system.. Account will be deleted within 30 days ");
  230.                 KickWithMessage(playerid,"This is the result of not setting up your email on time ");
  231.              }
  232.              else {
  233.              new tm[300];
  234.              format(tm, 300, PlayerInfo[playerid][pMail]);
  235.              new str[500];//CUSTIOM ||
  236.              format(str, sizeof(str),"Hello welcome to the Password Recovery System Please Follow Below to reset your password. The following is your PIN. Using this PIN you can reset your password immedeaitly ! PIN :- %d . You need to login with your PIN Then you will be able to change your password immediately! Go Soon ! ",PlayerInfo[playerid][pSPass]);
  237.              SendMail( tm, "sampaccountsys@phphoster09.comyr.com", "Server System", "Password Recovery", str );  
  238.              KickWithMessage(playerid,"We have sent you an email.. Please follow the instructions there. If it hasn't come try again or Contact an Admin!");
  239.             }
  240.             }
  241.  
  242.             else if( response )
  243.             {
  244.             new HashPass[129];
  245.             WP_Hash(HashPass, sizeof(HashPass), inputtext);
  246.             if(strcmp(HashPass, PlayerInfo[playerid][pPass]) == 0)
  247.                 {
  248.                     INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
  249.                     GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  250.                     SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
  251.                     ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
  252.                     if(PlayerInfo[playerid][pCMail] < 1)
  253.                     {
  254.                         SCM(playerid,COLOR_RED,"You haven't registered your Mail Please do it Now ! ");
  255.                         ShowPlayerDialog(playerid, DIALOG_MAIL, DIALOG_STYLE_INPUT, ""COL_WHITE"Setting up Mail",""COL_WHITE"Type your email ID for password recovery purposes \n You can't enter it later and if lost your password it \n can't be recovered ","Set","Abort");
  256.  
  257.                     }
  258.  
  259.                 }
  260.  
  261.             else if(strval(inputtext) == PlayerInfo[playerid][pSPass])
  262.                    {
  263.                     INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
  264.                     GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  265.                     SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
  266.                     ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Change your pass",""COL_RED"We have detected that you have logged in using you PIN So please change your password ","Ok","");
  267.                     ShowPlayerDialog(playerid, DIALOG_PASS, DIALOG_STYLE_PASSWORD,""COL_WHITE"Recovering...",""COL_WHITE"Type your new password below ..","Change","Quit");
  268.                    }
  269.  
  270.  
  271.                
  272.             else
  273.                 {
  274.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Forgot Pass");
  275.                 }
  276.             return 1;
  277.             }
  278.         }
  279.         case DIALOG_PASS:
  280.         {
  281.             if (!response) return Kick(playerid);
  282.             if(response)
  283.             {
  284.                 if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_PASS, DIALOG_STYLE_PASSWORD, ""COL_WHITE"Changing Your Pass..",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your new password yo chnage it.","Change","Quit");
  285.                 INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
  286.                 GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  287.                 SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
  288.                 SCM(playerid,COLOR_RED,"You have sucessfully saved your new password !");
  289.                 new INI:File = INI_Open(UserPath(playerid));
  290.                 INI_SetTag(File,"PlayerData");
  291.                 new HashPass[129];
  292.                 WP_Hash(HashPass, sizeof(HashPass), inputtext);
  293.                 INI_WriteString(File, "Password", HashPass);
  294.                 PlayerInfo[playerid][pSPass] = 100*random(10) + random(10) + random(10);
  295.                 INI_Close(File);
  296.  
  297.                 ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Account created!",""COL_GREEN"You've changed your password successfuly. ","Ok","");
  298.             }
  299.         }
  300.  
  301.         case DIALOG_MAIL:
  302.         {
  303.             if(!response){
  304.              SCM(playerid,COLOR_RED,"You will be asked on your next login to set it..If you won't its your bad ... ");
  305.              new INI:File = INI_Open(UserPath(playerid));
  306.              INI_SetTag(File,"PlayerData");
  307.              PlayerInfo[playerid][pCMail] = 0;
  308.              return 1;
  309.          }
  310.             if(response)
  311.             {
  312.                 if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_MAIL, DIALOG_STYLE_INPUT, ""COL_WHITE"Setting up Mail","Type a Valid Email Address \n"COL_WHITE"Type your email ID for password recovery purposes \n You can't enter it later and if lost your password it \n can't be recovered ","Set","Abort");
  313.                 format(PlayerInfo[playerid][pMail], 300, inputtext);
  314.                 new INI:File = INI_Open(UserPath(playerid));
  315.                 INI_SetTag(File,"PlayerData");
  316.                 PlayerInfo[playerid][pCMail] = 1;
  317.  
  318.             }
  319.         }
  320.     }
  321.  
  322.     return 1;
  323. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement