SA-MP Forums Archive
A bug .. - 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: A bug .. (/showthread.php?tid=373291)



A bug .. - Guitar - 29.08.2012

Hey guys, the bug is when the player registers it saves the password okay? but when he comes to log-in, it doesn't read his password .. he can type any password and just log-in and even without logging in his stats can be loaded, so

here are my /login and /register commands (I converted them from Dialogs to commands)

pawn Код:
CMD:login(playerid, params[])
{
    //if(PlayerInfo[playerid][pPass] == playerpassword
    //new tmp;
    //new INI:File = INI_Open(UserPath(playerid));
   
    //tmp = INI_Int(File,"Password",PlayerInfo[playerid][pPass]);
    if(sscanf(params,"s[128]",playerpassword)) return SendClientMessage(playerid, COLOR_ORANGE,"[REGISTRATION]/login <password>");
    if(strcmp(PlayerInfo[playerid][pPass],playerpassword,true))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
        SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED,""#COL_RED"You've entered a wrong password, try again!");
    }
    return 1;
}

CMD:register(playerid, params[])
{
    if(sscanf(params,"s[128]",playerpassword)) return SendClientMessage(playerid, COLOR_ORANGE,"[REGISTRATION]/register <password>");
   
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,".:-{ Player's Data }-:.");
    INI_WriteString(File,"Password", playerpassword);
    INI_WriteInt(File,"Cash",0);
    INI_WriteInt(File,"Admin",-1);
    INI_WriteInt(File,"Kills",0);
    INI_WriteInt(File,"Deaths",0);
    INI_WriteInt(File,"Zombie",0);
    INI_WriteInt(File,"Score",1);
    INI_WriteInt(File,"Team",-1);
    INI_Close(File);

    PlayerInfo[playerid][pTeam] = -1;
    PlayerInfo[playerid][pAdmin] = -1;
   
    SavePlayerStats(playerid);
    SendClientMessage(playerid, COLOR_ORANGE, "Congratulations! You have registered yourself and we're happy to have you here!");
    SendClientMessage(playerid, COLOR_RED,""#COL_GREEN"Type /starter for your starter pack.");
    return 1;
}



Re: A bug .. - C00K13M0N$73R - 29.08.2012

Im sure
pawn Код:
if(strcmp(PlayerInfo[playerid][pPass],playerpassword,true))
Should be
pawn Код:
if(!strcmp(PlayerInfo[playerid][pPass],playerpassword,true))
Код:
Returns	-1 if string1 comes before string2
1 if string1 comes after string2
0 if the strings are the same (for the matched length).
Код:
Important Note: This function also returns 0 if either string is empty.



Re: A bug .. - Guitar - 29.08.2012

So all I have to add now is the "!" ..?

Edit:

Nothing .. the problem is still the same.


Re: A bug .. - C00K13M0N$73R - 29.08.2012

Quote:
Originally Posted by Guitar
Посмотреть сообщение
So all I have to add now is the "!" ..?
That should work.

EDIT:try
pawn Код:
if(strcmp(playerpassword,PlayerInfo[playerid][pPass],true))



Re: A bug .. - Guitar - 29.08.2012

Nope nothing :S


Re: A bug .. - leonardo1434 - 30.08.2012

pawn Код:
if(strcmp(PlayerInfo[playerid][pPass],playerpassword) == 0) // make sure the array "PlayerInfo[playerid][pPass]" contains the password which is located at player file's.
about the command register, it will restart the stats of player that uses it, even being already registered, you should add another statement to prevent this.


Re: A bug .. - Guitar - 30.08.2012

The password is there, and yup I will be making something like status ..
Now the log-in cmd is like this:

pawn Код:
CMD:login(playerid, params[])
{
    if(PlayerInfo[playerid][pReg] == 1)
    {
        if(sscanf(params,"s[128]",playerpassword)) return SendClientMessage(playerid, COLOR_ORANGE,"[REGISTRATION]/login <password>");
        if(strcmp(PlayerInfo[playerid][pPass],playerpassword) == 0)
        {
            INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
            GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
            SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED,""#COL_RED"You've entered a wrong password, try again!");
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_ORANGE,"[REGISTRATION]/register <password>");
    }
    return 1;
}
and my register

pawn Код:
CMD:register(playerid, params[])
{
    if(PlayerInfo[playerid][pReg] == 0)
    {
        if(sscanf(params,"s[128]",playerpassword)) return SendClientMessage(playerid, COLOR_ORANGE,"[REGISTRATION]/register <password>");
   
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,".:-{ Player's Data }-:.");
        INI_WriteString(File,"Password", playerpassword);
        INI_WriteInt(File,"Cash",0);
        INI_WriteInt(File,"Admin",-1);
        INI_WriteInt(File,"Kills",0);
        INI_WriteInt(File,"Deaths",0);
        INI_WriteInt(File,"Zombie",0);
        INI_WriteInt(File,"Score",1);
        INI_WriteInt(File,"Team",-1);
        INI_WriteInt(File,"Registered",1);
        INI_Close(File);

        PlayerInfo[playerid][pTeam] = -1;
        PlayerInfo[playerid][pAdmin] = -1;
        PlayerInfo[playerid][pReg] = 1;

        SavePlayerStats(playerid);
        SendClientMessage(playerid, COLOR_ORANGE, "Congratulations! You have registered yourself and we're happy to have you here!");
        SendClientMessage(playerid, COLOR_RED,""#COL_GREEN"Type /starter for your starter pack.");
    }
    else if(PlayerInfo[playerid][pReg] == 1)
    {
        SendClientMessage(playerid, COLOR_GREEN,"You're already a member here, you can't use this command again.");
    }
    return 1;
}
I haven't tested them yet, I'm going now.

EDIT EDIT EDIT: something wrong now with the pLogged

pawn Код:
CMD:login(playerid, params[])
{
    if(PlayerInfo[playerid][pLogged] == 1)
    {
        if(PlayerInfo[playerid][pReg] == 1)
        {
            if(sscanf(params,"s[128]",playerpassword)) return SendClientMessage(playerid, COLOR_ORANGE,"[REGISTRATION]/login <password>");
            if(strcmp(PlayerInfo[playerid][pPass],playerpassword) == 0)
            {
                INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
                PlayerInfo[playerid][pLogged] = 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED,""#COL_RED"You've entered a wrong password, try again!");
            }
        }
        else if(PlayerInfo[playerid][pReg] == 0)
        {
            SendClientMessage(playerid, COLOR_ORANGE, "Please type /register to register your account.");
        }
    }
    else if(PlayerInfo[playerid][pLogged] == 0)
    {
        SendClientMessage(playerid, COLOR_ORANGE,"Please log into your account first, /login");
    }
    return 1;
}
    //if(PlayerInfo[playerid][pPass] == playerpassword
    //new tmp;
    //new INI:File = INI_Open(UserPath(playerid));

    //tmp = INI_Int(File,"Password",PlayerInfo[playerid][pPass]);

CMD:register(playerid, params[])
{
    if(PlayerInfo[playerid][pReg] == 0)
    {
        if(sscanf(params,"s[128]",playerpassword)) return SendClientMessage(playerid, COLOR_ORANGE,"[REGISTRATION]/register <password>");
   
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,".:-{ Player's Data }-:.");
        INI_WriteString(File,"Password", playerpassword);
        INI_WriteInt(File,"Cash",0);
        INI_WriteInt(File,"Admin",-1);
        INI_WriteInt(File,"Kills",0);
        INI_WriteInt(File,"Deaths",0);
        INI_WriteInt(File,"Zombie",0);
        INI_WriteInt(File,"Score",1);
        INI_WriteInt(File,"Team",-1);
        INI_WriteInt(File,"Registered",1);
        INI_WriteInt(File,"Logged",1);
        INI_Close(File);
       
        PlayerInfo[playerid][pLogged] = 1;
        PlayerInfo[playerid][pTeam] = -1;
        PlayerInfo[playerid][pAdmin] = -1;
        PlayerInfo[playerid][pReg] = 1;

        SavePlayerStats(playerid);
        SendClientMessage(playerid, COLOR_ORANGE, "Congratulations! You have registered yourself and we're happy to have you here!");
        SendClientMessage(playerid, COLOR_RED,""#COL_GREEN"Type /starter for your starter pack.");
    }
    else if(PlayerInfo[playerid][pReg] == 1)
    {
        SendClientMessage(playerid, COLOR_GREEN,"You're already a member here, you can't use this command again.");
    }
    return 1;
}
What is it?


Re: A bug .. - IceMeteor - 30.08.2012

The PlayerInfo[playerid][pLogged] == 1 should be 0 right? so if they havent logged in, they have to login, allso the PlayerInfo[playerid][pLogged] == 0, should be 1?


Re: A bug .. - Guitar - 30.08.2012

My mind is closed now man, because no matter what I do, the original problem will still be existing, which is you can type any password to log in .


Re: A bug .. - [GF]Logic - 30.08.2012

i don't know exactly how to make it but i guess you need to open the Password File (File,"Password", playerpassword) and check if the password written by the player is the same inside it. check some tutorials