Loading data with Y_INI
#1

Well this was pretty much written as a comment in a threat, but it doesn't seem like people scroll all the way down and read it.
I am working on a login/register system, using y_ini and whirlpool.
My current code is like this:

On top of the script:
pawn Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("Password", PlayerInfo[playerid][pPassword], 129);
    return 1;
}

stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),"Accounts/%s.ini",playername);
    return string;
}
OnPlayerConnect:
pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    if(!fexist(UserPath(playerid)))
    {
        new string[367 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is not registered. Please enter a Password to Register",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        format(string, sizeof(string), "{FFFF00}Requested username: {FFFFFF}%s\nThis username is: {009900}Available\n\n{AF0000}We suggest that you don't register\nwith an RP name (Firstname_Lastname)\nbecause you can manage multiple\ncharacters from one account.\nThe name you register now will not\nbe your in-game name.\n\n{FFFFFF}By registering,\nyou agree to our terms of use.\n\n{FFFF00}Enter a Password to register",name);
        ShowPlayerDialog(playerid, MENU_REGISTER, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Register", "Quit");
    }
    else
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        new string[80 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is already registered. Please log in with your Password",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        SendClientMessage(playerid, COLOR_GREY, "-MSG- Not your account? Then relog with another name");
        format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\nEnter your Password to log in",name);
        ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
    }
    return 1;
}
OnDialogResponse - when the login dialog responds:
pawn Код:
case MENU_LOGIN:
        {
            if (!response)
            {
                SendClientMessage(playerid, COLOR_DARKRED, "-MSG- You must log in in order to play on this server");
                Kick(playerid);
            }
            else
            {
                new buf[129];
                WP_Hash(buf, sizeof(buf), inputtext);
                if(!strcmp(buf, PlayerInfoInfo[playerid][pPassword], false))
                {
                    new string[80 + MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, name, sizeof(name));
                    format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\n{AF0000}Incorrect password!\n\n{FFFF00}Enter your Password to log in",name);
                    ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREEN, "-MSG- Welcome back!");
                }
            }
        }
When I compile, I get this error:
Quote:

C:\Users\Simon\Desktop\Ny mappe (3)\gamemodes\RP.pwn(6) : warning 201: redefinition of constant/macro (symbol "MAX_INI_ENTRY_TEXT")
C:\Users\Simon\Desktop\Ny mappe (3)\gamemodes\RP.pwn(32) : error 001: expected token: ")", but found "["
C:\Users\Simon\Desktop\Ny mappe (3)\gamemodes\RP.pwn(32) : warning 215: expression has no effect
C:\Users\Simon\Desktop\Ny mappe (3)\gamemodes\RP.pwn(32) : error 001: expected token: ";", but found "]"
C:\Users\Simon\Desktop\Ny mappe (3)\gamemodes\RP.pwn(32) : error 029: invalid expression, assumed zero
C:\Users\Simon\Desktop\Ny mappe (3)\gamemodes\RP.pwn(32) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.

Line 32 is this line:
pawn Код:
INI_String("Password", PlayerInfo[playerid][pPassword], 129);
To me, those errors makes no sense. Hope someone can help me. Thanks
Reply
#2

Код:
INI_String("Password", PlayerInfo[playerid][pPassword]);
Try this. I'm not sure it will work.
Reply
#3

Quote:
Originally Posted by dakata994
Посмотреть сообщение
Код:
INI_String("Password", PlayerInfo[playerid][pPassword]);
Try this. I'm not sure it will work.
Doesn't work. The 129 has to be there anyways, because that is the length.
Reply
#4

This?
Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPassword]);
    return 1;
}
You don't need string
Reply
#5

Quote:
Originally Posted by dakata994
Посмотреть сообщение
This?
Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPassword]);
    return 1;
}
You don't need string
Mayne, you are teaching him a wrong stuff....

pawn Код:
#include <a_samp>
#include <YSI\y_ini>

#define MENU_LOGIN 0
#define MENU_REGISTER 1

#define COLOR_YELLOW -1
#define COLOR_GREY -1
#define COLOR_GREEN -1
#define COLOR_DARKRED -1

native WP_Hash(buffer[],len,const str[]);

enum pInfo
{
    pPassword[129]
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("Password", PlayerInfo[playerid][pPassword], 129);
    return 1;
}

stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),"Accounts/%s.ini",playername);
    return string;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    if(!fexist(UserPath(playerid)))
    {
        new string[367 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is not registered. Please enter a Password to Register",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        format(string, sizeof(string), "{FFFF00}Requested username: {FFFFFF}%s\nThis username is: {009900}Available\n\n{AF0000}We suggest that you don't register\nwith an RP name (Firstname_Lastname)\nbecause you can manage multiple\ncharacters from one account.\nThe name you register now will not\nbe your in-game name.\n\n{FFFFFF}By registering,\nyou agree to our terms of use.\n\n{FFFF00}Enter a Password to register",name);
        ShowPlayerDialog(playerid, MENU_REGISTER, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Register", "Quit");
    }
    else
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        new string[80 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is already registered. Please log in with your Password",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        SendClientMessage(playerid, COLOR_GREY, "-MSG- Not your account? Then relog with another name");
        format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\nEnter your Password to log in",name);
        ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case MENU_LOGIN:
        {
            if (!response)
            {
                SendClientMessage(playerid, COLOR_DARKRED, "-MSG- You must log in in order to play on this server");
                Kick(playerid);
            }
            else
            {
                new buf[129];
                WP_Hash(buf, sizeof(buf), inputtext);
                if(!strcmp(buf, PlayerInfo[playerid][pPassword], false))
                {
                    new string[80 + MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, name, sizeof(name));
                    format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\n{AF0000}Incorrect password!\n\n{FFFF00}Enter your Password to log in",name);
                    ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREEN, "-MSG- Welcome back!");
                }
            }
        }
        case MENU_REGISTER:
        {
            // code .....
        }
    }
    return true;
}
Compilation
Код:
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:           2700 bytes
Code size:            64420 bytes
Data size:         17057772 bytes
Stack/heap size:      16384 bytes; estimated max. usage: unknown, due to recursion
Total requirements:17141276 bytes
[Finished in 6.1s]
The problem is you have an outdated YSI version, update it and your code should work fine

Lastest Update: https://sampforum.blast.hk/showthread.php?tid=321092
Reply
#6

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
Mayne, you are teaching him a wrong stuff....

pawn Код:
#include <a_samp>
#include <YSI\y_ini>

#define MENU_LOGIN 0
#define MENU_REGISTER 1

#define COLOR_YELLOW -1
#define COLOR_GREY -1
#define COLOR_GREEN -1
#define COLOR_DARKRED -1

native WP_Hash(buffer[],len,const str[]);

enum pInfo
{
    pPassword[129]
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("Password", PlayerInfo[playerid][pPassword], 129);
    return 1;
}

stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),"Accounts/%s.ini",playername);
    return string;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    if(!fexist(UserPath(playerid)))
    {
        new string[367 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is not registered. Please enter a Password to Register",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        format(string, sizeof(string), "{FFFF00}Requested username: {FFFFFF}%s\nThis username is: {009900}Available\n\n{AF0000}We suggest that you don't register\nwith an RP name (Firstname_Lastname)\nbecause you can manage multiple\ncharacters from one account.\nThe name you register now will not\nbe your in-game name.\n\n{FFFFFF}By registering,\nyou agree to our terms of use.\n\n{FFFF00}Enter a Password to register",name);
        ShowPlayerDialog(playerid, MENU_REGISTER, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Register", "Quit");
    }
    else
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        new string[80 + MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "-MSG- The username '%s' is already registered. Please log in with your Password",name);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        SendClientMessage(playerid, COLOR_GREY, "-MSG- Not your account? Then relog with another name");
        format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\nEnter your Password to log in",name);
        ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case MENU_LOGIN:
        {
            if (!response)
            {
                SendClientMessage(playerid, COLOR_DARKRED, "-MSG- You must log in in order to play on this server");
                Kick(playerid);
            }
            else
            {
                new buf[129];
                WP_Hash(buf, sizeof(buf), inputtext);
                if(!strcmp(buf, PlayerInfo[playerid][pPassword], false))
                {
                    new string[80 + MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, name, sizeof(name));
                    format(string, sizeof(string), "{FFFF00}Your username: {FFFFFF}%s\n\n{AF0000}Incorrect password!\n\n{FFFF00}Enter your Password to log in",name);
                    ShowPlayerDialog(playerid, MENU_LOGIN, DIALOG_STYLE_PASSWORD, "Hopes Hills RP Account", string, "Login", "Quit");
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREEN, "-MSG- Welcome back!");
                }
            }
        }
        case MENU_REGISTER:
        {
            // code .....
        }
    }
    return true;
}
Compilation
Код:
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:           2700 bytes
Code size:            64420 bytes
Data size:         17057772 bytes
Stack/heap size:      16384 bytes; estimated max. usage: unknown, due to recursion
Total requirements:17141276 bytes
[Finished in 6.1s]
The problem is you have an outdated YSI version, update it and your code should work fine

Lastest Update: https://sampforum.blast.hk/showthread.php?tid=321092
Thank you. But I still get the errors... Strange
Reply
#7

You're loading a STRING value from the file using y_ini's interger parsing....

It should be INI_String

EDIT: I saw you already fixed it, I'll post my loading process below, as your's is a bit different than mine, although my scripts use MySQL, y_ini is a backup account system, so please forgive me if the code isn't "up-to-date" and optimized

