[MSQL]How could i check if player is registered? -
Type-R - 05.06.2011
Hello, i am kind of trying to do a register, login system on mys server, and i have a problem, because when it checks the player, it doesn't change SaskYra = 0 it changes it to 1, but i am not registered, and then it shows me the login dialog. Here's the script:
onplayerconnect
Код:
GetPlayerName(playerid, ZStats[playerid][Vardas], MAX_PLAYER_NAME);
if(CheckAccountExists(ZStats[playerid][Vardas])) SaskYra[playerid] = 1;
else SaskYra[playerid] = 0;
bottom of script
Код:
CheckAccountExists(account[])
{
new string[128];
format(string, sizeof(string), "SELECT * FROM Saskaitos WHERE Vardas = '%s'", account);
mysql_query(string);
mysql_store_result();
new value;
value = mysql_num_rows();
mysql_free_result();
return value;
}
Dialog response, its after agreeing to server rules.
Код:
if(dialogid == 0) //Jei dialogid bus lygus 0
{
new vardas[MAX_PLAYER_NAME], string[180];
GetPlayerName(playerid, vardas, sizeof(vardas));
if(response)
{
if(SaskYra[playerid] == 1)
{
format(string, sizeof(string), "{FFFFFF}Zaidejas {FFAF00}%s {FFFFFF}yra registruotas.\n{FFFFFF}Iveskite slaptazodi noredami prisijungti:",vardas);
ShowPlayerDialog(playerid,200,DIALOG_STYLE_INPUT,"{A3E4FF}Prisijungimas",string,"Prisijungti","Atsaukti");
}
else if(SaskYra[playerid] == 0)
{
format(string, sizeof(string), "{FFFFFF}Zaidejo {FFAF00}%s {FFFFFF}registracija.\n{FFFFFF}Iveskite norima slaptazodi:",vardas);
ShowPlayerDialog(playerid,201,DIALOG_STYLE_INPUT,"{A3E4FF}Registracija",string,"Registruotis","Atsaukti");
}
}
else
{
SendClientMessage(playerid, raudona, "[FunZoneLT]>> Jus turite sutikti su taisyklemis, pries zaidziant!");
Kick(playerid);
}
}
The server somehow sets SaskYra to 1, but i am not registered... Could you help me fix this, or make another way? :/
Re: [MSQL]How could i check if player is registered? -
Burridge - 05.06.2011
As far as I can see you're not actually checking if the account is in the database. Below is some code I have quickly typed up, hopefully it helps you, and hopefully you'll be able to work out the rest. If it isn't what you wanted, then sorry. I'm using
BlueG's plugin for this code by the way.
pawn Код:
CheckAccountExists(playerid){
new Query[128], Result[128], Name[24], EscName[24]; //the result variable size may have to change, depending on how many stats you load, and how big they are
GetPlayerName(playerid, Name, 24); //get the player's name
mysql_real_escape_string(Name, EscName); //you'll need to escape the string for the name to stop MySQL injection attacks
format(Query, sizeof(Query), "SELECT * FROM Saskaitos WHERE Vardas = '%s'", EscName);
mysql_query(Query); mysql_store_result();
if(mysql_fetch_row_format(Result)){
//load stats here
}
else {
//account doesn't exist, so maybe load up the register dialog with a message telling them to register
}
mysql_free_result(); //free the result you stored in the Query
}
I've done it by playerid, and then detecting their name in the actual function.
Re: [MSQL]How could i check if player is registered? -
PrawkC - 05.06.2011
Код:
ExistingAccount(playerid) //Check to see if the account is already registered.
{
new query[124];
format(query, sizeof(query), "SELECT * FROM accts WHERE username = '%s'", getName(playerid));
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() > 0)
{
mysql_free_result();
return 1;
}
mysql_free_result();
return 0;
}
You're going to have to set query to yours, and also I didn't do any string escaping, as this is from an old script but see above how to do so
Re: [MSQL]How could i check if player is registered? -
Calgon - 05.06.2011
You don't need to select *, select "NULL"
Re: [MSQL]How could i check if player is registered? -
Type-R - 05.06.2011
Thank you guys for helping.