Issue with MySQL
#1

Trying to get help for a friend who has an issue with MySQL

Alright so I followed newbienoob's tutorial a while ago and converted my script into mysql by it. Now after a while of using it, I noticed a problem in which if the player with ID 0 quit and the player with ID 1 quit and then came back with the ID 0, it would result them into wrong password.


I tested this 3 times and each time it happened, I quit from my ID 0 while my friend was ID 1 then he'd quit and rejoin right away to take over ID 0 and MySql would seem to fail at loading his password (maybe even his whole data). However in other circumstances the script works fine without any issues.


Disconnection:
pawn Код:
forward SaveAccountStats(playerid);
public SaveAccountStats(playerid)
{
    if(Logged[playerid] == 1)
    {
        new query[1024];
        mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET `Money`=%d, `Admin`=%d, `Vip`=%d, `Kills`=%d, `Deaths`=%d, `Score`=%d, `Rank`=%d, `Banned`=%d, `Warns`=%d, ",\
        PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pVip] , PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pScore], PlayerInfo[playerid][pRank], PlayerInfo[playerid][pBanned],\
        PlayerInfo[playerid][pWarns]);
        mysql_format(mysql, query, sizeof(query), "%s`VW`=%d, `Interior`=%d, `Min`=%d, `Hours`=%d, `PM`=%d, `Color`=%d, `Turfs`=%d, `Clan`=%d, ",\
        query, PlayerInfo[playerid][pVW], PlayerInfo[playerid][pInt], PlayerInfo[playerid][pMin], PlayerInfo[playerid][pHour], PlayerInfo[playerid][pPM], PlayerInfo[playerid][pColor], PlayerInfo[playerid][pTurfs], PlayerInfo[playerid][pClan]);
        mysql_format(mysql, query, sizeof(query), "%s`ClRank`=%d, `ClLeader`=%d, `Invited`=%d, `Inviting`=%d  WHERE `ID`=%d",\
        query, PlayerInfo[playerid][pClRank], PlayerInfo[playerid][pClLeader], PlayerInfo[playerid][pInvited], PlayerInfo[playerid][pInviting],  PlayerInfo[playerid][pID]);
        mysql_tquery(mysql, query, "", "");
        return 1;
    }
    return 0;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    SendDeathMessage(INVALID_PLAYER_ID, playerid, 201);
    SaveAccountStats(playerid);
        Spawned[playerid] = 0;
    MOTD[playerid] = 0;
    gTeam[playerid] = 0;
        KillStreak[playerid] = 0;
        ABCheck[playerid] = 0;
    KillTimer(timer[playerid]);
    KillTimer(PlayTimer[playerid]);
    return 1;
}
Reply
#2

I don't see anything related to saving the passwords.
Also, you don't seem to clear data when someone disconnects.
Your PlayerInfo array is still filled with information about the last player who connected if you don't clear those variables.

When another player connects, that other player will get info from the previous player.

The pMoney variable for instance.
Player A logs in, he plays a bit, earns money, say 10k and he logs out.
His data is saved but not cleared.
Player B logs in and because you didn't clear data, he'll have the same amount of money as player A.

Can we also see your loading functions?
It's hard to see where it goes wrong if you only show saving functions.
Reply
#3

I don't see the point of saving passwords as they're only created once and never change script wise.


I reset all the PlayerInfo variables at OnPlayerConnect, is OnPlayerDisconnect neccessary as well?


This is from the function at OnPlayerConnect (I didn't copy it all as there is quite some stuff there regarding showing textdraws, sending messages, and resetting variables.
[pawn]

GetPlayerIp(playerid, IP[playerid], 16);
GetPlayerName(playerid, Name[playerid], 24);
mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `users` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);

pawn Код:
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows)
    {
        cache_get_field_content(0, "Password", PlayerInfo[playerid][pPass], mysql, 129);
        PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Crazy Street Wars", "{FFFFFF}Welcome back to {F81414}Crazy Street Wars.{FFFFFF}\nType in your password below to login.", "Login", "Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Crazy Street Wars", "{FFFFFF} Welcome to {F81414}Crazy Street Wars!{FFFFFF}\nType in your desired password below to register. ", "Register", "Quit");
    }
    return 1;
}

