Guest User

I Registration System

a guest
Dec 28th, 2012
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.63 KB | None | 0 0
  1. /*******************************************************************************
  2. *                SCRIPT NAME: I-Registration System
  3. *                SCRIPT VERSION: v1.0
  4. *                SCRIPT DEVELOPER: irfu aka playboy
  5. *
  6. *******************************************************************************/
  7. #define FILTERSCRIPT
  8.  
  9. //includes
  10. #include <a_samp>
  11. #include <YSI\y_ini>
  12.  
  13. #if defined FILTERSCRIPT
  14.  
  15. //defines
  16. #define DIALOG_REGISTER 1
  17. #define DIALOG_LOGIN 2
  18. #define DIALOG_SUCCESS_1 3
  19. #define DIALOG_SUCCESS_2 4
  20. #define PATH "/Accounts/%s.ini"
  21.  
  22. //color defines
  23. #define WHITE "{FFFFFF}"
  24. #define RED "{F81414}"
  25. #define GREEN "{00FF22}"
  26.  
  27. enum pInfo
  28. {
  29.     pPass,
  30.     pCash,
  31.     pKills,
  32.     pDeaths
  33. }
  34. new PlayerInfo[MAX_PLAYERS][pInfo];
  35.  
  36. //forwards
  37. forward LoadUser_data(playerid,name[],value[]);
  38.  
  39.  
  40. public OnFilterScriptInit()
  41. {
  42.     print("\n--------------------------------------");
  43.     print(" I-registration system v1.0 Loaded... ");
  44.     print("               By irfu aka playboy ");
  45.     print("--------------------------------------\n");
  46.     return 1;
  47. }
  48.  
  49. public OnFilterScriptExit()
  50. {
  51.     print("\n--------------------------------------");
  52.     print(" I-registration system v1.0 Unloaded... ");
  53.     print("                 By irfu aka playboy ");
  54.     print("--------------------------------------\n");
  55.     return 1;
  56. }
  57.  
  58. #else
  59.  
  60. main()
  61. {
  62.     print("\n--------------------------------------");
  63.     print("       I-registration system v1.0 ");
  64.     print("              By irfu aka playboy ");
  65.     print("--------------------------------------\n");
  66. }
  67.  
  68. #endif
  69.  
  70. public OnPlayerRequestClass(playerid, classid)
  71. {
  72.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  73.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  74.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  75.     return 1;
  76. }
  77.  
  78. public OnPlayerConnect(playerid)
  79. {
  80.     if(fexist(UserPath(playerid)))
  81.     {
  82.         INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  83.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""WHITE"Login",""WHITE"Type your password below to login.","Login","Quit");
  84.     }
  85.     else
  86.     {
  87.         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""WHITE"Register an Account",""WHITE"Type your password below to register a new account.","Register","Quit");
  88.     }
  89.     return 1;
  90. }
  91.  
  92. public OnPlayerDisconnect(playerid, reason)
  93. {
  94.     new INI:File = INI_Open(UserPath(playerid));
  95.     INI_SetTag(File,"data");
  96.     INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
  97.     INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
  98.     INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
  99.     INI_Close(File);
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerDeath(playerid, killerid, reason)
  104. {
  105.     PlayerInfo[killerid][pKills]++;
  106.     PlayerInfo[playerid][pDeaths]++;
  107.     return 1;
  108. }
  109.  
  110. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  111. {
  112.     switch( dialogid )
  113.     {
  114.         case DIALOG_REGISTER:
  115.         {
  116.             if (!response) return Kick(playerid);
  117.             if(response)
  118.             {
  119.                 if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""WHITE"Registering...",""RED"You have entered an invalid password.\n"WHITE"Type your password below to register a new account.","Register","Quit");
  120.                 new INI:File = INI_Open(UserPath(playerid));
  121.                 INI_SetTag(File,"data");
  122.                 INI_WriteInt(File,"Password",udb_hash(inputtext));
  123.                 INI_WriteInt(File,"Cash",0);
  124.                 INI_WriteInt(File,"Kills",0);
  125.                 INI_WriteInt(File,"Deaths",0);
  126.                 INI_Close(File);
  127.  
  128.                 SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  129.                 SpawnPlayer(playerid);
  130.                 ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""WHITE"Success!",""GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
  131.             }
  132.         }
  133.  
  134.         case DIALOG_LOGIN:
  135.         {
  136.             if ( !response ) return Kick ( playerid );
  137.             if( response )
  138.             {
  139.                 if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
  140.                 {
  141.                     INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  142.                     GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  143.                     ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""WHITE"Success!",""GREEN"You have successfully logged in!","Ok","");
  144.                 }
  145.                 else
  146.                 {
  147.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""WHITE"Login",""RED"You have entered an incorrect password.\n"WHITE"Type your password below to login.","Login","Quit");
  148.                 }
  149.                 return 1;
  150.             }
  151.         }
  152.     }
  153.     return 1;
  154. }
  155.  
  156. public LoadUser_data(playerid,name[],value[])
  157. {
  158.     INI_Int("Password",PlayerInfo[playerid][pPass]);
  159.     INI_Int("Cash",PlayerInfo[playerid][pCash]);
  160.     INI_Int("Kills",PlayerInfo[playerid][pKills]);
  161.     INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
  162.     return 1;
  163. }
  164. stock UserPath(playerid)
  165. {
  166.     new string[128],playername[MAX_PLAYER_NAME];
  167.     GetPlayerName(playerid,playername,sizeof(playername));
  168.     format(string,sizeof(string),PATH,playername);
  169.     return string;
  170. }
  171. stock udb_hash(buf[]) {
  172.     new length=strlen(buf);
  173.     new s1 = 1;
  174.     new s2 = 0;
  175.     new n;
  176.     for (n=0; n<length; n++)
  177.     {
  178.        s1 = (s1 + buf[n]) % 65521;
  179.        s2 = (s2 + s1)     % 65521;
  180.     }
  181.     return (s2 << 16) + s1;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment