fixed bug at40963

This commit is contained in:
Borja Ferrer 2006-07-16 13:23:56 +00:00
parent 87ac42cd98
commit 6ac889f6e2

View File

@ -3,10 +3,19 @@
GeoIP *gi = NULL; GeoIP *gi = NULL;
inline void StripPort(char *ip)
{
char *tmp = strchr(ip, ':');
if (!tmp)
return;
*tmp = '\0';
}
static cell AMX_NATIVE_CALL amx_geoip_code2(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_geoip_code2(AMX *amx, cell *params)
{ {
int len = 0; int len = 0;
char *ip = MF_GetAmxString(amx, params[1], 0, &len); char *ip = MF_GetAmxString(amx, params[1], 0, &len);
StripPort(ip);
const char *ccode = GeoIP_country_code_by_addr(gi, ip); const char *ccode = GeoIP_country_code_by_addr(gi, ip);
return MF_SetAmxString(amx, params[2], ccode?ccode:"error", 3); return MF_SetAmxString(amx, params[2], ccode?ccode:"error", 3);
} }
@ -15,6 +24,7 @@ static cell AMX_NATIVE_CALL amx_geoip_code3(AMX *amx, cell *params)
{ {
int len = 0; int len = 0;
char *ip = MF_GetAmxString(amx, params[1], 0, &len); char *ip = MF_GetAmxString(amx, params[1], 0, &len);
StripPort(ip);
const char *ccode = GeoIP_country_code3_by_addr(gi, ip); const char *ccode = GeoIP_country_code3_by_addr(gi, ip);
return MF_SetAmxString(amx, params[2], ccode?ccode:"error", 4); return MF_SetAmxString(amx, params[2], ccode?ccode:"error", 4);
} }
@ -23,6 +33,7 @@ static cell AMX_NATIVE_CALL amx_geoip_country(AMX *amx, cell *params)
{ {
int len = 0; int len = 0;
char *ip = MF_GetAmxString(amx, params[1], 0, &len); char *ip = MF_GetAmxString(amx, params[1], 0, &len);
StripPort(ip);
const char *ccode = GeoIP_country_name_by_addr(gi, ip); const char *ccode = GeoIP_country_name_by_addr(gi, ip);
return MF_SetAmxString(amx, params[2], ccode?ccode:"error", params[3]); return MF_SetAmxString(amx, params[2], ccode?ccode:"error", params[3]);
} }