Login/Register Bug
#1

Hello, i need help with my login and register system.
I created the login and register system with the help of Kush's Tutorial.

The bug is, when i disconnect, my Admin Level and VIP Level increased one text.

The underlined is the one that increased.
The Account.ini:
Quote:

[Player Account]
Password = 306643852
Cash = 35061
Scores = 5
Admin Level = 0
VIP Level = 0
Kills = 0
Deaths = 0
Admin Level = 0
VIP Level = 0

My OnPlayerDisconnect:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{    
    new INI:File = INI_Open(UserPath(playerid));
    new sztring[3000];
    format(sztring,sizeof(sztring),"%s Account",PlayerName(playerid));
    INI_SetTag(File, sztring);
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Scores",GetPlayerScore(playerid));
    INI_WriteInt(File,"Admin Level",pInfo[playerid][pLevel]);
    INI_WriteInt(File,"VIP Level",pInfo[playerid][pVIP]);
    INI_WriteInt(File,"Kills",pInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",pInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}
Any help ?
Sorry for bad english.
Reply
#2

Are you saving those somewhere else in the script too ? , Also show the OnDialogResponse Please
Reply
#3

If you're referring to the "Admin Level" and "VIP Level" appearing on the bottom rather between "Scores" and "Kills" is normally when you add those player variables into the account system after you've already made that account. Also, the string size for "sztring" is way too big. Instead of 3000, 32 should be plenty enough.
Reply
#4

@RockHopper:
Here you go,
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext))
                {
                    new sztring[3000];
                    format(sztring,sizeof(sztring),""COL_YELLOW"Hello {FF0000}%s"COL_YELLOW", welcome to the server!\n\n"COL_YELLOW"Please type your password to register to the server and continue\n{FF0000}NOTE: "COL_YELLOW"Don't give your password to other players even server administrators.",PlayerName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Account Register", sztring,"Register","Quit");
                }
                new INI:File = INI_Open(UserPath(playerid));
                new sztring[3000];
                format(sztring,sizeof(sztring),"%s Account",PlayerName(playerid));
                INI_SetTag(File,sztring);
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Scores",0);
                INI_WriteInt(File,"Admin Level",0);
                INI_WriteInt(File,"VIP Level",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);

                new stzring[3000];
                format(stzring,sizeof(stzring),""COL_YELLOW"Hello {FF0000}%s\n"COL_YELLOW"You have succesuflly registered your account.\n\nWelcome to Call of Duty - Battlefield Server !", PlayerName(playerid));
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,"Account Info", stzring,"Ok","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == pInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
                    SetPlayerScore(playerid, pInfo[playerid][pScores]);
                    new stzring[3000];
                    format(stzring,sizeof(stzring),""COL_YELLOW"Hello {FF0000}%s\n"COL_YELLOW"You have succesuflly login to your account.\n\n"COL_YELLOW"Admin Level: "COL_LIGHTBLUE"%d\n"COL_YELLOW"VIP Level: "COL_LIGHTBLUE"%d\n\n"COL_YELLOW"For more status, please type /stats command.", PlayerName(playerid), pInfo[playerid][pLevel], pInfo[playerid][pVIP]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,"Account Info", stzring,"Ok","");
                }
                else
                {
                    new sztring[3000];
                    format(sztring,sizeof(sztring),""COL_YELLOW"Hello {FF0000}%s"COL_YELLOW", welcome back to the server!\n\n"COL_YELLOW"Please type your password to login to the server and continue\n"COL_YELLOW"If you are not owner of this account please click {FF0000}'Quit' "COL_YELLOW"and choose a new name.\n"COL_RED"You have typed an incorrect password.",PlayerName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Authenticate", sztring,"Login","Quit");
                }
                return 1;
            }
        }
    }
    return true;
}

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password", pInfo[playerid][pPass]);
    INI_Int("Cash", pInfo[playerid][pMoney]);
    INI_Int("Scores", pInfo[playerid][pScores]);
    INI_Int("Admin Level", pInfo[playerid][pLevel]);
    INI_Int("VIP Level", pInfo[playerid][pVIP]);
    INI_Int("Kills", pInfo[playerid][pKills]);
    INI_Int("Deaths", pInfo[playerid][pDeaths]);
    return 1;
}
@DTV:
EDIT: Explain more please.
Reply
#5

