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 :/


All times are GMT -4. The time now is 01:30.

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