[Include] [WIP] Ban system
#17

Quote:
Originally Posted by AndreT
Посмотреть сообщение
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?
Well, basically, I'm storing IPs in one single variable, where each number represents an IP (for example, 2130706433 = 0x7F000001 = 127.0.0.1).
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'));
To later retrieve that value, you can do:
Код:
SELECT a, b, INET_NTOA(ip) FROM x WHERE y;
So you could put ip_start and ip_end fields in your table, and use the [url=http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between
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;
You could (and may) take code from my script and modify it a little bit to get this working.

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).
Reply


Messages In This Thread
Ban system - by Slice - 07.11.2011, 20:41
Re: [WIP] Ban system - by Pinguinn - 07.11.2011, 20:42
Respuesta: [WIP] Ban system - by Manuel7284 - 07.11.2011, 21:34
Re: [WIP] Ban system - by Fool - 08.11.2011, 03:09
Re: [WIP] Ban system - by RBTDM - 08.11.2011, 07:41
Re: [WIP] Ban system - by iPLEOMAX - 08.11.2011, 08:16
Re: [WIP] Ban system - by Slice - 08.11.2011, 08:36
Re: [WIP] Ban system - by Simon - 08.11.2011, 08:40
Re: [WIP] Ban system - by Slice - 08.11.2011, 08:52
Re: [WIP] Ban system - by Darius - 08.11.2011, 09:18
Re: [WIP] Ban system - by Simon - 08.11.2011, 09:58
Re: [WIP] Ban system - by Slice - 08.11.2011, 13:52
Re: [WIP] Ban system - by Mr_Scripter - 08.11.2011, 14:15
Re: [WIP] Ban system - by Slice - 10.11.2011, 17:52
Re: [WIP] Ban system - by AndreT - 10.11.2011, 18:10
Re : [WIP] Ban system - by Habdel - 10.11.2011, 18:33
Re: [WIP] Ban system - by Slice - 10.11.2011, 19:01
Re: [WIP] Ban system - by TheArcher - 10.11.2011, 19:13
Re: [WIP] Ban system - by AndreT - 10.11.2011, 20:45
Re: [WIP] Ban system - by Slice - 11.11.2011, 07:02
Re: [WIP] Ban system - by Calgon - 11.11.2011, 14:00
Re: [WIP] Ban system - by Slice - 15.11.2011, 13:33
Re: [WIP] Ban system - by thiaZ_ - 15.11.2011, 15:31
Re: [WIP] Ban system - by Pinguinn - 15.11.2011, 16:09
Re: [WIP] Ban system - by Slice - 15.11.2011, 16:22
Re: [WIP] Ban system - by Chris# - 15.11.2011, 16:54
Re: [WIP] Ban system - by Astralis - 15.11.2011, 19:28
Re: [WIP] Ban system - by Scenario - 16.11.2011, 02:41
Re: [WIP] Ban system - by Slice - 16.11.2011, 05:30
Re: [WIP] Ban system - by Slice - 16.11.2011, 18:58
Re: [WIP] Ban system - by TheArcher - 05.09.2012, 18:25
Re: [WIP] Ban system - by Ada32 - 06.01.2014, 12:44
Re: [WIP] Ban system - by Sojo12 - 11.01.2014, 08:59

Forum Jump:


Users browsing this thread: 6 Guest(s)