「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.
Full documentation can be found there, as well in include file:
PHP Code:
/** * Lookup the full country name for the given IP address. * * @param ip The IP address to lookup. * @param result The result of the geoip lookup. * @param len The maximum length of the result buffer. * @param id An optional player's index in order to return the result * in the player's language, if supported. * -1: the default language, which is english. * 0: the server language. You can use LANG_SERVER define. * >=1: the player's language. * * @return The result length on successful lookup, 0 otherwise. */ native geoip_country_ex(const ip[], result[], len, id = -1);
/** * Look up the full city name for the given IP address. * * @note This native requires GeoIP City database, which can be retrieved from: * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) * * @param ip The IP address to look up. * @param result The result of the geoip look up. * @param len The maximum length of the result buffer. * @param id An optional player's index in order to return the result * in the player's language, if supported. * -1: the default language, which is english. * 0: the server language. You can use LANG_SERVER define. * >=1: the player's language. * * @return The result length on successful lookup, 0 otherwise. */ native geoip_city(const ip[], result[], len, id = -1);
/** * Look up the region/state code for the given IP address. * e.g. "US-OH", "DE-HH", IT-82, "FR-U", etc. * * @note This native requires GeoIP City database, which can be retrieved from: * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) * * @param ip The IP address to look up. * @param result The result of the geoip look up. * @param len The maximum length of the result buffer. * * @return The result length on successful lookup, 0 otherwise. */ native geoip_region_code(const ip[], result[], len);
/** * Look up the full region/state name for the given IP address. * * @note This native requires GeoIP City database, which can be retrieved from: * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) * * @param ip The IP address to look up. * @param result The result of the geoip look up. * @param len The maximum length of the result buffer. * @param id An optional player's index in order to return the result * in the player's language, if supported. * -1: the default language, which is english. * 0: the server language. You can use LANG_SERVER define. * >=1: the player's language. * * @return The result length on successful lookup, 0 otherwise. */ native geoip_region_name(const ip[], result[], len, id = -1);
/** * Look up the full time zone for the given IP address. * e.g. America/Los_Angeles, Europe/Paris. * * @note This native requires GeoIP City database, which can be retrieved from: * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) * * @param ip The IP address to look up. * @param result The result of the geoip look up. * @param len The maximum length of the result buffer. * * @return The result length on successful lookup, 0 otherwise. */ native geoip_timezone(const ip[], result[], len);
/** * Look up the city's latitude for the given IP address. * * @note This native requires GeoIP City database, which can be retrieved from: * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) * * @param ip The IP address to look up. * * @return The result of the geoip look up, 0 if latitude is not found. */ native Float:geoip_latitude(const ip[]);
/** * Look up the city's longitude for the given IP address. * * @note This native requires GeoIP City database, which can be retrieved from: * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) * * @param ip The IP address to look up. * * @return The result of the geoip look up, 0 if longitude is not found. */ native Float:geoip_longitude(const ip[]);
/** * Calculate the distance between geographical coordinates, latitude and longitude. * * @note This native requires GeoIP City database, which can be retrieved from: * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) * * @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 = Metric(kilometers) or 1 = English(miles). * * @return The distance as result in specified system of measurement. */ #define SYSTEM_METRIC 0 // kilometers #define SYSTEM_IMPERIAL 1 // statute miles
native Float:geoip_distance(Float:lat1, Float:lon1, Float:lat2, Float:lon2, system = SYSTEM_METRIC);
/** * Look up the continent code for a given IP address. * * @note This native requires GeoIP City database, which can be retrieved from: * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) * @note The code can be retrieved as integer (See CONTINENT_* constants.) or string (2 characters). * @note Possible continent codes are AF, AN, AS, EU, NA, OC, SA for * Africa(1), Antarctica(2), Asia(3), Europe(4), North America(5), Oceania(6), South America(7). * * @param ip The IP address to look up. * @param result The result of the geoip look up. * * @return The continent id on successful lookup, 0 otherwise. */ enum Continent { CONTINENT_UNKNOWN = 0, CONTINENT_AFRICA, CONTINENT_ANTARCTICA, CONTINENT_ASIA, CONTINENT_EUROPE, CONTINENT_NORTH_AMERICA, CONTINENT_OCEANIA, CONTINENT_SOUTH_AMERICA, }; native Continent:geoip_continent_code(const ip[], result[3]);
/** * Look up the full continent name for the given IP address. * * @note This native requires GeoIP City database, which can be retrieved from: * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) * * @param ip The IP address to look up. * @param result The result of the geoip look up. * @param len The maximum length of the result buffer. * @param id An optional player's index in order to return the result * in the player's language, if supported. * -1: the default language, which is english. * 0: the server language. You can use LANG_SERVER define. * >=1: the player's language. * * @return The result length on successful lookup, 0 otherwise. */ native geoip_continent_name(const ip[], result[], len, id = -1);
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
v1.3.0 : February 19th, 2015
- Based on latest GeoIP from AMXX Dev
- Updated libmaxminddb to v.1.2.0
- Linux: Fixed undefined symbol (missing libm linking)
]v1.2.0 : February 19th, 2015
- Fixed various compatibility issues (ref: PR #198)
- Fixed a buffer issue when looking up an ip gives no result, native would return an old result (PR #200)
v1.1.0 : January 8th, 2015
Module has been rewritten from scratch using the new MaxMind GEOIP2 database and API.
The new natives are essentially the same for most except:
- geoip_region has been renamed to geoip_region_code and takes now an undefined buffer and length.
- geoip_continent_name has been added
This worth to be noted some natives 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.
For those natives, you will see an extra "id" parameter as well to specify a player's language or not.
v1.0.2 : June 28th, 2009
Fixed possible crash when no data is available from GeoIPCity.dat file for the given IP address.
v1.0.1 : June 27th, 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 optionall param.
v1.0.0 : June 26, 2009
Initial release.
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.
__________________
Last edited by Arkshine; 10-31-2016 at 16:32.
Reason: Updated to 1.3
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.
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);
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.
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 :/