Can I see your OnPlayerDisconnect or the stock you use for saving the account?
Reply
#6

Deleted. (I hit refresh by accident.)
Reply
#7

Here you go, all of it.
On Player Disconnect:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{    
    new INI:File = INI_Open(UserPath(playerid));
    new sztring[3000];
    format(sztring,sizeof(sztring),"%s Account",PlayerName(playerid));
    INI_SetTag(File, sztring);
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Scores",GetPlayerScore(playerid));
    INI_WriteInt(File,"Admin Level",pInfo[playerid][pLevel]);
    INI_WriteInt(File,"VIP Level",pInfo[playerid][pVIP]);
    INI_WriteInt(File,"Kills",pInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",pInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}
On Player Connect:
pawn Код:
if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        new sztring[3000];
        GetPlayerName(playerid,pname,sizeof(pname));
        format(sztring,sizeof(sztring),""COL_YELLOW"Hello {FF0000}%s"COL_YELLOW", welcome back to the server!\n\n"COL_YELLOW"Please type your password to login to the server and continue\n"COL_YELLOW"If you are not the owner of this account, please click {FF0000}'Quit'"COL_YELLOW" and use a new name.",PlayerName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Authenticate", sztring,"Login","Quit");
    }
    else
    {
        new sztring[3000];
        GetPlayerName(playerid,pname,sizeof(pname));
        format(sztring,sizeof(sztring),""COL_YELLOW"Hello {FF0000}%s"COL_YELLOW", welcome to the server!\n\n"COL_YELLOW"Please type your password to register to the server and continue\n{FF0000}NOTE: "COL_YELLOW"Don't give your password to other players even server administrators.",PlayerName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Account Register", sztring,"Register","Quit");
    }
Stocks:
pawn Код:
stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}

stock udb_hash(buf[]) {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password", pInfo[playerid][pPass]);
    INI_Int("Cash", pInfo[playerid][pMoney]);
    INI_Int("Scores", pInfo[playerid][pScores]);
    INI_Int("Admin Level", pInfo[playerid][pLevel]);
    INI_Int("VIP Level", pInfo[playerid][pVIP]);
    INI_Int("Kills", pInfo[playerid][pKills]);
    INI_Int("Deaths", pInfo[playerid][pDeaths]);
    return 1;
}
Save Path
pawn Код:
#define PATH "Folder/Users/%s.ini"
OnDialogResponse is shown above.
Reply
#8

Quote:
Originally Posted by ChandraLouis
Посмотреть сообщение
@DTV:
EDIT: Explain more please.
When it's set to [3000], it's set to store 3000 characters (it's actually more technical than that afaik, but the reasoning is roughly the same). If you're not using up that 3000 character limit, it's very inefficient and can slow your script down. "%s Account" is only going to be a maximum of 32 characters long, so it only need to be set to [32]. If [32] giving you errors, then just change it to [33].
Reply
#9

Quote:
Originally Posted by DTV
Посмотреть сообщение
When it's set to [3000], it's set to store 3000 characters (it's actually more technical than that afaik, but the reasoning is roughly the same). If you're not using up that 3000 character limit, it's very inefficient and can slow your script down. "%s Account" is only going to be a maximum of 32 characters long, so it only need to be set to [32]. If [32] giving you errors, then just change it to [33].
I have changed [3000] to [32], but it's same, not working.
Reply
#10

Quote:
Originally Posted by ChandraLouis
Посмотреть сообщение
I have changed [3000] to [32], but it's same, not working.
It won't fix the issue at hand here, but it's good practice as this will slow your script down in the long wrong if every string is [3000] or larger than it needs to be.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)