Example #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;
         }
     }
 }
Example #2
0
 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)));
 }
Example #3
0
 public static function printDebug($string)
 {
     if (Config::getInstance()->debug) {
         Logger::debug($string);
     }
 }
 private function callCommand($login, $text, $commandName, $parameters = array(), $polymorphicCommand = false)
 {
     $command = $this->registeredCommands[strtolower($commandName)][$polymorphicCommand ? -1 : count($parameters)];
     if (!count($command->authorizedLogin) || in_array($login, $command->authorizedLogin)) {
         if ($command->log) {
             Logger::info('[ChatCommand from ' . $login . '] ' . $text);
         }
         if ($command->addLoginAsFirstParameter) {
             array_unshift($parameters, $login);
         }
         call_user_func_array($command->callback, $parameters);
     } else {
         $this->connection->chatSendServerMessage('$f00You are not authorized to use this command!', $login, true);
     }
 }
Example #5
0
 /**
  * Writes error message into the standard log file and also
  * prints it to the console window.
  * @param \Exception $e
  */
 public static function displayAndLogError(\Exception $e)
 {
     $log = PHP_EOL . '    Occured on ' . date("d.m.Y") . ' at ' . date("H:i:s") . ' at process with ID #' . getmypid() . PHP_EOL . '    ---------------------------------' . PHP_EOL;
     Console::println('');
     foreach (self::computeMessage($e) as $line) {
         $log .= $line . PHP_EOL;
         Console::println(wordwrap('ERROR: ' . $e->getMessage(), 73, PHP_EOL . '      '));
     }
     Console::println('');
     Logger::error($log);
     // write into global error log if config says so
     if (\ManiaLive\Config\Config::getInstance()->globalErrorLog) {
         error_log($log, 3, APP_ROOT . 'logs' . DIRECTORY_SEPARATOR . 'GlobalErrorLog.txt');
     }
 }
Example #6
0
 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();
     }
 }
Example #7
0
 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;
 }
Example #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->author . '_' . $this->name));
 }
Example #9
0
 /**
  * @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));
     }
 }
Example #10
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));
     }
 }
 function onConstruct()
 {
     $this->addFilter(new \ManiaLib\Application\Filters\UserAgentCheck());
     $this->addFilter(new \ManiaLib\WebServices\ManiaConnectFilter());
     \ManiaLive\Utilities\Logger::getLog('Runtime')->disableLog();
 }