GeoIP_Plugin.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #if defined _GeoIP_Plugin_included
  2. #endinput
  3. #endif
  4. #define _GeoIP_Plugin_included
  5. const MAX_COUNTRY_NAME = 45;
  6. //const MAX_CITY_NAME = 0;
  7. native GetCountryCode(const ipaddress[], country[], size = sizeof country);
  8. native GetCountryCode3(const ipaddress[], country[], size = sizeof country);
  9. native GetCountryName(const ipaddress[], country[], size = sizeof country);
  10. native GetCityLatitude(const ipaddress[], &Float:lat);
  11. native GetCityLongitude(const ipaddress[], &Float:lon);
  12. native GetCountryCodeByName(const name[], country[], size = sizeof country);
  13. native GetCountryCode3ByName(const name[], country[], size = sizeof country);
  14. native GetCountryNameByName(const name[], country[], size = sizeof country);
  15. native GetCityLatitudeByName(const name[], &Float:lat);
  16. native GetCityLongitudeByName(const name[], &Float:lon);
  17. /* Non-native functions, Fake for pawno.
  18. native GetGMT(ip[]);
  19. native GetGMTByName(name[]);
  20. native GetPlayerGMT(playerid);
  21. native GetPlayerCountryCode(playerid);
  22. native GetPlayerCountryCode3(playerid);
  23. native GetPlayerCountryName(playerid);
  24. */
  25. stock GetGMT(const ip[])
  26. {
  27. new Float:lon;
  28. GetCityLongitude(ip, lon);
  29. return floatround(lon / 15.0);
  30. }
  31. stock GetGMTByName(const name[])
  32. {
  33. new Float:lon;
  34. GetCityLongitudeByName(name, lon);
  35. return floatround(lon / 15.0);
  36. }
  37. stock GetPlayerGMT(playerid)
  38. {
  39. new ip[16];
  40. GetPlayerIp(playerid, ip, sizeof(ip));
  41. return GetGMT(ip);
  42. }
  43. stock GetPlayerCountryCode(playerid)
  44. {
  45. new ip[16], country[MAX_COUNTRY_NAME];
  46. GetPlayerIp(playerid, ip, sizeof(ip));
  47. GetCountryCode(ip, country, size);
  48. return country;
  49. }
  50. stock GetPlayerCountryCode3(playerid)
  51. {
  52. new ip[16], country[MAX_COUNTRY_NAME];
  53. GetPlayerIp(playerid, ip, sizeof(ip));
  54. GetCountryCode3(ip, country, size);
  55. return country;
  56. }
  57. stock GetPlayerCountryName(playerid)
  58. {
  59. new ip[16], country[MAX_COUNTRY_NAME];
  60. GetPlayerIp(playerid, ip, sizeof(ip));
  61. new ret = GetCountryName(ip, country, sizeof(country));
  62. if(!ret)
  63. format(country, sizeof(country), "Private IP");
  64. return country;
  65. }
  66. // TODO:
  67. stock GetPlayerLocationInfos(playerid, country[], city[], &gmt, &Float:latitude = 0.0, &Float:longitude = 0.0)
  68. {
  69. /*new ip[16];
  70. GetPlayerIp(playerid, ip, sizeof(ip));
  71. if(!GetCountryName(ip, country, sizeof(country)))
  72. format(country, sizeof(country), "Private IP");
  73. if(!GetCityName(ip, city, sizeof(city)))
  74. format(city, sizeof(city), "Unknown City");
  75. gmt = GetGMT(ip);
  76. GetCityLatitude(ip, latitude);
  77. GetCityLongitude(ip, longitude);*/
  78. return false;
  79. }