2014-08-04 16:12:15 +04:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// GeoIP Module Functions
|
|
|
|
//
|
2004-09-10 07:12:38 +04:00
|
|
|
|
2007-01-26 08:56:10 +03:00
|
|
|
#if defined geoip_included
|
2014-08-01 02:58:02 +04:00
|
|
|
#endinput
|
2004-09-10 07:12:38 +04:00
|
|
|
#endif
|
|
|
|
#define _geoip_included
|
|
|
|
|
2006-05-10 14:42:49 +04:00
|
|
|
#if AMXX_VERSION_NUM >= 175
|
2014-08-01 02:58:02 +04:00
|
|
|
#pragma reqlib geoip
|
|
|
|
#if !defined AMXMODX_NOAUTOLOAD
|
|
|
|
#pragma loadlib geoip
|
|
|
|
#endif
|
2006-05-10 14:42:49 +04:00
|
|
|
#else
|
2014-08-01 02:58:02 +04:00
|
|
|
#pragma library geoip
|
2006-05-10 14:42:49 +04:00
|
|
|
#endif
|
2004-09-10 07:12:38 +04:00
|
|
|
|
2014-08-01 02:58:02 +04:00
|
|
|
/**
|
|
|
|
* @global IP addresses passed to these natives can contain ports, the ports will be ignored.
|
|
|
|
*/
|
2004-09-10 07:12:38 +04:00
|
|
|
|
2007-07-19 22:37:13 +04:00
|
|
|
/**
|
2014-08-01 02:58:02 +04:00
|
|
|
* Look up the two character country code for a given IP address.
|
2007-07-19 22:37:13 +04:00
|
|
|
* e.g: "US", "CA", etc.
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @param ip The IP address to lookup.
|
|
|
|
* @param result The result buffer. If the lookup does not succeed, the buffer is not modified.
|
|
|
|
*
|
|
|
|
* @return true on a successful lookup, false on a failed lookup.
|
2007-07-19 22:37:13 +04:00
|
|
|
*/
|
|
|
|
native bool:geoip_code2_ex(const ip[], result[3]);
|
|
|
|
|
|
|
|
/**
|
2014-08-01 02:58:02 +04:00
|
|
|
* Look up the three character country code for a given IP address.
|
2007-07-19 22:37:13 +04:00
|
|
|
* e.g: "USA", "cAN", etc.
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @param ip The IP address to lookup.
|
|
|
|
* @param result The result buffer. If the lookup does not succeed, the buffer is not modified.
|
|
|
|
*
|
|
|
|
* @return true on a successful lookup, false on a failed lookup.
|
2007-07-19 22:37:13 +04:00
|
|
|
*/
|
|
|
|
native bool:geoip_code3_ex(const ip[], result[4]);
|
|
|
|
|
|
|
|
/**
|
2015-02-07 18:18:39 +03:00
|
|
|
* Lookup the two character country code for a given IP address. Sets the buffer to "error" on
|
|
|
|
* an unsuccessful lookup.
|
2007-07-19 22:37:13 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @deprecated This native will overflow the buffer by one cell on an unknown ip lookup!
|
|
|
|
* Use geoip_code2_ex instead.
|
2007-07-19 22:37:13 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @param ip The IP address to lookup.
|
|
|
|
* @param result The result buffer.
|
|
|
|
*
|
2015-02-07 18:18:39 +03:00
|
|
|
* @return The result length.
|
2007-07-19 22:37:13 +04:00
|
|
|
*/
|
2014-08-13 15:18:33 +04:00
|
|
|
#pragma deprecated Use geoip_code2_ex() instead.
|
2007-01-26 08:56:10 +03:00
|
|
|
native geoip_code2(const ip[], ccode[3]);
|
2004-09-10 07:12:38 +04:00
|
|
|
|
2007-07-19 22:37:13 +04:00
|
|
|
/**
|
2015-02-07 18:18:39 +03:00
|
|
|
* Lookup the three character country code for a given IP address. Sets the buffer to "error" on
|
|
|
|
* an unsuccessful lookup.
|
2007-07-19 22:37:13 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @deprecated This native will overflow the buffer by one cell on an unknown ip lookup!
|
|
|
|
* Use geoip_code3_ex instead.
|
|
|
|
*
|
|
|
|
* @param ip The IP address to lookup.
|
|
|
|
* @param result The result buffer.
|
2007-07-19 22:37:13 +04:00
|
|
|
*
|
2015-02-07 18:18:39 +03:00
|
|
|
* @return The result length.
|
2007-07-19 22:37:13 +04:00
|
|
|
*/
|
2015-02-07 19:51:30 +03:00
|
|
|
#pragma deprecated Use geoip_code3_ex() instead.
|
2007-01-26 08:56:10 +03:00
|
|
|
native geoip_code3(const ip[], result[4]);
|
2004-09-10 07:12:38 +04:00
|
|
|
|
2007-07-19 22:37:13 +04:00
|
|
|
/**
|
|
|
|
* Lookup the full country name for the given IP address. Sets the buffer to "error" on
|
|
|
|
* an unsuccessful lookup.
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @param ip The IP address to lookup.
|
|
|
|
* @param result The result of the geoip lookup.
|
|
|
|
* @param len The maximum length of the result buffer.
|
2015-02-07 18:18:39 +03:00
|
|
|
*
|
|
|
|
* @return The result length.
|
|
|
|
*/
|
|
|
|
#pragma deprecated Use geoip_country_ex() instead.
|
|
|
|
native geoip_country(const ip[], result[], len = 45);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2014-08-01 02:58:02 +04:00
|
|
|
* @param id An optional player's index in order to return the result
|
Geoip: Add an optional parameter in some natves to get a result in player's language.
This is new with Geoip2 database where some entries, like country, city, etc, are translated in several languages.
So far: de, en, es, fr, ru, pt-BR, zh-CN.
2014-07-31 20:23:28 +04:00
|
|
|
* in the player's language, if supported.
|
|
|
|
* -1: the default language, which is english.
|
|
|
|
* 0: the server language. You can use LANG_SERVER define.
|
2014-08-01 02:58:02 +04:00
|
|
|
* >=1: the player's language.
|
|
|
|
*
|
|
|
|
* @return The result length on successful lookup, 0 otherwise.
|
2007-07-19 22:37:13 +04:00
|
|
|
*/
|
2015-02-07 18:18:39 +03:00
|
|
|
native geoip_country_ex(const ip[], result[], len, id = -1);
|
2014-07-30 18:02:32 +04:00
|
|
|
|
2014-08-01 02:58:02 +04:00
|
|
|
/**
|
2014-07-30 18:02:32 +04:00
|
|
|
* Look up the full city name for the given IP address.
|
2014-08-01 02:58:02 +04:00
|
|
|
*
|
2014-08-06 21:39:19 +04:00
|
|
|
* @note This native requires GeoIP City database, which can be retrieved from:
|
|
|
|
* http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary)
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @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
|
Geoip: Add an optional parameter in some natves to get a result in player's language.
This is new with Geoip2 database where some entries, like country, city, etc, are translated in several languages.
So far: de, en, es, fr, ru, pt-BR, zh-CN.
2014-07-31 20:23:28 +04:00
|
|
|
* in the player's language, if supported.
|
|
|
|
* -1: the default language, which is english.
|
|
|
|
* 0: the server language. You can use LANG_SERVER define.
|
2014-08-01 02:58:02 +04:00
|
|
|
* >=1: the player's language.
|
2014-07-30 18:02:32 +04:00
|
|
|
*
|
|
|
|
* @return The result length on successful lookup, 0 otherwise.
|
2014-08-01 02:58:02 +04:00
|
|
|
*/
|
|
|
|
native geoip_city(const ip[], result[], len, id = -1);
|
2014-07-31 00:19:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up the region/state code for the given IP address.
|
|
|
|
* e.g. "US-OH", "DE-HH", IT-82, "FR-U", etc.
|
|
|
|
*
|
2014-08-06 21:39:19 +04:00
|
|
|
* @note This native requires GeoIP City database, which can be retrieved from:
|
|
|
|
* http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary)
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @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.
|
2014-07-31 00:19:23 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @return The result length on successful lookup, 0 otherwise.
|
2014-07-31 00:19:23 +04:00
|
|
|
*/
|
2014-07-31 00:36:39 +04:00
|
|
|
native geoip_region_code(const ip[], result[], len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up the full region/state name for the given IP address.
|
|
|
|
*
|
2014-08-06 21:39:19 +04:00
|
|
|
* @note This native requires GeoIP City database, which can be retrieved from:
|
|
|
|
* http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary)
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @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
|
Geoip: Add an optional parameter in some natves to get a result in player's language.
This is new with Geoip2 database where some entries, like country, city, etc, are translated in several languages.
So far: de, en, es, fr, ru, pt-BR, zh-CN.
2014-07-31 20:23:28 +04:00
|
|
|
* in the player's language, if supported.
|
|
|
|
* -1: the default language, which is english.
|
|
|
|
* 0: the server language. You can use LANG_SERVER define.
|
2014-08-01 02:58:02 +04:00
|
|
|
* >=1: the player's language.
|
2014-07-31 00:36:39 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @return The result length on successful lookup, 0 otherwise.
|
2014-07-31 00:36:39 +04:00
|
|
|
*/
|
Geoip: Add an optional parameter in some natves to get a result in player's language.
This is new with Geoip2 database where some entries, like country, city, etc, are translated in several languages.
So far: de, en, es, fr, ru, pt-BR, zh-CN.
2014-07-31 20:23:28 +04:00
|
|
|
native geoip_region_name(const ip[], result[], len, id = -1);
|
2014-07-31 00:45:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up the full time zone for the given IP address.
|
|
|
|
* e.g. America/Los_Angeles, Europe/Paris.
|
|
|
|
*
|
2014-08-06 21:39:19 +04:00
|
|
|
* @note This native requires GeoIP City database, which can be retrieved from:
|
|
|
|
* http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary)
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @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.
|
2014-07-31 00:45:44 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @return The result length on successful lookup, 0 otherwise.
|
2014-07-31 00:45:44 +04:00
|
|
|
*/
|
2014-07-31 01:28:04 +04:00
|
|
|
native geoip_timezone(const ip[], result[], len);
|
|
|
|
|
2014-08-01 02:58:02 +04:00
|
|
|
/**
|
2014-07-31 01:28:04 +04:00
|
|
|
* Look up the city's latitude for the given IP address.
|
|
|
|
*
|
2014-08-06 21:39:19 +04:00
|
|
|
* @note This native requires GeoIP City database, which can be retrieved from:
|
|
|
|
* http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary)
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @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[]);
|
2014-07-31 01:28:04 +04:00
|
|
|
|
2014-08-01 02:58:02 +04:00
|
|
|
/**
|
|
|
|
* Look up the city's longitude for the given IP address.
|
|
|
|
*
|
2014-08-06 21:39:19 +04:00
|
|
|
* @note This native requires GeoIP City database, which can be retrieved from:
|
|
|
|
* http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary)
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @param ip The IP address to look up.
|
2014-07-31 01:28:04 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @return The result of the geoip look up, 0 if longitude is not found.
|
|
|
|
*/
|
2014-07-31 13:33:58 +04:00
|
|
|
native Float:geoip_longitude(const ip[]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the distance between geographical coordinates, latitude and longitude.
|
|
|
|
*
|
2014-08-06 21:39:19 +04:00
|
|
|
* @note This native requires GeoIP City database, which can be retrieved from:
|
|
|
|
* http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary)
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @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).
|
2014-07-31 13:33:58 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @return The distance as result in specified system of measurement.
|
2014-07-31 13:33:58 +04:00
|
|
|
*/
|
|
|
|
#define SYSTEM_METRIC 0 // kilometers
|
|
|
|
#define SYSTEM_IMPERIAL 1 // statute miles
|
|
|
|
|
2014-07-31 17:21:13 +04:00
|
|
|
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.
|
|
|
|
*
|
2014-08-06 21:39:19 +04:00
|
|
|
* @note This native requires GeoIP City database, which can be retrieved from:
|
|
|
|
* http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary)
|
2014-07-31 17:21:13 +04:00
|
|
|
* @note The code can be retrieved as integer (See CONTINENT_* constants.) or string (2 characters).
|
2014-08-06 00:57:48 +04:00
|
|
|
* @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).
|
2014-07-31 17:21:13 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @param ip The IP address to look up.
|
|
|
|
* @param result The result of the geoip look up.
|
2014-07-31 17:21:13 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @return The continent id on successful lookup, 0 otherwise.
|
2014-07-31 17:21:13 +04:00
|
|
|
*/
|
|
|
|
enum Continent
|
|
|
|
{
|
2014-08-06 21:39:19 +04:00
|
|
|
CONTINENT_UNKNOWN = 0,
|
2014-07-31 17:21:13 +04:00
|
|
|
CONTINENT_AFRICA,
|
2014-08-06 00:57:48 +04:00
|
|
|
CONTINENT_ANTARCTICA,
|
2014-07-31 17:21:13 +04:00
|
|
|
CONTINENT_ASIA,
|
|
|
|
CONTINENT_EUROPE,
|
|
|
|
CONTINENT_NORTH_AMERICA,
|
|
|
|
CONTINENT_OCEANIA,
|
2014-08-06 00:57:48 +04:00
|
|
|
CONTINENT_SOUTH_AMERICA,
|
2014-07-31 17:21:13 +04:00
|
|
|
};
|
2014-07-31 17:29:57 +04:00
|
|
|
native Continent:geoip_continent_code(const ip[], result[3]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up the full continent name for the given IP address.
|
|
|
|
*
|
2014-08-06 21:39:19 +04:00
|
|
|
* @note This native requires GeoIP City database, which can be retrieved from:
|
|
|
|
* http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary)
|
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @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
|
Geoip: Add an optional parameter in some natves to get a result in player's language.
This is new with Geoip2 database where some entries, like country, city, etc, are translated in several languages.
So far: de, en, es, fr, ru, pt-BR, zh-CN.
2014-07-31 20:23:28 +04:00
|
|
|
* in the player's language, if supported.
|
|
|
|
* -1: the default language, which is english.
|
|
|
|
* 0: the server language. You can use LANG_SERVER define.
|
2014-08-01 02:58:02 +04:00
|
|
|
* >=1: the player's language.
|
2014-07-31 17:29:57 +04:00
|
|
|
*
|
2014-08-01 02:58:02 +04:00
|
|
|
* @return The result length on successful lookup, 0 otherwise.
|
2014-07-31 17:29:57 +04:00
|
|
|
*/
|
Geoip: Add an optional parameter in some natves to get a result in player's language.
This is new with Geoip2 database where some entries, like country, city, etc, are translated in several languages.
So far: de, en, es, fr, ru, pt-BR, zh-CN.
2014-07-31 20:23:28 +04:00
|
|
|
native geoip_continent_name(const ip[], result[], len, id = -1);
|