View Single Post
Author Message
n3wton
Senior Member
Join Date: Mar 2010
Old 04-14-2010 , 20:16   [INC] GeoCity (Get Players City From IP)
Reply With Quote #1

Introduction

This include uses GeoLite City to calculate where a clients IP address "represents" there city to be.

Basically I took GeoLite Cities .csv file and put all the data into an SQlite database which can the be used to find the clients city.


Command

GeoipCity( const String:ip[], String:city[], const maxlength )

ip : IP Address of the client ( use sourcemods GetClientIP command )
city : A buffer to store the clients city in
maxlength : Maximum length of the buffer

Example

Code:
public OnClientConnected( client )
{
     new String:IP[16];
     new String:City[32];
     GetClientIP( client, IP, 16 );
     GeoipCity( IP, City, 32 );
     PrintToChat( client, "%N is from %s", client, City );
}
Installation

Download geocity.inc and put it in "addons\sourcemod\scripting\include".
Download GeoLiteCity.zip and extract GeoLiteCity.sq3 into "addons\sourcemod\data\sqlite" on the server.

Then just include geocity to your source code.
#include <geocity>

Note
1-There is a small amount of lag (< 0.1 second) when getting the city, so it is recomended that you only get the city on connect, then store it in a 2 dimensional array to call on when ever needed.

2-As the .zip containing the .sq3 database is ~50mb and these forums only allow up to 5mb, I will upload it to multiple download locations, though if someone has a server willing to host, please let me know.

3-This is still in a beta version, I think its 100% stable and I use it in one of my plugins, on my server and have had no problems.

Download

GeoLiteCity.zip {RapidShare}
GeoLiteCity.zip {MegaUpload}

Yours
N3wton
Attached Files
File Type: inc geocity.inc (4.8 KB, 1587 views)

Last edited by asherkin; 05-01-2012 at 08:10. Reason: Removed dead link to my site.
n3wton is offline