Quote:
Originally Posted by Gammix
I would recommend a subnet cum CIDR check which i implemented in GAdmin and also you can use IpMatch function:
pawn Код:
static GetIPVal(const ip[]) { new len = strlen(ip); if (!(len > 0 && len < 17)) return 0;
new count; for (new i; i < len; i++) { if (ip[i] == '.') count++; }
if (!(count == 3)) return 0;
new address = strval(ip) << 24; count = strfind(ip, ".", false, 0) + 1; address += strval(ip[count]) << 16; count = strfind(ip, ".", false, count) + 1; address += strval(ip[count]) << 8; count = strfind(ip, ".", false, count) + 1; address += strval(ip[count]); return address; }
stock 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); }
In this case you have to loop through all rows:
When the data load, use cache_get_field_content to retrieve a row's IP ( new rowip[18]).
And then compare with player's ip ( new pip[18]):
pawn Код:
if (IpMatch(rowip, pip)) { // player matched }
|
I'll search later on my PC if there's any other way to do that without looping through all rows.
But why do you use that awful way of converting an IP to decimal?
You can do something like this (Might have some indentation mistakes cause I'm on my phone)
Код:
GetIPVal(const ip[])
{
new ip1, ip2, ip3, ip4;
if (sscanf(ip, "p<.>iiii", ip1, ip2, ip3, ip4))
return 0;
if (!(0 <= ip1 <= 255) || !(0 <= ip2 <= 255) || !(0 <= ip3 <= 255) || !(0 <= ip4 <= 255))
return 0;
return ip1*16777216 + ip2*65536 + ip3*256 + ip4;
}