Advertisement
Guest User

Untitled

a guest
Mar 27th, 2021
27
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define DIALOG_REGISTER 1
  2. #define DIALOG_LOGIN 2
  3.  
  4. enum pInfo
  5. {
  6. pName[MAX_PLAYER_NAME],
  7. pPassword[64],
  8. pLevel,
  9. }
  10. new P_DATA[MAX_PLAYERS][pInfo];
  11.  
  12. public OnPlayerConnect(playerid)
  13. {
  14. new string[128];
  15. mysql_format(SQL, string, sizeof(string), "SELECT `Name` FROM `server_accounts` WHERE `Name` = '%e', getName(playerid));
  16. mysql_tquery(SQL, string, "CheckAccount", "i", playerid);
  17. return 1;
  18. }
  19.  
  20. forward CheckAccount(playerid);
  21. public CheckAccount(playerid)
  22. {
  23. if(cache_num_rows() > 0)
  24. {
  25. print("Contul a fost gasit cu succes!");
  26. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Introdu parola contului tau mai jos:", "Ok", "Close");
  27. }
  28. else ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Te rugam sa introduci parola pentru acest cont:", "Ok", "Close");
  29. }
  30.  
  31. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  32. {
  33. switch(dialogid)
  34. {
  35. case DIALOG_REGISTER:
  36. {
  37. CreateAccount(playerid, inputtext);
  38. }
  39. case DIALOG_LOGIN:
  40. {
  41. new string[128 + 64]; // 64 caractere de la parola + lungimea de 73 de la format + lungimea de la nume de maxim 24 caractere
  42. mysql_format(SQL, string, sizeof(string), "SELECT * FROM `server_accounts` WHERE `Name` = '%e' AND `Password` = '%e'", getName(playerid), inputtext);
  43. mysql_tquery(SQL, string, "LoadAccount", "i", playerid);
  44. }
  45. }
  46. }
  47.  
  48. forward CreateAccount(playerid, password[]);
  49. public CreateAccount(playerid, password[])
  50. {
  51. new string[128 + 64];
  52. mysql_format(SQL, string, sizeof(string), "INSERT INTO `server_accounts` (`Name`, `Password`) VALUES ('%e', '%e')", getName(playerid), password);
  53. mysql_tquery(SQL, string, "", "");
  54. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Introdu parola contului tau mai jos:", "Ok", "Close");
  55. return 1;
  56. }
  57.  
  58. forward LoadAccount(playerid);
  59. public LoadAccount(playerid)
  60. {
  61. if(cache_num_rows() > 0)
  62. {
  63. cache_get_field_content(0, "Name", P_DATA[playerid][pName], SQL, MAX_PLAYER_NAME);
  64. cache_get_field_content(0, "Password", P_DATA[playerid][pPassword], SQL, 64);
  65. cache_get_field_content_int(0, "Level", P_DATA[playerid][pLevel], SQL);
  66. }
  67. else
  68. {
  69. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Parola introdusa nu este corecta.\nTe rugam sa introduci parola acestui cont:", "Ok", "Close");
  70. }
  71. }
  72.  
  73. stock getName(playerid)
  74. {
  75. new name[MAX_PLAYER_NAME];
  76. if(!IsPlayerConnected(playerid)) name = "Unknown";
  77. else
  78. {
  79. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  80. format(name, sizeof(name), name);
  81. }
  82. return name;
  83. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement