Beispiel #1
0
 /**
  * Récupère les informations du serveur actuel (map, serveur, stats, joueurs)
  *
  * @param string $sortBy -> Le tri à faire sur la liste
  * @return array
  */
 public static function getCurrentServerInfo($sortBy = null)
 {
     global $client;
     $out = array();
     // JEU
     if (SERVER_VERSION_NAME == 'TmForever') {
         $queryName = array('getMapInfo' => 'GetCurrentChallengeInfo');
     } else {
         $queryName = array('getMapInfo' => 'GetCurrentMapInfo');
     }
     // REQUÊTES
     $client->addCall($queryName['getMapInfo']);
     if (AdminServAdminLevel::isType('Admin')) {
         $client->addCall('GetMapsDirectory');
     }
     $client->addCall('GetGameMode');
     $client->addCall('GetServerName');
     $client->addCall('GetStatus');
     $client->addCall('GetCurrentCallVote');
     if (AdminServAdminLevel::isType('SuperAdmin')) {
         $client->addCall('GetNetworkStats');
     }
     $client->addCall('GetPlayerList', array(AdminServConfig::LIMIT_PLAYERS_LIST, 0, 1));
     if (!$client->multiquery()) {
         $out['error'] = Utils::t('Client not initialized');
     } else {
         // DONNÉES DES REQUÊTES
         $queriesData = $client->getMultiqueryResponse();
         // GameMode
         $out['srv']['gameModeId'] = $queriesData['GetGameMode'];
         $out['srv']['gameModeName'] = self::getGameModeName($out['srv']['gameModeId']);
         $out['srv']['gameModeScriptName'] = null;
         if (self::isGameMode('Script', $out['srv']['gameModeId'])) {
             $client->query('GetModeScriptInfo');
             $getModeScriptInfo = $client->getResponse();
             if (isset($getModeScriptInfo['Name'])) {
                 $out['srv']['gameModeScriptName'] = self::formatScriptName($getModeScriptInfo['Name']);
             }
         }
         $displayTeamMode = self::checkDisplayTeamMode($out['srv']['gameModeId'], $out['srv']['gameModeScriptName']);
         // CurrentMapInfo
         $currentMapInfo = $queriesData[$queryName['getMapInfo']];
         $out['map']['name'] = TmNick::toHtml($currentMapInfo['Name'], 10, true, false, '#999');
         $out['map']['uid'] = $currentMapInfo['UId'];
         $out['map']['author'] = $currentMapInfo['Author'];
         $out['map']['enviro'] = $currentMapInfo['Environnement'];
         // MapThumbnail
         $out['map']['thumb'] = null;
         if (isset($queriesData['GetMapsDirectory']) && $currentMapInfo['FileName'] != null) {
             $mapFileName = $queriesData['GetMapsDirectory'] . $currentMapInfo['FileName'];
             if (file_exists($mapFileName)) {
                 if (SERVER_VERSION_NAME == 'TmForever') {
                     $Gbx = new GBXChallengeFetcher($queriesData['GetMapsDirectory'] . $currentMapInfo['FileName'], false, true);
                 } else {
                     $Gbx = new GBXChallMapFetcher(false, true);
                     $Gbx->processFile($queriesData['GetMapsDirectory'] . $currentMapInfo['FileName']);
                 }
                 $out['map']['thumb'] = base64_encode($Gbx->thumbnail);
             }
         }
         // CurrentCallVote
         $out['map']['callvote']['login'] = $queriesData['GetCurrentCallVote']['CallerLogin'];
         $out['map']['callvote']['cmdname'] = $queriesData['GetCurrentCallVote']['CmdName'];
         $out['map']['callvote']['cmdparam'] = $queriesData['GetCurrentCallVote']['CmdParam'];
         // TeamScores (mode team)
         if (self::isGameMode('Team', $out['srv']['gameModeId'])) {
             $client->query('GetCurrentRanking', 2, 0);
             $currentRanking = $client->getResponse();
             $out['map']['scores']['blue'] = $currentRanking[0]['Score'];
             $out['map']['scores']['red'] = $currentRanking[1]['Score'];
         }
         // ServerName
         $out['srv']['name'] = TmNick::toHtml($queriesData['GetServerName'], 10, true, false, '#999');
         // Status
         $out['srv']['status'] = $queriesData['GetStatus']['Name'];
         // NetworkStats
         if (isset($queriesData['GetNetworkStats']) && count($queriesData['GetNetworkStats']) > 0) {
             $networkStats = $queriesData['GetNetworkStats'];
             $out['net']['uptime'] = TimeDate::secToStringTime($networkStats['Uptime'], false);
             $out['net']['nbrconnection'] = $networkStats['NbrConnection'];
             $out['net']['meanconnectiontime'] = TimeDate::secToStringTime($networkStats['MeanConnectionTime'], false);
             $out['net']['meannbrplayer'] = $networkStats['MeanNbrPlayer'];
             $out['net']['recvnetrate'] = $networkStats['RecvNetRate'];
             $out['net']['sendnetrate'] = $networkStats['SendNetRate'];
             $out['net']['totalreceivingsize'] = $networkStats['TotalReceivingSize'];
             $out['net']['totalsendingsize'] = $networkStats['TotalSendingSize'];
         } else {
             $out['net'] = null;
         }
         // PlayerList
         $playerList = $queriesData['GetPlayerList'];
         $countPlayerList = count($playerList);
         if ($countPlayerList > 0) {
             $client->query('GetCurrentRanking', AdminServConfig::LIMIT_PLAYERS_LIST, 0);
             $rankingList = $client->GetResponse();
             $rankingKeyList = array('Rank', 'BestTime', 'BestCheckpoints', 'Score', 'NbrLapsFinished', 'LadderScore');
             $i = 0;
             foreach ($playerList as $player) {
                 // Nickname et Playerlogin
                 $out['ply'][$i]['NickName'] = TmNick::toHtml(htmlspecialchars($player['NickName'], ENT_QUOTES, 'UTF-8'), 10, true);
                 $out['ply'][$i]['Login'] = $player['Login'];
                 // PlayerStatus
                 if ($player['SpectatorStatus'] != 0) {
                     $playerStatus = Utils::t('Spectator');
                 } else {
                     $playerStatus = Utils::t('Player');
                 }
                 $out['ply'][$i]['PlayerStatus'] = $playerStatus;
                 // Others
                 $out['ply'][$i]['PlayerId'] = $player['PlayerId'];
                 $out['ply'][$i]['TeamId'] = $player['TeamId'];
                 if ($player['TeamId'] == 0) {
                     $teamName = Utils::t('Blue');
                 } else {
                     if ($player['TeamId'] == 1) {
                         $teamName = Utils::t('Red');
                     } else {
                         $teamName = Utils::t('Spectator');
                     }
                 }
                 $out['ply'][$i]['TeamName'] = $teamName;
                 $out['ply'][$i]['SpectatorStatus'] = $player['SpectatorStatus'];
                 // Rankings
                 foreach ($rankingKeyList as $rankName) {
                     if (isset($rankingList[$i][$rankName])) {
                         $out['ply'][$i][$rankName] = $rankingList[$i][$rankName];
                     }
                 }
                 if ($player['LadderRanking'] == -1) {
                     $player['LadderRanking'] = Utils::t('Not rated');
                 }
                 $out['ply'][$i]['LadderRanking'] = $player['LadderRanking'];
                 $i++;
             }
         } else {
             $out['ply'] = Utils::t('No player');
         }
         // Nombre de joueurs
         if ($countPlayerList > 1) {
             $out['nbp'] = $countPlayerList . ' ' . Utils::t('players');
         } else {
             $out['nbp'] = $countPlayerList . ' ' . Utils::t('player');
         }
         // TRI
         if (is_array($out['ply']) && count($out['ply']) > 0) {
             // Si on est en mode équipe, on tri par équipe
             if ($displayTeamMode) {
                 uasort($out['ply'], 'AdminServSort::sortByRank');
                 uasort($out['ply'], 'AdminServSort::sortByTeam');
             } else {
                 switch ($sortBy) {
                     case 'nickname':
                         uasort($out['ply'], 'AdminServSort::sortByNickName');
                         break;
                     case 'ladder':
                         uasort($out['ply'], 'AdminServSort::sortByLadderRanking');
                         break;
                     case 'login':
                         uasort($out['ply'], 'AdminServSort::sortByLogin');
                         break;
                     case 'status':
                         uasort($out['ply'], 'AdminServSort::sortByStatus');
                         break;
                     default:
                         uasort($out['ply'], 'AdminServSort::sortByRank');
                         uasort($out['ply'], 'AdminServSort::sortByStatus');
                 }
             }
         }
     }
     return $out;
 }