How to empty this string?
#1

Hi all,

I'm having difficulties with file loading for two weeks now and no solutions, I posted several topics on it but no-one seems to know what is going wrong, allright so here goes:

I have a gm which makes you register, the password and username will be saved in a file with Y_ini. When the script loads the password for a player out of that file and put it in Password[playerid], say the playerid is 0 ==> Password[0], that string will be unchanged till the next server restart. This means when player 0 logs out and another player with playerid 0 logs on he can only log in with the password of the previous player because this is still in Password[0]. I want to learn how to empty Password[0], no strdel or other str function will work, strdel does empty the string, but after that no other string can be put in Password[0]. It seems that a string can only once obtain a value out of a file :S I also tried using hash like ****** told me in the link I provided down here but that also doesn't seem to work.

How to solve this?

For more information on this problem see my other thread:
https://sampforum.blast.hk/showthread.php?tid=249663

Please no noob responds.
Reply
#2

Reset all variables when a player joins, when a player joins in my script I have a stock like. (setting everything to the number 0).

pawn Код:
stock ClearVars(playerid)
{
     Password[playerid] = 0;
};
Reply
#3

Quote:
Originally Posted by playbox12
Посмотреть сообщение
Reset all variables when a player joins, when a player joins in my script I have a stock like. (setting everything to the number 0).

pawn Код:
stock ClearVars(playerid)
{
     Password[playerid] = 0;
};
But I defined Password[playerid] as:
pawn Код:
new Password[MAX_PLAYERS][129]
and your method results in an error about the variable indexed uncorrectly which is understandable .
Reply
#4

pawn Код:
Password[playerid][0] = EOS;
Should work. EOS = End Of String = '\0'. This effectively empties the string, and if you use the strlen function it will also return 0.
Reply
#5

try

PHP код:
for(new i=0i<MAX_PLAYERSi++) strcpy(Password[i], ""); 
This will clear the entire array, you will need the strcpy() stock though:

PHP код:
stock strcpy(dest[], source[])
{
    
    new 
len strlen(source), i;
    for (
0len++) dest[i] = source[i];
    return 
1;

Reply
#6

Sorry, I missread your question, do;

pawn Код:
Password[playerid][0] = '\0';
EDIT: Lold, double beat, I should learn to refresh before posting..
Reply
#7

Quote:
Originally Posted by playbox12
Посмотреть сообщение
Sorry, I missread your question, do;

pawn Код:
Password[playerid][0] = '\0';
EDIT: Lold, double beat, I should learn to refresh before posting..
No, nothing of the above works :S A string which has gotten a value out of a file can NEVER obtain a new value through INI_String, not even if emptied before in ANY way. How do we normally solve this?
Reply
#8

That is really strange, as it should work, ask in the Y_Ini topic, or PM ****** as he is the author of yini.

(this works for me, I use mysql, I hear from other people using dini that this is how they do it aswell).
Reply
#9

Quote:
Originally Posted by playbox12
Посмотреть сообщение
That is really strange, as it should work, ask in the Y_Ini topic, or PM ****** as he is the author of yini.

(this works for me, I use mysql, I hear from other people using dini that this is how they do it aswell).
Yes I tried everything you just mentioned for like 4 times :P
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
There is simply no reason why this should be the case! Are you CERTAIN that it's not taking new values? And more to the point are you CERTAIN that the code to store the new values is not called? Could you post full example code which shows this issue, including any files you are attempting to load?
Sure, here:

Gamemode
pawn Код:
#define COLOR_WHITE         0xFFFFFFFF

#include <a_samp>
#include <YSI/y_ini>
#include "../include/loginsystem.inc"

main()
{
    print("AnteinoServer started.");
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(GetPVarInt(playerid, "logstatus") == 0){
        SendClientMessage(playerid, COLOR_WHITE, "SERVER: Kicked for teleporting from login.");
        Kick(playerid);
        return 1;
    }
    SetPlayerPos(playerid, 1754.0000, -1893.9800, 14.5000);
    SetPlayerFacingAngle(playerid, 270);
    SetCameraBehindPlayer(playerid);
    return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
   return 1;
}

SetupPlayerForClassSelection(playerid)
{
    PlayerPlaySound(playerid,1052,0.0,0.0,0.0);
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetupPlayerForClassSelection(playerid);
    return 1;
}

public OnGameModeInit()
{
    SetGameModeText("Amsterdam Roleplay");
    ShowPlayerMarkers(1);
    ShowNameTags(1);
    EnableStuntBonusForAll(0);
    return 1;
}
The included "../include/loginsystem.inc"
pawn Код:
new PlayerName[MAX_PLAYERS][MAX_PLAYER_NAME], Password[MAX_PLAYERS][MAX_PASSWORD], gPass[MAX_PASSWORD];

INI:playerlist[](playerid, name[], value[])
{
    INI_String(PlayerName[playerid], gPass, 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[...
    strpack(Password[playerid], gPass);
    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(Password[playerid], inputtext, 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;
}
and the file named playerlist.ini
pawn Код:
Max_Havelaar = mypass
Har_Levis = mypass3
Lead_Admin = mypass67
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)