23.10.2016, 16:01
IP is not a number (@Yaa) but a text, he had used "s" specifier correctly. You don't even need sscanf in the first place for a single string. One string and re-formatting is also a good practice than many strings for different purposes and GetPlayerPoolSize (which was added in 0.3.7) for loops if you don't use foreach.
EDIT: In the format, there was % instead of %s by the way - just noticed it after your comment.
PHP код:
// if not defined by the include:
#if !defined isnull
#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
ocmd:unbanip(playerid, params[])
{
if (!IsAdmin(playerid, 2)) return noaccess
if (isnull(params)) return SendClientMessage(playerid, -1, "/unbanip <IP>");
if (!IsValidIp(params)) return SendClientMessage(playerid, -1, "Not a valid IP address.");
new str[87];
format(str, sizeof(str), "%s hat die IP %s erfolgreich entbannt!", PlayerName(playerid), params);
for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if (!PlayerOnline(i)) continue;
if (!IsAdmin(i, 2)) continue;
SendClientMessage(i, GELB, str);
}
format(str, sizeof(str), "%s hat die IP-Adresse : %s erfolgreich entbannt!", PlayerName(playerid), params);
AddLog("log_unbanip.txt", str);
format(str, sizeof(str), "unbanip %s", params);
SendRconCommand(str);
SendRconCommand("reloadbans");
return 1;
}
IsValidIp(const player_ip[])
{
new p_ip[4];
return !sscanf(player_ip, "p<.>a<i>[4]", p_ip) && (0 <= p_ip[0] <= 255) && (0 <= p_ip[1] <= 255) && (0 <= p_ip[2] <= 255) && (0 <= p_ip[3] <= 255);
}