20.12.2014, 13:50
I am creating an account system using MySQL. I don't know what's wrong here, as the dialog to either to register/login won't show. Here's the code.
And yes, DIALOG_LOG and DIALOG_REG are already defined.
pawn Код:
public OnPlayerConnect(playerid)
{
//RESERTTING VARIABLES:
IsNewHere[playerid] = false;
MaxLoginAmount[playerid] = 0;
for(new playerdata:e; e < playerdata; ++e)
pData[playerid][e] = 0;
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]);
// - We use mysql_format instead of format because we can use an %e specifier. %e specifier escapes a string so we can avoid sql injection which means we don't have to use mysql_real_escape_string
// - Formatting our query; SELECT `Password`, `ID` FROM `players` WHERE `Username`='%e' means we are selecting a Password and ID's column in the table that has player's name in Username column.
// - LIMIT 1; we only need 1 result to be shown
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
//lets execute the formatted query and when the execution is done, a callback OnAccountCheck will be called
//You can name the callback however you like
return 1;
}
public OnAccountCheck(playerid)
{
new str[200];
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows)
{
cache_get_field_content(0, "PASS", pData[playerid][Password], mysql, 129);
pData[playerid][ID] = cache_get_field_content_int(0, "ID");
printf("%s", pData[playerid][Password]); //Debug
format(str, sizeof(str), "Welcome back to Reindience Roleplay, %s! \nLooks like your account is registered, please enter your password below:", GPName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOG, DIALOG_STYLE_PASSWORD, "Welcome back to Reindience Roleplay!", str, "Login", "Quit");
}
else
{
format(str, sizeof(str), "Welcome to Reindience Roleplay, %s! \nLooks like your account is not registered, please enter a password below:", GPName(playerid));
ShowPlayerDialog(playerid, DIALOG_REG, DIALOG_STYLE_PASSWORD, "Welcome to Reindience Roleplay!", str, "Register", "Quit");
}
return 1;
}