[HASH AND Y_INI] A couple of questions and problems
#1

Alright, I got a couple of questions -

1. I'm trying to create an achievements system, and here's how I am planning to do it [Y_INI] -

Suppose it's an achievement for getting 250+ kills
I'll check if the var 'AchName_250KILLS' is set to ONE in the file, which will indicate the player ALREADY has the achievement
If that var is NOT 1 and player's kills are 250, it means he has earned a new achievement.

I'm trying to read only ONE variable from the player's file, And INI_ParseFile loads all data, which I don't want to.
Any idea how I can execute my plan without loading all the data? My anti-cheats is kind of delicate, and I don't want players to lose money/score.


2. My hash system is a little bugged.
This is sort of a complicated problem.

Alright, -
1. On player register, I hash their passwords and save them into a file
2. I /q and I come back, password works fine
3. I CLOSE SAMP-SERVER.EXE AND START IT AGAIN TO LOAD SOME NEW UPDATES, and the OLD PASSWORD DOESN'T WORK!

I did some debugging too, here are the results -

pawn Код:
[18:46:12] Incoming connection: 127.0.0.1:65185
[18:46:12] [join] [A]Gangs has joined the server (1:127.0.0.1)
[18:46:16] [REGISTERED] [A]Gangs registered with pass testing [Hashed - 203293439]
[18:51:17] [part] [A]Gangs has left the server (1:1)
[18:51:26] --- Server Shutting Down.

[18:51:47] [join] [A]Gangs has joined the server (1:127.0.0.1)
[18:51:48] [LOGIN] Fail login of [A]Gangs with password testing [Hashed - 203293439]
[19:14:12] [LOGIN] Fail login of [A]Gangs with password testing [Hashed - 203293439]
[19:14:13] [LOGIN] Fail login of [A]Gangs with password testing [Hashed - 203293439]
[19:14:14] [LOGIN] Fail login of [A]Gangs with password testing [Hashed - 203293439]
[19:14:15] [LOGIN] Fail login of [A]Gangs with password testing [Hashed - 203293439]
[19:14:16] [LOGIN] Fail login of [A]Gangs with password testing [Hashed - 203293439]
I DID check if the player's password is same in the file, and it is!

Here is my check for checking player's password
pawn Код:
case DIALOG_LOGIN:
        {
            if (!response) return Kick (playerid);
            if(response)
            {
                if(udb_hash(inputtext) == pInfo[playerid][Password])
                {
                    INI_ParseFile(getini(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, pInfo[playerid][Money]);
                    printf("[LOGIN] Success login of %s with password %s [Hashed - %d] ", pname(playerid), inputtext, udb_hash(inputtext) );
                    ShowPlayerDialog(playerid, DIALOG_LOGIN_SUCCESS, DIALOG_STYLE_MSGBOX,"Success!","You have successfully logged in!","Ok","");
                }
                else
                {
                    printf("[LOGIN] Fail login of %s with password %s [Hashed - %d] ", pname(playerid), inputtext, udb_hash(inputtext) );
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 1;
            }
I am also doing this OnPlayerConnect to load pInfo[playerid][Password] -

pawn Код:
if(fexist(getbanini(playerid)))
        {
            SendClientMessage(playerid, RED, "[ERROR] You're banned! Stop ban evading! ");
            KickEx(playerid);
        }
        else
        {
            if(fexist(getini(playerid)))
            {
                INI_ParseFile(getini(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","Type your password below to login.","Login","Quit");
            }
            else
            {
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Registering...","Type your password below to register a new account.","Register","Quit");
                SendClientMessage(playerid, CYAN, "[SeRbErSShSHhs] W3lcUm t0 d4 sErVer");
            }
And here's my LoadUser functoin

pawn Код:
stock LoadUser_data(pid,name[],value[])
{
    INI_Int("Password",pInfo[pid][Password]);
    INI_Int("Money",pInfo[pid][Money]);
    INI_Int("AdminLevel",pInfo[pid][ALevel]);
    INI_Int("VIPLevel", pInfo[pid][VIPLevel]);
    INI_Int("Kills",pInfo[pid][Kills]);
    INI_Int("Deaths",pInfo[pid][Deaths]);
    INI_Int("Helper", pInfo[pid][Helper]);
    INI_Int("Password", pInfo[pid][Helper]);
    INI_Int("Experience", pInfo[pid][Experience]);
    INI_Int("Banned", pInfo[pid][Banned]);
    return 1;
}
Reply
#2

Quote:

I'm trying to read only ONE variable from the player's file, And INI_ParseFile loads all data, which I don't want to.

1. And this is what sets apart a good file system from a dini one (whoops mean't bad).

Quote:
Originally Posted by ******
I intend to add the option to load individual values later, but there's rarely any need if you do things properly
Reading and writing information are all here, https://sampforum.blast.hk/showthread.php?tid=175565. If you truly want help, let us see what you've attempted first (concept is OK).

2. debug info doesn't show this step
Quote:

I /q and I come back, password works fine

assuming you followed this tutorial, show your data for registration.
Reply
#3

Quote:
Originally Posted by arbit
Посмотреть сообщение
1. And this is what sets apart a good file system from a dini one (whoops mean't bad).



Reading and writing information are all here, https://sampforum.blast.hk/showthread.php?tid=175565. If you truly want help, let us see what you've attempted first (concept is OK).

2. debug info doesn't show this step

assuming you followed this tutorial, show your data for registration.
2. Debug info doesn't show the /Q thing, I can paste the full logs if you want!


I cannot paste the already-in-work code till now of achievements system, since I haven't begun.
Wait, Should I do this -

1. Create a seperate data tag for achievements
2. Create a function to load the var tags from that INI tag WITHOUT reading the [data], only reading [achievements]?


pawn Код:
stock RegisterUser(pid, pass)
{
    if(fexist(getini(pid))) return 0;
    if(!IsPlayerConnected(pid)) return 0;
    else
    {
        new INI:uh = INI_Open(getini(pid));
        INI_SetTag(uh, "data");
        INI_WriteString(uh, "Name", pname(pid) );
        INI_WriteString(uh, "IP", pip(pid) );
        INI_WriteInt(uh, "Password", pass);
        pInfo[pid][Password] = pass;
        INI_WriteInt(uh, "Kills", pInfo[pid][Kills]);
        INI_WriteInt(uh, "Deaths", pInfo[pid][Deaths]);
        INI_WriteInt(uh, "Experience", pInfo[pid][Experience]);
        INI_WriteInt(uh, "Helper", pInfo[pid][Helper]);
        INI_WriteInt(uh, "AdminLevel", pInfo[pid][ALevel]);
        INI_WriteInt(uh, "VIPLevel", pInfo[pid][VIPLevel]);
        INI_WriteInt(uh, "Banned", 0);
        INI_Close(uh);
    }
    return 1;
}

stock SaveUser(pid)
{
    if(!fexist(getini(pid))) return 0;
    if(!IsPlayerConnected(pid)) return 0;
    else
    {
        new INI:uh = INI_Open(getini(pid));
        INI_SetTag(uh, "data");
        INI_WriteString(uh, "Name", pname(pid) );
        INI_WriteString(uh, "IP", pInfo[pid][IP] );
        INI_WriteInt(uh, "Password", pInfo[pid][Password]);
        INI_WriteInt(uh, "Kills", pInfo[pid][Kills]);
        INI_WriteInt(uh, "Deaths", pInfo[pid][Deaths]);
        INI_WriteInt(uh, "Experience", pInfo[pid][Experience]);
        INI_WriteInt(uh, "Money", pInfo[pid][Money]);
        INI_WriteInt(uh, "Helper", pInfo[pid][Helper]);
        INI_WriteInt(uh, "AdminLevel", pInfo[pid][ALevel]);
        INI_WriteInt(uh, "VIPLevel", pInfo[pid][VIPLevel]);
        INI_WriteInt(uh, "Banned", pInfo[pid][Banned]);
        INI_Close(uh);
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by CreativityLacker
Посмотреть сообщение
1. Create a seperate data tag for achievements
2. Create a function to load the var tags from that INI tag WITHOUT reading the [data], only reading [achievements]?
if you plan on having multiple achievments creating a separate tag would work (as intended?) (y_ini's beauty i say). If you list everything under one tag, just read the data and store it for further use.

quick tip -> it'd be best to ONLY save frequently changing data (health, positions etc.) when disconnecting and the rest when modified (then and there). This way, you know certain data will ALWAYS save (the semi-important ones) and as for ones that may change constantly are not likely as important.
Reply
#5

Quote:
Originally Posted by arbit
Посмотреть сообщение
if you plan on having multiple achievments creating a separate tag would work (as intended?) (y_ini's beauty i say). If you list everything under one tag, just read the data and store it for further use.

quick tip -> it'd be best to ONLY save frequently changing data (health, positions etc.) when disconnecting and the rest when modified (then and there). This way, you know certain data will ALWAYS save (the semi-important ones) and as for ones that may change constantly are not likely as important.
I got it, but I just need your help in the hash and one last thing -

Currently, to load the user's shit , I'm using

pawn Код:
INI_ParseFile(getini(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);

stock LoadUser_data(pid,name[],value[])
{
    INI_Int("Password",pInfo[pid][Password]);
    INI_Int("Money",pInfo[pid][Money]);
    INI_Int("AdminLevel",pInfo[pid][ALevel]);
    INI_Int("VIPLevel", pInfo[pid][VIPLevel]);
    INI_Int("Kills",pInfo[pid][Kills]);
    INI_Int("Deaths",pInfo[pid][Deaths]);
    INI_Int("Helper", pInfo[pid][Helper]);
    INI_Int("Password", pInfo[pid][Helper]);
    INI_Int("Experience", pInfo[pid][Experience]);
    INI_Int("Banned", pInfo[pid][Banned]);
    return 1;
}
What do I have to change in this to ONLY read [data] tag and what do I have to do in order to create loading for only [achievements] tag?
Reply
#6

recommended: check out whirlpool.

what you already have will load the data. as for individual tags,

Код:
INI:filename[achievements](name[], value[])
{
    //code
}
i suggest taking a look at these 2 threads (a, b)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)