Advertisement
Guest User

Untitled

a guest
Nov 30th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. #include <a_samp>
  2. #include <YSI\y_ini>
  3.  
  4. #define DIALOG_REGISTER 1
  5. #define DIALOG_LOGIN 2
  6.  
  7. forward LoadUser_data(playerid, name[], value[]);
  8.  
  9. enum pInfo
  10. {
  11. pPass[65],
  12. pSalt[11],
  13. pAdmin
  14. }
  15. new PlayerInfo[MAX_PLAYERS][pInfo];
  16.  
  17. #define PATH "/Server_Files/PlayerAccounts/%s.ini"
  18.  
  19. public OnPlayerConnect(playerid)
  20. {
  21. if(fexist(AccountPath(playerid)))
  22. {
  23. INI_ParseFile(AccountPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  24. ShowAccountLoginDialog(playerid);
  25. }
  26. else
  27. {
  28. ShowAccountRegisterDialog(playerid);
  29. }
  30. return 1;
  31. }
  32.  
  33. public OnPlayerDisconnect(playerid, reason)
  34. {
  35. new INI:File = INI_Open(AccountPath(playerid)), plr_IP[16];
  36. INI_SetTag(File, "---Player_Data---");
  37. INI_WriteInt(File, "Admin_Level:", PlayerInfo[playerid][pAdmin]);
  38. INI_Close(File);
  39. return 1;
  40. }
  41.  
  42. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  43. {
  44. switch(dialogid)
  45. {
  46. case DIALOG_REGISTER:
  47. {
  48. new string[128], salt[11];
  49. if(!response) return KickEx(playerid);
  50. if(response)
  51. {
  52. if(!strlen(inputtext)) return ShowRegisterFailureDialog(playerid);
  53. new INI:File = INI_Open(AccountPath(playerid));
  54. for(new i; i < 10; i++)
  55. {
  56. salt[i] = random(79) + 47;
  57. }
  58. INI_SetTag(File, "---Player_Data---");
  59. INI_WriteInt(File, "Password:", SHA256_PassHash(inputtext, salt, PlayerInfo[playerid][pPass], 65));
  60. INI_WriteString(File, "Pass_Salt:", salt);
  61. INI_WriteInt(File, "Admin_Level:", 0);
  62. INI_Close(File);
  63. format(string, sizeof(string), "You have successfully registered your account. You have been automatically logged in!");
  64. SendMessage(playerid, COLOR_ADMIN, string);
  65. salt[10] = 0;
  66. }
  67. }
  68. case DIALOG_LOGIN:
  69. {
  70. if(!response) return KickEx(playerid);
  71. if(response)
  72. {
  73. new hash[65];
  74. SHA256_PassHash(inputtext, PlayerInfo[playerid][pSalt], hash, 64);
  75. if(!strcmp(hash, PlayerInfo[playerid][pPass]))
  76. {
  77. INI_ParseFile(AccountPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  78. }
  79. else
  80. {
  81. ShowLoginFailureDialog(playerid);
  82. }
  83. return 1;
  84. }
  85. }
  86. }
  87. return 1;
  88. }
  89.  
  90. public KickEx_Func(playerid)
  91. {
  92. Kick(playerid);
  93. return 1;
  94. }
  95.  
  96. public LoadUser_data(playerid, name[], value[])
  97. {
  98. INI_Int("Password:", PlayerInfo[playerid][pPass]);
  99. INI_Int("Pass_Salt", PlayerInfo[playerid][pSalt]);
  100. INI_Int("Admin_Level:", PlayerInfo[playerid][pAdmin]);
  101. return 1;
  102. }
  103.  
  104. stock ShowAccountLoginDialog(playerid)
  105. {
  106. new string[200], plr_name[128];
  107. format(plr_name, sizeof(plr_name), "Welcome back, %s. We missed you!\n\n", PlayerName(playerid));
  108. strcat(string, plr_name);
  109. strcat(string, "Please type your password in the box below to login.\n");
  110. strcat(string, "Note: Passwords are case sensitive.");
  111. return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Account Login", string, "Login", "Quit");
  112. }
  113.  
  114. stock ShowAccountRegisterDialog(playerid)
  115. {
  116. new string[200], plr_name[128];
  117. format(plr_name, sizeof(plr_name), "Welcome to the server, %s!\n\n", PlayerName(playerid));
  118. strcat(string, plr_name);
  119. strcat(string, "Please type in your desired password into the box below to register your account.\n");
  120. strcat(string, "Note: Passwords are case sensitive.");
  121. return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Account Registration", string, "Register", "Quit");
  122. }
  123.  
  124. stock ShowLoginFailureDialog(playerid)
  125. {
  126. new string[200], plr_name[128];
  127. format(plr_name, sizeof(plr_name), "Welcome back, %s.\n\n", PlayerName(playerid));
  128. strcat(string, plr_name);
  129. strcat(string, "It appears you got your password wrong. Please try again.\n");
  130. strcat(string, "Note: Passwords are case sensitive.");
  131. return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Account Login", string, "Login", "Quit");
  132. }
  133.  
  134. stock ShowRegisterFailureDialog(playerid)
  135. {
  136. new string[200], plr_name[128];
  137. format(plr_name, sizeof(plr_name), "Welcome to the server, %s!\n\n", PlayerName(playerid));
  138. strcat(string, plr_name);
  139. strcat(string, "You failed to type in an appropriate password. Please try again.\n");
  140. strcat(string, "Note: Passwords are case sensitive.");
  141. return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Account Registration", string, "Register", "Quit");
  142. }
  143.  
  144. stock KickEx(playerid)
  145. {
  146. new string[128];
  147. format(string, sizeof(string), "%s(%d) has been kicked from the server. (Reason: Refused to register their account)", PlayerName(playerid), playerid);
  148. SendMessageToAll(COLOR_ADMIN, string);
  149. SetTimerEx("KickEx_Func", 600, false, "i", playerid);
  150. return 1;
  151. }
  152.  
  153. stock AccountPath(playerid)
  154. {
  155. new string[128];
  156. format(string, sizeof(string), PATH, PlayerName(playerid));
  157. return string;
  158. }
  159.  
  160. stock PlayerName(playerid)
  161. {
  162. new name[MAX_PLAYER_NAME];
  163. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  164. return name;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement