Geoip: Add geoip_city() native.
This commit is contained in:
parent
0d59209e4c
commit
95bc1703a6
|
@ -147,9 +147,26 @@ static cell AMX_NATIVE_CALL amx_geoip_country(AMX *amx, cell *params)
|
||||||
const char *path[] = { "country", "names", "en", NULL };
|
const char *path[] = { "country", "names", "en", NULL };
|
||||||
const char *country = lookupByIp(stripPort(ip), path, &length);
|
const char *country = lookupByIp(stripPort(ip), path, &length);
|
||||||
|
|
||||||
|
if (!country)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return MF_SetAmxString(amx, params[2], country, length >= params[3] ? params[3] : length); // TODO: make this utf8 safe.
|
return MF_SetAmxString(amx, params[2], country, length >= params[3] ? params[3] : length); // TODO: make this utf8 safe.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// native geoip_city(const ip[], result[], len);
|
||||||
|
static cell AMX_NATIVE_CALL amx_geoip_city(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
int length;
|
||||||
|
char *ip = MF_GetAmxString(amx, params[1], 0, &length);
|
||||||
|
|
||||||
|
const char *path[] = { "city", "names", "en", NULL };
|
||||||
|
const char *city = lookupByIp(stripPort(ip), path, &length);
|
||||||
|
|
||||||
|
return MF_SetAmxString(amx, params[2], city ? city : "", length >= params[3] ? params[3] : length); // TODO: make this utf8 safe.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnAmxxAttach()
|
void OnAmxxAttach()
|
||||||
{
|
{
|
||||||
|
@ -215,6 +232,8 @@ AMX_NATIVE_INFO geoip_natives[] =
|
||||||
{ "geoip_code3_ex", amx_geoip_code3_ex },
|
{ "geoip_code3_ex", amx_geoip_code3_ex },
|
||||||
|
|
||||||
{ "geoip_country", amx_geoip_country },
|
{ "geoip_country", amx_geoip_country },
|
||||||
|
{ "geoip_city" , amx_geoip_city },
|
||||||
|
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -80,3 +80,21 @@ native geoip_code3(const ip[], result[4]);
|
||||||
* @param len The maximum length of the result buffer.
|
* @param len The maximum length of the result buffer.
|
||||||
*/
|
*/
|
||||||
native geoip_country(const ip[], result[], len=45);
|
native geoip_country(const ip[], result[], len=45);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The following natives require GeoIP City database, which can be retrieved from:
|
||||||
|
* http://dev.maxmind.com/geoip/geoip2/geolite2/ (MaxMind DB binary)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Look up the full city 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_city(const ip[], result[], len);
|
Loading…
Reference in New Issue
Block a user