Admins view ban reasons in game -
Sebz - 22.12.2015
Currently, I use a ban and kick system like this.
Код:
forward BanLog(string[]);
public BanLog(string[])
{
new entry[128];
format(entry, sizeof(entry), "%s\n",string);
new File:hFile;
hFile = fopen("/LOGS/bans.log", io_append);
fwrite(hFile, entry);
fclose(hFile);
}
forward KickLog(string[]);
public KickLog(string[])
{
new entry[128];
format(entry, sizeof(entry), "%s\n",string);
new File:hFile;
hFile = fopen("/LOGS/kicks.log", io_append);
fwrite(hFile, entry);
fclose(hFile);
}
CMD:ban(playerid, params[])
{
if(pInfo[playerid][Adminlevel] >= 1) {
new toplayerid, reason[ 128 ];
if (sscanf(params, "us[128]", toplayerid, reason))
{
SendClientMessage(playerid, 0xAA3333AA, "Syntax Error: /ban < Playerid > < Reason >");
return 1;
}
if (toplayerid == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, 0xAA3333AA, "Input Error: Player is not connected or it is yourself.");
return 1;
}
new banString[128], adminName[24], bannedName[24];
GetPlayerName(playerid, adminName, 24);
GetPlayerName(toplayerid, bannedName, 24);
format(banString, 128, "%s has been banned by Administrator %s. Reason: %s.", bannedName, adminName, reason);
SendClientMessageToAll(0xAA3333AA, banString);
BanLog(banString);
Ban(toplayerid);
}
return 1;
}
CMD:kick(playerid, params[])
{
if(pInfo[playerid][Adminlevel] >= 1) {
new toplayerid, reason[ 128 ];
if (sscanf(params, "us[128]", toplayerid, reason))
{
SendClientMessage(playerid, 0xAA3333AA, "Syntax Error: /kicktest < Playerid > < Reason >");
return 1;
}
if (toplayerid == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, 0xAA3333AA, "Input Error: Player is not connected or it is yourself.");
return 1;
}
new banString[128], adminName[24], bannedName[24];
GetPlayerName(playerid, adminName, 24);
GetPlayerName(toplayerid, bannedName, 24);
format(banString, 128, "%s has been kicked by Administrator %s. Reason: %s.", bannedName, adminName, reason);
SendClientMessageToAll(0xAA3333AA, banString);
KickLog(banString);
Kick(toplayerid);
}
return 1;
}
I'd like to have a cmd like /searchkick and /searchban where an admin can do /searchban NAME/PartofName and then the server will search through the file, sending them a message with the ban/kick reason(s) they have on that account. Is this possible? IF so, I need assistance with creating this system.
Re: Admins view ban reasons in game -
Younes44 - 22.12.2015
If u r using ladmin
then here you go
PHP код:
CMD:searchban(playerid,params[]) {
if(PlayerInfo[playerid][LoggedIn] == 1) {
if(PlayerInfo[playerid][Level] >= 1) {
new string[100],nickname[50];
if(sscanf(params, "s[50]s[48]", nickname)) return SCM(playerid, dred, "[LBAN]: /Searchban (New String)");
CMDMessageToAdmins(playerid,"SEARCHBAN");
format(string,sizeof(string),"/ladmin/bans/%s.ini", nickname);
return LSEARCHBAN(playerid,string);
} else return SendClientMessage(playerid,dred,"» Error « {BABABA} You are not a high enough level to use this command");
} else return SendClientMessage(playerid,red,"» Error « {BABABA} You must be logged in to use this commands");
}
CMD:sban(playerid,params[]) {
return cmd_searchban(playerid, params);
}
Change only
if(PlayerInfo[playerid][LoggedIn] == 1) {
if(PlayerInfo[playerid][Level] >= 1) {
to your own data
Re: Admins view ban reasons in game -
RoboN1X - 22.12.2015
You can use
fread,
fseek, and then search the line with
strfind function. But this way is not really recommended, because if your log file is so big (let's say, 10MB), your server will lag because it runs in the same thread as the gamemode script and so it will wait until the function finishes searching. It's better to save it to some database like MySQL or another data file plugin (which is threaded) so it can be searched quickly without having lag.
fread is to read the log file, fseek is to seek and jump the position (i.e. you are limiting the search to the last x lines, then you can skip the file reading with this), then strfind is to find the Search string from the fread.