AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Module: GeoIP+ (v1.3) (https://forums.alliedmods.net/showthread.php?t=95665)

Arkshine 06-25-2009 22:46

Module: GeoIP+ (v1.3)
 


GEüIPl

v1.3, October 31th, 2016
GitHub



Table of contents:

DESCRIPTION
0
「AMX Mod X Module, backported from dev version to be used with the current stable v1.8.2」

GeoIP+ module is a modification of the original GeoIP module shipped by default with AMX Mod X.
This adds several new natives in order to exploit others availaible datas like:
✓ City
✓ Region Code/Name
✓ Time Zone
✓ Continent Code/Name
✓ Latitude/Longitude/Distance
✓ Continent Code/Name
This is worth to note that it uses the new MaxMind GeoIP2 database format and some natives (country, city, region and continent) are localized, which means you can output data in others languages than english if available. For now the following languages are supported: de en es fr ja pt-BR ru zh-CN.

API
0
Quick preview of new natives:

Full documentation can be found there, as well in include file:

COMMAND
0
For debugging reasons, a geoip command is now implemented:
geoip version
This will gives the current GeoIP module version and informations about current loaded database.

geoip dump <IP> [file]
This allows you to dump all informations of a given IP in a JSON-like format. You can optionally provided a file to save dump there.

NOTES
0
You should be aware that it may not be always accurate depending the given ip. Keep in mind this uses the lite and free database version.
▹ If GeoIP City is not found, it will use the default GeoIP Country provided by default, the only usable natives will be the one pertaining to countries and distance.
▹ If an IP is not found, the natives will output an empty string.
▹ The charset of the country/city/region/continent name is set on UTF-8 so you should see specials characters like accents and such in game.

CREDITS
0
▹ xPaw : Testing and support.
▹ NiLuJe : Compiling linux version.
▹ vittu : Tips.

CHANGELOG
0

INSTALLATION
0
➀ Download latest GeoLite2 City MaxMind DB (~25 Mio)
➁ Retrieve the GeoLite2-City.mmdb file and copy it on your server in your 1amxmodx/data.
➂ Stop your server, download the provided geoip-files-x.y.zip and overwrite the content in your 1amxmodx.
➃ Start your server & enjoy.

➥ ➄ Optional - Check geoip version and database by typing in server console: geoip version

INSTALLATION FILES
0
Download geoip-files-1.3.zip from GitHub : contains binaries and pawn include files.

Arkshine 06-25-2009 22:51

Re: Module: GeoIP Extented
 
Just to say that I was not planned to do it. Just by playing I feel like after to do something better with the latest GeoIP source code and I wanted to modify the original module too since I would prefer to have one module than several doing the same thing. xPaw is aware and his thread should be trashed. :p

I did not test thoroughly so I hope that people will test it. The linux version is untested at all.
Since I'm fairly new making module, I hope the code is right.

Thanks !

vittu 06-26-2009 00:34

Re: Module: GeoIP Extended
 
Nice, I plan on trying this out....


Suggestion/Request: Add flag to return distance in either kilometers or miles.


I don't know if this is right but highlighted is what i changed. (Notes after snippet)
Code:
/**  * Calculate the distance between geographical coordinates, latitude and longitude.  *  * @param lat1      The first IP latitude.  * @param lon1      The first IP longitude.  * @param lat2      The second IP latitude.  * @param lon2      The second IP longitude.  * @param system    The system of measurement, 0 = Meteric(kilometers) or 1 = English(miles).    * @return      The distance as result in specified system of measurement.  */ native Float:geoip_distance( Float:lat1, Float:lon1, Float:lat2, Float:lon2, system = 0 );
Native defaults to kilometers if not specified.


Code:
static cell AMX_NATIVE_CALL amx_geoip_distance( AMX *amx, cell *params ) {     REAL RAD_CONVERT  = (REAL)0.017453292519943;     REAL EARTH_RADIUS = (REAL)params[5] ? 3959.0 : 6371.0;     REAL lat1 = amx_ctof( params[1] ) * RAD_CONVERT;     REAL lon1 = amx_ctof( params[2] ) * RAD_CONVERT;     REAL lat2 = amx_ctof( params[3] ) * RAD_CONVERT;     REAL lon2 = amx_ctof( params[4] ) * RAD_CONVERT;     return amx_ftoc( EARTH_RADIUS * acos( sin( lat1 ) * sin( lat2 ) + cos( lat1 ) * cos( lat2 ) * cos( lon2 - lon1 ) ) ); }
I used 0.017453292519943 instead of M_PI / 180 mainly because that is what xs uses for xs_deg2rad.

6371.0km is a bit more precise as it is the earth's mean radius not the equatorial radius of 6378.2km. (3959.0 is just the miles conversion of 6371.0)

Arkshine 06-26-2009 04:19

Re: Module: GeoIP Extended
 
Thanks !

I did not integrated the 'miles' option because I thought that you could do the conversion easily in your code. But it's true that's more neat to do that.

Changes are done. I'm waiting others feedbacks to see if need another changes before updating here.

xPaw 06-26-2009 04:46

Re: Module: GeoIP Extended
 
Oh noes there is my ip :mrgreen:

csl 06-26-2009 05:21

Re: Module: GeoIP Extended
 
but ISP ?

now we need a new plugin to show:

1.Country
2.City
3.STEAM
4.IP
5.ISP
6.Distance from server.


with cvars:)

Arkshine 06-26-2009 05:31

Re: Module: GeoIP Extended
 
Is there a specific reason to want ISP ? Because I don't see that as interesting.

xPaw 06-26-2009 05:40

Re: Module: GeoIP Extended
 
ISP is other geoip base and there is no lite (free) version of it.

csl 06-26-2009 05:40

Re: Module: GeoIP Extended
 
if u cant make it is ok...but for me is v. interesting, and more interesting like :
- Time Zone
- Continent Code

Quote:

ISP is other geoip base and there is no lite (free) version of it.
:(

SchlumPF* 06-26-2009 07:03

Re: Module: GeoIP Extended
 
PHP Code:

native bool:geoip_continent_code( const ip[], result[3] ); 

same like in the geoip which is provided by amxx, why do you have to predefine the length of result? if it returns "err" someone might want to fromat the string to something with more than 3 letters so it will be necessarry to create another variable :/

Arkshine 06-26-2009 07:38

Re: Module: GeoIP Extended
 
I've kept the same design like geoip_code[2|3]_ex() where it returns true on a successful lookup, false on a failed lookup. It will not return "err" btw. But I understand what you mean, though you can avoid to create another var depending how you code.

[ --<-@ ] Black Rose 06-26-2009 08:33

Re: Module: GeoIP Extended
 
Why even make the continent a string?
I mean, you still have to use an array.

Arkshine 06-26-2009 08:43

Re: Module: GeoIP Extended
 
Sorry Superiority, I don't understand well what you mean.

[ --<-@ ] Black Rose 06-26-2009 09:40

Re: Module: GeoIP Extended
 
... IT'S ENGLISH!

omfg...

Make this
Code:

native bool:geoip_continent_code( const ip[], result[3] );
into this
Code:

native bool:geoip_continent_code( const ip[], result );
or maby even this
Code:

native geoip_continent_code( const ip[] );
I vote option 2.
Make it return an integer instead of a string.

Arkshine 06-26-2009 09:46

Re: Module: GeoIP Extended
 
Quote:

... IT'S ENGLISH!

omfg...
My english fails often. No need to react like that. -_-'

Still I don't understand because the continent code is composed of 2 characters so the output would be a string not integer.

If not, explain better.

[ --<-@ ] Black Rose 06-26-2009 10:06

Re: Module: GeoIP Extended
 
Quote:

Originally Posted by arkshine (Post 857597)
My english fails often. No need to react like that. -_-'

Still I don't understand because the continent code is composed of 2 characters so the output would be a string not integer.

If not, explain better.

Exactly, why waste precious processor power, memory & time with strings?
You still need an array of the continents to use the full name. No one would ever use a 2 char code. That's only for comparsion/logs, and the comparsion would be even easier with integers.

Code:

#define Europe 1
#define Africa 2
// et.c.
 
// ...
 
new Contintent[][] = {
  "",
  "Europe",
  "Africa"
}
 
// ...
 
new ip[32];
get_user_ip(id, ip, 31);
server_print("Whatever: %s", Contintent[geoip_continent_code(ip);


Arkshine 06-26-2009 10:32

Re: Module: GeoIP Extended
 
Ok, now I understand. I would need to replace in the GeoIP code the continent code by numbers. But I would prefer to keep the characters since it can be useful for some people. ( like geoip_code[2|3]_ex() ). Then what about to return an integer AND to pass the characters but as optional param, people could do a choice so.

[ --<-@ ] Black Rose 06-26-2009 11:13

Re: Module: GeoIP Extended
 
Quote:

Originally Posted by arkshine (Post 857625)
Ok, now I understand. I would need to replace in the GeoIP code the continent code by numbers. But I would prefer to keep the characters since it can be useful for some people. ( like geoip_code[2|3]_ex() ). Then what about to return an integer AND to pass the characters but as optional param, people could do a choice so.

Your way seems really good.

Arkshine 06-27-2009 03:09

Re: Module: GeoIP Extended
 
Since I suck in english, I have some difficulty with the .inc.
Here the new version for geoip_continent_code().
Is someone can correct it since I'm not sure if it's well written or needs changes. I just want something perfect in english. :mrgreen:

Code:
/**  * Lookup the continent code for a given IP address.  *  * @note The code can be retrieved as integer number or string (2 characters).  * @note Possible continent codes are AF, AS, EU, NA, OC, SA for  * Africa(1), Asia(2), Europe(3), North America(4), Oceania(5) and South America(6).  *  * @param ip        The IP address to lookup.  * @param result    The result of the geoip lookup. This param is optional.  *                  If the lookup does not succeed, the buffer is not modified.  * @return          The result of the geoip lookup, 0 on a failed lookup.  */ enum Continent {     AFRICA = 1,     ASIA,     EUROPE,     NORTH_AMERICA,     OCEANIA,     SOUTH_AMERICA } native Continent:geoip_continent_code( const ip[], result[3] = "" );

diamond-optic 06-27-2009 11:09

Re: Module: GeoIP Extended
 
this is great... i just installed vc++ the other day and was gonna try and do this myself.. saved me the trouble :-)


only issue i have, is sometimes certain IPs seem to crash the server


like i setup a simple test plugin with a cmd to input my own IP and just started grabbing IPs from players on my server and running them thru it, and every now and then id get one that made the server crash


i wish i had wrote down the IP so that i could post it here for others to try

Arkshine 06-27-2009 14:24

Re: Module: GeoIP Extended
 
Updated.

Quote:

v1.0.1 : [ 27 jun 2009 ]
(+) geoip_distance() can return in Miles now.
(+) geoip_continent_code() returns by default an integer now. The two characters is still passed but as optional param.


SchlumPF* 06-27-2009 14:29

Re: Module: GeoIP Extended
 
Quote:

Originally Posted by arkshine (Post 858233)
Since I suck in english, I have some difficulty with the .inc.

"(to) look up", lookup is used for words like "lookup table" though. but you should wait for some native speaker like exolent.

Exolent[jNr] 06-27-2009 14:57

Re: Module: GeoIP Extended
 
Code:
/**  * Look up the continent code for a given IP address.  *  * @note The code can be retrieved as an integer or string (2 characters).  * @note Possible continent codes are AF, AS, EU, NA, OC, SA for  * Africa(1), Asia(2), Europe(3), North America(4), Oceania(5) and South America(6).  *  * @param ip        The IP address to look up.  * @param result    The result of the geoip lookup. This param is optional.  *                  If the lookup does not succeed, the buffer is not modified.  * @return          The result of the geoip lookup, 0 on a failed lookup.  */ enum Continent {     AFRICA = 1,     ASIA,     EUROPE,     NORTH_AMERICA,     OCEANIA,     SOUTH_AMERICA } native Continent:geoip_continent_code( const ip[], result[3] = "" );

I also suggest something like:
Code:
enum Continent {     CONTINENT_ERROR = 0,     AFRICA,     ASIA,     EUROPE,     NORTH_AMERICA,     OCEANIA,     SOUTH_AMERICA }

Then when you write code for it, you can do:
Code:
new const g_szContinentNames[Continent][] = {     "",     "Africa",     "Asia",     "Europe",     "North America",     "Oceania",     "South America" }; // ... new szIp[32]; get_user_ip(iPlayer, szIp, 31, 1); new Continent:iCont = geoip_continent_code(szIp); if( iCont == CONTINENT_ERROR ) {     client_print(client, print_chat, "You could not be found on the Earth!"); } else {     client_print(client, print_chat, "You are from %s? Awesome!", g_szContinentNames[iCont]); }

It would have more readability.

Arkshine 06-27-2009 15:02

Re: Module: GeoIP Extended (v1.0.1)
 
I agree. Thanks ! And updated.

diamond-optic 06-27-2009 15:22

Re: Module: GeoIP Extended (v1.0.1)
 
any specific reason why the linux binary is named differently now?

Arkshine 06-27-2009 15:44

Re: Module: GeoIP Extended (v1.0.1)
 
Oops I forgot to rename. :mrgreen:

EDIT: Done. Thanks.

diamond-optic 06-27-2009 16:01

Re: Module: GeoIP Extended (v1.0.1)
 
ok i found an IP that cuases crashing...

98.154.81.146


if you try to get the region of that IP, it crashes the server



finding country is fine, city gives error.. so im thinking maybe if i check for the error on the city lookup and skip the region lookup if it gives 'error' result, i might be able to avoid the crashing.. gonna do some testing and find some more IPs that give this problem tho

Arkshine 06-27-2009 16:29

Re: Module: GeoIP Extended (v1.0.1)
 
Woh. It's weird. Oo I'm trying to debug...

Arkshine 06-27-2009 18:00

Re: Module: GeoIP Extended (v1.0.1)
 
Ok, after some debug, it's the GeoIPCity.dat file fault. It seems that there are no data for region and city for this ip. But it's weird because latitude and longitude exist..

so in :

Code:

if ( rec )
{
        MF_SetAmxString( amx, params[2], rec->region, 2 );
        return 1;
}

rec is valid but rec->region is not initiliazed because of null and MF_SetAmxString() seems to not like null string.
So as fix, adding "&& rec->region" should be fine.

I'm going to test and I will update here ASAP.

Arkshine 06-28-2009 04:11

Re: Module: GeoIP Extended (v1.0.2)
 
Updated.

Quote:

v1.0.2 : [ 28 jun 2009 ]
(!) Fixed possible crash when no data is available from GeoIPCity.dat file for a given IP address.


diamond-optic 06-28-2009 11:41

Re: Module: GeoIP Extended (v1.0.2)
 
:-) thanks.. love this module


+kama sutra

nisam_ja 07-03-2009 22:41

Re: Module: GeoIP Extended (v1.0.2)
 
maybe dumb question but , does this give longitude/altitude of ISP (internet service provider) or ..'??

Alka 07-04-2009 03:51

Re: Module: GeoIP Extended (v1.0.2)
 
Quote:

Originally Posted by nisam_ja (Post 863778)
maybe dumb question but , does this give longitude/altitude of ISP (internet service provider) or ..'??

No, of IP.

nisam_ja 07-04-2009 12:23

Re: Module: GeoIP Extended (v1.0.2)
 
alka - you funny.
That is not an answer :)

my question was does longitude/altitude of my home... my home address...
not location of isp. because you might know , that ip is given to you by isp...

xPaw 07-04-2009 12:30

Re: Module: GeoIP Extended (v1.0.2)
 
He said, its not possible.

vittu 07-04-2009 12:35

Re: Module: GeoIP Extended (v1.0.2)
 
It's gets location by your IP address, you can see what it does by testing it here:
http://www.maxmind.com/app/locate_ip - click on "click here" for your info.

Alka 07-05-2009 07:49

Re: Module: GeoIP Extended (v1.0.2)
 
Can you stop with
http://up2.podbean.com/image-logos/44997_logo.gif?

Eugene. 07-10-2009 05:03

Re: Module: GeoIP Extended (v1.0.2)
 
I have thought up a way how to calculate a city, and now all will repeat?
Badly arrive: \

[ --<-@ ] Black Rose 07-10-2009 07:22

Re: Module: GeoIP Extended (v1.0.2)
 
You suck at english.

Eugene. 07-10-2009 09:21

Re: Module: GeoIP Extended (v1.0.2)
 
ok


All times are GMT -4. The time now is 17:26.

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