26.01.2015, 18:55
Quote:
The above code doesn't have any problems, show your register dialog.
|
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_LOGIN: //login dialog
{
if(!response) Kick(playerid); //if they clicked Quit, we will kick them
new hpass[129]; //for password hashing
new query[1024]; // for formatting our query.
WP_Hash(hpass, 129, inputtext); //hashing inputtext
if(!strcmp(hpass, pInfo[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 `accounts` WHERE `Name` = '%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, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "In order to play, you need to login\nWrong password!", "Login", "Quit");
}
}
case DIALOG_REGISTER: //register dialog
{
if(!response) return Kick(playerid); //if they clicked Quit, we will kick them
if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "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[1024];
WP_Hash(pInfo[playerid][Password], 129, inputtext); //hashing inputtext
mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `PosX`, `PosY`, `PosZ`, `FacingAngel`) VALUES ('%e', '%s', 701.8041,-519.4351,16.3318,261.1537)", Name[playerid], pInfo[playerid][Password]);
//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
}
}
return 1;
}