protected function init() { \ManiaLive\Utilities\Console::println('Running ManiaLive ' . Version . '...'); parent::init(); if (!\ManiaLive\Config\Config::getInstance()->lanMode) { Updater::getInstance(); } }
public static function printPlayerScore(Player $player) { $str = array(); $str[] = '[Score by ' . $player->login . ' : ' . $player->score . ']'; foreach ($player->bestCheckpoints as $i => $score) { $str[] = ' [Checkpoint #' . $i . ': ' . $score . ']'; } Console::println(implode(PHP_EOL, $str)); }
protected function init() { \ManiaLive\Utilities\Console::println('Running ManiaLive ' . VERSION . '...'); new \ManiaLive\Features\Tick\Ticker(); $config = \ManiaLive\DedicatedApi\Config::getInstance(); $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password); $this->connection->enableCallbacks(true); \ManiaLive\Data\Storage::getInstance(); \ManiaLive\Features\ChatCommand\Interpreter::getInstance(); \ManiaLive\Features\EchoHandler::getInstance(); \ManiaLive\Gui\GuiHandler::getInstance(); \ManiaLive\PluginHandler\PluginHandler::getInstance(); Dispatcher::dispatch(new Event(Event::ON_INIT)); }
/** * Routine that compares version number to * the latest version online. */ function checkUpdate() { try { $client = new UpdaterClient(); // $response = $client->checkVersion(\ManiaLiveApplication\Version); } catch (\Exception $e) { Console::println('ERROR: Update service was unable to contact server ...'); return; } // display message in console // if ($response->update) // { // $days = ceil((time() - strtotime($response->version->date)) / 86400); // Console::println(str_repeat('#', 79)); // Console::println('#' . str_repeat(' ', 77) . '#'); // Console::println(str_pad("# A new version of ManiaLive is available since $days day(s)!", 78) . "#"); // Console::println(str_pad("# An update is strongly recommended!", 78) . "#"); // Console::println('#' . str_repeat(' ', 77) . '#'); // Console::println(str_repeat('#', 79)); // } }
function onPlayerFinish($playerUid, $login, $timeOrScore) { if (!isset($this->players[$login])) { return; } $player = $this->players[$login]; switch ($this->gameInfos->gameMode) { // check stunts case GameInfos::GAMEMODE_STUNTS: if ($timeOrScore > 0 && ($player->score <= 0 || $timeOrScore > $player->score)) { $oldScore = $player->score; $this->updateRanking($this->connection->getCurrentRanking(-1, 0)); if ($player->score == $timeOrScore) { // sanity checks if (count($player->bestCheckpoints) != $this->currentMap->nbCheckpoints) { Console::println('Best score\'s checkpoint count does not match and was ignored!'); Console::printPlayerScore($player); $player->score = $oldScore; return; } Dispatcher::dispatch(new Event(Event::ON_PLAYER_NEW_BEST_SCORE, $player, $oldScore, $timeOrScore)); } } break; // check all other game modes // check all other game modes default: if ($timeOrScore > 0 && ($player->bestTime <= 0 || $timeOrScore < $player->bestTime)) { $oldBest = $player->bestTime; $this->updateRanking($this->connection->getCurrentRanking(-1, 0)); if ($player->bestTime == $timeOrScore) { // sanity checks $totalChecks = 0; switch ($this->gameInfos->gameMode) { case GameInfos::GAMEMODE_LAPS: $totalChecks = $this->currentMap->nbCheckpoints * $this->gameInfos->lapsNbLaps; break; case GameInfos::GAMEMODE_TEAM: case GameInfos::GAMEMODE_ROUNDS: case GameInfos::GAMEMODE_CUP: if ($this->currentMap->nbLaps > 0) { $totalChecks = $this->currentMap->nbCheckpoints * ($this->gameInfos->roundsForcedLaps ?: $this->currentMap->nbLaps); } else { $totalChecks = $this->currentMap->nbCheckpoints; } break; default: $totalChecks = $this->currentMap->nbCheckpoints; break; } if (count($player->bestCheckpoints) != $totalChecks) { Console::println('Best time\'s checkpoint count does not match and was ignored!'); Console::printPlayerBest($player); $player->bestTime = $oldBest; return; } Dispatcher::dispatch(new Event(Event::ON_PLAYER_NEW_BEST_TIME, $player, $oldBest, $timeOrScore)); } } break; } }
/** * 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'); } }
function onInit() { Console::println('[PluginHandler] Start plugin load process:'); foreach (\ManiaLive\Application\Config::getInstance()->plugins as $pluginId) { try { $this->register($pluginId); } catch (\Exception $e) { $this->unload($pluginId); ErrorHandling::processRuntimeException($e); } } foreach ($this->loadedPlugins as $pluginId => $plugin) { try { $this->prepare($plugin); } catch (\Exception $e) { $this->unload($pluginId); ErrorHandling::processRuntimeException($e); } } foreach ($this->loadedPlugins as $plugin) { $plugin->onReady(); } Console::println('[PluginHandler] All registered plugins have been loaded'); }
private function receiveResponses() { $results = $this->database->execute('SELECT commandId, threadId, result, timeTaken FROM ThreadingCommands WHERE result IS NOT NULL AND parentId=%d', getmypid()); if (!$results->recordAvailable()) { return; } $ids = array(); while ($result = $results->fetchArray()) { $commandId = (int) $result['commandId']; $threadId = (int) $result['threadId']; $timeTaken = (double) $result['timeTaken']; Console::printDebug('Got response for Command #' . $commandId . ' finished by Thread #' . $threadId . ' in ' . round($timeTaken, 3) . ' ms!'); if (isset($this->pendings[$threadId][$commandId])) { $command = $this->pendings[$threadId][$commandId]; $command->setResult(unserialize(base64_decode($result['result'])), $timeTaken); unset($this->pendings[$threadId][$commandId]); unset($this->tries[$commandId]); } if (isset($this->lastTick[$threadId])) { $this->lastTick[$threadId] = $this->tick; } ++$this->commandsCount; $this->commandsTotalTime += $timeTaken; $this->commandsAverageTime = $this->commandsTotalTime / $this->commandsCount; $ids[] = $commandId; } $this->database->execute('DELETE FROM ThreadingCommands WHERE commandId IN (%s) AND parentId=%d', implode(',', $ids), getmypid()); }
/** * Write message onto the commandline. * Prefix with Plugin's name and * @param string $text * @deprecated since version 2.7 */ protected final function writeConsole($text) { Console::println('[' . Console::getDatestamp() . '|' . $this->name . '] ' . $text); }