Advertisement
Guest User

Register/login Script

a guest
Dec 8th, 2011
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.86 KB | None | 0 0
  1. /*                              Login And Register System
  2.                                 Created for Olabvii
  3.                                 Credit To Michael ***
  4.                                 Olabvii Has Full Registeration Of This Script.
  5.                                 Hope this is a helping hand.
  6.  
  7. */
  8.  
  9. #include <a_samp>
  10. #include <YSI/y_ini>
  11.  
  12. #define DIALOG_REGISTER 1
  13. #define DIALOG_LOGIN 2
  14. #define DIALOG_SUCCESS_1 3
  15. #define DIALOG_SUCCESS_2 4 // dialogs.
  16.  
  17. #define COL_WHITE "{FFFFFF}"
  18. #define COL_RED "{F81414}"
  19. #define COL_GREEN "{00FF22}"
  20. #define COL_LIGHTBLUE "{00CED1}" // You may or may not have seen this format before. break down below.
  21.  
  22. /* COLOR Breakdown:
  23.     COL_WHITE "{FFFFFF}" This cannot be used as a main color. But it is usefull to use on dialogs etc.
  24.     Example:
  25.         SendClientMessage(playerid,000000FF,"Hey, I cant use "COL_RED"Color"); this will print a message Hey, I cant use "Then in red" Color.
  26.         basically you have changed the color mid script.
  27.  
  28. */
  29. #define PATH "/Accounts/%s.ini" // Change the Users if you want it to save somewhere else explained below:
  30.  
  31. /*
  32.  
  33. PATH Breakdown:
  34.     PATH "/Users/%.ini" This will create a file in the script file directory, in the sub directory of Users
  35. Examples:
  36.     PATH "/Server/Users/%s.ini" This will create a file in scriptfile directory, sub directory of Server then Users
  37.     PATH "/%s.ini" This can also be used, this will just save to your scriptfiles, i would recommend having some kind or directory though.
  38. */
  39.  
  40. enum pInfo
  41. {
  42.     pPassword,
  43.     pScore,
  44.     pMoney,
  45.     pDeaths,
  46.     pKills,
  47.     pAdmin
  48. }
  49. new Logged[MAX_PLAYERS];
  50. new PlayerInfo[MAX_PLAYERS][pInfo]; // This users the set data above to create a varible
  51. /* Now we need to get some stock functions.*/
  52. /*Credits to Dracoblue*/
  53. stock udb_hash(buf[]) {
  54.     new length=strlen(buf);
  55.     new s1 = 1;
  56.     new s2 = 0;
  57.     new n;
  58.     for (n=0; n<length; n++)
  59.     {
  60.        s1 = (s1 + buf[n]) % 65521;
  61.        s2 = (s2 + s1)     % 65521;
  62.     }
  63.     return (s2 << 16) + s1;
  64. } // Hashing the password, all good servers have this. Its not easy to be removed.
  65.  
  66. stock UserPath(playerid)
  67. {
  68.     new string[128],playername[MAX_PLAYER_NAME];
  69.     GetPlayerName(playerid,playername,sizeof(playername));
  70.     format(string,sizeof(string),PATH,playername);
  71.     return string;
  72. }// This will be your path that will be saved notice PATH is on the format.
  73.  
  74. stock SavePlayer(playerid)
  75. {
  76.     new INI:File = INI_Open(UserPath(playerid));
  77.     INI_WriteInt(File,"Score",PlayerInfo[playerid][pScore]);
  78.     INI_WriteInt(File,"Money",PlayerInfo[playerid][pMoney]);
  79.     INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
  80.     INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
  81.     INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]); // Saving Data
  82. }
  83.  
  84. forward LoadUser_data(playerid,name[],value[]);
  85. public LoadUser_data(playerid,name[],value[])
  86. {
  87.     INI_Int("Password",PlayerInfo[playerid][pPassword]); // Basically this is loading and then creating the saving process the now assigns "PlayerInfo[playerid][pPassword]" to Password
  88.     INI_Int("Score",PlayerInfo[playerid][pScore]);
  89.     INI_Int("Money",PlayerInfo[playerid][pMoney]);
  90.     INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
  91.     INI_Int("Kills",PlayerInfo[playerid][pKills]);
  92.     INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
  93.     return 1;
  94. }
  95. public OnPlayerDeath(playerid,killerid,reason)
  96. {
  97.     SendDeathMessage(killerid,playerid,reason);
  98.     PlayerInfo[playerid][pScore] --;
  99.     PlayerInfo[playerid][pDeaths] ++;
  100.     PlayerInfo[killerid][pScore] ++;
  101.     PlayerInfo[killerid][pKills] ++;
  102.     return 1;
  103. }
  104. public OnPlayerDisconnect(playerid,reason)
  105. {
  106.     SavePlayer(playerid);
  107.     return 1;
  108. }
  109.  
  110. public OnPlayerConnect(playerid)
  111. {
  112.     if(fexist(UserPath(playerid))) // If the players path exists continue
  113.     {
  114.         INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  115.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
  116.     }
  117.     else // Register the player
  118.     {
  119.         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,""COL_WHITE"Register",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
  120.     }
  121.     return 1;
  122. }
  123.  
  124. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  125. {
  126.     switch(dialogid)
  127.     {
  128.         case DIALOG_REGISTER:
  129.         {
  130.             if(!response) return Kick(playerid); // This will kick the player if the hit "quit"
  131.             if(response)
  132.             {
  133.                 if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, ""COL_WHITE"Register",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
  134.                 new INI:File = INI_Open(UserPath(playerid));
  135.                 INI_SetTag(File,"Sexy Name");
  136.                 INI_WriteInt(File,"Password",udb_hash(inputtext));
  137.                 INI_WriteInt(File,"Score",0);
  138.                 INI_WriteInt(File,"Money",0);
  139.                 INI_WriteInt(File,"Deaths",0);
  140.                 INI_WriteInt(File,"Kills",0);
  141.                 INI_WriteInt(File,"Admin",0);
  142.  
  143.                 SendClientMessage(playerid,0xFFFFFF,"Thank You For Registering.");
  144.  
  145.                 Logged[playerid] = 1;
  146.             }
  147.         }
  148.         case DIALOG_LOGIN:
  149.         {
  150.             if(!response) return Kick(playerid);
  151.             if(response)
  152.             {
  153.                 if(udb_hash(inputtext) == PlayerInfo[playerid][pPassword])
  154.                 {
  155.                     INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  156.                     GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
  157.                     SetPlayerScore(playerid,PlayerInfo[playerid][pScore]); // Loading the score.
  158.                 }
  159.                 else
  160.                 {
  161.                     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","Quit");
  162.                 }
  163.                 return 1;
  164.             }
  165.         }
  166.     }
  167.     return 1;
  168. }
  169.  
  170.  
  171.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement