ISource2ModGeoIP
Country, city and the rest of where an IP address is.
Lookups go to a MaxMind GeoLite2 database (.mmdb) through libmaxminddb. The database is not shipped: download GeoLite2-City.mmdb (or the smaller GeoLite2-Country.mmdb, which has no city, region, time zone or location) from MaxMind and put it where core.json's "GeoIPDatabase" says -- addons/source2mod/geoip/GeoLite2-City.mmdb by default. Without it every lookup returns false and the core says so once in its log.
An address may carry a port ("1.2.3.4:27005"); it is cut off.
Interface id ISource2ModGeoIP001 (SOURCE2MOD_GEOIP_INTERFACE) · Global g_pSource2ModGeoIP · Header source2mod/ISource2ModGeoIP.h
Methods
IsLoaded
virtual bool IsLoaded() = 0;Whether a database is open.
GetDatabaseType
virtual const char* GetDatabaseType() = 0;The database's type, "GeoLite2-City" / "GeoLite2-Country"; "" when none is open.
Lookup
virtual bool Lookup(const char* ip, Source2ModGeoIPField field, char* out, size_t maxlen, const char* language = nullptr) = 0;Looks one field of an address up.
| Parameter | Type | Default | Description |
|---|---|---|---|
ip | const char* | IPv4 or IPv6, a port is allowed. | |
field | Source2ModGeoIPField | What to read. | |
out | char* | Receives it, "" on failure. | |
maxlen | size_t | Size of out. | |
language | const char* | nullptr | For the names: "en", "de", "es", "fr", "ja", "pt-BR", "ru", "zh-CN"; nullptr = "en". Falls back to English when the database has no name in that language. |
Returns bool — false when there is no database, the address is not in it, or the database has no such field for it.
LookupPlayer
virtual bool LookupPlayer(CPlayerSlot slot, Source2ModGeoIPField field, char* out, size_t maxlen, const char* language = nullptr) = 0;Lookup() for the address of the player in this slot.
| Parameter | Type | Default |
|---|---|---|
slot | CPlayerSlot | |
field | Source2ModGeoIPField | |
out | char* | |
maxlen | size_t | |
language | const char* | nullptr |
GetLocation
virtual bool GetLocation(const char* ip, double& latitude, double& longitude) = 0;Latitude and longitude. City database only.
| Parameter | Type |
|---|---|
ip | const char* |
latitude | double& |
longitude | double& |
LookupPath
virtual bool LookupPath(const char* ip, const char* path, char* out, size_t maxlen) = 0;Any string, number or bool of the record, by its path.
g_pSource2ModGeoIP->LookupPath("8.8.8.8", "country/names/de", buf, sizeof(buf));
g_pSource2ModGeoIP->LookupPath("8.8.8.8", "subdivisions/0/iso_code", buf, sizeof(buf));| Parameter | Type | Description |
|---|---|---|
ip | const char* | |
path | const char* | Keys and array indices separated by '/'. |
out | char* | |
maxlen | size_t |
GetPlayerIP
virtual bool GetPlayerIP(CPlayerSlot slot, char* out, size_t maxlen) = 0;The player's IP address without the port; false for an empty slot or a bot.
| Parameter | Type |
|---|---|
slot | CPlayerSlot |
out | char* |
maxlen | size_t |
Enums
Source2ModGeoIPField
enum Source2ModGeoIPFieldWhat Lookup() reads.
| Name | Value | Description |
|---|---|---|
SOURCE2MOD_GEOIP_COUNTRY_CODE | 0 | ISO 3166-1 alpha-2, "US". |
SOURCE2MOD_GEOIP_COUNTRY | 1 | "United States". |
SOURCE2MOD_GEOIP_CONTINENT_CODE | 2 | Two letters, "NA". |
SOURCE2MOD_GEOIP_CONTINENT | 3 | "North America". |
SOURCE2MOD_GEOIP_REGION_CODE | 4 | The first subdivision's ISO code, "CA". City database only. |
SOURCE2MOD_GEOIP_REGION | 5 | "California". City database only. |
SOURCE2MOD_GEOIP_CITY | 6 | "Mountain View". City database only. |
SOURCE2MOD_GEOIP_TIMEZONE | 7 | IANA time zone, "America/Los_Angeles". City database only. |
SOURCE2MOD_GEOIP_POSTAL_CODE | 8 | Postal code. City database only. |