Guest User

Untitled

a guest
Apr 2nd, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. public OnPlayerConnect(playerid)
  2. {
  3. new query[128]; //We use this variable to format our query
  4. GetPlayerName(playerid, Name[playerid], 24); //Getting player's name
  5. GetPlayerIp(playerid, IP[playerid], 16); //Getting layer's IP
  6. mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
  7. mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
  8. return 1;
  9. }
  10.  
  11. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  12. {
  13. switch(dialogid)
  14. {
  15. case dlogin: //login dialog
  16. {
  17. if(!response) {Kick(playerid);} //if they clicked Quit, we will kick them
  18. new hpass[129]; //for password hashing
  19. new query[100]; // for formatting our query.
  20. WP_Hash(hpass, 129, inputtext); //hashing inputtext
  21. if(!strcmp(hpass, PlayerInfo[playerid][Password])) //remember we have loaded player's password into this variable, pInfo[playerid][Password] earlier. Now let's use it to compare the hashed password with password that we load
  22. { //if the hashed password matches with the loaded password from database
  23. mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
  24. //let's format our query
  25. //We select all rows in the table that has your name and limit the result to 1
  26. mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
  27. //lets execute the formatted query and when the execution is done, a callback OnAccountLoad will be called
  28. //You can name the callback however you like
  29. }
  30. else //if the hashed password didn't match with the loaded password(pInfo[playerid][Password])
  31. {
  32. //we tell them that they have inserted a wrong password
  33. ShowPlayerDialog(playerid, dlogin, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login\nWrong password!", "Login", "Quit");
  34. }
  35. }
  36. case dregister: //register dialog
  37. {
  38. if(!response) {Kick(playerid);} //if they clicked Quit, we will kick them
  39. if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, dregister, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.\nYour password must be at least 6 characters long!", "Register", "Quit");
  40. //strlen checks a lenght of a string. so if player types their password that is lower than 6, we tell them; Your password must be at least 6 characters long!
  41. new query[300];
  42. WP_Hash(PlayerInfo[playerid][Password], 129, inputtext); //hashing inputtext
  43. mysql_format(mysql, query, sizeof(query), "INSERT INTO `players`(`Username`,`Password`,`IP`,`pAdmin`,`pDonateRank`,`pCash`,`pPos_x`,`pPos_y`,`pPos_z`) VALUES ('%e', '%s', '%s', 0, 0, 0, 0.0, 0.0, 0.0)", Name[playerid], PlayerInfo[playerid][Password], IP[playerid], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z]);
  44. //Now let's create a new row and insert player's information in it
  45. mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
  46. //let's execute the query
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment