new Query[80],pName[24],tstring[164];
GetPlayerName(playerid,pName,24);
format(Query,sizeof(Query),"SELECT `Username` FROM `Users` WHERE `Username` = '%s' LIMIT 1;",pName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
format(tstring,sizeof(tstring),"Hey, %s! \nYour account is registered. \nPlease enter your password to login!",pName);
ShowPlayerDialog(playerid,Logindialog,DIALOG_STYLE_INPUT,"Re gister",tstring,"Register","");
}
else
{
format(tstring,sizeof(tstring),"Hey, %s! \nYour account is NOT registered.\nPlease type a password to register!",pName);
ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,"Lo g in",tstring,"Login","");
}
mysql_free_result();
if(dialogid == Regdialog)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
}
else
{
new escpass[100];
mysql_real_escape_string(inputtext, escpass);
RegisterPlayer(playerid, escpass);
}
}
if(dialogid == Logindialog)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,Logindialog,DIALOG_STYLE_INPUT,"Login","Please enter your passsword to continue!","Login","");
}
else
{
LoginPlayer(playerid,inputtext);
}
}
stock RegisterPlayer(playerid, passwordstring[])
{
new query[235], buf[129];
WP_Hash(buf,129,passwordstring);
format(query, sizeof(query), "INSERT INTO `users` (`UserName`,`Password`,`Score`,`Money`,`WantedLevel`,`AdminLevel`,`VipLevel`,`ArmyRights`,`SwatRights`,`SGRights`,`MedicLevel`,`RapistLevel`,`MechanicLevel`,`RobSkill`) VALUES('%s','%s',0,100,0,0,0,0,0,0,0,0,0,0)", GetName(playerid), buf);
mysql_query(query);
SendClientMessage(playerid, -1,"You have been succesfuly registered on this server!");
printf("Hashed pass: %s",buf);
return 1;
}
stock LoginPlayer(playerid,const password[])
{
new EscapedText[60];
new EscapedPass[129];
new Query[140];
new buf[129];
mysql_real_escape_string(password, EscapedText);
WP_Hash(buf,129,EscapedText);
mysql_real_escape_string(buf, EscapedPass);
format(Query,sizeof(Query),"SELECT * FROM `users` WHERE `Username` = '%s' AND `Password` = '%s'",GetName(playerid), EscapedPass);
mysql_query(Query);
new rows = mysql_store_result();
if(rows == 1)
{
SendClientMessage(playerid,-1,"You have been logged in!");
LoadStats(playerid);
}
if(!rows)
{
new tstring[164];
SendClientMessage(playerid,-1,"Wrong password!");
MaxLoginAttempts[playerid]++;
format(tstring,sizeof(tstring),"Hey, %s! \nYour account is registered. \nPlease enter your password to login!",GetName(playerid));
ShowPlayerDialog(playerid,Logindialog,DIALOG_STYLE_INPUT,"Re gister",tstring,"Register","");
if(MaxLoginAttempts[playerid] == 3)
{
Kick(playerid);
}
}
mysql_free_result();
return 1;
}
Recomiendo mejor la R7 desde que BlueG dejу el proyecto de MySQL ese plugin pasу a ser medio 'garcha'
|
new cad1[200] = "INSERT INTO users (name, pass) VALUES ";
new cad2[100];
format(cad2, 100, "('%s', '%s')", %s, %s);
/* ^ ^
name pass
*/
strcat(cad1, cad2, sizeof(cad1));
/* Mandar query con los datos de cad1 */