Reading a string from a file using Dini
#1

Hey.
I have a system that writes an info about IP being banned into a file using Dini, however I don't really know (yes, what a shame) how to read the written string afterwards and check if it matches with something.
For example, it will write "Banned=Yes", and I want to check if "Banned" is really "Yes" or "No".

I've got something like this:

Код:
new tmp2[100];
	GetPlayerIp(playerid,tmp2,100);
	format(string, sizeof(string), "Bans/%s.ini", tmp2);
	if(fexist(string))
	{
	    new tmp = dini_Get(string, "Banned");
		if(strcmp(tmp, "Yes.", true) == 0)
		{
			Kick(playerid);
		}
	}
But I guess the strcmp isn't right solution here. Any ideas?
Thank you in advance.
Reply
#2

pawn Код:
if( dini_Get(string, "Banned") == "yes" )
{
    // if 'Banned' in the file equals to 'yes'
}
else
{
    // if the player isnt banned, equals to 'no'
}
That will do it
Reply
#3

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
pawn Код:
if( dini_Get(string, "Banned") == "yes" )
{
    // if 'Banned' in the file equals to 'yes'
}
else
{
    // if the player isnt banned, equals to 'no'
}
That will do it
error 033: array must be indexed (variable "dini_Get").
Reply
#4

pawn Код:
if(!strcmp(dini_Get(string, "Banned"), "Yes", true))
Should work IIRC.
Reply
#5

Quote:
Originally Posted by llama
Посмотреть сообщение
pawn Код:
if(!strcmp(dini_Get(string, "Banned"), "Yes", true))
Should work IIRC.
Yes it does, thanks!
Now I have another problem with Dini... When I attempt to open an exact folder by typing a command (/readfile lol - which opens file lol.ini), it never opens, because the string I have:

format(string, sizeof(string), "Bans/%s.ini", strval(tmp));

attempts to open this: Bans/\lol.ini (it should be without the '\', otherwise it's fine).
Any more ideas? :S
Reply
#6

pawn Код:
format(string, sizeof(string), "Bans\%s.ini", tmp);
Reply
#7

That attempts to open "Bans\ol.ini" instead of lol.ini - one letter is missing as well as there is the \ instead of / (don't know if that is a real problem as well) :S
Reply
#8

Bump.
Reply
#9

Post your /readfile command code.
Reply
#10

It's an /unban command, and looks like this:

Код:
if(strcmp(cmd, "/unban", true) == 0)
    {
        if(IsPlayerConnected(playerid))
	    {
	        tmp = strtok(cmdtext,idx);
	        if(pAdmin[playerid] >= 1337)
	        {
	            if(!strlen(tmp))
				{
		    		SendClientMessage(playerid,COLOR_GREY,"USAGE: /unban [IP Adress]");
		    		return 1;
				}
				format(string, sizeof(string), "Bans\%s.ini", strval(tmp));
				SendClientMessage(playerid, COLOR_OTHER, string);
				if(fexist(string))
				{
					if(!fexist(string)) { dini_Create(string); }
				 	dini_Set(string, "Banned", "No.");
				    SendClientMessage(playerid, COLOR_OTHER, "[OOC] The IP has been successfully unbanned.");
			    }
			    else
			    {
			        SendClientMessage(playerid, COLOR_OTHER, "[OOC] That IP was not banned (yet).");
			    }
            }else{
			SendClientMessage(playerid, COLOR_GREY, "* You need an higher level to use this command!");
			}
		}
		return 1;
	}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)