geoip.inc
Original include source with line numbers.
| 1 | // vim: set ts=4 sw=4 tw=99 noet: |
| 2 | // |
| 3 | // AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO"). |
| 4 | // Copyright (C) The AMX Mod X Development Team. |
| 5 | // |
| 6 | // This software is licensed under the GNU General Public License, version 3 or higher. |
| 7 | // Additional exceptions apply. For full license details, see LICENSE.txt or visit: |
| 8 | // https://alliedmods.net/amxmodx-license |
| 9 | |
| 10 | // |
| 11 | // GeoIP+ Module Functions |
| 12 | // |
| 13 | |
| 14 | #if defined geoip_included |
| 15 | #endinput |
| 16 | #endif |
| 17 | #define _geoip_included |
| 18 | |
| 19 | #pragma reqlib geoip |
| 20 | #if !defined AMXMODX_NOAUTOLOAD |
| 21 | #pragma loadlib geoip |
| 22 | #endif |
| 23 | |
| 24 | /** |
| 25 | * @global IP addresses passed to these natives can contain ports, the ports will be ignored. |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * Look up the two character country code for a given IP address. |
| 30 | * e.g: "US", "CA", etc. |
| 31 | * |
| 32 | * @param ip The IP address to lookup. |
| 33 | * @param result The result buffer. If the lookup does not succeed, the buffer is not modified. |
| 34 | * |
| 35 | * @return true on a successful lookup, false on a failed lookup. |
| 36 | */ |
| 37 | native bool:geoip_code2_ex(const ip[], result[3]); |
| 38 | |
| 39 | /** |
| 40 | * Look up the three character country code for a given IP address. |
| 41 | * e.g: "USA", "cAN", etc. |
| 42 | * |
| 43 | * @param ip The IP address to lookup. |
| 44 | * @param result The result buffer. If the lookup does not succeed, the buffer is not modified. |
| 45 | * |
| 46 | * @return true on a successful lookup, false on a failed lookup. |
| 47 | */ |
| 48 | native bool:geoip_code3_ex(const ip[], result[4]); |
| 49 | |
| 50 | /** |
| 51 | * Lookup the two character country code for a given IP address. Sets the buffer to "error" on |
| 52 | * an unsuccessful lookup. |
| 53 | * |
| 54 | * @deprecated This native will overflow the buffer by one cell on an unknown ip lookup! |
| 55 | * Use geoip_code2_ex instead. |
| 56 | * |
| 57 | * @param ip The IP address to lookup. |
| 58 | * @param result The result buffer. |
| 59 | * |
| 60 | * @return The result length. |
| 61 | */ |
| 62 | //#pragma deprecated Use geoip_code2_ex() instead. |
| 63 | native geoip_code2(const ip[], ccode[3]); |
| 64 | |
| 65 | /** |
| 66 | * Lookup the three character country code for a given IP address. Sets the buffer to "error" on |
| 67 | * an unsuccessful lookup. |
| 68 | * |
| 69 | * @deprecated This native will overflow the buffer by one cell on an unknown ip lookup! |
| 70 | * Use geoip_code3_ex instead. |
| 71 | * |
| 72 | * @param ip The IP address to lookup. |
| 73 | * @param result The result buffer. |
| 74 | * |
| 75 | * @return The result length. |
| 76 | */ |
| 77 | //#pragma deprecated Use geoip_code3_ex() instead. |
| 78 | native geoip_code3(const ip[], result[4]); |
| 79 | |
| 80 | /** |
| 81 | * Lookup the full country name for the given IP address. Sets the buffer to "error" on |
| 82 | * an unsuccessful lookup. |
| 83 | * |
| 84 | * @param ip The IP address to lookup. |
| 85 | * @param result The result of the geoip lookup. |
| 86 | * @param len The maximum length of the result buffer. |
| 87 | * |
| 88 | * @return The result length. |
| 89 | */ |
| 90 | //#pragma deprecated Use geoip_country_ex() instead. |
| 91 | native geoip_country(const ip[], result[], len = 45); |
| 92 | |
| 93 | /** |
| 94 | * Lookup the full country name for the given IP address. |
| 95 | * |
| 96 | * @param ip The IP address to lookup. |
| 97 | * @param result The result of the geoip lookup. |
| 98 | * @param len The maximum length of the result buffer. |
| 99 | * @param id An optional player's index in order to return the result |
| 100 | * in the player's language, if supported. |
| 101 | * -1: the default language, which is english. |
| 102 | * 0: the server language. You can use LANG_SERVER define. |
| 103 | * >=1: the player's language. |
| 104 | * |
| 105 | * @return The result length on successful lookup, 0 otherwise. |
| 106 | */ |
| 107 | native geoip_country_ex(const ip[], result[], len, id = -1); |
| 108 | |
| 109 | /** |
| 110 | * Look up the full city name for the given IP address. |
| 111 | * |
| 112 | * @note This native requires GeoIP City database, which can be retrieved from: |
| 113 | * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) |
| 114 | * |
| 115 | * @param ip The IP address to look up. |
| 116 | * @param result The result of the geoip look up. |
| 117 | * @param len The maximum length of the result buffer. |
| 118 | * @param id An optional player's index in order to return the result |
| 119 | * in the player's language, if supported. |
| 120 | * -1: the default language, which is english. |
| 121 | * 0: the server language. You can use LANG_SERVER define. |
| 122 | * >=1: the player's language. |
| 123 | * |
| 124 | * @return The result length on successful lookup, 0 otherwise. |
| 125 | */ |
| 126 | native geoip_city(const ip[], result[], len, id = -1); |
| 127 | |
| 128 | /** |
| 129 | * Look up the region/state code for the given IP address. |
| 130 | * e.g. "US-OH", "DE-HH", IT-82, "FR-U", etc. |
| 131 | * |
| 132 | * @note This native requires GeoIP City database, which can be retrieved from: |
| 133 | * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) |
| 134 | * |
| 135 | * @param ip The IP address to look up. |
| 136 | * @param result The result of the geoip look up. |
| 137 | * @param len The maximum length of the result buffer. |
| 138 | * |
| 139 | * @return The result length on successful lookup, 0 otherwise. |
| 140 | */ |
| 141 | native geoip_region_code(const ip[], result[], len); |
| 142 | |
| 143 | /** |
| 144 | * Look up the full region/state name for the given IP address. |
| 145 | * |
| 146 | * @note This native requires GeoIP City database, which can be retrieved from: |
| 147 | * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) |
| 148 | * |
| 149 | * @param ip The IP address to look up. |
| 150 | * @param result The result of the geoip look up. |
| 151 | * @param len The maximum length of the result buffer. |
| 152 | * @param id An optional player's index in order to return the result |
| 153 | * in the player's language, if supported. |
| 154 | * -1: the default language, which is english. |
| 155 | * 0: the server language. You can use LANG_SERVER define. |
| 156 | * >=1: the player's language. |
| 157 | * |
| 158 | * @return The result length on successful lookup, 0 otherwise. |
| 159 | */ |
| 160 | native geoip_region_name(const ip[], result[], len, id = -1); |
| 161 | |
| 162 | /** |
| 163 | * Look up the full time zone for the given IP address. |
| 164 | * e.g. America/Los_Angeles, Europe/Paris. |
| 165 | * |
| 166 | * @note This native requires GeoIP City database, which can be retrieved from: |
| 167 | * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) |
| 168 | * |
| 169 | * @param ip The IP address to look up. |
| 170 | * @param result The result of the geoip look up. |
| 171 | * @param len The maximum length of the result buffer. |
| 172 | * |
| 173 | * @return The result length on successful lookup, 0 otherwise. |
| 174 | */ |
| 175 | native geoip_timezone(const ip[], result[], len); |
| 176 | |
| 177 | /** |
| 178 | * Look up the city's latitude for the given IP address. |
| 179 | * |
| 180 | * @note This native requires GeoIP City database, which can be retrieved from: |
| 181 | * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) |
| 182 | * |
| 183 | * @param ip The IP address to look up. |
| 184 | * |
| 185 | * @return The result of the geoip look up, 0 if latitude is not found. |
| 186 | */ |
| 187 | native Float:geoip_latitude(const ip[]); |
| 188 | |
| 189 | /** |
| 190 | * Look up the city's longitude for the given IP address. |
| 191 | * |
| 192 | * @note This native requires GeoIP City database, which can be retrieved from: |
| 193 | * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) |
| 194 | * |
| 195 | * @param ip The IP address to look up. |
| 196 | * |
| 197 | * @return The result of the geoip look up, 0 if longitude is not found. |
| 198 | */ |
| 199 | native Float:geoip_longitude(const ip[]); |
| 200 | |
| 201 | /** |
| 202 | * Calculate the distance between geographical coordinates, latitude and longitude. |
| 203 | * |
| 204 | * @note This native requires GeoIP City database, which can be retrieved from: |
| 205 | * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) |
| 206 | * |
| 207 | * @param lat1 The first IP latitude. |
| 208 | * @param lon1 The first IP longitude. |
| 209 | * @param lat2 The second IP latitude. |
| 210 | * @param lon2 The second IP longitude. |
| 211 | * @param system The system of measurement, 0 = Metric(kilometers) or 1 = English(miles). |
| 212 | * |
| 213 | * @return The distance as result in specified system of measurement. |
| 214 | */ |
| 215 | #define SYSTEM_METRIC 0 // kilometers |
| 216 | #define SYSTEM_IMPERIAL 1 // statute miles |
| 217 | |
| 218 | native Float:geoip_distance(Float:lat1, Float:lon1, Float:lat2, Float:lon2, system = SYSTEM_METRIC); |
| 219 | |
| 220 | /** |
| 221 | * Look up the continent code for a given IP address. |
| 222 | * |
| 223 | * @note This native requires GeoIP City database, which can be retrieved from: |
| 224 | * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) |
| 225 | * @note The code can be retrieved as integer (See CONTINENT_* constants.) or string (2 characters). |
| 226 | * @note Possible continent codes are AF, AN, AS, EU, NA, OC, SA for |
| 227 | * Africa(1), Antarctica(2), Asia(3), Europe(4), North America(5), Oceania(6), South America(7). |
| 228 | * |
| 229 | * @param ip The IP address to look up. |
| 230 | * @param result The result of the geoip look up. |
| 231 | * |
| 232 | * @return The continent id on successful lookup, 0 otherwise. |
| 233 | */ |
| 234 | enum Continent |
| 235 | { |
| 236 | CONTINENT_UNKNOWN = 0, |
| 237 | CONTINENT_AFRICA, |
| 238 | CONTINENT_ANTARCTICA, |
| 239 | CONTINENT_ASIA, |
| 240 | CONTINENT_EUROPE, |
| 241 | CONTINENT_NORTH_AMERICA, |
| 242 | CONTINENT_OCEANIA, |
| 243 | CONTINENT_SOUTH_AMERICA, |
| 244 | }; |
| 245 | native Continent:geoip_continent_code(const ip[], result[3]); |
| 246 | |
| 247 | /** |
| 248 | * Look up the full continent name for the given IP address. |
| 249 | * |
| 250 | * @note This native requires GeoIP City database, which can be retrieved from: |
| 251 | * http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary) |
| 252 | * |
| 253 | * @param ip The IP address to look up. |
| 254 | * @param result The result of the geoip look up. |
| 255 | * @param len The maximum length of the result buffer. |
| 256 | * @param id An optional player's index in order to return the result |
| 257 | * in the player's language, if supported. |
| 258 | * -1: the default language, which is english. |
| 259 | * 0: the server language. You can use LANG_SERVER define. |
| 260 | * >=1: the player's language. |
| 261 | * |
| 262 | * @return The result length on successful lookup, 0 otherwise. |
| 263 | */ |
| 264 | native geoip_continent_name(const ip[], result[], len, id = -1); |
| 265 | |