pawn Код:
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    PlayerInfo[playerid][pMoney] = cache_get_field_content_int(0, "Money");
    PlayerInfo[playerid][pAdmin] = cache_get_field_content_int(0, "Admin");
    PlayerInfo[playerid][pVip] = cache_get_field_content_int(0, "Vip");
    PlayerInfo[playerid][pKills] = cache_get_field_content_int(0, "Kills");
    PlayerInfo[playerid][pDeaths] = cache_get_field_content_int(0, "Deaths");
    PlayerInfo[playerid][pScore] = cache_get_field_content_int(0, "Score");
    PlayerInfo[playerid][pRank] = cache_get_field_content_int(0, "Rank");
    PlayerInfo[playerid][pBanned] = cache_get_field_content_int(0, "Banned");
    PlayerInfo[playerid][pWarns] = cache_get_field_content_int(0, "Warns");
    PlayerInfo[playerid][pVW] = cache_get_field_content_int(0, "VW");
    PlayerInfo[playerid][pInt] = cache_get_field_content_int(0, "Interior");
    PlayerInfo[playerid][pMin] = cache_get_field_content_int(0, "Min");
    PlayerInfo[playerid][pHour] = cache_get_field_content_int(0, "Hours");
    PlayerInfo[playerid][pPM] = cache_get_field_content_int(0, "PM");
    PlayerInfo[playerid][pColor] = cache_get_field_content_int(0, "Color");
    PlayerInfo[playerid][pTurfs] = cache_get_field_content_int(0, "Turfs");
    PlayerInfo[playerid][pClan] = cache_get_field_content_int(0, "Clan");
    PlayerInfo[playerid][pClRank] = cache_get_field_content_int(0, "ClRank");
    PlayerInfo[playerid][pClLeader] = cache_get_field_content_int(0, "ClLeader");
    PlayerInfo[playerid][pInvited] = cache_get_field_content_int(0, "Invited");
    PlayerInfo[playerid][pInviting] = cache_get_field_content_int(0, "Inviting");
    return 1;


I also noticed that I forgot to reset pID and pPass variables at the time this was posted, however resetting them at OnPlayerConnect did not help. In case you need anything else, feel free to say so.
Reply
#4

You can also try to use "printf" statements all over the place to print some debug info to the server console.

You might find the problem that way.
During your OnAccountCheck and OnAccountLoad callbacks, print the data and also the playerid.

That's how I usually find most problems.

pawn Код:
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
    printf("OnAccountCheck for playerid: %i", playerid);
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows)
    {
        cache_get_field_content(0, "Password", PlayerInfo[playerid][pPass], mysql, 129);
        printf("Password: %s", PlayerInfo[playerid][pPass]);
        PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
        printf("ID: %i", PlayerInfo[playerid][pID]);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Crazy Street Wars", "{FFFFFF}Welcome back to {F81414}Crazy Street Wars.{FFFFFF}\nType in your password below to login.", "Login", "Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Crazy Street Wars", "{FFFFFF} Welcome to {F81414}Crazy Street Wars!{FFFFFF}\nType in your desired password below to register. ", "Register", "Quit");
    }
    return 1;
}
pawn Код:
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    printf("OnAccountLoad for playerid: %i", playerid);
    PlayerInfo[playerid][pMoney] = cache_get_field_content_int(0, "Money");
    printf("Money: %i", PlayerInfo[playerid][pMoney]);
    PlayerInfo[playerid][pAdmin] = cache_get_field_content_int(0, "Admin");
    printf("Adminlevel: %i", PlayerInfo[playerid][pAdmin]);
    PlayerInfo[playerid][pVip] = cache_get_field_content_int(0, "Vip");
    PlayerInfo[playerid][pKills] = cache_get_field_content_int(0, "Kills");
    PlayerInfo[playerid][pDeaths] = cache_get_field_content_int(0, "Deaths");
    PlayerInfo[playerid][pScore] = cache_get_field_content_int(0, "Score");
    PlayerInfo[playerid][pRank] = cache_get_field_content_int(0, "Rank");
    PlayerInfo[playerid][pBanned] = cache_get_field_content_int(0, "Banned");
    PlayerInfo[playerid][pWarns] = cache_get_field_content_int(0, "Warns");
    PlayerInfo[playerid][pVW] = cache_get_field_content_int(0, "VW");
    PlayerInfo[playerid][pInt] = cache_get_field_content_int(0, "Interior");
    PlayerInfo[playerid][pMin] = cache_get_field_content_int(0, "Min");
    PlayerInfo[playerid][pHour] = cache_get_field_content_int(0, "Hours");
    PlayerInfo[playerid][pPM] = cache_get_field_content_int(0, "PM");
    PlayerInfo[playerid][pColor] = cache_get_field_content_int(0, "Color");
    PlayerInfo[playerid][pTurfs] = cache_get_field_content_int(0, "Turfs");
    PlayerInfo[playerid][pClan] = cache_get_field_content_int(0, "Clan");
    PlayerInfo[playerid][pClRank] = cache_get_field_content_int(0, "ClRank");
    PlayerInfo[playerid][pClLeader] = cache_get_field_content_int(0, "ClLeader");
    PlayerInfo[playerid][pInvited] = cache_get_field_content_int(0, "Invited");
    PlayerInfo[playerid][pInviting] = cache_get_field_content_int(0, "Inviting");
    return 1;
}
And so on.
If everything prints correctly (when you used the variables where you store the data), your loading system is fine and you need to look elsewhere (and possibly add some other printf statements everywhere you want to check your functions).
If it doesn't print correctly, you need to check your loading system.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)