Ejemplo n.º 1
0
 protected function init()
 {
     \ManiaLive\Utilities\Console::println('Running ManiaLive ' . Version . '...');
     parent::init();
     if (!\ManiaLive\Config\Config::getInstance()->lanMode) {
         Updater::getInstance();
     }
 }
Ejemplo n.º 2
0
 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));
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 /**
  * 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));
     //		}
 }
Ejemplo n.º 5
0
 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;
     }
 }
Ejemplo n.º 6
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');
     }
 }
Ejemplo n.º 7
0
 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');
 }
Ejemplo n.º 8
0
 /**
  * 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);
 }