From c11f721ad46cd241b53997e87d08a828c466d5d3 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Wed, 30 Jul 2014 22:36:39 +0200 Subject: [PATCH] Geoip: Add geoip_region_name() native. --- dlls/geoip/geoip_amxx.cpp | 12 ++++++++++++ plugins/include/geoip.inc | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/dlls/geoip/geoip_amxx.cpp b/dlls/geoip/geoip_amxx.cpp index fedb187c..80f63e2b 100755 --- a/dlls/geoip/geoip_amxx.cpp +++ b/dlls/geoip/geoip_amxx.cpp @@ -206,6 +206,18 @@ static cell AMX_NATIVE_CALL amx_geoip_region_code(AMX *amx, cell *params) return MF_SetAmxString(amx, params[2], finalLength ? code : "", finalLength >= params[3] ? params[3] : finalLength); } +// native geoip_region_name(const ip[], result[], len); +static cell AMX_NATIVE_CALL amx_geoip_region_name(AMX *amx, cell *params) +{ + int length; + char *ip = MF_GetAmxString(amx, params[1], 0, &length); + + const char *path[] = { "subdivisions", "0", "names", "en", NULL }; // First result. + const char *region = lookupByIp(stripPort(ip), path, &length); + + return MF_SetAmxString(amx, params[2], region ? region : "", length >= params[3] ? params[3] : length); // TODO: make this utf8 safe. +} + void OnAmxxAttach() { diff --git a/plugins/include/geoip.inc b/plugins/include/geoip.inc index e740112c..d27f3fdf 100755 --- a/plugins/include/geoip.inc +++ b/plugins/include/geoip.inc @@ -109,4 +109,15 @@ native geoip_city(const ip[], result[], len); * * @return The result length on successful lookup, 0 otherwise. */ -native geoip_region_code(const ip[], result[], len); \ No newline at end of file +native geoip_region_code(const ip[], result[], len); + +/** + * Look up the full region/state 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_region_name(const ip[], result[], len); \ No newline at end of file