From abaee9f4a3b6c0fbc9ebe43e7337564ed47a7e0e Mon Sep 17 00:00:00 2001 From: Arkshine Date: Thu, 31 Jul 2014 15:29:57 +0200 Subject: [PATCH] Geoip: Add geoip_continent_name() native. --- dlls/geoip/geoip_amxx.cpp | 13 +++++++++++++ plugins/include/geoip.inc | 13 ++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/dlls/geoip/geoip_amxx.cpp b/dlls/geoip/geoip_amxx.cpp index 3e4ca3c5..5063d2fa 100755 --- a/dlls/geoip/geoip_amxx.cpp +++ b/dlls/geoip/geoip_amxx.cpp @@ -340,6 +340,18 @@ static cell AMX_NATIVE_CALL amx_geoip_continent_code(AMX *amx, cell *params) return getContinentId(code); } +// native geoip_continent_name(const ip[], result[], len); +static cell AMX_NATIVE_CALL amx_geoip_continent_name(AMX *amx, cell *params) +{ + int length; + char *ip = MF_GetAmxString(amx, params[1], 0, &length); + + const char *path[] = { "continent", "names", "en", NULL }; + const char *continent = lookupString(stripPort(ip), path, &length); + + return MF_SetAmxString(amx, params[2], continent ? continent : "", length >= params[3] ? params[3] : length); // TODO: make this utf8 safe. +} + void OnAmxxAttach() { @@ -416,6 +428,7 @@ AMX_NATIVE_INFO geoip_natives[] = { "geoip_distance" , amx_geoip_distance }, { "geoip_continent_code", amx_geoip_continent_code }, + { "geoip_continent_name", amx_geoip_continent_name }, { NULL, NULL }, }; diff --git a/plugins/include/geoip.inc b/plugins/include/geoip.inc index f67c6275..95942f22 100755 --- a/plugins/include/geoip.inc +++ b/plugins/include/geoip.inc @@ -190,4 +190,15 @@ enum Continent CONTINENT_OCEANIA, CONTINENT_SOUTH_AMERICA }; -native Continent:geoip_continent_code(const ip[], result[3]); \ No newline at end of file +native Continent:geoip_continent_code(const ip[], result[3]); + +/** + * Look up the full continent name for the given IP address. + * + * @param ip The IP address to look up. + * @param result The result of the geoip look up. + * @param len The maximum length of the result buffer. + * + * @return The result length on successful lookup, 0 otherwise. + */ +native geoip_continent_name(const ip[], result[], len);