Raised This Month: $51 Target: $400
 12% 

[SNIPPET] Get Client's City


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SAMURAI16
BANNED
Join Date: Sep 2006
Old 10-27-2008 , 00:25   [SNIPPET] Get Client's City
Reply With Quote #1

I know with geoip you can get client's countrys.
Now with this you can get cities/towns also
I'll have to thanks to Alka for making this on amxx

First download this : http://geolite.maxmind.com/download/...y_20090601.zip
Extract, and put that 2 files .csv in your /sourcemod/configs/geoip/ folder

code:
Code:
#include <sourcemod> public Plugin:myinfo = {     name = "Get Client City",     author = "SAMURAI",     description = "",     version = "1.0",     url = "www.cs-utilz.net" } enum {     a = 0,     b,     c,     d }; new String:g_szDataBlock[128]; new String:g_szLocationData[128]; public OnPluginStart() {     RegConsoleCmd("test_city",fn_cmdTest);     } public OnConfigsExecuted() {     BuildPath(Path_SM,g_szDataBlock,sizeof(g_szDataBlock),"configs/geoip/GeoLiteCity-Blocks.csv");     BuildPath(Path_SM,g_szLocationData,sizeof(g_szLocationData),"configs/geoip/GeoLiteCity-Location.csv"); } public Action:fn_cmdTest(client,args) {     // get client IP     new String:szIP[32];     GetClientIP(client,szIP,sizeof(szIP),true);         new iIP = ip_to_num(szIP); // we need IP in number format     new iLoc = get_loc_id(iIP); // location id from number IP         // now we get city     new String:szCity[64];     get_city(iLoc, szCity);         // printing     PrintToChat(client,"I'm from City : %s (IP:%d | Locid:%d)", szCity, iIP, iLoc); } stock ip_to_num(const String:szIp[32]) {     if(!szIp[0])         return 0;         new String:szTemp[4][16];     str_piece(szIp, szTemp, sizeof szTemp, sizeof(szTemp[]), '.');             new iIP;     iIP = (16777216 * StringToInt(szTemp[a])) + (65536 * StringToInt(szTemp[b])) + (256 * StringToInt(szTemp[c])) + StringToInt(szTemp[d]);         return iIP; } stock get_loc_id(iIP) {     new Handle:iFile = OpenFile(g_szDataBlock,"rt");         new String:szBuffer[256], String:szTemp[3][64];     new iLoc;     while(!IsEndOfFile(iFile))     {         ReadFileLine(iFile, szBuffer, sizeof(szBuffer));                 TrimString(szBuffer);                 str_piece(szBuffer, szTemp, sizeof(szTemp), sizeof (szTemp[]), ',');                 for(new i = 0 ; i < 3 ; i++)             StripQuotes(szTemp[i]);                 if(StringToInt(szTemp[0]) <= iIP <= StringToInt(szTemp[1]))         {             iLoc = StringToInt(szTemp[2]);             break;         }     }     CloseHandle(iFile);     return iLoc; } stock get_city(iLocid, String:szCity[64]) {     new Handle:iFile = OpenFile(g_szLocationData,"rt");         new String:szBuffer[256], String:szTemp[10][64];     while(!IsEndOfFile(iFile))     {         ReadFileLine(iFile, szBuffer, sizeof (szBuffer));         TrimString(szBuffer);                 str_piece(szBuffer, szTemp, sizeof szTemp, sizeof(szTemp[]), ',');                 if((StringToInt(szTemp[0]) == iLocid))         {             StripQuotes(szTemp[3]);             FormatEx(szCity, sizeof(szCity), "%s", szTemp[3]);             break;         }     }     CloseHandle(iFile); } stock str_piece(const String:input[], String:output[][], outputsize, piecelen, token = '|') {     new i = -1, pieces, len = -1 ;         while ( input[++i] != 0 )     {         if ( input[i] != token )         {             if ( ++len < piecelen )                 output[pieces][len] = input[i] ;         }         else         {             output[pieces++][++len] = 0 ;             len = -1 ;                         if ( pieces == outputsize )                 return pieces ;         }     }     return pieces + 1; }

My result:
I'm from City : Piatra Neamt (IP:1449916455 | Locid:52753)

Last edited by SAMURAI16; 06-06-2009 at 12:52.
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 10-27-2008 , 15:27   Re: [SNIPPET] Get Client's City
Reply With Quote #2

Heh ;P
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
stylerro
Senior Member
Join Date: Mar 2007
Old 11-07-2008 , 02:50   Re: [SNIPPET] Get Client's City
Reply With Quote #3

1. "I'll have to thanks to Alka for making this on amxx"

where is amxx version? i search and didt find ..
pls a link

2. Can u make to show for any player when they join in server ? and show isp too?

ty and sorry for my english

Last edited by stylerro; 11-07-2008 at 02:54.
stylerro is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 11-07-2008 , 06:52   Re: [SNIPPET] Get Client's City
Reply With Quote #4

I don't still have amxx version but it's simple to convert it
About isp, via sourcemod is impossible. For amxx you can use netdb module

Last edited by SAMURAI16; 11-07-2008 at 06:56.
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 11-07-2008 , 11:44   Re: [SNIPPET] Get Client's City
Reply With Quote #5

Sure is nice and all as a feature, but it takes like 3 to 5 seconds to get the location (at least for me) and it makes the server freeze during the query... that's not cool.
__________________
plop
p3tsin is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 11-07-2008 , 11:49   Re: [SNIPPET] Get Client's City
Reply With Quote #6

yea i noticed that. For me also it takes few seconds (Romania) ;
Someone from USA tested and no server freeze
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
eforie
BANNED
Join Date: Dec 2008
Location: Romania
Old 06-06-2009 , 07:37   Re: [SNIPPET] Get Client's City
Reply With Quote #7

how to convert this script to amxmodx ?
please help me
eforie is offline
Send a message via Yahoo to eforie Send a message via Skype™ to eforie
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 06-06-2009 , 08:52   Re: [SNIPPET] Get Client's City
Reply With Quote #8

Very nice snippet Samurai/Alka

Innovative features such as this are very cool to see, even if they have bugs.
__________________
CrimsonGT is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 06-06-2009 , 10:41   Re: [SNIPPET] Get Client's City
Reply With Quote #9

Good job Samurai.
You can write a script that will convert this file into sqlite DB on plugin start so during the game there won't be any lags, you can use TQueries for this.
p.s. it seems that link is broken (The requested [url] was not found on this server.)
__________________
For admins: My plugins

For developers: Colors library

Last edited by exvel; 06-06-2009 at 10:43.
exvel is offline
Send a message via ICQ to exvel
SAMURAI16
BANNED
Join Date: Sep 2006
Old 06-06-2009 , 12:51   Re: [SNIPPET] Get Client's City
Reply With Quote #10

the link is with old database
updated
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:00.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode