[MySql] Players boot data -
[LTU]mindux9[TCS] - 05.01.2012
Is this code neat? Or for errors, if any, that you can submit revised code
Код:
stock LoginPlayer( playerid, password[ ] )
{
// Funckija LoginPlayer( playerid, password[ ] )
// Priskiriame zaidejui kintamuosius is duomenu bazes, jei irasytas
// slaptazodis yra teisingas, jei ne, isspiriame ji is zaidimo.
new
string [ 1000 ],
pKey [ 128 ],
trash [ 30 ],
money,
score,
SQLID = MySQLNameCheck( PlayerName2( playerid ) );
format( string, 2024, "SELECT * FROM `players` WHERE `id`=%d LIMIT 1", SQLID );
mysql_query ( string );
mysql_store_result( );
if ( !mysql_fetch_row( string ) )
{
SendClientMessage( playerid, red, "Prisijungimo klaida #001" );
SendClientMessage( playerid, red, "Nerasti MySQL duomenys." );
Kick( playerid );
}
sscanf( string, "p<|>{ds[24]}s[129]s[1000]", pKey,
string );
if ( !strcmp( pKey, password, true ) )
{
if ( sscanf( string, "p<|>s[20]ddddddddddddfffdd",
trash,
PlayerInfo[playerid][banned],
PlayerInfo[playerid][Level],
PlayerInfo[playerid][SEELevel],
money,
score,
PlayerInfo[playerid][Kills],
PlayerInfo[playerid][Deaths],
PlayerInfo[playerid][GTLLevel],
PlayerInfo[playerid][SMPLevel],
PlayerInfo[playerid][LSTLevel],
PlayerInfo[playerid][TSGLevel],
PlayerInfo[playerid][eLevel],
PlayerInfo[playerid][Exp],
PlayerInfo[playerid][pos_x],
PlayerInfo[playerid][pos_y],
PlayerInfo[playerid][pos_z],
PlayerInfo[playerid][FavSkin],
PlayerInfo[playerid][rBan]
) ) print ( "SSCANF FAIL" );
ResetPlayerMoney( playerid );
GivePlayerMoney ( playerid, money );
SetPlayerScore ( playerid, score );
PlayerInfo[playerid][LoggedIn] = 1;
PlayerInfo[playerid][Registered] = 1;
return true;
}
else
{
return false;
}
}
Re: [MySql] Players boot data -
[LTU]mindux9[TCS] - 06.01.2012
Help.
Re: [MySql] Players boot data -
Joe_ - 06.01.2012
What do you mean by neat? I think that's personal because every scripter has a different style.
A couple of things that might help you though.
Код:
SELECT * FROM `players` WHERE `id`=%d LIMIT 1
What is the use of the id field? if it's for finding the players record, you can use your name field.
For example:
Код:
SELECT * FROM `players` WHERE `username` = '%s'
And remember to escape the string to stop injections.
Another thing that might be usefull to know, but not necessary is a specifier for SSCANF, you can use the enum specifier to enumerate the data you retrieve using sscanf, for example in your code:
Код:
if ( sscanf( string, "p<|>s[20]ddddddddddddfffdd",
trash,
PlayerInfo[playerid][banned],
PlayerInfo[playerid][Level],
PlayerInfo[playerid][SEELevel],
money,
score,
PlayerInfo[playerid][Kills],
PlayerInfo[playerid][Deaths],
PlayerInfo[playerid][GTLLevel],
PlayerInfo[playerid][SMPLevel],
PlayerInfo[playerid][LSTLevel],
PlayerInfo[playerid][TSGLevel],
PlayerInfo[playerid][eLevel],
PlayerInfo[playerid][Exp],
PlayerInfo[playerid][pos_x],
PlayerInfo[playerid][pos_y],
PlayerInfo[playerid][pos_z],
PlayerInfo[playerid][FavSkin],
PlayerInfo[playerid][rBan]
) )
Can become:
Код:
if ( sscanf( string, "e<p<|>s[20]ddddddddddddfffdd>",
PlayerInfo[playerid]
) )
However, your enumerator (the one used for PlayerInfo) will have to be in the SAME order as the mysql table for players.
Re: [MySql] Players boot data -
[LTU]mindux9[TCS] - 06.01.2012
- sscanf( string, "p<|>{ds[24]}s[129]s[1000]", pKey,
string );
what does it do?
pKey, who this??
- if ( sscanf( string, "p<|>s[20]ddddddddddddfffdd",
p<|>s[20]
who this??
- trash
Why do need it?
Re: [MySql] Players boot data -
Joe_ - 06.01.2012
You should read the sscanf thread, it tells you what each specifier does...
p is to specify a deliminator, when it finds that character you specified, it will move onto the next parameter.
I'm not too good at explaining things, but I will try.
Код:
// Example
// string is formatted as followed: "13|92.0|hello"
// sscanf will split the string into the parameters, using the deliminator '|'.
// pinteger = 13, pfloat = 92.0, pstr = "hello".
sscanf(string, "p<|>dfs[128]", pinteger, pfloat, pstr);
Re: [MySql] Players boot data -
[LTU]mindux9[TCS] - 06.01.2012
<|>
who this?
Re: [MySql] Players boot data -
[HiC]TheKiller - 06.01.2012
That's a delimiter. It tells sscanf when to split the string and in MySQL's case, the data is formatted like this:
Re: [MySql] Players boot data -
[LTU]mindux9[TCS] - 06.01.2012
so, p<|> is delimiter?
Re: [MySql] Players boot data -
[LTU]mindux9[TCS] - 06.01.2012
so, p<|> is delimiter?