Y-INI help
#1

Hello everyone.
I am working on my login/register system using y_ini and whirlpool.
I have seen that many scripts use this to load the file when the player connects:
pawn Код:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
But by using that line, it will load the whole file, right? Because I only need to load the string from the "password" field in the file. Not stuff like weapons and health etc.
What is the best way to do that?

Hope you can help. Thanks.
Reply
#2

INI_ParseFile doesn't load the whole file.. You properly don't know how to use it.. Example
pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    new String[50]; format(String, sizeof(String), "Users/%s.ini", GetName(playerid));
    INI_ParseFile(String, "LoadPlayerData", .bExtra = true, .extra = playerid);
    return 1;
}

forward LoadPlayerData(playerid, name[], value[]);
public LoadPlayerData(playerid, name[], value[])
{
    INI_String("password", pInfo[playerid][Password], 128); //That will only load "Password" and put it in pInfo[playerid][Password];
    return 1;
}
I don't know if there is a way to load just one field.. I use y_INI and I use parsefile to get any value, even if it was only one..
Reply
#3

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
INI_ParseFile doesn't load the whole file.. You properly don't know how to use it.. Example
pawn Код:
public OnPlayerConnect(playerid)
{
        new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    new String[50]; format(String, sizeof(String), "Users/%s.ini", GetName(playerid));
    INI_ParseFile(String, "LoadPlayerData", .bExtra = true, .extra = playerid);
        return 1;
}

forward LoadPlayerData(playerid, name[], value[]);
public LoadPlayerData(playerid, name[], value[])
{
    INI_String("password", pInfo[playerid][Password], 128);
    return 1;
}
I don't know if there is a way to load just one field.. I use y_INI and I use parsefile to get any value, even if it was only one..
So the code in your example will only load the password, because that is the only parameter you added in your function "LoadPlayerData" right?
Reply
#4

Quote:
Originally Posted by sim_sima
Посмотреть сообщение
So the code in your example will only load the password, because that is the only parameter you added in your function "LoadPlayerData" right?
Yes!
Reply
#5

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
Yes!
Alright, thanks.
But can you tell me what .bExtra and .extra means?
Reply
#6

I got a new problem. Why doesn't this work?
pawn Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_String("password",PlayerInfo[playerid][pPassword], sizeof(PlayerInfo[playerid][pPassword]));
    return 1;
}
I get this error when compiling:
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.

The password in the ini file is hashed with whirlpool, and is 128 characters long.
Reply
#7

Write the real size instead of sizeof. I think you cannot do like that with enums and sizeof's of your enums.
Reply
#8

I did this in stead:
pawn Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    new buf[129];
    INI_String("password", buf, sizeof(buf));
    PlayerInfo[playerid][pPassword] = strval(buf);
    return 1;
}
And in OnPlayerConnect:
pawn Код:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
And when the login dialog responds in OnDialogRespond:
pawn Код:
new buf[129];
if (WP_Hash(buf, sizeof(buf), inputtext) != PlayerInfo[playerid][pPassword])
{
    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!");
}
It does not give any errors when I compile, but no matter what password I type when logging in, I get logged in.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)