01.11.2014, 09:42
I have a little problem with saving my stats upon disconnecting
I registered, and then disconnected, this is the result
and also my pass wont show up in the database, but when I login, i can just type any word and i continue and play
I don't see anything wrong.. please help, and it compiles with no errors.
I registered, and then disconnected, this is the result
PHP код:
public OnPlayerDisconnect(playerid) {
Invisible[playerid] = 0;
IsControlling[playerid] = 0;
ControlNumber[playerid] = -1;
OrigPName[playerid] = "\0";
OrigTName[playerid] = "\0";
Mysql_SAVE(playerid);
return 1;
}
stock Mysql_SAVE(playerid)
{
new query[256];
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET `PosX` = %f, `PosY`=%f,`PosZ`=%f,`Admin`=%d,`Cash`=%d,`Kills`=%d,`Deaths`=%d,`Skin`=%d,`IsBanned`=%d WHERE `UID` = %d", x, y, z, PlayerInfo[playerid][pAdmin],PlayerInfo[playerid][pCash],PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths],PlayerInfo[playerid][pSkin],PlayerInfo[playerid][pBanned], PlayerInfo[playerid][UID]);
mysql_tquery(mysql, query);
return 1;
}
PHP код:
public OnPlayerConnect(playerid)
{
new query[128];
GetPlayerIp(playerid, IP[playerid], 16);
mysql_format(mysql, query, sizeof(query),"SELECT `Pass`,`UID` FROM `users` WHERE `Name` = '%s'", GetName(playerid));
mysql_tquery(mysql, query, "OnConnection", "i", playerid);
cp[playerid] = 1;
SetPlayerCheckpoint(playerid,1642.5245,-2241.6150,-2.7038,5);
return 1;
}
forward OnConnection(playerid);
public OnConnection(playerid) {
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows) {
cache_get_field_content(0, "Pass", PlayerInfo[playerid][pPass], mysql, 129);
PlayerInfo[playerid][UID] = cache_get_field_content_int(0, "UID");
printf("%s", PlayerInfo[playerid][pPass]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Your account is found in our database!\nPlease enter your password to continue!", "Login", "Quit");
} else {
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Your account is not found in our databse!\nPlease enter a password so that you can save your stats and load it in the future.", "Register", "Quit");
}
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new query[144], ip[20];
switch( dialogid )
{
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid); //If the player clicks the second button
if(response) //If he clicks the first button
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering","You have entered an invalid password.\nType your password below to register a new account.","Register","Quit"); //This happens if the user has input no password. You can add limits here.
else {
WP_Hash(PlayerInfo[playerid][pPass], 129, inputtext);
GetPlayerIp(playerid, ip, sizeof(ip));
mysql_format(mysql, query, sizeof(query), "INSERT INTO `users` (Name, Pass, IP) VALUES ('%s', '%e', '%s')", GetName(playerid), PlayerInfo[playerid][pPass], ip);
mysql_tquery(mysql, query, "OnRegisteration", "i", playerid);
SendMessage(playerid, "Succesfully registered!");
}
pNewlyRegged[playerid] = true; //Changing the value of our boolean
}
}
case DIALOG_LOGIN:
{
if ( !response ) return Kick ( playerid ); //If the player clicks the second button
if( response )
{
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
if(!strcmp(hashpass, PlayerInfo[playerid][pPass], false)) //Compares the inputtext to the player's pass, pPass.
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `users` WHERE `Name` = '%s' AND `Pass` = '%e'" , GetName(playerid), hashpass);
mysql_tquery(mysql, query, "OnLogin", "i", playerid);
TogglePlayerSpectating(playerid, false);
SetTimerEx("UnsetFirstSpawn", 5000, false, "i", playerid); //We're using this for other purposes, to fix a bug in skin selection (OnPlayerRequestClass)
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit"); //If the player has entered an invalid password, he's prompted to retype his password
}
return 1;
}
}
}
return 1;
}
forward OnRegisteration(playerid);
public OnRegisteration(playerid) {
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows) {
PlayerInfo[playerid][UID] = cache_get_field_content_int(0, "UID");
Logged[playerid] = 1;
SpawnPlayer(playerid);
}
return 1;
}
forward OnLogin(playerid);
public OnLogin(playerid) {
new rows, fields;
cache_get_data(rows, fields);
if(rows)
{
PlayerInfo[playerid][UID] = cache_get_field_content_int(0, "UID");
PlayerInfo[playerid][pAdmin] = cache_get_field_content_int(0, "Admin");
PlayerInfo[playerid][pKills] = cache_get_field_content_int(0, "Kills");
PlayerInfo[playerid][pDeaths] = cache_get_field_content_int(0, "Deaths");
PlayerInfo[playerid][pBanned] = cache_get_field_content_int(0, "IsBanned");
SpawnPlayer(playerid);
Logged[ playerid ] = 1;
GivePlayerCash(playerid, PlayerInfo[playerid][pCash]);
SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], PlayerInfo[playerid][posX], PlayerInfo[playerid][posY], PlayerInfo[playerid][posZ], 1.0, -1, -1, -1, -1, -1, -1);
SendMessage(playerid, "Succesfully logged in!");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "It seems that the password you have entered is incorrect.\nPlease enter a correct one.\n", "Login", "Quit");
}
return 1;
}