08.07.2014, 09:00
I have a problem with loading data from a file using Y_ini.For example if I ban myself and reconnect again the ban appears, but if i restart the server the ban disappear, and I can't understand why.
Here are my codes:
Here are my codes:
pawn Код:
stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),afile,playername);
return string;
}
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Admin",ainfo[playerid][admlv]);
INI_Bool("Ban",ainfo[playerid][ban]);
INI_Int("Kicks",ainfo[playerid][kicks]);
return 1;
}
public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
if(ainfo[playerid][ban] != false)
{
for(new i=0;i<25;i++)
{
SendClientMessage(playerid,COLOR_WHITE,"");
}
new IP[16],string[64],bname[25];
GetPlayerIp(playerid,IP,16);
GetPlayerName(playerid,bname,25);
SendClientMessage(playerid,COLOR_YELLOW,"|__________________[Ban Info]__________________|");
SendClientMessage(playerid,COLOR_YELLOW,"[BAN]: This account is suspended on this server !");
format(string,sizeof(string),"Name:{FFFFFF}%s",bname);
SendClientMessage(playerid,COLOR_YELLOW,string);
format(string,sizeof(string),"IP:{FFFFFF}%s",IP);
SendClientMessage(playerid,COLOR_YELLOW,string);
SendClientMessage(playerid,COLOR_YELLOW,"________________________________________");
TogglePlayerControllable(playerid,0);
TextDrawShowForPlayer(playerid,txtbanned);
TextDrawShowForPlayer(playerid,boxbanned);
SetTimerEx("TKick",1500,false,"i",playerid);
}
}
else
{
new INI:file = INI_Open(UserPath(playerid));
INI_SetTag(file,"TAG");
INI_WriteInt(file,"Admin",ainfo[playerid][admlv] = 0);
INI_WriteBool(file,"Ban",false);
INI_WriteInt(file,"Kicks",ainfo[playerid][kicks] = 0);
INI_Close(file);
}
return 1;
}
public OnPlayerDisconnect(playerid,reason)
{
new INI:file = INI_Open(UserPath(playerid));
INI_SetTag(file,"TAG");
INI_WriteInt(file,"Admin",ainfo[playerid][admlv]);
INI_WriteBool(file,"Ban",ainfo[playerid][ban]);
INI_WriteInt(file,"Kicks",ainfo[playerid][kicks]);
INI_Close(file);
return 1;
}
CMD:ban(playerid,params[])
{
new id,name[MAX_PLAYER_NAME];
new admin[MAX_PLAYER_NAME],reason[64];
new string[128];
new y,mh,d; getdate(y,mh,d);
new h,m,s; gettime(h,m,s);
if(ainfo[playerid][admlv] > 0)
{
if(sscanf(params,"us[64]",id,reason)) return SendClientMessage(playerid,COLOR_GREY, "Syntax: /ban [PlayerID/Name] [Reason]");
else if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_GREY, "That player isn't connected !");
else
{
GetPlayerName(playerid,admin,sizeof(admin));
GetPlayerName(id,name,sizeof(name));
if(ainfo[id][admlv] > ainfo[playerid][admlv])
{
format(string,sizeof(string),"[Warning]: Administrator %s tried to ban you !",admin);
SendClientMessage(id,COLOR_YELLOW,string);
SendClientMessage(playerid,COLOR_YELLOW,"[AdmCmd]: You tried to ban a higher admin than you !");
SetTimerEx("TKick",500,false,"i",playerid);
}
else
{
format(string,sizeof(string),"[AdmCmd]: Administrator %s banned %s. Reason %s",admin,name,reason);
SendClientMessageToAll(COLOR_RED,string);
ainfo[id][ban] = true;
new INI:tmp = INI_Open(UserPath(id));
INI_ParseFile(UserPath(id), "LoadUser_%s", .bExtra = true, .extra = playerid);
INI_WriteBool(tmp,"Ban",true);
INI_Close(tmp);
SetTimerEx("TKick",500,false,"i",id);
format(string,sizeof(string),"Date:[%d/%d/%d] Time:[%d/%d/%d] Admin: %s Player: %s Reason: %s",y,mh,d,h,m,s,admin,name,reason);
BanLog(string);
}
}
}
else {SendClientMessage(playerid,COLOR_GREY, "You aren't authorized to use this command !");}
return 1;
}