Thread: GeoIPCity
View Single Post
Author Message
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 07-15-2010 , 11:24   GeoIPCity
Reply With Quote #1

GeoIPCity

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).

Installation:
  • 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

Usage:

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.

PHP Code:
// geoipcity.inc

/**
 * 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[45], String:region[45], String:country_name[45], String:country_code[3], String:country_code3[4]); 
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.

http://forums.alliedmods.net/showpos...3&postcount=47

Changelog:
Quote:
GeoIPCity 1.1.2
- Fixed memory leak.

GeoIPCity 1.1.1
- Fixed crash when failing to load IP database.
- Fixed incorrect extension version being shown.
- Cleaned up project files.

GeoIPCity 1.1.0
- Fixed a major bug when LAN users join the server
- Updated sample plugin

GeoIPCity 1.0.0
- Initial release
Attached Files
File Type: zip GeoIPCity-1.1.2.zip (199.7 KB, 10381 views)
File Type: zip GeoIPCity-1.1.2-src.zip (68.2 KB, 3175 views)
__________________

Last edited by GoD-Tony; 04-06-2015 at 04:18.
GoD-Tony is offline