Every new player gets admin level problem
#1

I noticed that many players get level 5 admin automaticly when they register and i checked all of my register system everything is fine and i have searched all of my gm to check if a player is given admin with some command but nothing

i will give you my register system
pawn Код:
native WP_Hash(buffer[],len,const str[]);

enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Deaths, //User's deaths
    Last,
    NoPM
}
new pInfo[MAX_PLAYERS][PlayerInfo];
pawn Код:
forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/

    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    return 1;
}
pawn Код:
if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back,To [PG]Call of Duty Server. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        return 1;
    }
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new string[128], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,MAX_PLAYER_NAME);//Get the player's name
    format(string,sizeof string,"{FF9915}%s {FFFFFF}has left {FF9915}[PG]Call of Duty Server (0.3x){FFC800}.",pName);//the message to everyone
    SendClientMessageToAll(0xFFFFFFAA,string);//this is used to send the message to everyone who is in the server
    new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
        INI_Close(file);
    pInfo[playerid][Last] = -1;
    pInfo[playerid][NoPM] = 0;
    return 1;
}
pawn Код:
if(dialogid == dregister) //If dialog id is a register dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            if(!strlen(inputtext)) //If they didn't enter any password
            {// then we will tell to them to enter the password to register
                ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                return 1;
            }
            //If they have entered a correct password for his/her account...
            new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
            new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
            INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
            INI_WriteInt(file,"VIPLevel",0);//As explained above
            INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
            INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
            INI_WriteInt(file,"Kills",0);//As explained above
            INI_WriteInt(file,"Deaths",0);//As explained above
            INI_Close(file);//Now after we've done saving their data, we now need to close the file
            SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
            SetPVarInt(playerid, "NoNPCSpawn", 1);
            return 1;
        }
    }
    if(dialogid == dlogin) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass, pInfo[playerid][Pass], false)) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
                SetPVarInt(playerid, "NoNPCSpawn", 1);
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                SetPVarInt(playerid, "NoNPCSpawn", 1);
                return 1;
            }
        }
    }

Does this code have any problem cause the player gets admin when he registered
Reply
#2

Do you reset the variables on connect? If not and if the previous user was an admin and after disconnecting a new player connects with that playerid and he's not registered, he will get the admin of the previous user.
Reply
#3

What do you mean reset variables i am using newbienewbes tutorial of register system and everything works fine on other gms i made when the player registers and after that disconnects then he gets admin level 4 or 5 i couldnt seem to find any problem in my gm can you help me solve it and what variable do you mean?
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Do you reset the variables on connect? If not and if the previous user was an admin and after disconnecting a new player connects with that playerid and he's not registered, he will get the admin of the previous user.
This should be the correct answer, yes.
Reply
#5

So basically, you are not resetting the variables, so the previous player that has an admin rank and the other player joined with the same ID, he will get the same information, and that is why he gets an administrator rank, basically you just loop the size of the enumerator and reset them.

pawn Код:
new
    ResetEnum[ PlayerInfo ];

public OnPlayerConnect(playerid)
{
    //rest of the code.
    return pInfo[ playerid ] = ResetEnum, true;
}

public OnPlayerDisconnect(playerid, reason)
{
    //rest of the code.
    return pInfo[ playerid ] = ResetEnum, true;
}
Reply
#6

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
So basically, you are not resetting the variables, so the previous player that has an admin rank and the other player joined with the same ID, he will get the same information, and that is why he gets an administrator rank, basically you just loop the size of the enumerator and reset them.

pawn Код:
new
    ResetEnum[ PlayerInfo ];

public OnPlayerConnect(playerid)
{
    return pInfo[ playerid ] = ResetEnum, true;
}

public OnPlayerDisconnect(playerid, reason)
{
    return pInfo[ playerid ] = ResetEnum, true;
}
Correct.
Reply
#7

Guys as i said when the player joins he dosent have the admin but when he disconnects he gets it and i cant seem to find the problem


[EDIT]You guys are right if someone leaves and you get his id it gives you his stats how do i fix it ?
Reply
#8

As the guy stated above.
Reply
#9

@AlonzoTorres: The file does not exist so it doesn't assign anything.

Quote:
Originally Posted by DarkLored
Посмотреть сообщение
What do you mean reset variables i am using newbienewbes tutorial of register system and everything works fine on other gms i made when the player registers and after that disconnects then he gets admin level 4 or 5 i couldnt seem to find any problem in my gm can you help me solve it and what variable do you mean?
You must reset the variables on connect because new player will get the stats of the previous user (who had the same playerid).


---

There are three ways of resetting with your case (array + enum).

You can use:
pawn Код:
pInfo[playerid][Adminlevel] = 0;
pInfo[playerid][VIPlevel] = 0;
pInfo[playerid][Money] = 0;
pInfo[playerid][Scores] = 0;
pInfo[playerid][Kills] = 0;
pInfo[playerid][Deaths] = 0;
or
pawn Код:
new x[PlayerInfo];
pInfo[playerid] = x;
or a loop with the enum's tag and set to 0.
Reply
#10

Quote:
Originally Posted by DarkLored
Посмотреть сообщение
Like this?

pawn Код:
public OnPlayerConnect(playerid)
{
     pInfo[playerid][Adminlevel] = 0;
    pInfo[playerid][VIPlevel] = 0;
    pInfo[playerid][Money] = 0;
    pInfo[playerid][Scores] = 0;
    pInfo[playerid][Kills] = 0;
    pInfo[playerid][Deaths] = 0;
    pInfo[playerid][Last] = -1;
    pInfo[playerid][NoPM] = 0;
    //Login Stuff under
    return 1;
}

did i put it correctly?
Yes that should be correct. You should not use -1 on Last though?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)