Lately there has been a bit of demand to get the city names from an IP address. After seeing a few attempts in the snippits forum, I decided to create my own addon.
This extension will do the same thing, only it's several thousand times faster than the Pawn/SQL/CSV methods that have been posted. It also supports UTF8 (the others did not).
- Download the free version of the GeoIPCity database. Click: GeoLiteCity.dat.gz
- Extract it to /addons/sourcemod/configs/geoip/
- Rename it to GeoIPCity.dat (the name of the paid version)
- Install the GeoIPCity extension as usual
You will notice that all of the data is grabbed at once, meaning you only have to make one query and can cache the results to use however you like.
* Gets the GeoIP record from an IP address.
* @param ip Ip to determine the country code.
* @param city Destination string buffer to store the city name. (45 characters max)
* @param region The region/province/state name. (45 characters max)
* @param country_name The country name. (45 characters max)
* @param country_code The two character country code. (US, CA, etc)
* @param country_code3 The three character country code. (USA, CAN, etc)
* @return True on success, false if no record found.
native bool:GeoipGetRecord(const String:ip, String:city, String:region, String:country_name, String:country_code, String:country_code3);
Provided below is a modified version of Arg!'s Connect Announce
plugin. This will use GeoIPCity for city/region support, and will fall back to the default GeoIP extension if GeoIPCity isn't loaded.
- Fixed memory leak.
- Fixed crash when failing to load IP database.
- Fixed incorrect extension version being shown.
- Cleaned up project files.
- Fixed a major bug when LAN users join the server
- Updated sample plugin
- Initial release