GeoIP_Plugin.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 GetIPCountry(ip[]);
  24. native GetPlayerCountryName(playerid);
  25. */
  26. stock GetGMT(const ip[])
  27. {
  28. new Float:lon;
  29. GetCityLongitude(ip, lon);
  30. return floatround(lon / 15.0);
  31. }
  32. stock GetGMTByName(const name[])
  33. {
  34. new Float:lon;
  35. GetCityLongitudeByName(name, lon);
  36. return floatround(lon / 15.0);
  37. }
  38. stock GetPlayerGMT(playerid)
  39. {
  40. new ip[16];
  41. GetPlayerIp(playerid, ip, sizeof(ip));
  42. return GetGMT(ip);
  43. }
  44. stock GetIPCountry(ip[])
  45. {
  46. new country[MAX_COUNTRY_NAME];
  47. new ret = GetCountryName(ip, country, sizeof(country));
  48. if(!ret)
  49. format(country, sizeof(country), "Unknown");
  50. return country;
  51. }
  52. stock GetPlayerCountryCode(playerid)
  53. {
  54. new ip[16], country[MAX_COUNTRY_NAME];
  55. GetPlayerIp(playerid, ip, sizeof(ip));
  56. GetCountryCode(ip, country, size);
  57. return country;
  58. }
  59. stock GetPlayerCountryCode3(playerid)
  60. {
  61. new ip[16], country[MAX_COUNTRY_NAME];
  62. GetPlayerIp(playerid, ip, sizeof(ip));
  63. GetCountryCode3(ip, country, size);
  64. return country;
  65. }
  66. stock GetPlayerCountryName(playerid)
  67. {
  68. new ip[16], country[MAX_COUNTRY_NAME];
  69. GetPlayerIp(playerid, ip, sizeof(ip));
  70. new ret = GetCountryName(ip, country, sizeof(country));
  71. if(!ret)
  72. format(country, sizeof(country), "Unknown");
  73. return country;
  74. }
  75. // TODO:
  76. stock GetPlayerLocationInfos(playerid, country[], city[], &gmt, &Float:latitude = 0.0, &Float:longitude = 0.0)
  77. {
  78. /*new ip[16];
  79. GetPlayerIp(playerid, ip, sizeof(ip));
  80. if(!GetCountryName(ip, country, sizeof(country)))
  81. format(country, sizeof(country), "Unknown IP City");
  82. if(!GetCityName(ip, city, sizeof(city)))
  83. format(city, sizeof(city), "Unknown City");
  84. gmt = GetGMT(ip);
  85. GetCityLatitude(ip, latitude);
  86. GetCityLongitude(ip, longitude);*/
  87. return false;
  88. }