PDA

View Full Version : Loading an ip in y_ini


newbienoob
03/04/2013, 06:55 AM
How to load a string in y_ini from user files? I have this


CMD:unban(playerid, params[])
{
new name[24],str[128];
if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, -1, ""herror" Usage: /unban [Player name]");
format(str,sizeof(str),UserPath,name);
if(!fexist(str)) return SendClientMessage(playerid, red, "Player is not banned/found!");
new INI:file = INI_Open(str);
INI_SetTag(file,"PlayerData");
INI_WriteInt(file,"Banned",0);
INI_Close(file);
INI_ParseFile(str, "loadip", .bExtra = true, .extra = playerid);
format(str,sizeof(str),""hpurple"* Admin %s(%d) has unbanned %s.", PlayerName(playerid),playerid,name);
foreach(new i: Player)
{
if(pInfo[i][Admin] >= 1)
{
SendClientMessage(i, -1, str);
}
}
return 1;
}


forward loadip(name[],value[]);
public loadip(name[],value[])
{
new ip[16], str[50];
INI_String("IP",ip,16);
SendClientMessageToAll(-1,"ip"); //debug
format(str,sizeof(str),"unbanip %s",ip);
SendRconCommand(str);
return 1;
}



It's an unban command. It's working fine. But the loadip part didn't work. It didn't load an ip from user's account.

Sithis
03/04/2013, 08:59 AM
And also, try to document your code a little better. Some comments (// or /* .. */) won't hurt.

newbienoob
20/04/2013, 05:19 PM
If you read the y_ini tutorial you will see that variables are loaded in to globals and dealt with after the INI_ParseFile line.
Global variables? You mean something like.. pInfo[playerid][IP]? If so, I can't! I want to open an offline player's file. So they don't have an ID([playerid]).

EDIT: I understand now. But there's one problem

new pIP[16]; //global

forward loadip(name[],value[]);
public loadip(name[],value[])
{
INI_String("IP", pIP, 16);
return 1;
}

CMD:unban(playerid, params[])
{
new name[24],str[128];
if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, -1, ""herror" Usage: /unban [Player name]");
format(str,sizeof(str),UserPath,name);
if(!fexist(str)) return SendClientMessage(playerid, red, "Player is not banned/found!");
new INI:file = INI_Open(str);
INI_SetTag(file,"PlayerData");
INI_WriteInt(file,"Banned",0);
INI_Close(file);

INI_ParseFile(str,"loadip",.bExtra = true);
format(str,sizeof(str),"unbanip %s",pIP);
SendRconCommand(str);
printf("%s",str); //////////////////////


return 1;
}


It prints "unbanip Year" and something like, "Spos3SpawnAngle". Those are from my accounts keywords(?)

newbienoob
21/04/2013, 08:37 AM
up..

newbienoob
22/04/2013, 01:43 PM
Why are you saving the file then instantly loading it again?
Well.. I want to change "Banned" to 0 and then I want to load an IP from player's account so I can unban their IP.

newbienoob
22/04/2013, 01:48 PM
Yes.
....
....
IP = 127.0.0.1
....
....

newbienoob
22/04/2013, 01:59 PM
:o
Thank you!