<?php 
/*======================================================================*\
|| #################################################################### ||
|| # EoT-Clan BC2 Server Stats                                        # ||
|| # ---------------------------------------------------------------- # ||
|| # Dieses Copyright darf nicht entfernt werden                      # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # -----------------BC2 Server Stats is a free Software-------------# ||
|| #                      http://eot-clan.net                         # ||
|| #################################################################### ||
\*======================================================================*/
if (!defined('INCLUDE_ME')){ 
die('access not allowed'); 
}
$ServerPlayers = array();
foreach ($aServerips as $serverdatas){
	$BC2Conn = new BC2Conn($serverdatas['ip'],$serverdatas['qport']);
	if (!$BC2Conn->isConnected()){ 
      include ("error/servererror.html"); 
 }else{
 
	$Players_ar = '';
 	 $ServerData = $BC2Conn->getPlayerlist(); 
	$ii = 0;
	for ($i = 12; $i < count($ServerData); $i+=9){	
		$Players_ar[$ii]['name'] = $ServerData[$i+1];
		++$ii;
	}
	if (is_array($Players_ar)) foreach ($Players_ar as $Players){
 	$ServerPlayers[] = $Players['name'];
}

 
 	if(strlen($BC2Conn->getServerName()) <= 100) {
           $ServerName = $BC2Conn->getServerName();
        } else {
          $ServerName = substr($BC2Conn->getServerName(),0,100) . '...'; 
      }
    $Map = $BC2Conn->getCurrentMap();
    include ('inc/map_array.php');
    
if ($Map == 'NAM_MP_002' or $Map == 'NAM_MP_003' or $Map == 'NAM_MP_005' or $Map == 'NAM_MP_006' or $Map == 'NAM_MP_007'){
	$gameversion = 'BFBC2:<span class="sonstige">Vietnam</span>';
}else{
	$gameversion = 'BFBC2:<span class="sonstige">Vanilla</span>';
}  


   if ($BC2Conn->getVersionID() >= '617877'){
$Settings = $BC2Conn->getServerInfo();
if ($BC2Conn->getCurrentPlaymode() == 'SQDM'){
	$plus = '2';
}else{
$plus = '';
}
$serveruptime = sprintf("%02dh %02dm %02ds",$Settings[16+$plus]/60/60,$Settings[16+$plus]/60%60,$Settings[16+$plus]%60);
$Mapruntime = sprintf(" %02dm %02ds",$Settings[17+$plus]/60,$Settings[17+$plus]%60);
} 

$Settings = $BC2Conn->getServerInfo();
   if ($BC2Conn->getVersionID() >= '617877'){
if ($BC2Conn->getCurrentPlaymode() == 'SQDM'){
	$plus = '2';
}else{
$plus = '';
}
	$serveruptime = sprintf("%02dh %02dm %02ds",$Settings[16+$plus]/60/60,$Settings[16+$plus]/60%60,$Settings[16+$plus]%60);
	$Mapruntime = sprintf(" %02dm %02ds",$Settings[17+$plus]/60,$Settings[17+$plus]%60);
}

 $sVersion = $BC2Conn->getVersionID();
    $Version = array(
    "556157" => "R16",
    "581637" => "R22",
    "556157" => "R23",
    "593485" => "R24",
    "602833" => "R25",
    "609063" => "R26",
    "617877" => "R27",
    "621775" => "R28",
    "638140" => "R30"
    );
    
 if (array_key_exists($sVersion, $Version)){
 	 $sVersion = $Version[$sVersion];
 }else{
 	 $sVersion = $BC2Conn->getVersionID();
}

$Mod = $BC2Conn->getCurrentPlaymode();
$Gamemod = array(
    "CONQUEST" => "Conquest",
    "RUSH" => "Rush",
    "SQRUSH" => "Squad Rush",
    "SQDM" => "SQDM"
    );
    
    
 if (array_key_exists($Mod, $Gamemod)){
 	 $Gamemod = $Gamemod[$Mod];
 }else{
 	$Gamemod = $Mod;
}

 if ($BC2Conn->getVersionID() >= '617877'){
	if ($BC2Conn->getCurrentPlaymode() == 'SQDM'){
	$plus = '2';
}else{
$plus = '';
}
	
	
	if ($Settings[15+$plus] == 'false'){
		$passwort = 'nopw';
		$passwortt = 'No Password';
}else{
	 $passwort = 'pw';
	 $passwortt = 'Password';
}

if(preg_match("/\bhc\b/i",$Settings[1]) or preg_match("/\b[hc]\b/i",$Settings[1]) or preg_match("/\bhardcore\b/i",$Settings[1]) or preg_match("/\b[hardcore]\b/i",$Settings[1])){ 
     $Hardcore = 'hardcore';
     $Hardcoret = 'Hardcore';
	} else{
		 $Hardcore = 'softcore';
		 $Hardcoret = 'No Hardcore';
}



	$serveruptime = sprintf("%02dh %02dm %02ds",$Settings[16+$plus]/60/60,$Settings[16+$plus]/60%60,$Settings[16+$plus]%60);
	$Mapruntime = sprintf(" %02dm %02ds",$Settings[17+$plus]/60,$Settings[17+$plus]%60);
	
	
if ($Settings[13+$plus] == 'false'){
		$ranked = 'norank';
		$rankedt = 'Unranked';
}else{
	 $ranked = 'rank';
	 $rankedt = 'Ranked';
}

	if ($Settings[14+$plus] == 'false'){
		$punkbuster = 'nopb';
		$punkbustert = 'No Punkbuster';
}else{
	 $punkbuster = 'pb';
	 $punkbustert = 'Punkbuster On';
  }
}
 ?>
 <td class="default_h" >
 	<hr width="800px"><b><?php echo htmlspecialchars($ServerName); ?></b><hr width="800px">
   <div style="width:520px;float:left;">
 	  <div style="float:left;width:260px;text-align:left;height:18px;margin-left:10px;margin-top:10px;"><?php echo server_ip; ?>: <?php echo  $BC2Conn->getServerIP() ?></div>
 	  <div style="float:left;width:250px;text-align:left;height:18px;margin-top:10px;"><?php echo server_gversion; ?>: <?php echo  $gameversion ?></div>
 	  <div style="float:left;width:260px;text-align:left;height:18px;margin-left:10px;"><?php echo server_version; ?>: <?php echo  $sVersion ?></div>
 	  <div style="float:left;width:250px;text-align:left;height:18px;"><?php echo server_modus; ?>: <?php echo $Gamemod;  ?></div>
 	  <div style="float:left;width:260px;text-align:left;height:18px;margin-left:10px;"><?php echo server_map; ?>: <span class="sonstige"><?php echo $Mapname; ?></span></div>
 	  <div style="float:left;width:250px;text-align:left;height:18px;"><?php echo server_round; ?>: <?php echo $Settings[6]; ?>/<?php echo $Settings[7]; ?></div>
 	  <div style="float:left;width:260px;text-align:left;height:18px;margin-left:10px;"><?php echo server_player; ?>: <span class="sonstige"><?php echo $Settings[2]; ?> / <?php echo $Settings[3]; ?></span></div>
   <?php if ($BC2Conn->getVersionID() >= '617877'){ ?>
     <div style="float:left;width:250px;text-align:left;height:18px;"><?php echo server_server_runtime; ?><?php echo $serveruptime; ?></div>
     <div style="float:left;width:260px;text-align:left;height:18px;margin-left:10px;"><?php echo server_map_runtime; ?><?php echo $Mapruntime; ?></div>
     <div style="float:left;width:70px;text-align:left;height:18px;"><?php echo server_setting; ?></div><div style="float:left;width:170px;text-align:left;height:18px;margin-left:10px;">
     	  	<img src="img/<?php echo $passwort; ?>.png" border="0" title="<?php echo $passwortt ?>" alt="PW"/>
         	<img src="img/<?php echo $ranked; ?>.png" border="0" title="<?php echo $rankedt ?>" alt="Ranked"/>
         	<img src="img/<?php echo $punkbuster; ?>.png" border="0" title="<?php echo $punkbustert ?>" alt="PB" />
         	<img src="img/<?php echo $Hardcore; ?>.png" border="0" title="<?php echo $Hardcoret ?>" alt="Hardcore" />
        </div>
   <?php } ?>    
   </div>
  <div style="width:250px;float:right;">
    <div style="float:right;width:380px;height:122px;text-align:center;"><img class="maps" src="img/maps/<?php echo $Map ?>.jpg" /></div>
  </div>
   <a id="serverstats_<?php echo $serverdatas['id']; ?>" href="server_viewer.php?serverID=<?php echo $serverdatas['id']; ?>"><b><span class="button" style="float:left;margin-left:10px;">Server Details</span></b></a><br />
  <?php if ($dChatlog == 1){ ?>
   <a id="serverstats_<?php echo $serverdatas['id']; ?>" href="stats/chatentrys.php?server=<?php echo urlencode($BC2Conn->getServerName()); ?>"><b><span class="button">Chatlog</span></b></a><br />
  <?php } ?>
  <?php if ($Banlist == 1){ ?>
   <a id="serverstats_<?php echo $serverdatas['id']; ?>" href="stats/general_server.php?serverID=<?php echo $serverdatas['id']; ?>"><b><span class="button">Banlist etc.</span></b></a><br />
 <?php } ?>
 </td> 
<tr>
		<script type="text/javascript">  	
		$(document).ready(function() {
	
			$("a#serverstats_<?php echo $serverdatas['id'] ?>").fancybox({
			'autoDimensions'	: true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'padding' : 0
			});
     });
	</script>
   <?php 
   
 }
}
  	