예제 #1
0
 function onTick()
 {
     $timers = array();
     $this->tick++;
     if ($this->tick % 8 == 0) {
         gc_collect_cycles();
         $mtime = microtime(true);
         foreach ($this->blockedPlayers as $login => $time) {
             $this->updateKarma($login);
         }
         $timers['blocked'] = microtime(true) - $mtime;
     }
     if ($this->tick % 15 == 0 && $this->maintenanceMode) {
         $this->connection->chatSendServerMessageToLanguage($this->dictionary->getChat(array(array('textId' => 'maintenance', 'params' => array($this->maintenanceMessage)))));
     }
     //If there is some match needing players
     //find backup in ready players and send them to the match server
     $mtime = microtime(true);
     if ($this->tick % 3 == 0) {
         $this->runReplacerMaker();
     }
     $timers['backups'] = microtime(true) - $mtime;
     if ($this->config->matchMakerDelay == 0 && $this->isMatchMakerAllowed() && $this->tick % 2 == 0 || $this->config->matchMakerDelay != 0 && $this->tick % $this->config->matchMakerDelay == 0) {
         $this->runMatchMaker();
     }
     foreach ($this->replacerCountDown as $login => $countDown) {
         $login = (string) $login;
         switch (--$countDown) {
             case -15:
                 unset($this->replacerCountDown[$login]);
                 break;
             case 0:
                 $match = $this->matchMakingService->getPlayerCurrentMatch($login, $this->storage->serverLogin, $this->scriptName, $this->titleIdString);
                 $player = $this->storage->getPlayerObject($login);
                 if ($match && $match->state >= Match::PREPARED) {
                     if ($this->sendToServer($login, $match->matchServerLogin)) {
                         //TODO Add transfer textId to AbstractGUI
                         $this->gui->createLabel($this->gui->getTransferText(), $login, null, false, false);
                         $this->connection->addGuest($login, true);
                         $this->connection->chatSendServerMessageToLanguage($this->dictionary->getChat(array(array('textId' => 'substituteMoved', 'params' => array(self::PREFIX, $player->nickName)))));
                         $this->matchMakingService->updatePlayerState($this->replacers[$login], $match->id, Services\PlayerInfo::PLAYER_STATE_REPLACED);
                     } else {
                         //Something bad happened
                     }
                 } else {
                     \ManiaLive\Utilities\Logger::debug(sprintf('For replacer %s, match does not exist anymore', $login));
                 }
                 unset($match, $player);
                 //nobreak
             //nobreak
             default:
                 $this->replacerCountDown[$login] = $countDown;
                 break;
         }
     }
     unset($login, $countDown);
     $this->runJumper();
     //Clean guest list for not in match players
     if ($this->tick % 29 == 0) {
         $mtime = microtime(true);
         $guests = $this->connection->getGuestList(-1, 0);
         if (count($guests)) {
             $guests = Structures\Player::getPropertyFromArray($guests, 'login');
             $logins = $this->matchMakingService->getPlayersJustFinishedAllMatches($this->storage->serverLogin, $guests);
             if ($logins) {
                 foreach ($logins as $login) {
                     $this->connection->removeGuest($login, true);
                 }
             }
         }
         $timers['cleanGuest'] = microtime(true) - $mtime;
     }
     if ($this->tick % 31 == 0) {
         $mtime = microtime(true);
         $this->setLobbyInfo();
         $timers['lobbyInfo'] = microtime(true) - $mtime;
     }
     if ($this->tick % 6 == 0) {
         $mtime = microtime(true);
         $this->updateLobbyWindow();
         $timers['lobbyWindow'] = microtime(true) - $mtime;
     }
     if ($this->config->showMasters && $this->tick % 6 == 0) {
         $this->updateMasterList();
     }
     if ($this->tick % 12 == 0) {
         if ($this->scriptName == 'Elite' || $this->scriptName == 'Combo') {
             $endedMatches = $this->matchMakingService->getEndedMatchesSince($this->storage->serverLogin, $this->scriptName, $this->titleIdString);
             foreach ($endedMatches as $endedMatch) {
                 if ($endedMatch->team1) {
                     $states = $endedMatch->playersState;
                     $connectedPlayersCallBack = function ($login) use($states) {
                         return $states[$login] == Services\PlayerInfo::PLAYER_STATE_CONNECTED;
                     };
                     $team1 = array_filter($endedMatch->team1, $connectedPlayersCallBack);
                     $team2 = array_filter($endedMatch->team2, $connectedPlayersCallBack);
                     $blue = implode(', ', array_map('\\ManiaLib\\Utils\\Formatting::stripStyles', $team1));
                     $red = implode(', ', array_map('\\ManiaLib\\Utils\\Formatting::stripStyles', $team2));
                 } else {
                     $blue = \ManiaLib\Utils\Formatting::stripStyles($endedMatch->players[0]);
                     $red = \ManiaLib\Utils\Formatting::stripStyles($endedMatch->players[1]);
                 }
                 $this->connection->chatSendServerMessage(sprintf(self::PREFIX . '$<$00f%s$> $o%d - %d$z $<$f00%s$>', $blue, $endedMatch->mapPointsTeam1, $endedMatch->mapPointsTeam2, $red));
             }
         }
     }
     // Update playerlist every 3sec
     if ($this->updatePlayerList && $this->tick % 3 == 0) {
         $maxAlliesCount = $this->matchMaker->getPlayersPerMatch() / 2 - 1;
         $this->gui->updatePlayerList($this->blockedPlayers, $this->setLocalAllyAction, $this->unsetLocalAllyAction, $maxAlliesCount);
         $this->updatePlayerList = false;
     }
     if ($this->tick % 12 == 0) {
         $this->registerLobby();
     }
     Services\PlayerInfo::CleanUp();
     if ($this->tick % 11 == 0) {
         $this->allyService->removePlayerAway();
     }
     $this->connection->executeMulticall();
     //Debug
     $timers = array_filter($timers, function ($v) {
         return $v > 0.1;
     });
     if (count($timers)) {
         $line = array();
         foreach ($timers as $key => $value) {
             $line[] = sprintf('%s:%f', $key, $value);
         }
         \ManiaLive\Utilities\Logger::debug(implode('|', $line));
     }
 }