unchangable variable
#1

I got this code (part of my code)
pawn Код:
new PlayerName[MAX_PLAYERS][MAX_PLAYER_NAME], Password[MAX_PLAYERS][MAX_PASSWORD];

INI:playerlist[](playerid, name[], value[])
{
    INI_String(PlayerName[playerid], Password[playerid], MAX_PASSWORD);
    return 0;
}

stock CheckPlayer(playerid){
    GetPlayerName(playerid, PlayerName[playerid], MAX_PLAYER_NAME);
    INI_Load("playerlist.ini", true, playerid); // if set to true, playerid will be passed over to INI:playerlist[...
    if(strlen(Password[playerid]) == 0){
        ShowPlayerDialog(playerid, 30, 1, "Register", "To register you must first give in the first name of your character.", "OK", "");
        return 1;
    }
    else{
        ShowPlayerDialog(playerid, 33, 1, "Login", "Please give in your password.", "OK", "");
        return 1;
    }
}
When I first log in with playername Max_Havelaar and his password is mypass I will succeed. But when I log in with Lead_Admin and his pass is mypass2 I can still only log in with mypass. This means the Password[playerid] won't be overwritten, which is a problem. I've tried to empty Password[playerid] after every log in by that playerid but then it'll be permanently empty and still no value can be assigned to it :S

How to solve this? I've tried everything
Reply
#2

Do you even know what playerid is? - it is a NUMBER assigned to an individual person who comes on your server therefore if you log off, and then come back on your server with the same player id, before the server restarts, your "password" will be the initial one that you "registered" with before... that is why you must SAVE the password - with dini/mysql/etc... - but just assigning the players' password to a variable wont work.
Reply
#3

Quote:
Originally Posted by airsoft
Посмотреть сообщение
Do you even know what playerid is? - it is a NUMBER assigned to an individual person who comes on your server therefore if you log off, and then come back on your server with the same player id, before the server restarts, your "password" will be the initial one that you "registered" with before... that is why you must SAVE the password - with dini/mysql/etc... - but just assigning the players' password to a variable wont work.
Yes I know, and I already made a register system with Y_ini (AS you can see..), but you need a variable to put the value taken out of the file in. And once you have put someone's password in Password[0] (if his playerid is 0) it will be there forever, and if another player with playerid == 0 will log in the pass taken out of the file can't be stored in Password[0]

Here's the whole code
pawn Код:
new PlayerName[MAX_PLAYERS][MAX_PLAYER_NAME], Password[MAX_PLAYERS][MAX_PASSWORD];

INI:playerlist[](playerid, name[], value[])
{
    INI_String(PlayerName[playerid], Password[playerid], MAX_PASSWORD);
    return 0;
}

stock CheckPlayer(playerid){
    GetPlayerName(playerid, PlayerName[playerid], MAX_PLAYER_NAME);
    INI_Load("playerlist.ini", true, playerid); // if set to true, playerid will be passed over to INI:playerlist[...
    SendClientMessage(playerid, COLOR_WHITE, PlayerName[playerid]);
    SendClientMessage(playerid, COLOR_WHITE, Password[playerid]);
    if(strlen(Password[playerid]) == 0){
        ShowPlayerDialog(playerid, 30, 1, "Register", "To register you must first give in the first name of your character.", "OK", "");
        return 1;
    }
    else{
        ShowPlayerDialog(playerid, 33, 1, "Login", "Please give in your password.", "OK", "");
        return 1;
    }
}

stock CheckForSymbols(inputtext[], &error){
    if(strfind(inputtext, "/") != -1) error = true;
    if(strfind(inputtext, "~") != -1) error = true;
    if(strfind(inputtext, "`") != -1) error = true;
    if(strfind(inputtext, "!") != -1) error = true;
    if(strfind(inputtext, "@") != -1) error = true;
    if(strfind(inputtext, "#") != -1) error = true;
    if(strfind(inputtext, "$") != -1) error = true;
    if(strfind(inputtext, "%") != -1) error = true;
    if(strfind(inputtext, "^") != -1) error = true;
    if(strfind(inputtext, "&") != -1) error = true;
    if(strfind(inputtext, "*") != -1) error = true;
    if(strfind(inputtext, "(") != -1) error = true;
    if(strfind(inputtext, ")") != -1) error = true;
    if(strfind(inputtext, "-") != -1) error = true;
    if(strfind(inputtext, "+") != -1) error = true;
    if(strfind(inputtext, "=") != -1) error = true;
    if(strfind(inputtext, "|") != -1) error = true;
    if(strfind(inputtext, "1") != -1) error = true;
    if(strfind(inputtext, "2") != -1) error = true;
    if(strfind(inputtext, "3") != -1) error = true;
    if(strfind(inputtext, "4") != -1) error = true;
    if(strfind(inputtext, "5") != -1) error = true;
    if(strfind(inputtext, "6") != -1) error = true;
    if(strfind(inputtext, "7") != -1) error = true;
    if(strfind(inputtext, "8") != -1) error = true;
    if(strfind(inputtext, "9") != -1) error = true;
    if(strfind(inputtext, "0") != -1) error = true;
    if(strfind(inputtext, ",") != -1) error = true;
    if(strfind(inputtext, ".") != -1) error = true;
    if(strfind(inputtext, ";") != -1) error = true;
    if(strfind(inputtext, ":") != -1) error = true;
    if(strfind(inputtext, "'") != -1) error = true;
    if(strfind(inputtext, "\"") != -1) error = true;
    if(strfind(inputtext, "[") != -1) error = true;
    if(strfind(inputtext, "]") != -1) error = true;
    if(strfind(inputtext, "{") != -1) error = true;
    if(strfind(inputtext, "}") != -1) error = true;
    if(strfind(inputtext, "?") != -1) error = true;
    if(strfind(inputtext, "_") != -1) error = true;
    if(strfind(inputtext, " ") != -1) error = true;
    return 1;
}

public OnPlayerConnect(playerid){
    SetPVarInt(playerid, "logstatus", 0);
    CheckPlayer(playerid);
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){
    if(response == 0){
        if(dialogid >= 30 && dialogid <= 33){
            CheckPlayer(playerid);
            return 0;
        }
    }
    if(response){
        switch(dialogid){
            case 30:{
                new bool:error;
                CheckForSymbols(inputtext, error);
                if(error == true){
                    SendClientMessage(playerid, COLOR_WHITE, "SERVER: Don't use symbols.");
                    ShowPlayerDialog(playerid, 30, 1, "Register", "Please give in the first name of your character.", "OK", "");
                    return 0;
                }
                if(strlen(inputtext) < 2){
                    SendClientMessage(playerid, COLOR_WHITE, "SERVER: That firstname is too short.");
                    ShowPlayerDialog(playerid, 30, 1, "Register", "Please give in the first name of your character.", "OK", "");
                    return 0;
                }
                SetPVarString(playerid, "FirstName", inputtext);
                ShowPlayerDialog(playerid, 31, 1, "Register", "Please give in the last name of your character.", "OK", "Back");
                return 0;
            }
            case 31:{
                new bool:error, msg[128], name;
                CheckForSymbols(inputtext, error);
                if(error == true){
                    SendClientMessage(playerid, COLOR_WHITE, "SERVER: Don't use symbols.");
                    ShowPlayerDialog(playerid, 31, 1, "Register", "Please give in the last name of your character.", "OK", "Back");
                    return 0;
                }
                if(strlen(inputtext) < 2){
                    SendClientMessage(playerid, COLOR_WHITE, "SERVER: That lastname is too short.");
                    ShowPlayerDialog(playerid, 31, 1, "Register", "Please give in the last name of your character.", "OK", "");
                    return 0;
                }
                SetPVarString(playerid, "LastName", inputtext);
                name = GetPVarString(playerid, "FirstName", msg, sizeof(msg)) + GetPVarString(playerid, "LastName", msg, sizeof(msg));
                if(name > 23 || name < 5){
                    SendClientMessage(playerid, COLOR_WHITE, "SERVER: Your character's total name is either too long or too short.");
                    ShowPlayerDialog(playerid, 31, 1, "Register", "Please give in the last name of your character.", "OK", "Back");
                    return 0;
                }
                format(msg, sizeof(msg), "Please give in a password between 5 and %d characters.", MAX_PASSWORD);
                ShowPlayerDialog(playerid, 32, 1, "Register", msg, "OK", "Back");
                return 0;
            }
            case 32:{
                if(strlen(inputtext) < 5 || strlen(inputtext) > MAX_PASSWORD){
                    new msg[128];
                    SendClientMessage(playerid, COLOR_WHITE, "SERVER: Your password is either too long or too short.");
                    format(msg, sizeof(msg), "Please give in a password between 5 and %d characters.", MAX_PASSWORD);
                    ShowPlayerDialog(playerid, 32, 1, "Register", msg, "OK", "Back");
                    return 0;
                }
                new FirstName[MAX_PLAYER_NAME - 4], LastName[MAX_PLAYER_NAME - 4], FullName[MAX_PLAYER_NAME], msg[128];
                GetPVarString(playerid, "FirstName", FirstName, sizeof(FirstName));
                GetPVarString(playerid, "LastName", LastName, sizeof(LastName));
                format(msg, sizeof(msg), "SERVER: You can now login with username %s_%s.", FirstName, LastName);
                SendClientMessage(playerid, COLOR_WHITE, msg);
                format(FullName, sizeof(FullName), "%s_%s", FirstName, LastName);
                new INI:playerlist = INI_Open("playerlist.ini");
                INI_WriteString(playerlist, FullName, inputtext);
                INI_Close(playerlist);
                SetPlayerName(playerid, FullName);
                SetPVarInt(playerid, "logstatus", 1);
                return 0;
            }
            case 33:{
                if(strlen(inputtext) == 0){
                    SendClientMessage(playerid, COLOR_WHITE, "SERVER: Wrong password.");
                    ShowPlayerDialog(playerid, 33, 1, "Login", "Please give in your password.", "OK", "");
                    return 0;
                }
                if(strcmp(inputtext, Password[playerid], false) == 0){
                    SetPVarInt(playerid, "logstatus", 1);
                    return 0;
                }
                else{
                    SendClientMessage(playerid, COLOR_WHITE, "SERVER: Wrong password.");
                    ShowPlayerDialog(playerid, 33, 1, "Login", "Please give in your password.", "OK", "");
                    return 0;
                }
            }
        }
    }
    return 0;
}
Reply
#4

Refresh.
Reply
#5

Replace playerlist.ini with just .ini and make it save to your scriptfiles folder.

That might help.
Reply
#6

No that won't help, then the script can't read the whole file anymore.

Any other suggestions people?
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
Hash your passwords! ALWAYS hash your passwords! I suggest using the whirlpool plugin and if I'm right (even if I'm not you still need to hash them) that will fix your problem.
Allright, I don't know what that is but i'll figure it out thanks!
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
Hash your passwords! ALWAYS hash your passwords! I suggest using the whirlpool plugin and if I'm right (even if I'm not you still need to hash them) that will fix your problem.
****** I tried to hash my passwords and I succeeded but I still got the same error :S
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)