10.11.2011, 19:01
Quote:
I'm not using it, but I'm fascinated by your work and would like to implement your method of range banning for my own server. My project currently has 4 fields which store the IP exploded by a period. But looking at how your scripts always have top notch features and are at the same time optimized to the max, I assume that the way you store IPs is better than using 4 separate fields for it. If so, can you confirm and also post a few tips on how to implement similar functionality to a MySQL based script?
|
To do this conversion in a MySQL query, you can use the function INET_ATON(ip).
For example:
Код:
INSERT INTO x (a, b, ip) VALUES ('a', 'b', INET_ATON('127.0.0.1'));
Код:
SELECT a, b, INET_NTOA(ip) FROM x WHERE y;
BETWEEN ... AND ...[/url] operator to find a matching range (that's how I do it).
For example:
Код:
SELET * FROM bans WHERE INET_ATON('127.0.0.1') BETWEEN ip_start AND ip_end;
If you don't understand how a single number can fit an IP, here's a quick explanation on that:
Variables in PAWN scripting for SA-MP have the size 4 bytes (32 bits). One byte can have 255 unique values - either -127 to 127, or 0 to 255.
Therefore, by isolating each byte, we can store 4 values ranging from 0 to 255 in one variable!
However, because format is buggy, you can't put negative numbers or certain very high numbers without getting strange results. You could have a look at the way I solved it, or you could simply use the queries above and put IPs in dot-notation in your queries (x.x.x.x).