SA-MP Forums Archive
sscanf split not working as intended and login dialog shown to everyone when a player joins - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: sscanf split not working as intended and login dialog shown to everyone when a player joins (/showthread.php?tid=388796)



sscanf split not working as intended and login dialog shown to everyone when a player joins - NewerthRoleplay - 30.10.2012

Hey I am making a login and register system with MySQL and when I think it was done I get more problems, one is that my data is not being split into my enum here is the enum and the query to load user stats:
Enum:
pawn Код:
enum pInfo
{
    pUsername,
    pPassword,
    pSex,
    pAge,
    pOrigin,
    pWarns,
    pMoney,
    pLevel,
    pVIP,
    pAdmin,
    pTester,
    pKills,
    pDeaths,
    pMuted,
    pJailed,
    pBanned,
    Float:pPosX,
    Float:pPosY,
    Float:pPosZ,
    pJob,
    pFaction,
    pRank,
    pModel
}
new PlayerInfo[MAX_PLAYERS][pInfo];
And here is the code that handles loading user stats:
pawn Код:
public OnPlayerLogin(playerid)
{
    new query[1000];
    new username[MAX_PLAYER_NAME];
    GetPlayerName(playerid, username, sizeof(username));
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        if(mysql_fetch_row_format(query, "|"))
        {
            sscanf(query,"e<p<|>s[24]s[32]iiiiiiiiiiiiiifffiiii>", PlayerInfo[playerid]);
            new str[80];
            format(str, sizeof(str),"Welcome %s, you have been loged to your account, your admin rank is: %i",username, PlayerInfo[playerid][pAdmin]);
            SendClientMessage(playerid, COLOR_BLUE, str);
            SetPlayerInterior(playerid, 0);
            SetPlayerVirtualWorld(playerid, 0);
            if(PlayerInfo[playerid][pPosX] != 0 && PlayerInfo[playerid][pPosY] != 0 && PlayerInfo[playerid][pPosZ] != 0)
            {
                SetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
            }
            SpawnPlayer(playerid);
        }
    }
    else
    {
        ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Login.","Wrong password:","Login","Cancel");
    }
}
pawn Код:
stock LoginPlayer(playerid, pass[])
{
    new query[1000], username[MAX_PLAYER_NAME];
    GetPlayerName(playerid, username, sizeof(username));
    format(query, sizeof(query),"SELECT * FROM `Users` WHERE Username = '%s' AND password = md5('%s')",username, pass);
    mysql_function_query(dbconnect, query, false, "OnPlayerLogin", "");
}
And here is where the dialog is show to the player:
pawn Код:
case LOGIN_DIALOG:
        {
            if(!response)
            {
                SendClientMessage(playerid, COLOR_LIGHTRED,"You need to be logged in!");
                Kick(playerid);
            }
            LoginPlayer(playerid, inputtext);
        }
        case REGISTER_DIALOG:
        {
            if(!response)
            {
                SendClientMessage(playerid, COLOR_LIGHTRED,"You need to be logged in!");
                Kick(playerid);
            }
            new query[512], username[MAX_PLAYER_NAME];
            GetPlayerName(playerid, username, sizeof(username));
            format(query, sizeof(query),"INSERT INTO `Users` (Username,Password) VALUES ('%s',md5('%s'))",username, inputtext);
            mysql_function_query(dbconnect, query, false, "OnQueryFinish", "");
            ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Login","Enter your password below to login:","Login","Cancel");
        }
and
pawn Код:
public UserCheck(playerid)
{
    mysql_store_result();
    if(mysql_num_rows() == 0)
    {
        ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Register","Enter your password below to register:","Register","Cancel");
    }
    else
    {
        ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Login","Enter your password below to login","Login","Cancel");
    }
    mysql_free_result();
    return 1;
}
The user check query:
pawn Код:
public OnPlayerConnect(playerid)
{
    InitFly(playerid);
    new Query[512], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE Username='%s'", name);
    mysql_function_query(dbconnect, Query, false, "UserCheck", "");
    return 1;
}
Many thanks, Connor (Howelley)


Re: sscanf split not working as intended and login dialog shown to everyone when a player joins - HuSs3n - 30.10.2012

what version of Mysql plugin are you using?
i see that u'r using mysql_function_query and sscanf
AFAIK if u'r mysql plugin version is R7 you wont need to split using sscanf
check the tutorial here https://sampforum.blast.hk/showthread.php?tid=337810


Re: sscanf split not working as intended and login dialog shown to everyone when a player joins - NewerthRoleplay - 30.10.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
You told sscanf that the first and second elements in your enum are strings, when they're clearly not.
I'm now getting this in my server log when I changed the first two elements in the enum into strings.
Код:
[19:34:48] sscanf warning: String buffer overflow.



Re: sscanf split not working as intended and login dialog shown to everyone when a player joins - NewerthRoleplay - 30.10.2012

Also nobody has responded in regard to my second issue : s


Re: sscanf split not working as intended and login dialog shown to everyone when a player joins - gtakillerIV - 30.10.2012

Search next time:

https://sampforum.blast.hk/showthread.php?tid=196353


Re: sscanf split not working as intended and login dialog shown to everyone when a player joins - playbox12 - 30.10.2012

Adding to, I would personally recommend to always put sscanf in a if statement (sscanf returns false when it actually works so keep that in mind). Now you're just assuming it worked properly.


Re: sscanf split not working as intended and login dialog shown to everyone when a player joins - NewerthRoleplay - 30.10.2012

Yea I knew clearly the string size was to small but I'm not sure in what string, they all seem to fit, however they are clearly not, and it still doesn't solve the issue that when another player joins the server everybody gets the same dialog that the user who has just joined should have gotten.