INI Help.
#1

Hi all,

I've managed to get the y_ini account saving working, but now, it writes in the file, but when I connect and I have the Admin = 1 in the .ini file, it doesn't load it, nor does it load anything else.


My CheckAccount stock.
Код:
stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}
stock CheckAccount(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"{00FF00}Login","{FFFFFF}Account status:{00FF00} REGISTERED\n{FFFFFF}Put your password to login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"{00FF00}Register","{FFFFFF}Account status:{FF0000} NOT-REGISTERED\n{FFFFFF}Put your desired password to register.","Register","Quit");
    }
	return 1;
}
LoadUserData stock.
Код:
forward loadUserData(playerid,name[],value[]);
public loadUserData(playerid,name[],value[])
{
    INI_Int("Key", PlayerInfo[playerid][pKey]);
    INI_Int("Admin", PlayerInfo[playerid][pAdmin]);
    INI_Int("Banned", PlayerInfo[playerid][pBanned]);
    INI_Int("PermBand", PlayerInfo[playerid][pPermBand]);
    INI_Int("BanReason", PlayerInfo[playerid][pBanReason]);
    INI_Int("PrisonReason", PlayerInfo[playerid][pPrisonReason]);
	INI_Int("AdminJailed", PlayerInfo[playerid][pAdminJailed]);
	INI_Int("PrisonedBy", PlayerInfo[playerid][pPrisonedBy]);
	INI_Int("Donor", PlayerInfo[playerid][pDonor]);
	INI_Int("XP", PlayerInfo[playerid][pExp]);
	INI_Int("Cash", PlayerInfo[playerid][pCash]);
    INI_Int("Kills", PlayerInfo[playerid][pKills]);
    INI_Int("Deaths", PlayerInfo[playerid][pDeaths]);
    INI_Int("Skin", PlayerInfo[playerid][pSkin]);
	INI_Int("Tikis", PlayerInfo[playerid][pTikis]);
    INI_Int("MinigunAccess", PlayerInfo[playerid][pMinigunAccess]);
    return 1;
}
SaveAccount stock
Код:
stock SaveAccount(playerid)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File, "data");
    INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File, "Banned", PlayerInfo[playerid][pBanned]);
    INI_WriteInt(File, "PermBand", PlayerInfo[playerid][pPermBand]);
    INI_WriteInt(File, "BanReason", PlayerInfo[playerid][pBanReason]);
    INI_WriteInt(File, "PrisonReason", PlayerInfo[playerid][pPrisonReason]);
    INI_WriteInt(File, "AdminJailed", PlayerInfo[playerid][pAdminJailed]);
    INI_WriteInt(File, "PrisonedBy",PlayerInfo[playerid][pPrisonedBy]);
    INI_WriteInt(File, "Donor",PlayerInfo[playerid][pDonor]);
    INI_WriteInt(File, "XP", PlayerInfo[playerid][pExp]);
    INI_WriteInt(File, "Cash", GetPlayerMoney(playerid));
    INI_WriteInt(File, "Kills", PlayerInfo[playerid][pKills]);
    INI_WriteInt(File, "Deaths", PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File, "Skin", PlayerInfo[playerid][pSkin]);
    INI_WriteInt(File, "Tikis", PlayerInfo[playerid][pTikis]);
    INI_WriteInt(File, "MinigunAccess", PlayerInfo[playerid][pMinigunAccess]);
    INI_Close(File);
    return 1;
}
OnPlayerDisconnect
Код:
public OnPlayerDisconnect(playerid, reason)
{
	new string[512];
	SaveAccount(playerid);
	if(reason == 0)
	{
		format(string, 256, "{00BFFF}%s{FFFFFF}has left the server. Reason:{00BFFF}Timeout{FFFFFF}", PlayerName(playerid));
		SendClientMessageToAll(-1, string);
	}
	else if(reason == 1)
	{
	    format(string, 256, "{00BFFF}%s{FFFFFF}has left the server. Reason:{00BFFF}Quit{FFFFFF}", PlayerName(playerid));
	    SendClientMessageToAll(-1, string);
	}
	else if(reason == 2)
	{
	    format(string, 256, "{00BFFF}%s{FFFFFF}has left the server. Reason:{00BFFF}Kicked/Banned{FFFFFF}", PlayerName(playerid));
	    SendClientMessageToAll(-1, string);
	}
	PlayerInfo[playerid][pAdmin] = 0;
	PlayerInfo[playerid][pBanned] = 0;
	PlayerInfo[playerid][pPermBand] = 0;
	PlayerInfo[playerid][pBanReason] = 0;
	PlayerInfo[playerid][pPrisonReason] = 0;
	PlayerInfo[playerid][pAdminJailed] = 0;
	PlayerInfo[playerid][pPrisonedBy] = 0;
	PlayerInfo[playerid][pDonor] = 0;
	PlayerInfo[playerid][pExp] = 0;
	PlayerInfo[playerid][pCash] = 0;
	PlayerInfo[playerid][pKills] = 0;
	PlayerInfo[playerid][pDeaths] = 0;
	PlayerInfo[playerid][pSkin] = 0;
	PlayerInfo[playerid][pTikis] = 0;
	PlayerInfo[playerid][pMinigunAccess] = 0;
	return 1;
}
Register & Login dialogs.
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
		case DIALOG_REGISTER:
        {
            if (!response) return PKick(playerid);
            if(response)
            {
                WP_Hash(PlayerInfo[playerid][pKey], 129, inputtext);
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFFFF}Registering...","{FF0000}You have entered an invalid password.\n{FFFFFF}Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteString(File, "Key", PlayerInfo[playerid][pKey]);
                INI_WriteInt(File, "Admin",0);
                INI_WriteInt(File, "Banned", 0);
                INI_WriteInt(File, "PermBand",0);
                INI_WriteInt(File, "BanReason",0);
                INI_WriteInt(File, "PrisonReason",0);
                INI_WriteInt(File, "AdminJailed",0);
                INI_WriteInt(File, "PrisonedBy",0);
                INI_WriteInt(File, "Donor",0);
                INI_WriteInt(File, "Exp", 0);
                INI_WriteInt(File, "Cash", 0);
    		    INI_WriteInt(File, "Kills",0);
        		INI_WriteInt(File, "Deaths", 0);
        		INI_WriteInt(File, "Skin", 0);
        		INI_WriteInt(File, "Tikis", 0);
        		INI_WriteInt(File, "MinigunAccess", 0);
                INI_Close(File);
			}
        }

		case DIALOG_LOGIN:
        {
            new pwhash[129];
            WP_Hash(pwhash, sizeof(pwhash), inputtext);
            if (!response) return PKick(playerid);
            if(response)
            {
                if(!strcmp(pwhash, PlayerInfo[playerid][pKey]))
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerScore(playerid, PlayerInfo[playerid][pExp]);
				}
     		}
       		else
         	{
          		SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this.");
				PKick(playerid);
     		}
			return 1;
		}
