Guest User

Untitled

a guest
Nov 9th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. public OnPlayerRegister(playerid, password[])
  2. {
  3. mysql_store_result(mCon);
  4. if(!mysql_num_rows(mCon))
  5. {
  6. mysql_real_escape_string(password, password);
  7.  
  8. new pass[129];
  9. WP_Hash(pass, 129, password);
  10.  
  11. new query[128 * 5];
  12. format(query, sizeof(query), "INSERT INTO `users` (Name, Password, AdminLevel,) VALUES ('%s', '%s', '0')",PlayerInfo[playerid][pName], pass);
  13. mysql_function_query(mCon, query, false, "OnPlayerQuery", "");
  14. ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");
  15. printf("[SERVER]: Player: %s has just created an account.",PlayerInfo[playerid][pName]);
  16. }
  17. else
  18. {
  19. ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");
  20. }
  21. mysql_free_result(mCon);
  22. return 1;
  23. }
  24.  
  25. public OnPlayerLogin(playerid, type, password[])
  26. {
  27. mysql_store_result(mCon);
  28. if(!type)
  29. {
  30. if(!mysql_num_rows(mCon))
  31. {
  32. SendClientMessage(playerid,COLOR_ERROR,"Error, (/register) first."), mysql_free_result(mCon);
  33. ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Please register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
  34. return 1;
  35. }
  36. mysql_real_escape_string(password, password);
  37. new pass[129];
  38. WP_Hash(pass, 129, password);
  39.  
  40. new query[128+129];
  41. format(query, sizeof(query), "SELECT * FROM `users` WHERE `Name` = '%s' AND `Password` = '%s' LIMIT 1",PlayerInfo[playerid][pName], pass);
  42. mysql_function_query(mCon, query, false, "OnPlayerLogin", "dd", playerid, 1);
  43. }
  44. if(type)
  45. {
  46. if(!mysql_num_rows(mCon))
  47. {
  48. SendClientMessage(playerid,COLOR_ERROR,"Error, incorrect password");
  49. ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
  50. return 1;
  51. }
  52. new result[256];
  53. mysql_fetch_row(result);
  54. sscanf(result, "p<|>{s[25]s[130]}i",PlayerInfo[playerid][pAdminLevel]);
  55. PlayerInfo[playerid][pLogged] = 1;
  56.  
  57. // printf("[SERVER]: Player: %s has just logged into their account",PlayerInfo[playerid][pName]);
  58. }
  59. mysql_free_result(mCon);
  60. return 1;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment