Creating an empty file
#1

Well I don't really know how to explain this, but I was making a new gamemode.
I started off with making a registration system, but I found a bug.

If I click on "Quit" before registering, for some reason it's creating the .ini file, but empty.
And that would stop me from registering, and will ask me to login.

pawn Код:
case DIALOG_REGISTER:
{
    if(!response)
        return Kick(playerid);

    if(response)
    {
        if(strlen(inputtext) < 3 || strlen(inputtext) > 32)
            return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registering...", "Welcome to the server!\nPlease enter a password to register.\n\n{FF0000}The password must be between 3 and 32 characters.", "Register", "Quit");

        new hashedpass[129];
        WP_Hash(hashedpass, sizeof (hashedpass), inputtext);
       
        new INI:file = INI_Open(UserPath(playerid));
        INI_WriteString(file, "Password", hashedpass);
        INI_WriteInt(file, "Admin", 0);
        INI_WriteInt(file, "Money", 0);
        INI_WriteInt(file, "Score", 0);
        INI_WriteInt(file, "Kills", 0);
        INI_WriteInt(file, "Deaths", 0);
        INI_Close(file);
   
        // Rest of the code
   
    }
}
Reply
#2

Use "fexist" function to check if there's a file existing with the player name. AFAIK, fexist only checks if a file exists or not, it doesn't create a new one.
Reply
#3

Well what do you exactly mean?
Even if I check it would still create the file.

It would be very helpful if you explain more.

EDIT: I checked some admin filterscripts / gamemodes which use Y_INI but I couldn't get anything.
A lot of them actually have this.
Reply
#4

24 hour bump.
It would be good if someone helps.
Reply
#5

The problem isn't in the code. It's either an outdated plugin or include. We can't fix it for you.
Reply
#6

Include's up to date.
Like I said I was starting a new gamemode so I don;t have any plugins.
Reply
#7

Oops, did I say plugin? My bad.

The problem could also reside in the file permissions that your hosting provider has set. Contact them to make sure you have the correct permissions.
Reply
#8

The problem is in the OnPlayerDisconnect callback, you are saving the user data when a player disconnect so it saves the unregistered player's data. So make a variable to check if the player is registered or not to save his data.
Reply
#9

Why didn't I think of that..
Thanks, Juvanii.
Reply
#10

So the file wasn't empty... it was just the wrong values...
Thanks for clearing that up Stinged, you could have saved a lot of time.
Reply


Forum Jump:


Users browsing this thread: