Reading a string from a file using Dini -
Homerman - 12.10.2011
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.
Re: Reading a string from a file using Dini -
Wesley221 - 12.10.2011
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
Re: Reading a string from a file using Dini -
Homerman - 13.10.2011
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").
Re: Reading a string from a file using Dini -
llama - 13.10.2011
pawn Код:
if(!strcmp(dini_Get(string, "Banned"), "Yes", true))
Should work IIRC.
Re: Reading a string from a file using Dini -
Homerman - 13.10.2011
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
Re: Reading a string from a file using Dini -
llama - 13.10.2011
pawn Код:
format(string, sizeof(string), "Bans\%s.ini", tmp);
Re: Reading a string from a file using Dini -
Homerman - 13.10.2011
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
Re: Reading a string from a file using Dini -
Homerman - 14.10.2011
Bump.
Re: Reading a string from a file using Dini -
llama - 14.10.2011
Post your /readfile command code.
Re: Reading a string from a file using Dini -
Homerman - 14.10.2011
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;
}