AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to define a large integer? (https://forums.alliedmods.net/showthread.php?t=171134)

wwzw 11-02-2011 08:38

How to define a large integer?
 
I want to convert ip address to a digital, like this:
PHP Code:

 new ip[16],str[12],str1[4],str2[4],str3[4],str4[4];
 
get_user_ip(ip,15,1);
 
split(ipstr13str12".");
 
split(strstr23str12".");
 
split(strstr33str43".");
 new 
intip str_to_num(str1) * 256 256 256 str_to_num(str2) * 256 256 str_to_num(str3) * 256 str_to_num(str4);
 
result dbi_query(sql,"SELECT `address` FROM `cs_ipdata` WHERE (`ipstart` <= '%d') And (`ipend` >= '%d')",intip,intip); 

But error, please teach me !

Bugsy 11-02-2011 09:20

Re: How to define a large integer?
 
Explain what exactly you want to do.

Sylwester 11-02-2011 09:43

Re: How to define a large integer?
 
Check this: http://forums.alliedmods.net/showthr...58#post1529958
My code in that post contains ip_to_num function.

wwzw 11-02-2011 10:26

Re: How to define a large integer?
 
My goal is to convert IP numbers from 0 to 4294967295
However, the default variable is -2147483648 to 2147483647
If the calculation result is greater than 2147483647, the actual output is a negative number:
Actual output = The results - 4294967296
How to set variable unsigned?

Sylwester 11-02-2011 10:47

Re: How to define a large integer?
 
You could store bytes separately and let mysql convert it to a single number or you could store numbers in a string and implement your own * and + operators working on strings, but to me it kinda looks like XY problem: your real goal is probably not to convert ip to unsigned int, but to do something with ip ranges, so why don't you explain what do you want to do with those ips and we will see if there is better solution.

Bugsy 11-02-2011 10:51

Re: How to define a large integer?
 
There is no unsigned data type in Pawn. As Sylwester says, explain better what you want to do, you can accomplish this if you're working with ranges

Easier way to load data into a cell:

new IP[ 1 ]
IP{ 0 } = 128
IP{ 1 } = 12
IP{ 2 } = 221
IP{ 3 } = 125
IP[ 0 ] holds address

wwzw 11-02-2011 10:57

Re: How to define a large integer?
 
I put the IP address of the data conversion from 0 to 4294967295, stored in a mysql database.
In AMXX, I need to use the player's IP address lookup players come from.
So I need to convert the player's IP address is a positive integer from 0 to 4294967295, to the mysql database queries.
If I can not define variables in AMXX as a large integer or unsigned integer, I may only modify the database of preservation methods to adapt to AMXX.

Sylwester 11-02-2011 11:14

Re: How to define a large integer?
 
That's not an explanation I asked for. I'm asking what are you going to do with table full of those converted ips. Why are you using something like this: ... WHERE (`ipstart` <= '%d') And (`ipend` >= '%d') ... ?

wwzw 11-02-2011 11:33

Re: How to define a large integer?
 
My IP address data like this:
0.0.0.0 0.255.255.255 IANA reserved address
......
192.168.0.0 192.168.255.255 Lan
......
Style in the database:
ipfrom ipto address
0 16777215 IANA reserved address
......
3232235520 3232301055 Lan
......

If I want to check the IP address 192.168.1.101 come from.
First I must change 192.168.1.101 converted to digital: 3232235877(192*256*256*256+168*256*256+1*256+ 101), and then query the database to get the final result is "Lan"

Bugsy 11-02-2011 11:36

Re: How to define a large integer?
 
So do you only want to verify if two parts of IP are same? 192.168.x.x?


All times are GMT -4. The time now is 14:22.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.