<?php
include "mysql.inc";
mysql_select_db("l2jdb");
include "status.inc";
if($game_s){
$mreply=mysql_fetch_array(mysql_query("select count(online) from characters where online"));
$online=stripslashes($mreply["count(online)"]);
echo "
<a class='online'>Онлайн сервера: $online</a>";
$file = fopen("online.txt", "w");
fwrite($file, $online);
fclose($file);
}else{
echo "
<a class='offline'>Сервер оффлайн</a>";}
?>
<?php
//$server_ip = '213.219.221.4'; // есно айпи сервера (либо адрес)
$server_ip = '127.0.0.1'; // есно айпи сервера (либо адрес)
$time_check = 30; // в сек.
unset($tmp,$fs,$t,$login_s,$game_s);
if(file_exists('server_status.temp')){
$tmp = file('server_status.temp');
list($t,$login_s,$game_s) = split(":",$tmp[0]);
if((time()-$t)>$time_check){
$tmp = check_ports($server_ip);
check_ports_to_file($tmp);
list($login_s,$game_s) = split(":",$tmp);
}
}else{
$tmp = check_ports($server_ip);
check_ports_to_file($tmp);
list($login_s,$game_s) = split(":",$tmp);
}
//---------------------
function check_ports_to_file($tmp){
$fs = fopen('server_status.temp','w');
fputs($fs,time().":".$tmp);
fclose($fs);
}
//---------------------
function check_ports($host){
$login_s=0;
$game_s=0;
$fp = @fsockopen($host, 2106, $err_n, $err_str, 0.5);
if ($fp)
{
fclose($fp);
$login_s=1;
}
$fp = @fsockopen($host, 7777, $err_n, $err_str, 0.5);
if ($fp)
{
fclose($fp);
$game_s=1;
}
return ($login_s.":".$game_s.":");
}
?>