Unlogical problem with sscanf (i guess) ...
#1

Hey, thanks for reading.

Since I started using sscanf in my account-load function (as a replacement of split(); ) it's having some problems.
Sometimes, the player's stats are not correctly loaded. Some of the variables such as 'username' are empty. That's a real problem, because I use SetPlayerName later on in my script, and if the input of SetPlayerName is blank, the server will crash. That has happened a few times now.

So I want to get rid of this bug, but how? I've worked over a year with sscanf now, and i really cannot explain this.
I tried e<> for the enum, i tried changing some datatypes in my database (from VARCHAR to float) but that doesn't work either. I would be very glad if someone could help me.

At last, the code causing the problem:

pawn Код:
mysql_fetch_row_format(mysqlquery, "|");
                if(!sscanf(mysqlquery,"p<|>ds[25]s[42]s[40]s[20]dddddddddds[50]s[50]s[50]dddddddffffdddds[15]dddddddddddddddddddd",
                    AccountInfo[extraid][identification],
                    AccountInfo[extraid][username],
                    AccountInfo[extraid][spassword],
                    AccountInfo[extraid][emailaddress],
                    AccountInfo[extraid][ipaddress],
                    AccountInfo[extraid][status],
                    AccountInfo[extraid][autologin],
                    AccountInfo[extraid][language],
                    AccountInfo[extraid][age],
                    AccountInfo[extraid][carlicense],
                    AccountInfo[extraid][flylicense],
                    AccountInfo[extraid][boatlicense],
                    AccountInfo[extraid][viprank],
                    AccountInfo[extraid][property1],
                    AccountInfo[extraid][property2],
                    AccountInfo[extraid][warnreason1],
                    AccountInfo[extraid][warnreason2],
                    AccountInfo[extraid][warnreason3],
                    AccountInfo[extraid][serversounds],
                    AccountInfo[extraid][phone],
                    AccountInfo[extraid][daysplayed],
                    AccountInfo[extraid][hoursplayed],
                    AccountInfo[extraid][minutesplayed],
                    AccountInfo[extraid][money],
                    AccountInfo[extraid][bankmoney],
                    AccountInfo[extraid][positionx],
                    AccountInfo[extraid][positiony],
                    AccountInfo[extraid][positionz],
                    AccountInfo[extraid][angle],
                    AccountInfo[extraid][interior],
                    AccountInfo[extraid][faction],
                    AccountInfo[extraid][frank],
                    AccountInfo[extraid][factioncode],
                    AccountInfo[extraid][fjoindate],
                    AccountInfo[extraid][fishingexp],
                    AccountInfo[extraid][fish],
                    AccountInfo[extraid][cigarettes],
                    AccountInfo[extraid][beer],
                    AccountInfo[extraid][sprunk],
                    pWeapons[extraid][0][0],
                    pWeapons[extraid][0][1],
                    pWeapons[extraid][1][0],
                    pWeapons[extraid][1][1],
                    pWeapons[extraid][2][0],
                    pWeapons[extraid][2][1],
                    pWeapons[extraid][3][0],
                    pWeapons[extraid][3][1],
                    pWeapons[extraid][4][0],
                    pWeapons[extraid][4][1],
                    pWeapons[extraid][5][0],
                    pWeapons[extraid][5][1],
                    pWeapons[extraid][6][0],
                    pWeapons[extraid][6][1],
                    JailInfo[extraid][2])) printf("[ERROR]: Something went wrong on LoadAccount. Accountname: %s",PlayerName[extraid]);
Greetz,
Danny
Reply
#2

First of all, put your sscanf line in a if statement, sscanf returns false when it worked (when all values have been parsed correctly). That way, you can give the player a message, saying something wen't wrong and he has to relog. I'm about 99 percent sure it's your script having a flaw, however this solution does not eliminate it, it'll however make sure your server will not crash. (Unless something is really wrong, and the values actually do get parsed correctly).

If you want to debug more, just print everything out, as soon as you see that it crashes, compare it with a time that it did go right, see what is the difference, that would help you pin point exactly what wen't wrong.

(Small thing, max name size is 24, you have it specified on 25, not that it would cause a problem, just thought I'd mention it).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)