//
// Проверка статуса серверов и т.п.
//
function get_status($ip, $port, &$info, $status_refresh_time = 5)
{
global $data_dir;
$info = array();
$data_file = "scripts/cache/{$ip}-{$port}.status";
if (!file_exists($data_file))
{
$fh = fopen($data_file, "w+");
if ($port > 7000)
{
fputs($fh, "time:online:world:max:current:playing:store:unk0:unk1:unk2:unk3:unk4:unk5:unk6:unk7:unk8:unk9:unk10:unk11\n");
fputs($fh, "0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0\n");
}
else
{
fputs($fh, "time:online\n");
fputs($fh, "0:0\n");
}
fclose($fh);
}
$fh = fopen($data_file, "r");
$str = trim(fgets($fh));
$keys = explode(":", $str);
$str = trim(fgets($fh));
$values= explode(":", $str);
fclose($fh);
$info = array_combine($keys, $values);
unset($keys, $values);
if (($info["time"] + $status_refresh_time) < time())
{
if ($fp = @fsockopen($ip, $port, $ERROR_NO, $ERROR_STR, (float) 0.5))
{
if ($port > 7000)
{
$packet = pack("vCi", 6, 0, -3);
fwrite($fp, $packet);
$returned = fread($fp, 73);
$info = unpack("vtime/Conline/iworld/imax/icurrent/iplaying/istore/iunk0/iunk1/iunk2/iunk3/iunk4/iunk5/iunk6/iunk7/iunk8/iunk9/iunk10/iunk11", $returned);
}
fclose($fp);
$info["online"] = 1;
}
else
{
$info["online"] = 0;
$info["current"] = 0;
$info["store"] = 0;
}
$info["time"] = time();
$fh = fopen($data_file, "w+");
fputs($fh, implode(":", array_keys($info))."\n");
fputs($fh, implode(":", array_values($info))."\n");
fclose($fh);
}
return $info["online"];
}