Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. // Includes
  2. #include <a_samp>
  3. #include <YSI\y_ini>
  4.  
  5. #define DIALOG_REGISTER 1
  6. #define DIALOG_LOGIN 2
  7.  
  8. #define PATH "/Users/%s.ini"
  9.  
  10. enum pInfo
  11. {
  12. pPass,
  13. pCash,
  14. pAdmin
  15. }
  16. new PlayerInfo[MAX_PLAYERS][pInfo];
  17.  
  18. forward LoadUser_data(playerid,name[],value[]);
  19. public LoadUser_data(playerid,name[],value[])
  20. {
  21. INI_Int("Password",PlayerInfo[playerid][pPass]);
  22. INI_Int("Cash",PlayerInfo[playerid][pCash]);
  23. INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
  24. return 1;
  25. }
  26.  
  27. stock UserPath(playerid)
  28. {
  29. new string[128],playername[MAX_PLAYER_NAME];
  30. GetPlayerName(playerid,playername,sizeof(playername));
  31. format(string,sizeof(string),PATH,playername);
  32. return string;
  33. }
  34.  
  35. stock udb_hash(buf[])
  36. {
  37. new length=strlen(buf);
  38. new s1 = 1;
  39. new s2 = 0;
  40. new n;
  41. for (n=0; n<length; n++)
  42. {
  43. s1 = (s1 + buf[n]) % 65521;
  44. s2 = (s2 + s1) % 65521;
  45. }
  46. return (s2 << 16) + s1;
  47. }
  48.  
  49. main()
  50. {
  51. print("\n----------------------------------");
  52. print(" Blank Gamemode by your name here");
  53. print("----------------------------------\n");
  54. }
  55.  
  56. public OnPlayerConnect(playerid)
  57. {
  58. if(fexist(UserPath(playerid)))
  59. {
  60. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  61. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Type your password below to login.", "Login", "Quit");
  62. }
  63. else
  64. {
  65. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering", "Type your password below to register a new account.", "Register", "Quit");
  66. }
  67. return 1;
  68. }
  69.  
  70. public OnPlayerDisconnect(playerid, reason)
  71. {
  72. new INI:File = INI_Open(UserPath(playerid));
  73. INI_SetTag(File,"data");
  74. INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
  75. INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
  76. INI_Close(File);
  77. return 1;
  78. }
  79.  
  80. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  81. {
  82. switch( dialogid )
  83. {
  84. case DIALOG_REGISTER:
  85. {
  86. if (!response) return Kick(playerid);
  87. if(response)
  88. {
  89. if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering", "You have entered an invalid password.\nType your password below to register a new account.", "Register", "Quit");
  90. new INI:File = INI_Open(UserPath(playerid));
  91. INI_SetTag(File,"data");
  92. INI_WriteInt(File,"Password",udb_hash(inputtext));
  93. INI_WriteInt(File,"Cash",0);
  94. INI_WriteInt(File,"Admin",0);
  95. INI_Close(File);
  96. }
  97. }
  98. case DIALOG_LOGIN:
  99. {
  100. if ( !response ) return Kick ( playerid );
  101. if( response )
  102. {
  103. if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
  104. {
  105. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  106. GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  107. }
  108. else
  109. {
  110. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "You have entered an incorrect password.\nType your password below to login.", "Login", "Quit");
  111. }
  112. return 1;
  113. }
  114. }
  115. }
  116. return 1;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement