02.04.2016, 16:51
(
Последний раз редактировалось Gammix; 26.08.2016 в 19:51.
)
Ipmatch
(originally by R@f, modified by me)
Checks if the 2 IPs match using the CIDR IP system. (This can be used to create your own range ban script)
Returns true if the 2 ips matches
Returns false if the 2 ips does not match
Usage
If you want to blacklist an ip (say 0.0.0.0 is blacklisted):
(originally by R@f, modified by me)
Checks if the 2 IPs match using the CIDR IP system. (This can be used to create your own range ban script)
Returns true if the 2 ips matches
Returns false if the 2 ips does not match
pawn Код:
GetIPVal(const ip[])
{
new len = strlen(ip);
if (!(len > 0 && len < 17))
return 0;
new count;
new pos;
new dest[3];
new val[4];
for (new i; i < len; i++)
{
if (ip[i] == '.' || i == len)
{
strmid(dest, ip, pos, i);
pos = (i + 1);
val[count] = strval(dest);
if (!(1 <= val[count] <= 255))
return 0;
count++;
if (count > 3)
return 0;
}
}
if (count != 3)
return 0;
return ((val[0] * 16777216) + (val[1] * 65536) + (val[2] * 256) + (val[3]));
}
IpMatch(const ip1[], const ip2[], rangetype = 26)
{
new ip = GetIPVal(ip1);
new subnet = GetIPVal(ip2);
new mask = -1 << (32 - rangetype);
subnet &= mask;
return bool:((ip & mask) == subnet);
}
If you want to blacklist an ip (say 0.0.0.0 is blacklisted):
pawn Код:
public OnPlayerConnect(playerid)
{
new ip[18];
GetPlayerIp(playerid, ip, sizeof (ip));
if (ipmatch("0.0.0.0", ip))
{
SendClientMessage(playerid, 0xFF0000FF, "Your IP is blacklisted.");
return Kick(playerid);
}
return 1;
}