Exemple #1
0
 function run()
 {
     while (true) {
         $task = $this->nextTask();
         if ($task) {
             \ManiaLive\Utilities\Logger::debug('Executing Command #' . $task['commandId'] . '...', true, array('Process #' . $this->parentId . '.' . $this->threadId));
             $startTime = microtime(true);
             $result = $task['task']->run();
             $timeTaken = (microtime(true) - $startTime) * 1000;
             $this->database->execute('UPDATE ThreadingCommands SET result=%s, timeTaken=%f WHERE commandId=%d AND parentId=%d', $this->database->quote(base64_encode(serialize($result))), $timeTaken, $task['commandId'], $this->parentId);
             \ManiaLive\Utilities\Logger::debug('Command #' . $task['commandId'] . ' done in ' . round($timeTaken, 3) . ' ms!', true, array('Process #' . $this->parentId . '.' . $this->threadId));
         } else {
             sleep(1);
         }
         if (!$this->isParentRunning()) {
             exit;
         }
     }
 }
 protected function updateMaps()
 {
     $config = Config::getInstance();
     //Clear old maps
     $currentMaps = $this->connection->getMapList(-1, 0);
     foreach ($currentMaps as $maps) {
         $this->connection->removeMap($maps->fileName, true);
     }
     $this->connection->executeMulticall();
     //Add new maps
     $newMapsDirectory = $this->getLatestMapDirectory();
     $newMaps = scandir($newMapsDirectory);
     foreach ($newMaps as $map) {
         if (!in_array($map, array(".", ".."))) {
             $this->connection->addMap($newMapsDirectory . DIRECTORY_SEPARATOR . $map, true);
         }
     }
     $this->connection->executeMulticall();
     \ManiaLive\Utilities\Logger::debug(sprintf('Maps updated: %s', implode(', ', $newMaps)));
 }
Exemple #3
0
 public static function printDebug($string)
 {
     if (Config::getInstance()->debug) {
         Logger::debug($string);
     }
 }
 private function restartThread($threadId)
 {
     if (!$this->enabled || !isset($this->threads[$threadId])) {
         return;
     }
     $commandDiscarded = false;
     if (empty($this->pendings[$threadId])) {
         Logger::debug('Thread #' . $threadId . ' died...', true, array('Process #' . getmypid()));
         Dispatcher::dispatch(new Event(Event::ON_THREAD_DIES, $threadId));
     } else {
         Logger::debug('Thread #' . $threadId . ' timed out...', true, array('Process #' . getmypid()));
         Dispatcher::dispatch(new Event(Event::ON_THREAD_TIMES_OUT, $threadId));
         // If we already tried this command too many times, we discard it...
         $command = reset($this->pendings[$threadId]);
         $lastCommandId = $command->getId();
         if (++$this->tries[$lastCommandId] > Config::getInstance()->maxTries) {
             $this->database->execute('DELETE FROM ThreadingCommands WHERE commandId=%d AND parentId=%d', $lastCommandId, getmypid());
             unset($this->pendings[$threadId][$lastCommandId]);
             unset($this->tries[$lastCommandId]);
             Logger::debug('Command #' . $lastCommandId . ' has been discarded after ' . Config::getInstance()->maxTries . ' unsuccessful tries...', true, array('Process #' . getmypid()));
             $commandDiscarded = true;
         }
     }
     // Respawning the thread
     $threadHandle = $this->threads[$threadId];
     proc_terminate($threadHandle);
     proc_close($threadHandle);
     ++$this->deadThreadsCount;
     $this->threads[$threadId] = $this->spawnThread($threadId);
     $this->lastTick[$threadId] = $this->tick;
     Dispatcher::dispatch(new Event(Event::ON_THREAD_RESTART, $threadId));
     Logger::debug('Thread #' . $threadId . ' restarted!', true, array('Process #' . getmypid()));
     if ($commandDiscarded) {
         $command->fail();
     }
 }
 protected function changeState($state)
 {
     if ($this->intervals[$state]) {
         if ($this->state != static::PLAYER_LEFT || $this->state != $state) {
             $this->nextTick = new \DateTime($this->intervals[$state]);
         }
         $this->enableTickerEvent();
     } else {
         $this->disableTickerEvent();
     }
     if ($this->state != self::SLEEPING || $this->tick - $this->lastRegisterTick > 12) {
         $this->matchMakingService->registerMatchServer($this->storage->serverLogin, $this->lobby->login, $this->state, $this->scriptName, $this->titleIdString, $this->storage->currentMap->name);
         $this->lastRegisterTick = $this->tick;
     }
     if ($this->state != $state) {
         \ManiaLive\Utilities\Logger::debug(sprintf('State: %d', $state));
     }
     $this->state = $state;
 }
Exemple #6
0
 /**
  * Write message into the plugin's logfile.
  * Prefix with Plugin's name.
  * @param string $text
  * @deprecated since version 2.7
  */
 protected final function writeLog($text)
 {
     Logger::debug($text, true, array($this->author . '_' . $this->name));
 }
 /**
  * @param $login
  */
 private function updateKarma($login)
 {
     $player = $this->storage->getPlayerObject($login);
     $playerInfo = Services\PlayerInfo::Get($login);
     if ($player && $playerInfo) {
         $penalty = $this->matchMakingService->getPlayerPenalty($login, $this->storage->serverLogin, $this->scriptName, $this->titleIdString);
         if ($penalty > 0) {
             if (array_key_exists($login, $this->blockedPlayers)) {
                 if (time() - $this->blockedPlayers[$login] >= $penalty) {
                     $this->matchMakingService->decreasePlayerPenalty($login, time() - $this->blockedPlayers[$login], $this->storage->serverLogin, $this->scriptName, $this->titleIdString);
                 }
             } else {
                 $this->blockedPlayers[$login] = time();
                 $this->connection->chatSendServerMessageToLanguage($this->dictionary->getChat(array(array('textId' => 'playerSuspended', 'params' => array(self::PREFIX, $player->nickName)))));
             }
             $this->setPlayerNotReady($login);
             $this->resetShortKey($login);
             $this->updatePlayerList = true;
             $this->gui->updateWaitingScreenLabel($this->gui->getBadKarmaText($penalty), $login);
             $this->gui->disableReadyButton($login);
         } else {
             unset($this->blockedPlayers[$login]);
             $this->setPlayerNotReady($login);
             $this->gui->updateWaitingScreenLabel(null, $login);
             $this->gui->disableReadyButton($login, false);
         }
     } else {
         if (array_key_exists($login, $this->blockedPlayers)) {
             unset($this->blockedPlayers[$login]);
         }
         \ManiaLive\Utilities\Logger::debug(sprintf('UpdateKarma for not connected player %s', $login));
     }
 }
Exemple #8
0
 /**
  * Write message into the plugin's logfile.
  * Prefix with Plugin's name.
  * @param string $text
  * @deprecated since version 2.7
  */
 protected final function writeLog($text)
 {
     Logger::debug($text, true, array($this->id));
 }
 /**
  * @param bool $ready
  */
 function setReady($ready = true)
 {
     if (!$this->isAway()) {
         $this->readySince = $ready ? new \DateTime() : null;
         $this->notReadySince = $ready ? null : new \DateTime();
     } else {
         \ManiaLive\Utilities\Logger::debug(sprintf('Setting %s ready but is away', $this->login));
     }
 }