Guest User

Untitled

a guest
Aug 12th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #define DIALOG_REGISTER 1
  2. #define DIALOG_LOGIN 2
  3. #define RAUDONA 0xFF0000FF
  4. #define MELYNA 0x0087FFFF
  5. #define LIME 0x19FF00FF
  6. new manomysql;
  7.  
  8. forward OnUserCheck(playerid);
  9.  
  10. public OnGameModeInit()
  11. {
  12. manomysql = mysql_connect(db_host, db_user, db_db, db_pass);
  13. return 1;
  14. }
  15. public OnGameModeExit()
  16. {
  17. mysql_close(manomysql);
  18. return 1;
  19. }
  20. public OnUserCheck(playerid)
  21. {
  22. new num_rows, num_fields;
  23. cache_get_data(num_rows, num_fields, manomysql);
  24. if(num_rows == 0)
  25. {
  26. //Register
  27. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registracija", "Prašome įvesti sugalvotą slaptažodį!", "Registruotis", "Išeiti");
  28. }
  29. else
  30. {
  31. //Login
  32. }
  33. return 1;
  34. }
  35. public OnPlayerConnect(playerid)
  36. {
  37. new vardas [MAX_PLAYER_NAME], query[64];
  38. GetPlayerName(playerid, vardas, sizeof(vardas));
  39. format(query, sizeof(query), "SELECT `id` FROM `user` WHERE `vardas` = '%s'", vardas);
  40. mysql_function_query(manomysql, query, true, "OnUserCheck", "i", playerid);
  41. return 1;
  42. }
  43. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  44. {
  45. if(dialogid == DIALOG_REGISTER)
  46. {
  47. if(response)
  48. {
  49. //Slaptažodžio ilgis
  50. new vardas[MAX_PLAYER_NAME], query[64], slaptazodis[32];
  51. GetPlayerName(playerid, vardas, sizeof(vardas));
  52. if(strlen(inputtext) >= 6)
  53. {
  54. mysql_escape_string(inputtext, slaptazodis, manomysql);
  55. format(query, sizeof(query), "INSERT INTO `user` (`vardas`, `slaptazodis`) VALUES ('%s', '%s')", vardas, inputtext);
  56. mysql_function_query(manomysql, query, false, "", "");
  57. SendClientMessage(playerid, LIME, "Sėkmingai užsiregistravote serveryje! Gero žaidimo");
  58. }
  59. else
  60. {
  61. SendClientMessage(playerid, MELYNA, "Slaptažodis turi būti bent 6 simbolių ilgio!");
  62. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registracija", "Prašome įvesti sugalvotą slaptažodį!", "Registruotis", "Išeiti");
  63. }
  64. }
  65. else
  66. {
  67. Kick(playerid);
  68. SendClientMessage(playerid, RAUDONA, "Atšaukėte registraciją!");
  69. }
  70. }
  71. return 1;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment