Пример #1
0
 protected function runJumper()
 {
     foreach ($this->countDown as $matchId => $countDown) {
         switch (--$countDown) {
             case -15:
                 unset($this->countDown[$matchId]);
                 break;
             case -10:
                 //nobreak;
             //nobreak;
             case -5:
                 $match = $this->matchMakingService->getMatch($matchId);
                 //FIXME: maybe use storage which is a safer way to know if a player is still here
                 $players = array_filter($match->players, function ($p) {
                     return !Services\PlayerInfo::Get($p)->isAway();
                 });
                 if ($players) {
                     \ManiaLive\Utilities\Logger::debug('re-display jumper for: ' . implode(',', $players));
                     $this->sendToServer($players, $match->matchServerLogin);
                 } else {
                     //no need to keep this countdown if all player are gone
                     unset($this->countDown[$matchId]);
                     continue;
                 }
                 $this->countDown[$matchId] = $countDown;
                 break;
             case 0:
                 \ManiaLive\Utilities\Logger::debug(sprintf('prepare jump for match : %d', $matchId));
                 $match = $this->matchMakingService->getMatch($matchId);
                 if ($match->state >= Match::PREPARED) {
                     \ManiaLive\Utilities\Logger::debug(sprintf('jumping to server : %s', $match->matchServerLogin));
                     $players = array_map(array($this->storage, 'getPlayerObject'), $match->players);
                     $this->sendToServer($match->players, $match->matchServerLogin);
                     $nicknames = array();
                     foreach ($players as $player) {
                         if ($player && !array_key_exists($player->login, $this->blockedPlayers)) {
                             $nicknames[] = '$<' . \ManiaLib\Utils\Formatting::stripStyles($player->nickName) . '$>';
                             $this->connection->addGuest($player, true);
                         }
                     }
                     $this->connection->chatSendServerMessageToLanguage($this->dictionary->getChat(array(array('textId' => 'matchJoin', 'params' => array(self::PREFIX, implode(' & ', $nicknames))))));
                 } else {
                     \ManiaLive\Utilities\Logger::debug(sprintf('jump cancel match state is : %d', $match->state));
                     foreach ($match->players as $player) {
                         $this->setReadyLabel($player);
                     }
                 }
                 unset($match);
                 //nobreak
             //nobreak
             default:
                 $this->countDown[$matchId] = $countDown;
                 break;
         }
     }
 }