PHP код:
forward Geo_OnPlayerConnect(playerid);
public Geo_OnPlayerConnect(playerid)
{
new string[128],ip[16];
GetPlayerIp(playerid,ip,sizeof(ip));
format(string,128,"speed-tester.info/ip_location.php?ip=%s",ip);
HTTP(playerid,HTTP_GET,string,"","GeoResponse");
}
forward GeoResponse(index, response_code, data[]);
public GeoResponse(index, response_code, data[])
{
if(response_code == 200)
{
new ep = 0, sp = ep, stringNum = 0;
do
{
ep = strfind(data, "\n", false, sp);
if(-1 < ep < strlen(data))
{
stringNum++;
if(stringNum == 27)
{
new temp[128],PlayerCountry[64];
strmid(temp,data,sp,ep);
strmid(PlayerCountry,temp,20,strfind(temp,"<br>",true)-4);
SetPVarString(index,"Country",PlayerCountry);
}
if(stringNum == 28)
{
new temp[128],PlayerCity[64];
strmid(temp,data,sp,ep);
strmid(PlayerCity,temp,62,strfind(temp,"\";",true)-2);
SetPVarString(index,"City",PlayerCity);
}
}
sp = ep+1;
}
while(-1 < ep < strlen(data));
}
return;
}
stock GetPlayerCountry(playerid,country[])
{
GetPVarString(playerid,"Country",country,64);
return country;
}
stock GetPlayerCity(playerid,city[])
{
GetPVarString(playerid,"City",city,64);
return city;
}