Update GeoIP2 extension to new GeoLite2 .mmdb database format (#1245)
* Add support for Maxmind GeoIP2 database files (#913). * Copy/paste error. * Mark GeoipCode3 as deprecated. * Fix build when compiling with AMBuild. * Replace loose libmaxminddb files with submodule. * Fix Linux build. * One more hack for submodule. * Actually fix Linux build. * GeoIP2 extension to sourcemod * Update basevotes When a player leaves during a voteban, he will be banned anyway. Also added a cvar with a ban time setting. * Update basevotes.sp * Update AMBuilder * ke::AString to std::string * Update extension.cpp * Update AMBuilder * Added coordination natives Added GeoipLatitude, GeoipLongitude, GeoipDistance natives. * Create osdefs.h * Update maxminddb_config.h * Update extension.cpp * Update extension.cpp * Added automatic search for database file * Fix automatic search for database file * Update extension.cpp * Update geoip.inc * .gitmodules revert * Update geoip.inc * Update libmaxminddb to version 1.5.2 * Update extension.cpp * Check language in the DB * Removed langCount variable * Determination of the client's language * Update geoip.inc * Update geoip.inc * Update extension.cpp * Update geoip.inc * Update extension.cpp * space instead of tab in .inc * Update extension.cpp * Update geoip.inc * Optimizing length measurement region code * Update package script to fetch the new GeoLite2 database This package is the last CC-BY-SA licensed GeoLite2-City database extracted from https://src.fedoraproject.org/rpms/geolite2 from december 2019. This doubles the download size for SM packages, but it's what we have to deal with atm :( * Fix potentially returning uninitialized memory in GeoipRegionCode If the lookup failed, we'd copy back whatever is on the stack in the ccode buffer. Co-authored-by: Nick Hastings <[email protected]> Co-authored-by: Headline <[email protected]> Co-authored-by: Accelerator74 <[email protected]> Co-authored-by: Peace-Maker <[email protected]>
This commit is contained in:
co-authored by
Nick Hastings
Headline
Accelerator74
Peace-Maker
parent
c38d45b9e7
commit
b0563a493c
+143
-4
@@ -35,6 +35,22 @@
|
||||
#endif
|
||||
#define _geoip_included
|
||||
|
||||
enum Continent
|
||||
{
|
||||
CONTINENT_UNKNOWN = 0,
|
||||
CONTINENT_AFRICA,
|
||||
CONTINENT_ANTARCTICA,
|
||||
CONTINENT_ASIA,
|
||||
CONTINENT_EUROPE,
|
||||
CONTINENT_NORTH_AMERICA,
|
||||
CONTINENT_OCEANIA,
|
||||
CONTINENT_SOUTH_AMERICA,
|
||||
};
|
||||
|
||||
// The system of measurement for calculate the distance between geographical coordinates
|
||||
#define SYSTEM_METRIC 0 // kilometers
|
||||
#define SYSTEM_IMPERIAL 1 // statute miles
|
||||
|
||||
#include <core>
|
||||
|
||||
/**
|
||||
@@ -46,7 +62,7 @@
|
||||
*
|
||||
* @param ip Ip to determine the country code.
|
||||
* @param ccode Destination string buffer to store the code.
|
||||
* @return True on success, false if no country found.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool GeoipCode2(const char[] ip, char ccode[3]);
|
||||
|
||||
@@ -55,20 +71,133 @@ native bool GeoipCode2(const char[] ip, char ccode[3]);
|
||||
*
|
||||
* @param ip Ip to determine the country code.
|
||||
* @param ccode Destination string buffer to store the code.
|
||||
* @return True on success, false if no country found.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool GeoipCode3(const char[] ip, char ccode[4]);
|
||||
|
||||
/**
|
||||
* Gets the full country name. (max length of output string is 45)
|
||||
* Gets the region code with country code from an IP address. (US-IL, CH-CHE, etc)
|
||||
*
|
||||
* @param ip Ip to determine the region code.
|
||||
* @param ccode Destination string buffer to store the code.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool GeoipRegionCode(const char[] ip, char ccode[12]);
|
||||
|
||||
/**
|
||||
* Gets the two character continent code from an IP address. (EU, AS, etc)
|
||||
*
|
||||
* @param ip Ip to determine the continent code.
|
||||
* @param ccode Destination string buffer to store the code.
|
||||
* @return The continent id on success, 0 otherwise.
|
||||
*/
|
||||
native Continent GeoipContinentCode(const char[] ip, char ccode[3]);
|
||||
|
||||
/**
|
||||
* Gets the full country name.
|
||||
*
|
||||
* @param ip Ip to determine the country code.
|
||||
* @param name Destination string buffer to store the country name.
|
||||
* @param maxlength Maximum length of output string buffer.
|
||||
* @return True on success, false if no country found.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool GeoipCountry(const char[] ip, char[] name, int maxlength);
|
||||
|
||||
/**
|
||||
* Gets the full country name.
|
||||
*
|
||||
* @param ip Ip to determine the country code.
|
||||
* @param name Destination string buffer to store the country name.
|
||||
* @param maxlength Maximum length of output string buffer.
|
||||
* @param client Client index in order to return the result in the player's language
|
||||
* -1: the default language, which is english.
|
||||
* 0: the server language. You can use LANG_SERVER define.
|
||||
* >=1: the player's language.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool GeoipCountryEx(const char[] ip, char[] name, int maxlength, int client = -1);
|
||||
|
||||
/**
|
||||
* Gets the full continent name.
|
||||
*
|
||||
* @param ip Ip to determine the continent code.
|
||||
* @param name Destination string buffer to store the continent name.
|
||||
* @param maxlength Maximum length of output string buffer.
|
||||
* @param client Client index in order to return the result in the player's language
|
||||
* -1: the default language, which is english.
|
||||
* 0: the server language. You can use LANG_SERVER define.
|
||||
* >=1: the player's language.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool GeoipContinent(const char[] ip, char[] name, int maxlength, int client = -1);
|
||||
|
||||
/**
|
||||
* Gets the full region name.
|
||||
*
|
||||
* @param ip Ip to determine the region code.
|
||||
* @param name Destination string buffer to store the region name.
|
||||
* @param maxlength Maximum length of output string buffer.
|
||||
* @param client Client index in order to return the result in the player's language
|
||||
* -1: the default language, which is english.
|
||||
* 0: the server language. You can use LANG_SERVER define.
|
||||
* >=1: the player's language.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool GeoipRegion(const char[] ip, char[] name, int maxlength, int client = -1);
|
||||
|
||||
/**
|
||||
* Gets the city name.
|
||||
*
|
||||
* @param ip Ip to determine the city code.
|
||||
* @param name Destination string buffer to store the city name.
|
||||
* @param maxlength Maximum length of output string buffer.
|
||||
* @param client Client index in order to return the result in the player's language
|
||||
* -1: the default language, which is english.
|
||||
* 0: the server language. You can use LANG_SERVER define.
|
||||
* >=1: the player's language.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool GeoipCity(const char[] ip, char[] name, int maxlength, int client = -1);
|
||||
|
||||
/**
|
||||
* Gets the timezone.
|
||||
*
|
||||
* @param ip Ip to determine the timezone.
|
||||
* @param name Destination string buffer to store the timezone.
|
||||
* @param maxlength Maximum length of output string buffer.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool GeoipTimezone(const char[] ip, char[] name, int maxlength);
|
||||
|
||||
/**
|
||||
* Gets the city's latitude
|
||||
*
|
||||
* @param ip Ip to determine the city latitude.
|
||||
* @return The result of the latitude, 0 if latitude is not found
|
||||
*/
|
||||
native float GeoipLatitude(const char[] ip);
|
||||
|
||||
/**
|
||||
* Gets the city's longitude
|
||||
*
|
||||
* @param ip Ip to determine the city longitude.
|
||||
* @return The result of the longitude, 0 if longitude is not found
|
||||
*/
|
||||
native float GeoipLongitude(const char[] ip);
|
||||
|
||||
/*
|
||||
* 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 = Metric(kilometers) or 1 = English(miles).
|
||||
*
|
||||
* @return The distance as result in specified system of measurement.
|
||||
*/
|
||||
native float GeoipDistance(float lat1, float lon1, float lat2, float lon2, int system = SYSTEM_METRIC);
|
||||
|
||||
/**
|
||||
* @endsection
|
||||
*/
|
||||
@@ -97,6 +226,16 @@ public void __ext_geoip_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("GeoipCode2");
|
||||
MarkNativeAsOptional("GeoipCode3");
|
||||
MarkNativeAsOptional("GeoipRegionCode");
|
||||
MarkNativeAsOptional("GeoipContinentCode");
|
||||
MarkNativeAsOptional("GeoipCountry");
|
||||
MarkNativeAsOptional("GeoipCountryEx");
|
||||
MarkNativeAsOptional("GeoipContinent");
|
||||
MarkNativeAsOptional("GeoipRegion");
|
||||
MarkNativeAsOptional("GeoipCity");
|
||||
MarkNativeAsOptional("GeoipTimezone");
|
||||
MarkNativeAsOptional("GeoipLatitude");
|
||||
MarkNativeAsOptional("GeoipLongitude");
|
||||
MarkNativeAsOptional("GeoipDistance");
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user