Witam
Mam stronę na której można dodać serwery popularnej gry counter strike, strona pokazuje ile graczy jest aktualnie na wszystkich serwerach i co chwile aktualizuję te dane. Chcę zrobić taki napis: Rekordowa ilość graczy online: xxxx. tylko nie wiem jak to zrobić.
Podam tutaj kod tej podstrony.
<?php
include_once("config.php");
///////////////////////////////////////////////////////////////////////////////////////////////////
if($main['debug'])
else
include_once("inc/functions.php");
include_once("inc/class_PQ.php");
if(!class_exists("XTemplate")) include_once("inc/xtemplate.php");
///////////////////////////////////////////////////////////////////////////////////////////////////
// $id represents server id, depending on config.php, notice, id cannot be zero (it refers to all servers)
if(isset($_GET['id'])) $id = (int
) $_GET['id']; else $id = 0;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
if($id) // show specific server
{
$id--;
if(cache_read
($cache,$main['cache'],$id) && ( (time() - $cache[$id]['hlss_update_time']) < $main['cache_outdate'])) { //cache read ok and no need for update
$pqinfo = $cache[$id];
}
else
{
$pq = PQ::create($server[$id]);
$pqinfo = $pq->query(array('info','rules','players')); //this is the moment when we check server status $pqinfo['hlss_update_time'] = time();// mark the date when server was visited last time $pqinfo['update_time'] = date($main['dateformat'],$pqinfo['hlss_update_time']);
}
if(!@$pqinfo['ping']) $pqinfo['timeout'] = 1 ; else $pqinfo['timeout'] = 0 ;
$server[$id]['id'] = $id+1;
$server[$id]["name"] = htmlspecialchars($server[$id]["name"],ENT_QUOTES
);// replace strange chars with html equivalents $server[$id]['skin'] = substr($server[$id]['template'],0
,strrpos($server[$id]['template'],".")); if(!@$server[$id]["offline_img"]) $server[$id]["offline_img"] = $main['offline_img'];
if(!@$server[$id]["online_img"]) $server[$id]["online_img"] = $main['online_img'];
if(!@$server[$id]['nicklength']) $server[$id]['nicklength'] = $main['nicklength'];
$server[$id]['online_percent'] = floor(100
*@$pqinfo['totalplayers']/@$pqinfo['maxplayers']);
{
//default is template display mode, otherwise return image contents
// image return mode works only for single server!!!
load_template($tpl,$server[$id]['template']);
$tpl->assign($server[$id]);
$tpl->assign($pqinfo);
}
if($pqinfo['timeout'])
{
{
{// if we got plr var then we want to return players number on server
switch($_GET['plr'])
{
default:
case "1": //image depend on player number
if(!isset($server[$id]["online_img_plr_off"])) $server[$id]["online_img_plr_off"] = @$main["online_img_plr_off"];
output_img($server[$id]["online_img_plr_off"]);
break;
case "2": //return image depend on percentage of server fill
if(!isset($server[$id]["online_img_plr_off%"])) $server[$id]["online_img_plr_off%"] = @$main["online_img_plr_off%"];
output_img($server[$id]["online_img_plr_off%"]);
break;
}
}
else
{
output_img($server[$id]["offline_img"]); //automaticaly invoked php exit on
}
}
else
{
$tpl->parse("MAIN.TIMEOUT");
}
}
else
{
// fix images, transport from $main to $server[$id]
for ($i=0;$i<=32;$i++) //server maxplayers is 32, we run from 0 slot server to 32 (yea, a bit ugly)
{
if(!isset($server[$id]["online_img_plr_".$i])) $server[$id]["online_img_plr_".$i] = @$main["online_img_plr_".$i];
for ($j=0;$j<=$i;$j++)
{ if($i==0) break;//division by zero fix
if(!isset($server[$id]["online_img_plr_".$plr."%"])) $server[$id]["online_img_plr_".$plr."%"] = @$main["online_img_plr_".$plr."%"];
}
}
$plr = "";
{
{
switch($_GET['plr'])
{
default:
case "1": //image depend on player number
$plr = $pqinfo['totalplayers'];
output_img($server[$id]["online_img_plr_".$plr]);
break;
case "2": //return image depend on percentage of server fill, but
$plr = floor(100
*$pqinfo['totalplayers']/$pqinfo['maxplayers']); output_img($server[$id]["online_img_plr_".$plr."%"]);
break;
}
}
else
{
output_img($server[$id]["online_img"]);//automaticaly invoked php exit on
}
}
else
{
////////////////////////////////////////////////////////////////////////////
$jj=0;
////////////////////////////////////////////////////////////////////////////
}
}
if($main['showall'])
$tpl->assign(array("showall" => showall
($tpl))); else
$tpl->assign(array("showall" => ""));
$tpl->assign($main);
$tpl->parse("MAIN");
$tpl->out("MAIN");
$cache[$id] = $pqinfo;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// show all servers
else
{
load_template($tpl,$main['template']);
$totalPlayers = 0;
$maxPlayers = 0;
foreach ($server as $skey =>$sval){
if($sval['disable']) continue;//server disabled, do not display it in list mode
unset($pq,$pqinfo);// make sure we do not get wrong values from previous foreach() loop
if(cache_read
($cache,$main['cache'],$skey) && ( (time() - $cache[$skey]['hlss_update_time']) < $main['cache_outdate'])) { //cache read ok and no need for update
$pqinfo = $cache[$skey];
}
else
{
$pq = PQ::create($server[$skey]);
$pqinfo = $pq->query(array('info','rules','players')); //this is the moment when we check server status $pqinfo['hlss_update_time'] = time();// mark the date when server was visited last time $pqinfo['update_time'] = date($main['dateformat'],$pqinfo['hlss_update_time']); // notice that udate_time is set only everytime server query is performed, even if server is not responding
}
if(!@$pqinfo['ping']) $pqinfo['timeout'] = 1 ; else $pqinfo['timeout'] = 0 ;
$sval['id'] = $skey+1;
$sval['skin'] = substr($main['template'],0
,strrpos($main['template'],".")); if(!@$sval['nicklength']) $sval['nicklength'] = $main['nicklength'];
$sval['online_percent'] = floor(100
*@$pqinfo['totalplayers']/@$pqinfo['maxplayers']); $totalPlayers += $pqinfo['totalplayers'];
$maxPlayers += $pqinfo['maxplayers'];
$wolnych = ($maxPlayers - $totalPlayers);
$tpl->assign($sval);
$tpl->assign($pqinfo);
if($pqinfo['timeout'])
{
$tpl->parse("MAIN.TIMEOUT");
}
else
{
////////////////////////////////////////////////////////////////////////////
$jj=0;
foreach($pqinfo['players'] as $plr)
{
unset($player);//make sure w will not get values from previous row
if(strlen($player['player_name'])>@$sval['nicklength']) $player['player_shortname'] = htmlspecialchars(substr($player['player_name'],0
,$sval['nicklength']-3)."...",ENT_QUOTES
);
$player['player_id'] = $plr['id'];
$player['player_kills'] = $plr['kills'];
$player['player_time'] = $plr['onlinetime']; //seconds
$player['player_time_min'] = date("H:i:s",$plr['onlinetime']-3600
); //seconds, need to fix it $player['j']=$jj;
$player['i']=($jj++%2);
$tpl->assign($player);
$tpl->parse("MAIN.STATUS.PLAYERS.PLAYER");
}
$tpl->parse("MAIN.STATUS.PLAYERS");
$tpl->parse("MAIN.STATUS");
////////////////////////////////////////////////////////////////////////////
}
$cache[$skey] = $pqinfo;
}
if($main['showall'])
$tpl->assign(array("showall" => showall
($tpl))); else
$tpl->assign(array("showall" => ""));
$tpl->assign( 'graczy', $totalPlayers );
$tpl->assign( 'wolnych', $wolnych );
$tpl->assign($main);
$tpl->parse("MAIN");
$tpl->out("MAIN");
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
cache_write($cache,$main['cache']);
//ob_flush();
?>