Geoip: Add geoip_continent_name() native.

This commit is contained in:
Arkshine 2014-07-31 15:29:57 +02:00
parent fc19f53ea9
commit abaee9f4a3
2 changed files with 25 additions and 1 deletions

View File

@ -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 },
};

View File

@ -191,3 +191,14 @@ enum Continent
CONTINENT_SOUTH_AMERICA
};
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);