17.06.2016, 04:19
Hey guys, pretty complicated for a damn ban CMD, is there a way to make it shorter/better ?
Thanks in advice.
PHP Code:
CMD:banip(playerid, params[])
{
if(!IsAuth(playerid, 3)) return NoAuth(playerid);
new ip[16];
if(sscanf(params, "s[16]s[128]", ip, params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /banip [IP] [reason]");
if(RIPID(ip) > -1)
{
new string[248];
format(string, sizeof(string), "This IP is connected to the server using the name %s (ID: %d), use /ban instead.", RPN(RIPID(ip)), RIPID(ip));
SendClientMessage(playerid, COLOR_WHITE, string);
return 1;
}
new Cache:result, query[128];
mysql_format(mysql, query, sizeof(query), "SELECT `AdminLevel`, `Username` from `Admins` WHERE `IP`='%e'", ip);
result = mysql_query(mysql, query);
if(cache_get_row_count(mysql))
{
new adminlevel, aname[MAX_PLAYER_NAME], string[400];
adminlevel = cache_get_row_int(0, 0, mysql);
cache_get_row(0, 1, aname, mysql, sizeof(aname));
if(aInfo[playerid][aLevel] < 5) SendClientMessage(playerid, COLOR_WHITE, "This IP is registered to an Administrator, You have to be Elite Admin or above to ban him.");
else if(adminlevel > aInfo[playerid][aLevel])
{
format(string ,sizeof(string), "This IP is registered to %s, who is a %d level Administrator, you can't ban him.", aname, adminlevel);
SendClientMessage(playerid, COLOR_WHITE, string);
}
else
{
format(string, sizeof(string), "%s %s has banned IP Address %s (Registered to %s), Reason: %s", RPARN(playerid), RPN(playerid), ip, aname, params);
SendAMessage(1, string);
new ban[30];
format(ban, sizeof(ban), "banip %s", ip);
SendRconCommand(ban);
Log("logs/bans.log", string);
}
cache_delete(result);
return 1;
}
else
{
new string[248];
format(string, sizeof(string), "%s %s has banned IP Address %s, Reason: %s", RPARN(playerid), RPN(playerid), ip, params);
SendAMessage(1, string);
Log("logs/bans.log", string);
new ban[30];
format(ban, sizeof(ban), "banip %s", ip);
SendRconCommand(ban);
cache_delete(result);
return 1;
}
}