Raised This Month: $ Target: $400
 0% 

[SNIPPET] Get Client's City


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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:46.


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