I don't know why it doesn't load it from loadUserData.

Anyone can help?
~Kevin
Reply
#2

Awww but I thought you are an INI expert :3

OT: You are not using the callback you created anywhere, why create a callback for a small function? just make a normal function and use it on the player login dialog.
Reply
#3

I have not worked with a Y_INI, but I think it is worth paying attention to these lines:


Код:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
Код:
forward loadUserData(playerid,name[],value[]);
public loadUserData(playerid,name[],value[])
From SA:MP Wiki:

Код:
INI_ParseFile("myfile.ini", "Callback_%s", .bFileFirst = true, .bPassTag = true);
 
public Callback_myfile_ini(tag[], identifier[], text[])
{
	if (!strcmp(tag, "some_tag"))
	{
		...
	}
}
My tip, try this (not tested):
Код:
INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid);
Reply
#4

Quote:
Originally Posted by DarkLored
Посмотреть сообщение
Awww but I thought you are an INI expert :3

OT: You are not using the callback you created anywhere, why create a callback for a small function? just make a normal function and use it on the player login dialog.
I never was an expert, you're making up your own quotes and thoughts.

I am using the callback loadUserData, on the DIALOG_LOGIN, as you see, INI_ParseFile blah blah loadUserData_%s
Reply
#5

Quote:
Originally Posted by povargek
Посмотреть сообщение
I have not worked with a Y_INI, but I think it is worth paying attention to these lines:


Код:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
Код:
forward loadUserData(playerid,name[],value[]);
public loadUserData(playerid,name[],value[])
From SA:MP Wiki:

Код:
INI_ParseFile("myfile.ini", "Callback_%s", .bFileFirst = true, .bPassTag = true);
 
public Callback_myfile_ini(tag[], identifier[], text[])
{
	if (!strcmp(tag, "some_tag"))
	{
		...
	}
}
My tip, try this (not tested):
Код:
INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid);
Oh wow, it worked, thanks. Althought, the password is now fucked. Whatever password I enter, it will log me in.

I'm using Whirlpool.

Код:
native WP_Hash(buffer[], len, const str[]);
Код:
case DIALOG_REGISTER:
        {
            if (!response) return PKick(playerid);
            if(response)
            {
                WP_Hash(PlayerInfo[playerid][pKey], 129, inputtext);
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFFFF}Registering...","{FF0000}You have entered an invalid password.\n{FFFFFF}Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteString(File, "Key", PlayerInfo[playerid][pKey]);
                INI_WriteInt(File, "Admin",0);
                INI_WriteInt(File, "Banned", 0);
                INI_WriteInt(File, "PermBand",0);
                INI_WriteInt(File, "BanReason",0);
                INI_WriteInt(File, "PrisonReason",0);
                INI_WriteInt(File, "AdminJailed",0);
                INI_WriteInt(File, "PrisonedBy",0);
                INI_WriteInt(File, "Donor",0);
                INI_WriteInt(File, "Exp", 0);
                INI_WriteInt(File, "Cash", 0);
    		    INI_WriteInt(File, "Kills",0);
        		INI_WriteInt(File, "Deaths", 0);
        		INI_WriteInt(File, "Skin", 0);
        		INI_WriteInt(File, "Tikis", 0);
        		INI_WriteInt(File, "MinigunAccess", 0);
                INI_Close(File);
			}
        }
Код:
case DIALOG_LOGIN:
        {
            new pwhash[129];
            WP_Hash(pwhash, sizeof(pwhash), inputtext);
            if (!response) return PKick(playerid);
            if(response)
            {
                if(!strcmp(pwhash, PlayerInfo[playerid][pKey]))
                {
                    INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerScore(playerid, PlayerInfo[playerid][pExp]);
				}
     		}
       		else
         	{
          		SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this.");
				PKick(playerid);
     		}
			return 1;
		}
Any idea what's wrong?
Reply
#6

Код:
case DIALOG_LOGIN:
        {
            new pwhash[129];
            WP_Hash(pwhash, sizeof(pwhash), inputtext);
            if (!response) return PKick(playerid);
            if(response)
            {
                if(!strcmp(pwhash, PlayerInfo[playerid][pKey]))
                {
                    INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerScore(playerid, PlayerInfo[playerid][pExp]);
				}
     		}
       		else
         	{
          		SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this.");
				PKick(playerid);
     		}
			return 1;
		}
You a check password, when the account is not loaded. The "PlayerInfo[playerid][pKey]" is empty.
Reply
#7

Quote:
Originally Posted by povargek
Посмотреть сообщение
Код:
case DIALOG_LOGIN:
        {
            new pwhash[129];
            WP_Hash(pwhash, sizeof(pwhash), inputtext);
            if (!response) return PKick(playerid);
            if(response)
            {
                if(!strcmp(pwhash, PlayerInfo[playerid][pKey]))
                {
                    INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerScore(playerid, PlayerInfo[playerid][pExp]);
				}
     		}
       		else
         	{
          		SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this.");
				PKick(playerid);
     		}
			return 1;
		}
You a check password, when the account is not loaded. The "PlayerInfo[playerid][pKey]" is empty.
So, can I get a fixed code bud?
Reply
#8

Quote:
Originally Posted by KevinExec
Посмотреть сообщение
So, can I get a fixed code bud?
Try this:

Код:
forward loadUserData(playerid,name[],value[]);
public loadUserData(playerid,name[],value[])
{
	new filepassword[129];
	INI_String("Password",filepassword,129);
	
	if(strcmp(filepassword, PlayerInfo[playerid][pKey], true) == 0)
	{
		//INI_Int("Key", PlayerInfo[playerid][pKey]); - password not is a integer!
		INI_Int("Admin", PlayerInfo[playerid][pAdmin]);
		INI_Int("Banned", PlayerInfo[playerid][pBanned]);
		INI_Int("PermBand", PlayerInfo[playerid][pPermBand]);
		INI_Int("BanReason", PlayerInfo[playerid][pBanReason]);
		INI_Int("PrisonReason", PlayerInfo[playerid][pPrisonReason]);
		INI_Int("AdminJailed", PlayerInfo[playerid][pAdminJailed]);
		INI_Int("PrisonedBy", PlayerInfo[playerid][pPrisonedBy]);
		INI_Int("Donor", PlayerInfo[playerid][pDonor]);
		INI_Int("XP", PlayerInfo[playerid][pExp]);
		INI_Int("Cash", PlayerInfo[playerid][pCash]);
		INI_Int("Kills", PlayerInfo[playerid][pKills]);
		INI_Int("Deaths", PlayerInfo[playerid][pDeaths]);
		INI_Int("Skin", PlayerInfo[playerid][pSkin]);
		INI_Int("Tikis", PlayerInfo[playerid][pTikis]);
		INI_Int("MinigunAccess", PlayerInfo[playerid][pMinigunAccess]);
	
		GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
		SetPlayerScore(playerid, PlayerInfo[playerid][pExp]);
	}
	else
	{
		SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this.");
		PKick(playerid);
	}
	return 1;
}

case DIALOG_LOGIN:
{
	new pwhash[129];
	WP_Hash(pwhash, sizeof(pwhash), inputtext);
	if (!response) return PKick(playerid);

	strmid(PlayerInfo[playerid][pKey], pwhash, 0, strlen(pwhash), 129);
	INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid);
	return 1;
}
UPD: You must check a player logged status on SaveAccount: If player disconnect on not logged status, account values set to default.

Example:

Код:
new gPlayerLogged[MAX_PLAYERS];

On OnPlyerConnect:

public OnPlyerConnect(playerid)
{
	gPlayerLogged[playerid] = 0;
	//code.....
	return 1;
}

On loadUserData:

public loadUserData(playerid,name[],value[])
{
	// code...
	
	if(strcmp(filepassword, PlayerInfo[playerid][pKey], true) == 0)
	{
		// code...
	
		GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
		SetPlayerScore(playerid, PlayerInfo[playerid][pExp]);
		
		gPlayerLogged[playerid] = 1;
	}
	else
	{
		// code...
	}
	return 1;
}

stock SaveAccount(playerid)
{
	if(gPlayerLogged[playerid])
	{
		new INI:File = INI_Open(UserPath(playerid));
		INI_SetTag(File, "data");
		INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
		INI_WriteInt(File, "Banned", PlayerInfo[playerid][pBanned]);
		INI_WriteInt(File, "PermBand", PlayerInfo[playerid][pPermBand]);
		INI_WriteInt(File, "BanReason", PlayerInfo[playerid][pBanReason]);
		INI_WriteInt(File, "PrisonReason", PlayerInfo[playerid][pPrisonReason]);
		INI_WriteInt(File, "AdminJailed", PlayerInfo[playerid][pAdminJailed]);
		INI_WriteInt(File, "PrisonedBy",PlayerInfo[playerid][pPrisonedBy]);
		INI_WriteInt(File, "Donor",PlayerInfo[playerid][pDonor]);
		INI_WriteInt(File, "XP", PlayerInfo[playerid][pExp]);
		INI_WriteInt(File, "Cash", GetPlayerMoney(playerid));
		INI_WriteInt(File, "Kills", PlayerInfo[playerid][pKills]);
		INI_WriteInt(File, "Deaths", PlayerInfo[playerid][pDeaths]);
		INI_WriteInt(File, "Skin", PlayerInfo[playerid][pSkin]);
		INI_WriteInt(File, "Tikis", PlayerInfo[playerid][pTikis]);
		INI_WriteInt(File, "MinigunAccess", PlayerInfo[playerid][pMinigunAccess]);
		INI_Close(File);
	}
    return 1;
}
Reply
#9

Won't work, gives 26 errors in total.
Reply
#10

Quote:
Originally Posted by KevinExec
Посмотреть сообщение
Won't work, gives 26 errors in total.
Show the errors, or send errors to PM me.

UPD:

I did not notice that the account load's in CheckAccount (where show a login dialog) (load's accounts before show for player a login dialog - very bad idea), and I saw this line:

Код:
INI_Int("Key", PlayerInfo[playerid][pKey]);
You keep your password as a string and load it as the number.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)