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.

ParameterTypeDefaultDescription
ipconst char*IPv4 or IPv6, a port is allowed.
fieldSource2ModGeoIPFieldWhat to read.
outchar*Receives it, "" on failure.
maxlensize_tSize of out.
languageconst char*nullptrFor 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.

ParameterTypeDefault
slotCPlayerSlot
fieldSource2ModGeoIPField
outchar*
maxlensize_t
languageconst char*nullptr

GetLocation

virtual bool GetLocation(const char* ip, double& latitude, double& longitude) = 0;

Latitude and longitude. City database only.

ParameterType
ipconst char*
latitudedouble&
longitudedouble&

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));
ParameterTypeDescription
ipconst char*
pathconst char*Keys and array indices separated by '/'.
outchar*
maxlensize_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.

ParameterType
slotCPlayerSlot
outchar*
maxlensize_t

Enums

Source2ModGeoIPField

enum Source2ModGeoIPField

What Lookup() reads.

NameValueDescription
SOURCE2MOD_GEOIP_COUNTRY_CODE0ISO 3166-1 alpha-2, "US".
SOURCE2MOD_GEOIP_COUNTRY1"United States".
SOURCE2MOD_GEOIP_CONTINENT_CODE2Two letters, "NA".
SOURCE2MOD_GEOIP_CONTINENT3"North America".
SOURCE2MOD_GEOIP_REGION_CODE4The first subdivision's ISO code, "CA". City database only.
SOURCE2MOD_GEOIP_REGION5"California". City database only.
SOURCE2MOD_GEOIP_CITY6"Mountain View". City database only.
SOURCE2MOD_GEOIP_TIMEZONE7IANA time zone, "America/Los_Angeles". City database only.
SOURCE2MOD_GEOIP_POSTAL_CODE8Postal code. City database only.

On this page