Geoip: Add geoip_continent_code() native.
This commit is contained in:
parent
81d56dfdc0
commit
fc19f53ea9
|
@ -86,6 +86,40 @@ double lookupDouble(const char *ip, const char **path)
|
|||
return result.double_value;
|
||||
}
|
||||
|
||||
int getContinentId(const char *code)
|
||||
{
|
||||
#define CONTINENT_UNKNOWN 0
|
||||
#define CONTINENT_AFRICA 1
|
||||
#define CONTINENT_ASIA 2
|
||||
#define CONTINENT_EUROPE 3
|
||||
#define CONTINENT_NORTH_AMERICA 4
|
||||
#define CONTINENT_OCEANIA 5
|
||||
#define CONTINENT_SOUTH_AMERICA 6
|
||||
|
||||
int index = CONTINENT_UNKNOWN;
|
||||
|
||||
if (code)
|
||||
{
|
||||
switch (code[0])
|
||||
{
|
||||
case 'A':
|
||||
{
|
||||
switch (code[1])
|
||||
{
|
||||
case 'F': index = CONTINENT_AFRICA; break;
|
||||
case 'S': index = CONTINENT_ASIA; break;
|
||||
}
|
||||
}
|
||||
case 'E': index = CONTINENT_EUROPE; break;
|
||||
case 'O': index = CONTINENT_OCEANIA; break;
|
||||
case 'N': index = CONTINENT_NORTH_AMERICA; break;
|
||||
case 'S': index = CONTINENT_SOUTH_AMERICA; break;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
// native geoip_code2(const ip[], ccode[3]);
|
||||
// Deprecated.
|
||||
static cell AMX_NATIVE_CALL amx_geoip_code2(AMX *amx, cell *params)
|
||||
|
@ -292,6 +326,20 @@ static cell AMX_NATIVE_CALL amx_geoip_distance(AMX *amx, cell *params)
|
|||
return amx_ftoc(earthRadius * acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1)));
|
||||
}
|
||||
|
||||
// native Continent:geoip_continent_code(const ip[], result[3] = "");
|
||||
static cell AMX_NATIVE_CALL amx_geoip_continent_code(AMX *amx, cell *params)
|
||||
{
|
||||
int length;
|
||||
char *ip = MF_GetAmxString(amx, params[1], 0, &length);
|
||||
|
||||
const char *path[] = { "continent", "code", NULL };
|
||||
const char *code = lookupString(stripPort(ip), path, &length);
|
||||
|
||||
MF_SetAmxString(amx, params[2], code ? code : "", code ? 2 : 0);
|
||||
|
||||
return getContinentId(code);
|
||||
}
|
||||
|
||||
|
||||
void OnAmxxAttach()
|
||||
{
|
||||
|
@ -367,6 +415,8 @@ AMX_NATIVE_INFO geoip_natives[] =
|
|||
{ "geoip_longitude", amx_geoip_longitude },
|
||||
{ "geoip_distance" , amx_geoip_distance },
|
||||
|
||||
{ "geoip_continent_code", amx_geoip_continent_code },
|
||||
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
|
|
|
@ -167,3 +167,27 @@ native Float:geoip_longitude(const ip[]);
|
|||
#define SYSTEM_IMPERIAL 1 // statute miles
|
||||
|
||||
native Float:geoip_distance(Float:lat1, Float:lon1, Float:lat2, Float:lon2, system = SYSTEM_METRIC);
|
||||
|
||||
/**
|
||||
* Look up the continent code for a given IP address.
|
||||
*
|
||||
* @note The code can be retrieved as integer (See CONTINENT_* constants.) or string (2 characters).
|
||||
* @note Possible continent codes are AF, AS, EU, NA, OC, SA for
|
||||
* Africa(1), Asia(2), Europe(3), North America(4), Oceania(5) and South America(6).
|
||||
*
|
||||
* @param ip The IP address to look up.
|
||||
* @param result The result of the geoip look up.
|
||||
*
|
||||
* @return The continent id on successful lookup, 0 otherwise.
|
||||
*/
|
||||
enum Continent
|
||||
{
|
||||
CONTINENT_UNKNOW = 0,
|
||||
CONTINENT_AFRICA,
|
||||
CONTINENT_ASIA,
|
||||
CONTINENT_EUROPE,
|
||||
CONTINENT_NORTH_AMERICA,
|
||||
CONTINENT_OCEANIA,
|
||||
CONTINENT_SOUTH_AMERICA
|
||||
};
|
||||
native Continent:geoip_continent_code(const ip[], result[3]);
|
Loading…
Reference in New Issue
Block a user