Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
|
08-27-2012
, 10:53
Module: Special Geoip v1.0.0.1 (Linux + Windows)
|
#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(Num, Output[], Len) { static Tmp[16], OutputPos = 0, NumPos = 0, NumLen = 0;
OutputPos = NumPos = 0;
if (Num < 0) { Output[OutputPos++] = '-';
Num = abs(Num); }
NumLen = num_to_str(Num, Tmp, charsmax(Tmp));
if (NumLen <= 3) OutputPos += copy(Output[OutputPos], Len, Tmp);
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) - 1; Iterator >= 0; Iterator--) { if (Address[Iterator] == ':') { Address[Iterator] = '^0';
break; } } }
stock GeoipFloatCommas(Float:Value, Buffer[], Size) { AddCommas(floatround(Value), Buffer, Size); }
stock GeoipNumCommas(Value, Buffer[], Size) { AddCommas(Value, Buffer, Size); }
/** Math predefinitions. */ #define F_Cos floatcos #define F_Sin floatsin
stock Float:F_ACos(Float:Value) { return floatacos(Value, radian); }
stock Float:F_ASin(Float:Value) { return floatasin(Value, radian); }
/** 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:Info, Buffer[], 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.0, Float:fAddressLongitude = 0.0, Float:fOtherLatitude = 0.0, Float:fOtherLongitude = 0.0;
if (GeoipInfo(Address, GI_Latitude, AddressLatitude, charsmax(AddressLatitude)) && GeoipInfo(Other, GI_Latitude, OtherLatitude, charsmax(OtherLatitude)) && \ GeoipInfo(Address, GI_Longitude, AddressLongitude, charsmax(AddressLongitude)) && GeoipInfo(Other, GI_Longitude, OtherLongitude, charsmax(OtherLongitude))) { fAddressLatitude = str_to_float(AddressLatitude) * 0.017453, fOtherLatitude = str_to_float(OtherLatitude) * 0.017453; fAddressLongitude = str_to_float(AddressLongitude) * 0.017453, fOtherLongitude = 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(Client, bool: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", ServerAddress, charsmax(ServerAddress));
GeoipStripAddress(ServerAddress);
get_user_ip(Client, ClientAddress, charsmax(ClientAddress), 1);
Distance = GeoipDistance(ClientAddress, ServerAddress, Imperial);
if (Distance == 0.0) { get_cvar_string("ip", ServerAddress, charsmax(ServerAddress));
GeoipStripAddress(ServerAddress);
Distance = GeoipDistance(ClientAddress, ServerAddress, Imperial); }
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.0, Float:ClientDistance = 0.0;
register_plugin("Special Geoip", "1.0", "Hattrick (Claudiu HKS)");
GeoipInfo(g_Address, GI_Country, Country, charsmax(Country)); GeoipInfo(g_Address, GI_City, City, charsmax(City)); GeoipInfo(g_Address, GI_Region, Region, charsmax(Region)); GeoipInfo(g_Address, GI_TimeZone, TimeZone, charsmax(TimeZone)); GeoipInfo(g_Address, GI_PostalCode, PostalCode, charsmax(PostalCode)); GeoipInfo(g_Address, GI_DmaCode, DmaCode, charsmax(DmaCode)); GeoipInfo(g_Address, GI_MetroCode, MetroCode, charsmax(MetroCode)); GeoipInfo(g_Address, GI_NetMask, NetMask, charsmax(NetMask)); GeoipInfo(g_Address, GI_Longitude, Longitude, charsmax(Longitude)); GeoipInfo(g_Address, GI_Latitude, Latitude, charsmax(Latitude)); GeoipInfo(g_Address, GI_CountryCode, CountryCode, charsmax(CountryCode)); GeoipInfo(g_Address, GI_CountryCode3, CountryCode3, charsmax(CountryCode3)); GeoipInfo(g_Address, GI_RegionCode, RegionCode, charsmax(RegionCode)); GeoipInfo(g_Address, GI_Continent, Continent, charsmax(Continent)); GeoipInfo(g_Address, GI_ContinentCode, ContinentCode, charsmax(ContinentCode)); GeoipInfo(g_Address, GI_Charset, Charset, charsmax(Charset)); GeoipInfo(g_Address, GI_AreaCode, AreaCode, charsmax(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_Other, GI_Country, Country, charsmax(Country)); GeoipInfo(g_Other, GI_City, City, charsmax(City)); GeoipInfo(g_Other, GI_Region, Region, charsmax(Region)); GeoipInfo(g_Other, GI_TimeZone, TimeZone, charsmax(TimeZone)); GeoipInfo(g_Other, GI_PostalCode, PostalCode, charsmax(PostalCode)); GeoipInfo(g_Other, GI_DmaCode, DmaCode, charsmax(DmaCode)); GeoipInfo(g_Other, GI_MetroCode, MetroCode, charsmax(MetroCode)); GeoipInfo(g_Other, GI_NetMask, NetMask, charsmax(NetMask)); GeoipInfo(g_Other, GI_Longitude, Longitude, charsmax(Longitude)); GeoipInfo(g_Other, GI_Latitude, Latitude, charsmax(Latitude)); GeoipInfo(g_Other, GI_CountryCode, CountryCode, charsmax(CountryCode)); GeoipInfo(g_Other, GI_CountryCode3, CountryCode3, charsmax(CountryCode3)); GeoipInfo(g_Other, GI_RegionCode, RegionCode, charsmax(RegionCode)); GeoipInfo(g_Other, GI_Continent, Continent, charsmax(Continent)); GeoipInfo(g_Other, GI_ContinentCode, ContinentCode, charsmax(ContinentCode)); GeoipInfo(g_Other, GI_Charset, Charset, charsmax(Charset)); GeoipInfo(g_Other, GI_AreaCode, AreaCode, charsmax(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_Address, g_Other); GeoipFloatCommas(Distance, FormattedDistance, charsmax(FormattedDistance)); Distance != 0.0 ? server_print("Miles: %s", FormattedDistance) : server_print("Miles: %s", "N/A");
Distance = GeoipDistance(g_Address, g_Other, false); GeoipFloatCommas(Distance, FormattedDistance, charsmax(FormattedDistance)); Distance != 0.0 ? server_print("Kilometers: %s", FormattedDistance) : server_print("Kilometers: %s", "N/A");
ClientDistance = GeoipClientDistance(0); GeoipFloatCommas(ClientDistance, FormattedDistance, charsmax(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(0, false); GeoipFloatCommas(ClientDistance, FormattedDistance, charsmax(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(Id, Ip, 63, 1); GeoipInfo(Ip, GI_Country, Country, 63); GeoipInfo(Ip, GI_City, City, 63); get_user_name(Id, Name, 63); formatex(Buffer, 255, "^x04[Special GeoIP]^x03 %s^x01 connected from [^x03%s^x01] [^x03%s^x01]", Name, Country, City); for (Id = 1; Id <= get_maxplayers(); Id++) { if (!is_user_connected(Id)) continue; message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, Id); write_byte(get_maxplayers() + 1); write_string(Buffer); message_end(); } }
__________________
Last edited by claudiuhks; 02-12-2015 at 17:12.
|
|