<?php
/*======================================================================*\
|| #################################################################### ||
|| # EoT-Clan BC2 Leaderboard                                         # ||
|| # ---------------------------------------------------------------- # ||
|| # Dieses Copyright darf nicht entfernt werden                      # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # -----------------BC2 Leaderboard is a free Software--------------# ||
|| #                      http://eot-clan.net                         # ||
|| #################################################################### ||
\*======================================================================*/


 //Map Name
    $Map = $BC2Conn->getCurrentMap();
    $find = array("GR","CQ","SR","SDM","Levels","/","levels","gr","cq","sr","sdm","r","R");
    $replace = array("","","","","","","","","","","","","");
    $Map = str_replace($find, $replace, $Map);
    $Map = strtoupper($Map);
    
    $Mapname = array(
    "MP_001" => "Panama Canal",
    "MP_002" => "Valparaiso",
    "MP_003" => "Laguna Alta",
    "MP_004" => "Isla Inocentes",
    "MP_005" => "Atacama Desert",
    "MP_006" => "Arica Harbor",
    "MP_007" => "Panama Canal",
    "MP_008" => "Nelson Bay",
    "MP_009" => "Laguna Presa",
    "MP_012" => "Port Valdez",
    "BC1_OASIS_" => "Oasis",
    "BC1_HAVEST_DAY_" => "Harvest Day",
    "MP_SP_002" => "Cold War",
    "MP_SP_005" => "Heavy Metal",
    "NAM_MP_002" => "Vantage Point",
    "NAM_MP_003" => "Hill 137",
    "NAM_MP_005" => "Khao san Temple",
    "NAM_MP_006" => "Phu Bai Valley",
    "NAM_MP_007" => "Operations Hasting",
    );

$version = $BC2Conn->getVersion();

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:<font color=orange>Vietnam</font>';
}else{
	$gameversion = 'BFBC2:<font color=orange>Vanilla</font>';
}

  if (array_key_exists($Map, $Mapname)){
 	 $Mapname = $Mapname[$Map];
 }else{
 	$Mapname = $Map;
}

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

 //Versions Info 
  $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();
}


    //Online Offline Status
      if ($BC2Conn->isServerOnline() == 1){
	       $sStatus = '<font color=#00FF00> Online </font>';
     }

     // eventuelle Kürzung des Server Namens
        if(strlen($BC2Conn->getServerName()) <= 100) {
           $ServerName = $BC2Conn->getServerName();
        } else {
          $ServerName = substr($BC2Conn->getServerName(),0,100) . '...'; 
      }



       if ($BC2Conn->getCurrentPlaymode() == 'RUSH'){
          $Team1 = 'Attacker';
          $Team2 = 'Defender';
     }elseif ($BC2Conn->getCurrentPlaymode() == 'CONQUEST'){
          $Team1 = 'USA';
          if ($gameversion == 'BFBC2:<font color=orange>Vietnam</font>'){
          	$Team2 = 'NVA';
          }else{
          $Team2 = 'Russians';
        }
     }else{
        	$Team1 = 'Alpha';
          $Team2 = 'Bravo';
          $Team3 = 'Charlie';
          $Team4 = 'Delta';
   }


      $ServerData =$BC2Conn->getPlayerlist();
    
	$ii = 0;
	for ($i = 12; $i < count($ServerData); $i+=9){
		$Players_ar[$ii]['clantag'] = $ServerData[$i];
		$Players_ar[$ii]['name'] = $ServerData[$i+1];
		$Players_ar[$ii]['teamid'] = $ServerData[$i+3];
		$Players_ar[$ii]['squadid'] = $ServerData[$i+4];
		$Players_ar[$ii]['kills'] = $ServerData[$i+5];
		$Players_ar[$ii]['deaths'] = $ServerData[$i+6];
		$Players_ar[$ii]['score'] = $ServerData[$i+7];
		$Players_ar[$ii]['ping'] = $ServerData[$i+8];
		++$ii;
	}

	$aServerSettings = $BC2Conn->getServerInfo();

	if ($aServerSettings[2] > 0){
	function compare($a, $b) { return $a["score"]<$b["score"]; }
usort($Players_ar, "compare");
}
	
	
      $Settings = $BC2Conn->getServerInfo();
 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';
  }
}

if ($BC2Conn->getCurrentPlaymode() == 'SQDM'){
        $NeedAplha = ($aServerSettings[13]-$aServerSettings[9]);
         $NeedBravo = ($aServerSettings[13]-$aServerSettings[10]);
        $NeedCharlie = ($aServerSettings[13]-$aServerSettings[11]);
       $NeedDelta = ($aServerSettings[13]-$aServerSettings[12]);
}
