Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public OnPlayerConnect(playerid)
- {
- new query[128]; //We use this variable to format our query
- GetPlayerName(playerid, Name[playerid], 24); //Getting player's name
- GetPlayerIp(playerid, IP[playerid], 16); //Getting layer's IP
- mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
- mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case dlogin: //login dialog
- {
- if(!response) {Kick(playerid);} //if they clicked Quit, we will kick them
- new hpass[129]; //for password hashing
- new query[100]; // for formatting our query.
- WP_Hash(hpass, 129, inputtext); //hashing inputtext
- 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
- { //if the hashed password matches with the loaded password from database
- mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
- //let's format our query
- //We select all rows in the table that has your name and limit the result to 1
- mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
- //lets execute the formatted query and when the execution is done, a callback OnAccountLoad will be called
- //You can name the callback however you like
- }
- else //if the hashed password didn't match with the loaded password(pInfo[playerid][Password])
- {
- //we tell them that they have inserted a wrong password
- ShowPlayerDialog(playerid, dlogin, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login\nWrong password!", "Login", "Quit");
- }
- }
- case dregister: //register dialog
- {
- if(!response) {Kick(playerid);} //if they clicked Quit, we will kick them
- 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");
- //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!
- new query[300];
- WP_Hash(PlayerInfo[playerid][Password], 129, inputtext); //hashing inputtext
- 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]);
- //Now let's create a new row and insert player's information in it
- mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
- //let's execute the query
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment