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

Module: Special Geoip v1.0.0.1 (Linux + Windows)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 08-27-2012 , 10:53   Module: Special Geoip v1.0.0.1 (Linux + Windows)
Reply With Quote #1

Special Geoip
1.0.0.1




Download
Download latest GeoLiteCity.dat (GeoLite City GZip version) from MaxMind
View C++ source code
GeoIP C Sources

Informations

♠ Compiled on March 16, 2014 GMT.
♠ It uses the latest C sources.
♠ Returns N/A if nothing was found.

AMX Mod X integration

PHP Code:
/** Special Geoip v1.0.0.1
 * by Hattrick (Claudiu HKS)
 */

#if defined _special_geoip_included
   #endinput
#endif

#define _special_geoip_included

#if AMXX_VERSION_NUM >= 175
   #pragma reqlib special_geoip

   #if !defined AMXMODX_NOAUTOLOAD
      #pragma loadlib special_geoip
   #endif
#else
   #pragma library special_geoip
#endif

/** Util functions.
 */
stock AddCommas(NumOutput[], Len)
{
   static 
Tmp[16], OutputPos 0NumPos 0NumLen 0;

   
OutputPos NumPos 0;

   if (
Num 0)
   {
      
Output[OutputPos++] = '-';

      
Num abs(Num);
   }

   
NumLen num_to_str(NumTmpcharsmax(Tmp));

   if (
NumLen <= 3)
      
OutputPos += copy(Output[OutputPos], LenTmp);

   else
   {
      while (
NumPos NumLen && OutputPos Len)
      {
         
Output[OutputPos++] = Tmp[NumPos++];

         if (
NumLen NumPos && !((NumLen NumPos) % 3))
            
Output[OutputPos++] = ',';
      }

      
Output[OutputPos] = '^0';
   }
}

stock GeoipStripAddress(Address[])
{
   static 
Iterator 0;

   for (
Iterator strlen(Address) - 1Iterator >= 0Iterator--)
   {
      if (
Address[Iterator] == ':')
      {
         
Address[Iterator] = '^0';

         break;
      }
   }
}

stock GeoipFloatCommas(Float:ValueBuffer[], Size)
{
   
AddCommas(floatround(Value), BufferSize);
}

stock GeoipNumCommas(ValueBuffer[], Size)
{
   
AddCommas(ValueBufferSize);
}

/** Math predefinitions.
 */
#define F_Cos floatcos
#define F_Sin floatsin

stock Float:F_ACos(Float:Value)
{
   return 
floatacos(Valueradian);
}

stock Float:F_ASin(Float:Value)
{
   return 
floatasin(Valueradian);
}

/** Defines Geoip charsets.
 */
enum GeoCharset
{
   
GC_ISO8859 =    0,    // Normal characters.
   
GC_UTF8 =    1    // Special characters.
};

/** Defines Geoip informations.
 */
enum GeoInfo
{
   
/** Some examples below.
    */
   
GI_Country =        0,    // Romania        United States
   
GI_CountryCode =    1,    // RO            US
   
GI_CountryCode3 =    2,    // ROU            USA
   
GI_Region =        3,    // Cluj            New York
   
GI_TimeZone =        4,    // Europe/Bucharest    America/New_York
   
GI_City =        5,    // Turda            New Rochelle
   
GI_ContinentCode =    6,    // EU            NA
   
GI_RegionCode =        7,    // 13            NY
   
GI_Latitude =        8,    // 46.566700        40.911499
   
GI_Longitude =        9,    // 23.783300        -73.782303
   
GI_AreaCode =        10,    // 0            914
   
GI_PostalCode =        11,    // N/A            N/A
   
GI_MetroCode =        12,    // 0            501
   
GI_DmaCode =        13,    // 0            501
   
GI_NetMask =        14,    // 21            22
   
GI_Continent =        15,    // Europe            North America
   
GI_Charset =        16    // 1            1
};

/** Retrieves a result.
 *
 * @param Address        The IP address to retrieve information from.
 * @param Info        The information to retrieve.
 * @param Buffer        The variable to store result in.
 * @param Size        The variable that represents the buffer size.
 *
 * @return        True if success.
 */
native /* bool */        bool:GeoipInfo(const Address[], GeoInfo:InfoBuffer[], Size);

/** Changes charset.
 *
 * @param Charset        The charset to set.
 *
 * @return        True.
 */
native /* void */        GeoipCharset(GeoCharset:Charset);

/** Retrieves distance.
 *
 * Thanks Arkshine (@Forums.AlliedMods.Com) for this.
 * 0.017453 means PI / 180U and 3959U and 6371U means Earth radius both for imperial and metrical measurement systems.
 *
 * @param Address        The first IP address.
 * @param Other        The second IP address.
 * @param Imperial        Whether or not to use imperial measurement system.
 *
 * @return        The distance, if any. Otherwise, zero.
 */
stock /* long double */    Float:GeoipDistance(const Address[], const Other[], bool:Imperial true)
{
   static 
AddressLatitude[16], AddressLongitude[16], OtherLatitude[16], OtherLongitude[16], \
      
Float:fAddressLatitude 0.0Float:fAddressLongitude 0.0Float:fOtherLatitude 0.0Float:fOtherLongitude 0.0;

   if (
GeoipInfo(AddressGI_LatitudeAddressLatitudecharsmax(AddressLatitude)) && GeoipInfo(OtherGI_LatitudeOtherLatitudecharsmax(OtherLatitude)) && \
      
GeoipInfo(AddressGI_LongitudeAddressLongitudecharsmax(AddressLongitude)) && GeoipInfo(OtherGI_LongitudeOtherLongitudecharsmax(OtherLongitude)))
      {
         
fAddressLatitude str_to_float(AddressLatitude) * 0.017453fOtherLatitude str_to_float(OtherLatitude) * 0.017453;
         
fAddressLongitude str_to_float(AddressLongitude) * 0.017453fOtherLongitude str_to_float(OtherLongitude) * 0.017453;

         return 
Imperial ? \
            
F_ACos(F_Sin(fAddressLatitude) * F_Sin(fOtherLatitude) + F_Cos(fAddressLatitude) * F_Cos(fOtherLatitude) * F_Cos(fOtherLongitude fAddressLongitude)) * 3959.0 : \
            
F_ACos(F_Sin(fAddressLatitude) * F_Sin(fOtherLatitude) + F_Cos(fAddressLatitude) * F_Cos(fOtherLatitude) * F_Cos(fOtherLongitude fAddressLongitude)) * 6371.0;
   }

   return 
0.0;
}

/** Retrieves distance between client and server.
 *
 * Experimental function. This will only work whether server's IP address is the real one (not the local one).
 *
 * @param Client        Client to compare distance with.
 * @param Imperial        Whether or not to use imperial measurement system.
 *
 * @return        The distance, if any. Otherwise, zero.
 */
stock /* long double */    Float:GeoipClientDistance(Clientbool:Imperial true)
{
   static 
ServerAddress[64], ClientAddress[64], \
      
Float:Distance 0.0;

   if (!
is_user_connected(Client) || is_user_bot(Client))
   {
      return 
0.0;
   }

   
get_cvar_string("net_address"ServerAddresscharsmax(ServerAddress));

   
GeoipStripAddress(ServerAddress);

   
get_user_ip(ClientClientAddresscharsmax(ClientAddress), 1);

   
Distance GeoipDistance(ClientAddressServerAddressImperial);

   if (
Distance == 0.0)
   {
      
get_cvar_string("ip"ServerAddresscharsmax(ServerAddress));

      
GeoipStripAddress(ServerAddress);

      
Distance GeoipDistance(ClientAddressServerAddressImperial);
   }

   return 
Distance;

PHP Code:
#include amxmodx 
#include special_geoip

new const g_Address[] =    "24.44.246.135";
new const 
g_Other[] =    "86.124.107.135";

public 
plugin_init()
{
   new 
Country[64], City[64], Region[64], TimeZone[64], PostalCode[64], DmaCode[64], MetroCode[64], NetMask[64], Longitude[64], Latitude[64], CountryCode[64], CountryCode3[64], \
      
RegionCode[64], Continent[64], ContinentCode[64], Charset[64], AreaCode[64], FormattedDistance[64], Float:Distance 0.0Float:ClientDistance 0.0;

   
register_plugin("Special Geoip""1.0""Hattrick (Claudiu HKS)");

   
GeoipInfo(g_AddressGI_CountryCountrycharsmax(Country));
   
GeoipInfo(g_AddressGI_CityCitycharsmax(City));
   
GeoipInfo(g_AddressGI_RegionRegioncharsmax(Region));
   
GeoipInfo(g_AddressGI_TimeZoneTimeZonecharsmax(TimeZone));
   
GeoipInfo(g_AddressGI_PostalCodePostalCodecharsmax(PostalCode));
   
GeoipInfo(g_AddressGI_DmaCodeDmaCodecharsmax(DmaCode));
   
GeoipInfo(g_AddressGI_MetroCodeMetroCodecharsmax(MetroCode));
   
GeoipInfo(g_AddressGI_NetMaskNetMaskcharsmax(NetMask));
   
GeoipInfo(g_AddressGI_LongitudeLongitudecharsmax(Longitude));
   
GeoipInfo(g_AddressGI_LatitudeLatitudecharsmax(Latitude));
   
GeoipInfo(g_AddressGI_CountryCodeCountryCodecharsmax(CountryCode));
   
GeoipInfo(g_AddressGI_CountryCode3CountryCode3charsmax(CountryCode3));
   
GeoipInfo(g_AddressGI_RegionCodeRegionCodecharsmax(RegionCode));
   
GeoipInfo(g_AddressGI_ContinentContinentcharsmax(Continent));
   
GeoipInfo(g_AddressGI_ContinentCodeContinentCodecharsmax(ContinentCode));
   
GeoipInfo(g_AddressGI_CharsetCharsetcharsmax(Charset));
   
GeoipInfo(g_AddressGI_AreaCodeAreaCodecharsmax(AreaCode));

   
server_print("^n----------------------------------------------------------");
   
server_print("Address: %s"g_Address);
   
server_print("Country: %s"Country);
   
server_print("City: %s"City);
   
server_print("Region: %s"Region);
   
server_print("Time Zone: %s"TimeZone);
   
server_print("Postal Code: %s"PostalCode);
   
server_print("Dma Code: %s"DmaCode);
   
server_print("Metro Code: %s"MetroCode);
   
server_print("Area Code: %s"AreaCode);
   
server_print("Net Mask: %s"NetMask);
   
server_print("Longitude: %s"Longitude);
   
server_print("Latitude: %s"Latitude);
   
server_print("Country Code: %s"CountryCode);
   
server_print("Country Code 3: %s"CountryCode3);
   
server_print("Region Code: %s"RegionCode);
   
server_print("Continent: %s"Continent);
   
server_print("Continent Code: %s"ContinentCode);
   
server_print("Charset: %s"Charset);
   
server_print("----------------------------------------------------------");

   
GeoipInfo(g_OtherGI_CountryCountrycharsmax(Country));
   
GeoipInfo(g_OtherGI_CityCitycharsmax(City));
   
GeoipInfo(g_OtherGI_RegionRegioncharsmax(Region));
   
GeoipInfo(g_OtherGI_TimeZoneTimeZonecharsmax(TimeZone));
   
GeoipInfo(g_OtherGI_PostalCodePostalCodecharsmax(PostalCode));
   
GeoipInfo(g_OtherGI_DmaCodeDmaCodecharsmax(DmaCode));
   
GeoipInfo(g_OtherGI_MetroCodeMetroCodecharsmax(MetroCode));
   
GeoipInfo(g_OtherGI_NetMaskNetMaskcharsmax(NetMask));
   
GeoipInfo(g_OtherGI_LongitudeLongitudecharsmax(Longitude));
   
GeoipInfo(g_OtherGI_LatitudeLatitudecharsmax(Latitude));
   
GeoipInfo(g_OtherGI_CountryCodeCountryCodecharsmax(CountryCode));
   
GeoipInfo(g_OtherGI_CountryCode3CountryCode3charsmax(CountryCode3));
   
GeoipInfo(g_OtherGI_RegionCodeRegionCodecharsmax(RegionCode));
   
GeoipInfo(g_OtherGI_ContinentContinentcharsmax(Continent));
   
GeoipInfo(g_OtherGI_ContinentCodeContinentCodecharsmax(ContinentCode));
   
GeoipInfo(g_OtherGI_CharsetCharsetcharsmax(Charset));
   
GeoipInfo(g_OtherGI_AreaCodeAreaCodecharsmax(AreaCode));

   
server_print("Address: %s"g_Other);
   
server_print("Country: %s"Country);
   
server_print("City: %s"City);
   
server_print("Region: %s"Region);
   
server_print("Time Zone: %s"TimeZone);
   
server_print("Postal Code: %s"PostalCode);
   
server_print("Dma Code: %s"DmaCode);
   
server_print("Metro Code: %s"MetroCode);
   
server_print("Area Code: %s"AreaCode);
   
server_print("Net Mask: %s"NetMask);
   
server_print("Longitude: %s"Longitude);
   
server_print("Latitude: %s"Latitude);
   
server_print("Country Code: %s"CountryCode);
   
server_print("Country Code 3: %s"CountryCode3);
   
server_print("Region Code: %s"RegionCode);
   
server_print("Continent: %s"Continent);
   
server_print("Continent Code: %s"ContinentCode);
   
server_print("Charset: %s"Charset);
   
server_print("----------------------------------------------------------");

   
Distance GeoipDistance(g_Addressg_Other);
   
GeoipFloatCommas(DistanceFormattedDistancecharsmax(FormattedDistance));
   
Distance != 0.0 server_print("Miles: %s"FormattedDistance) : server_print("Miles: %s""N/A");

   
Distance GeoipDistance(g_Addressg_Otherfalse);
   
GeoipFloatCommas(DistanceFormattedDistancecharsmax(FormattedDistance));
   
Distance != 0.0 server_print("Kilometers: %s"FormattedDistance) : server_print("Kilometers: %s""N/A");

   
ClientDistance GeoipClientDistance(0);
   
GeoipFloatCommas(ClientDistanceFormattedDistancecharsmax(FormattedDistance));
   
ClientDistance != 0.0 server_print("Miles between client zero and server: %s"FormattedDistance) : server_print("Miles between client zero and server: %s""N/A");

   
ClientDistance GeoipClientDistance(0false);
   
GeoipFloatCommas(ClientDistanceFormattedDistancecharsmax(FormattedDistance));
   
ClientDistance != 0.0 server_print("Kilometers between client zero and server: %s^n"FormattedDistance) : server_print("Kilometers between client zero and server: %s^n""N/A");

In game pictures





Plug-in example:

PHP Code:
#include amxmodx
#include special_geoip

public client_putinserver(Id)
{
 static 
Name[64], Ip[64], Country[64], City[64], Buffer[256];
 
get_user_ip(IdIp631);
 
GeoipInfo(IpGI_CountryCountry63);
 
GeoipInfo(IpGI_CityCity63);
 
get_user_name(IdName63);
 
formatex(Buffer255"^x04[Special GeoIP]^x03 %s^x01 connected from [^x03%s^x01] [^x03%s^x01]"NameCountryCity);
 for (
Id 1Id <= get_maxplayers(); Id++)
 {
  if (!
is_user_connected(Id)) continue;
  
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _Id);
  
write_byte(get_maxplayers() + 1);
  
write_string(Buffer);
  
message_end();
 }

__________________

Last edited by claudiuhks; 02-12-2015 at 17:12.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-27-2012 , 11:25   Re: MetaMod :: SpecialGeoip 1.0 [2011 C Sources] Linux + AMXX Connectors
Reply With Quote #2

I've also done an update to an unreleased version of my geoip extented module, but I guess a metamod plugin can be useful for some situations.

So, the main advantage of this modules is basically : having the ability to access to player's geo datas from another module, right ?

I'm not sure how the AMXX connector is useful, using the default geoip module is way more simple and appropriate (open/close a file each time a player connects is really not a good thing)

And last thing, why linux only ?
__________________

Last edited by Arkshine; 08-27-2012 at 11:26.
Arkshine is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 08-27-2012 , 11:34   Re: MetaMod :: SpecialGeoip 1.0 [2011 C Sources] Linux + AMXX Connectors
Reply With Quote #3

The basic advantage is that you may get the player's geographical data with other modules like AMX Mod X.
You may get AreaCode, ContinentName, ContinentCode, PostalCode and MetroCode.
The strings are between quotes and may be easily parsed.
I will try do it on Windows too, but if someone will do it before it would be greatly appreciated.
Now I'm testing Windows 8 and I can't compile it.

The reason I wanted to do it is because it's a MetaMod extension and I like the mode it's getting the geographical data on ClientPutInServer. You don't have to use AMX Mod X anymore.
__________________

Last edited by claudiuhks; 08-27-2012 at 22:47.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-27-2012 , 11:42   Re: MetaMod: SpecialGeoip 1.0 [2011 C Sources] Linux + AMXX Connectors
Reply With Quote #4

Quote:
You may get AreaCode, ContinentName, ContinentCode, PostalCode and MetroCode.
Something US only, is kind of useless, though I guess you will always some people finding that useful. Guess will readd them in my module.

Will see If I will try to compile it or not under windows.
__________________
Arkshine is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 08-27-2012 , 11:45   Re: MetaMod: SpecialGeoip 1.0 [2011 C Sources] Linux + AMXX Connectors
Reply With Quote #5

Quote:
Originally Posted by Arkshine View Post
Something US only, is kind of useless, though I guess you will always some people finding that useful. Guess will readd them in my module.

Will see If I will try to compile it or not under windows.
Thank you for that. You have a better artillery of programs in Windows like I have seen.
__________________

Last edited by claudiuhks; 08-28-2012 at 03:11.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Shumaxer96
Senior Member
Join Date: Jun 2011
Old 08-31-2012 , 06:26   Re: MetaMod: SpecialGeoip 1.0 [2011 C Sources] Linux + AMXX Connectors
Reply With Quote #6

i add this modul in my server but when i connect my server eror and go out server why ?
Shumaxer96 is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 08-31-2012 , 07:32   Re: MetaMod: SpecialGeoip 1.0 [2011 C Sources] Linux + AMXX Connectors
Reply With Quote #7

Hmmm, I don't understand what you say, you may see the pictures posted above, in the first post.
It's definitely working!
__________________

Last edited by claudiuhks; 08-31-2012 at 07:33.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Shumaxer96
Senior Member
Join Date: Jun 2011
Old 08-31-2012 , 08:07   Re: MetaMod: SpecialGeoip 1.0 [2011 C Sources] Linux + AMXX Connectors
Reply With Quote #8

this write look pichure http://s43.radikal.ru/i102/1208/fd/63fd1e945ff5.jpg
Shumaxer96 is offline
Shumaxer96
Senior Member
Join Date: Jun 2011
Old 08-31-2012 , 08:32   Re: MetaMod: SpecialGeoip 1.0 [2011 C Sources] Linux + AMXX Connectors
Reply With Quote #9

aaa this modul it's for linux i use windows
Shumaxer96 is offline
KORD_12.7
Senior Member
Join Date: Aug 2009
Location: Russia, Vladivostok
Old 08-31-2012 , 09:08   Re: MetaMod: SpecialGeoip 1.0 [2011 C Sources] Linux + AMXX Connectors
Reply With Quote #10

claudiuhks, good job

offtop:
Spoiler
__________________

Vi Veri Veniversum Vivus Vici
Russian Half-Life and Adrenaline Gamer community
KORD_12.7 is offline
Send a message via ICQ to KORD_12.7
Reply


Thread Tools
Display Modes

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 05:00.


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