AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET] Get Client's City (https://forums.alliedmods.net/showthread.php?t=79647)

SAMURAI16 10-27-2008 00:25

[SNIPPET] Get Client's City
 
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)

Alka 10-27-2008 15:27

Re: [SNIPPET] Get Client's City
 
Heh ;P

stylerro 11-07-2008 02:50

Re: [SNIPPET] Get Client's City
 
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

SAMURAI16 11-07-2008 06:52

Re: [SNIPPET] Get Client's City
 
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

p3tsin 11-07-2008 11:44

Re: [SNIPPET] Get Client's City
 
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. :nono:

SAMURAI16 11-07-2008 11:49

Re: [SNIPPET] Get Client's City
 
yea i noticed that. For me also it takes few seconds (Romania) ;
Someone from USA tested and no server freeze

eforie 06-06-2009 07:37

Re: [SNIPPET] Get Client's City
 
how to convert this script to amxmodx ?
please help me

CrimsonGT 06-06-2009 08:52

Re: [SNIPPET] Get Client's City
 
Very nice snippet Samurai/Alka :)

Innovative features such as this are very cool to see, even if they have bugs.

exvel 06-06-2009 10:41

Re: [SNIPPET] Get Client's City
 
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.)

SAMURAI16 06-06-2009 12:51

Re: [SNIPPET] Get Client's City
 
the link is with old database
updated

eforie 06-07-2009 09:21

Re: [SNIPPET] Get Client's City
 
samurai could you make this ,working with amxx ?
i don`t know to convert from source to amxx

eforie 08-07-2009 07:32

Re: [SNIPPET] Get Client's City
 
samurai thank you for your help
you are a good man !

bl4nk 08-07-2009 15:16

Re: [SNIPPET] Get Client's City
 
FYI, this has been updated since the first post. You can get the (current) newest version here:

http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/GeoLiteCity_20090801.zip

It's updated on the first day of every month. You can get the new file here:

http://www.maxmind.com/app/geolitecity

Just look for the link that says "Download the latest GeoLite City CSV Format".

kokzok 12-19-2009 03:13

Re: [SNIPPET] Get Client's City
 
How to use it?
I have compiled a code, have put in <server>\addons\sourcemod\plugins\
Extract .csv files in <server>\addons\sourcemod\configs\geoip
But at connect on a server, in a chat the information on a city of the player is not deduced

p.s. Tested on L4D2 (sm 1.4.0 (Dec 16 2009), sm 1.3.0 (xx xx 2009)) and TF2 (sm 1.2.3 (Aug 28 2009))

noodleboy347 01-10-2010 17:53

Re: [SNIPPET] Get Client's City
 
Can someone post a compiled version? It's not working for me..

ltgenkd 01-12-2010 02:00

Re: [SNIPPET] Get Client's City
 
Same here, errors compiling on web compiler AND compiler in local sourcemod folder. Same errors for each compiler.

Code:

/home/groups/sourcemod/upload_tmp/phpDes4Ex.sp(0) : error 075: input line too long (after substitutions)
/home/groups/sourcemod/upload_tmp/phpDes4Ex.sp(1) : error 038: extra characters on line
/home/groups/sourcemod/upload_tmp/phpDes4Ex.sp(1) : error 075: input line too long (after substitutions)
/home/groups/sourcemod/upload_tmp/phpDes4Ex.sp(3) : error 010: invalid function or declaration


ltgenkd 01-12-2010 04:26

Re: [SNIPPET] Get Client's City
 
3 Attachment(s)
I DL the most recent .CSV files from the link in bl4nks's post above.
Added them to configs/geoip folder.
I also copied and pasted SAMURAI's original code onto Notepad++ and recompiled and tested. It worked but lagged the server big time. It prints out an ip that is unfamiliar to me but, did a little more snooping around. If you go HERE you can try the demo and put your ip that prints to chat and its right on the money.
Tested plugin on L4d running windows. If we can get someone to right a script as exvel stated here it would be a lot better. Screen shot of print to chat and .smx and .sp attached.

willy1234x1 04-30-2010 05:26

Re: [SNIPPET] Get Client's City
 
The only issue I see with this is that it could be a whole privacy thing, implementing it any plugin I'd suggest making a menu that asks the player if they'd allow it like most browsers with Geoip.

urus 05-28-2010 09:52

Re: [SNIPPET] Get Client's City
 
Maxmind geolitecity database is huge.
Correct method will be import csv files into MySQL and special fast query to take data.

http://atomboy.isa-geek.com/plone/Me...ile-into-mysql

maza51 07-08-2010 11:47

Re: [SNIPPET] Get Client's City
 
Does not work =(((


All times are GMT -4. The time now is 18:08.

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