Register system isnt saving
#1

Hello so i made a register system but i noticed when i go to my user file it shows everything in zero even the password when i set myself admin through ini file it dosent save it

here is my code:

pawn Код:
enum PlayerInfo
{
    pPass[129],
    pCash,
    pScore,
    pAdmin,
    pKills,
    pDeaths,
    Last,
    NoPM
}
new pInfo[MAX_PLAYERS][PlayerInfo];
pawn Код:
native WP_Hash(buffer[],len,const str[]);
forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][pPass],129);
    INI_Int("Cash",pInfo[playerid][pCash]);
    INI_Int("Score",pInfo[playerid][pScore]);
    INI_Int("Admin",pInfo[playerid][pAdmin]);
    INI_Int("Kills",pInfo[playerid][pKills]);
    INI_Int("Deaths",pInfo[playerid][pDeaths]);
    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    switch(reason)
    {
        case 0: format(string, sizeof(string), "{FEFEFE}%s has left the server. (Lost Connection)", pname);
        case 1: format(string, sizeof(string), "{FEFEFE}%s has left the server. (Leaving)", pname);
        case 2: format(string, sizeof(string), "{FEFEFE}%s has left the server. (Kicked)", pname);
    }
    SendClientMessageToAll(0xAAAAAAAA, string);
    new INI:file = INI_Open(Path(playerid));
    INI_SetTag(file,"data");
    INI_WriteInt(file,"Password",pInfo[playerid][pPass]);
    INI_WriteInt(file,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(file,"Score",GetPlayerScore(playerid));
    INI_WriteInt(file,"Admin",pInfo[playerid][pAdmin]);
    INI_WriteInt(file,"Kills",pInfo[playerid][pKills]);
    INI_WriteInt(file,"Deaths",pInfo[playerid][pDeaths]);
    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,"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,"Cash",0);
            INI_WriteInt(file,"Score",0);
            INI_WriteInt(file,"Admin",0);
            INI_WriteInt(file,"Kills",0);
            INI_WriteInt(file,"Deaths",0);
            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
            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][pPass], 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][pScore]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][pCash]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. To Project Gaming Freeroam. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
Reply
#2

any help?
Reply
#3

INI_WriteInt(file,"Password",pInfo[playerid][pPass]);

Is to be a string not an integer.

INI_WriteString(file,"Password",pInfo[playerid][pPass]);
Reply
#4

i mean the password is getting saved but the admin score etc.. dosent
Reply
#5

make sure that u have the right folder with the right name in the right place
Reply
#6

everything is right it does save the file but the file isnt getting updated its like i am getting registerd all the time and its sets all the values to 0 and i dont know whats the problem i used it in another gm and it worked fine i even double checked everything in a different script and made sure everything is the same and i think i miss something on there
Reply
#7

i see that ur missing OnPlayerConnect callback, u have to load user data there
Reply
#8

i dont miss it i just didnt post it since i checked it and everything is fine there i gave the general stuff that host it
Reply
#9

Try this!

pawn Код:
#define USERS_PATH "/Users/%s.ini" //Make a new folder in your scriptfiles folder called "Users"
#define DIALOG_LOGIN 1
#define DIALOG_REGISTER 2

enum PlayerInfo
{
    pPass[129],
    pCash,
    pScore,
    pAdmin,
    pKills,
    pDeaths,
    Last,
    NoPM
}
new pInfo[MAX_PLAYERS][PlayerInfo];

stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),USERS_PATH,playername);
    return string;
}

stock SavePlayerStats(playerid)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(file,"Password",pInfo[playerid][pPass]);
    INI_WriteInt(file,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(file,"Score",GetPlayerScore(playerid));
    INI_WriteInt(file,"Admin",pInfo[playerid][pAdmin]);
    INI_WriteInt(file,"Kills",pInfo[playerid][pKills]);
    INI_WriteInt(file,"Deaths",pInfo[playerid][pDeaths]);
    INI_Close(file);
    INI_Close(File);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    SavePlayerStats(playerid);
    return 1;
}


public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Test","Test","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Test","Test","Register","Quit");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(strlen(inputtext))
                {
                    new INI:File = INI_Open(UserPath(playerid));
                    INI_SetTag(File,"data");
                    INI_WriteInt(File,"Password",udb_hash(inputtext));
                    INI_WriteInt(file,"Cash",0);
                    INI_WriteInt(file,"Score",0);
                    INI_WriteInt(file,"Admin",0);
                    INI_WriteInt(file,"Kills",0);
                    INI_WriteInt(file,"Deaths",0);
                    INI_Close(File);

                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Test","Test","Login","Quit");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Test","Test","Register","Quit");
                }
            }
        }
        case DIALOG_LOGIN:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                }
                return 1;
            }
        }
    }
    return 1;
}
Reply
#10

i get this 10 errors
Код:
freeroam.pwn(3435) : error 017: undefined symbol "udb_hash"
freeroam.pwn(3436) : error 017: undefined symbol "file"
freeroam.pwn(3437) : error 017: undefined symbol "file"
freeroam.pwn(3438) : error 017: undefined symbol "file"
freeroam.pwn(3439) : error 017: undefined symbol "file"
freeroam.pwn(3440) : error 017: undefined symbol "file"
freeroam.pwn(3457) : error 017: undefined symbol "udb_hash"
freeroam.pwn(3457) : warning 215: expression has no effect
freeroam.pwn(3457) : error 001: expected token: ";", but found "]"
freeroam.pwn(3457) : error 029: invalid expression, assumed zero
freeroam.pwn(3457) : fatal error 107: too many error messages on one line
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)