pawn Код:
#define Userpath "Admin System/Users/%s.txt"
#define INI_Exists(%0) fexist(%0)
#define INI_Bit(%1,%3,%2,%4) if(!strcmp((%1),name,true)) return boolstr(value) ? BitGive(%3,%2,%4) : BitTake(%3,%2,%4)
#define INI_WriteBit(%1,%2,%3,%4,%5) INI_AddToBuffer(%1, %2, BitCheck(%3, %4, %5) ? ("true") : ("false"))
//Under my OnPlayerConnect
    if(INI_Exists(Path(playerid)))//Check
    {
        INI_ParseFile(Path(playerid), "loadaccount_%s", .bExtra = true, .extra = playerid);
        if(!strcmp(IPCheck,pInfo[playerid][pIP], true))//Let's check his IP, if it matches, let's automatically log the player in!
        {
            //IPs match
        }
        else
        {
            //IPs don't match
        }
    }
    else
    {
        //Player has no account, put register code here
        }

forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    new count = GetTickCount();
    INI_String("Password", pInfo[playerid][pPass],129);
    INI_Int("AdminLevel",pInfo[playerid][pAdmin]);
    INI_String("IP", pInfo[playerid][pIP], 16);
    INI_Int("Money",pInfo[playerid][pMoney]);
    INI_Int("Score",pInfo[playerid][pScore]);
    INI_Int("Warnings", pInfo[playerid][pWarns]);
    INI_Int("Kills", pInfo[playerid][pKills]);
    INI_Int("Deaths", pInfo[playerid][pDeaths]);
    INI_Int("DonatorLevel", pInfo[playerid][pDonated]);
    INI_Int("CommandSpam", pInfo[playerid][pLastCommand]);
    INI_Int("Muted", pInfo[playerid][pMuted]);
    INI_Int("HelperLevel", pInfo[playerid][bLevel]);
    INI_Int("OnlineTime", pInfo[playerid][pTime]);//Online time stored in seconds, which is divided upon connection!
    INI_Int("PlayerColor", pInfo[playerid][pColor]);
    INI_Int("VIPChatColor", pInfo[playerid][pVIPChatColor]);
    INI_String("Country", pInfo[playerid][pCountry], 90);
    INI_String("ISP", pInfo[playerid][pISP], 90);
    INI_String("City", pInfo[playerid][pCity], 90);
   
    printf("[CUSTOM CALLBACK] loadaccount_user: Firing callback took %d milliseconds!", GetTickCount() - count);
    return 1;
}
Reply
#8

Quote:
Originally Posted by sim_sima
Посмотреть сообщение
Thank you. But I still get the errors... Strange
Did you try mine ? If you tried and it won't work try this:
Код:
// ------- Accounts ------//

#define PATH "/Users/%s.ini"
#define DIALOG_REGISTER 1
enum pInfo
{

    pPassword

}


public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPassword]);
    return 1;
}

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


stock udb_hash(buf[]) {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}



public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Authentication","{FFFFFF}Wellcome back to {FF0000} CHANGE IT \n{FFFFFF}Type your password to Login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Authentication","{FFFFFF}Wellcome to {FF0000}CHANGE IT \n{FFFFFF}Type your password to Register.","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)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_Close(File);
			}
        }
        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);
                    SpawnPlayer(playerid);
                }
                else
                {
                    Kick(playerid);
                }
                return 1;
            }
        }
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by Sgt.TheDarkness
Посмотреть сообщение
You're loading a STRING value from the file using y_ini's interger parsing....

It should be INI_String
This line
pawn Код:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
is not the problem.

This line:
pawn Код:
INI_String("Password", PlayerInfo[playerid][pPassword], 129);
is the problem.
If you are refering to this line, then yes, I am using INI_String.
Reply
#10

Quote:
Originally Posted by dakata994
Посмотреть сообщение
Did you try mine ? If you tried and it won't work try this:
Код:
// ------- Accounts ------//

#define PATH "/Users/%s.ini"
#define DIALOG_REGISTER 1
enum pInfo
{

    pPassword

}


public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPassword]);
    return 1;
}

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


stock udb_hash(buf[]) {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}



public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Authentication","{FFFFFF}Wellcome back to {FF0000} CHANGE IT \n{FFFFFF}Type your password to Login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Authentication","{FFFFFF}Wellcome to {FF0000}CHANGE IT \n{FFFFFF}Type your password to Register.","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)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_Close(File);
			}
        }
        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);
                    SpawnPlayer(playerid);
                }
                else
                {
                    Kick(playerid);
                }
                return 1;
            }
        }
    }
    return 1;
}
I am not using udb_hash, I am using Whirlpool. It works differently, which means that the password hash is a string, and that is why I have to use INI_String in stead of INI_Int, unfortunately
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)