Advertisement
Guest User

Untitled

a guest
Mar 31st, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. forward @LoadUserData(playerid, name[], value[]);
  2.  
  3. public OnPlayerConnect(playerid)
  4. {
  5. new pName[MAX_PLAYER_NAME];
  6. GetPlayerName(playerid, pName, sizeof(pName));
  7. if(!fexist(UserPath(playerid)))
  8. {
  9. // registered
  10. ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Account", "Register account\n\nEnter a password", "Register", "Quit");
  11. }
  12. else
  13. {
  14. // login
  15. INI_ParseFile(UserPath(playerid), "LoadUserData_%s", .bExtra = true, .extra = playerid);
  16. ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Account", "Login to your account\n\nEnter your password", "Login", "Quit");
  17. }
  18. return 1;
  19. }
  20.  
  21.  
  22. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  23. {
  24. switch(dialogid)
  25. {
  26. case 1:
  27. {
  28. if(!response)
  29. {
  30. Kick(playerid);
  31. }
  32. else
  33. {
  34. new INI:File = INI_Open(UserPath(playerid)), buf[129];
  35. WP_Hash(buf, sizeof(buf), inputtext);
  36. INI_SetTag(File,"Data");
  37. INI_WriteString(File, "Password", buf);
  38. INI_WriteInt(File, "Kills", 0);
  39. INI_WriteInt(File, "Deaths", 0);
  40. INI_Close(File);
  41. SendClientMessage(playerid, Green, "Registered");
  42. }
  43. }
  44. case 2:
  45. {
  46. if(!response)
  47. {
  48. Kick(playerid);
  49. }
  50. else
  51. {
  52. new buf[129];
  53. WP_Hash(buf, sizeof (buf), inputtext);
  54. if(!strcmp(buf, PlayerInfo[playerid][pPassword]))
  55. {
  56. INI_ParseFile(UserPath(playerid), "LoadUserData_%s", .bExtra = true, .extra = playerid);
  57. SendClientMessage(playerid, Green, "Logged in");
  58. }
  59. else
  60. {
  61. SendClientMessage(playerid, Red, "Wrong password);
  62. }
  63. return 1;
  64. }
  65. }
  66. }
  67. return 1;
  68. }
  69.  
  70. @LoadUserData(playerid, name[], value[])
  71. {
  72. INI_String("Password", PlayerInfo[playerid][pPassword], 129);
  73. INI_Int("Kills", PlayerInfo[playerid][pKills]);
  74. INI_Int("Deaths", PlayerInfo[playerid][pDeaths]);
  75. return 1;
  76. }
  77.  
  78. stock UserPath(playerid)
  79. {
  80. new string[128], pName[MAX_PLAYER_NAME];
  81. GetPlayerName(playerid, pName, sizeof(pName));
  82. format(string, sizeof(string), USER_FILE_PATH, pName);
  83. return string;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement