protected function __construct()
 {
     set_error_handler('\\ManiaLive\\Application\\ErrorHandling::createExceptionFromError');
     if (extension_loaded('pcntl')) {
         pcntl_signal(SIGTERM, array($this, 'kill'));
         pcntl_signal(SIGINT, array($this, 'kill'));
         declare (ticks=1);
     }
     try {
         $configFile = CommandLineInterpreter::preConfigLoad();
         // load configuration file
         $loader = Loader::getInstance();
         $loader->setConfigFilename(APP_ROOT . 'config' . DIRECTORY_SEPARATOR . $configFile);
         $loader->run();
         // load configureation from the command line ...
         CommandLineInterpreter::postConfigLoad();
         // add logfile prefix ...
         $manialiveConfig = \ManiaLive\Config\Config::getInstance();
         $serverConfig = \ManiaLive\DedicatedApi\Config::getInstance();
         if ($manialiveConfig->logsPrefix != null) {
             $manialiveConfig->logsPrefix = str_replace('%ip%', str_replace('.', '-', $serverConfig->host), $manialiveConfig->logsPrefix);
             $manialiveConfig->logsPrefix = str_replace('%port%', $serverConfig->port, $manialiveConfig->logsPrefix);
         }
         // disable logging?
         /*if(!$manialiveConfig->runtimeLog)
         		\ManiaLive\Utilities\Logger::getLog('runtime')->disableLog();*/
     } catch (\Exception $e) {
         // exception on startup ...
         ErrorHandling::processStartupException($e);
     }
 }
示例#2
0
 protected function init()
 {
     \ManiaLive\Utilities\Console::println('Running ManiaLive ' . Version . '...');
     parent::init();
     if (!\ManiaLive\Config\Config::getInstance()->lanMode) {
         Updater::getInstance();
     }
 }
示例#3
0
 private function initDatabase()
 {
     $options = getopt(null, array('dbHost::', 'dbPort::', 'dbUsername::', 'dbPassword::', 'dbDatabase::'));
     $dbConfig = \ManiaLive\Database\Config::getInstance();
     foreach ($options as $key => $value) {
         $dbConfig->{lcfirst(substr($key, 2))} = $value;
     }
     $this->database = Connection::getConnection($dbConfig->host, $dbConfig->username, $dbConfig->password, $dbConfig->database, 'MySQL', $dbConfig->port);
     // load configs from DB
     $configs = array('config' => \ManiaLive\Config\Config::getInstance(), 'wsapi' => \ManiaLive\Features\WebServices\Config::getInstance(), 'manialive' => \ManiaLive\Application\Config::getInstance(), 'server' => \ManiaLive\DedicatedApi\Config::getInstance(), 'threading' => Config::getInstance());
     foreach ($configs as $dbName => $instance) {
         $data = $this->getData($dbName, array());
         foreach ((array) $data as $key => $value) {
             $instance->{$key} = $value;
         }
     }
 }
 static function postConfigLoad()
 {
     $options = getopt(null, array('rpcport::', 'address::', 'password::', 'dedicated_cfg::', 'user::', 'logsPrefix::', 'debug::'));
     $serverConfig = \ManiaLive\DedicatedApi\Config::getInstance();
     if (isset($options['logsPrefix'])) {
         \ManiaLive\Config\Config::getInstance()->logsPrefix = $options['logsPrefix'];
     }
     if (isset($options['debug'])) {
         \ManiaLive\Config\Config::getInstance()->debug = true;
     }
     if (isset($options['user'])) {
         if ($options['user'] != 'SuperAdmin' && $options['user'] != 'Admin' && $options['user'] != 'User') {
             echo 'Invalid Username' . PHP_EOL . $help;
             exit;
         }
         $serverConfig->user = $options['user'];
     }
     if (isset($options['dedicated_cfg'])) {
         $filename = \ManiaLive\Config\Config::getInstance()->dedicatedPath . '/UserData/Config/' . $options['dedicated_cfg'];
         if (file_exists($filename)) {
             //Load the config file
             $config = simplexml_load_file($filename);
             $serverConfig->port = (int) $config->system_config->xmlrpc_port;
             foreach ($config->authorization_levels->children() as $level) {
                 if ($serverConfig->user == (string) $level->name) {
                     $serverConfig->password = (string) $level->password;
                     break;
                 }
             }
         } else {
             throw new Exception('Configuration file not found...' . PHP_EOL . 'stopping software...');
         }
     } else {
         if (isset($options['rpcport'])) {
             $serverConfig->port = $options['rpcport'];
         }
         if (isset($options['password'])) {
             $serverConfig->password = $options['password'];
         }
     }
     if (isset($options['address'])) {
         $serverConfig->host = $options['address'];
     }
 }
示例#5
0
 public static function printDebug($string)
 {
     if (Config::getInstance()->debug) {
         Logger::debug($string);
     }
 }
示例#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');
     }
 }
示例#7
0
 private function spawnThread($threadId)
 {
     $config = \ManiaLive\Config\Config::getInstance();
     $dbConfig = \ManiaLive\Database\Config::getInstance();
     $outputFile = $config->logsPath . '/' . ($config->logsPrefix ? $config->logsPrefix . '-' : '') . 'threading-error.txt';
     $descriptors = array(1 => array('file', $outputFile, 'a'), 2 => array('file', $outputFile, 'a'));
     $args = array('threadId' => $threadId, 'parentId' => getmypid(), 'dbHost' => $dbConfig->host, 'dbPort' => $dbConfig->port, 'dbUsername' => $dbConfig->username, 'dbPassword' => $dbConfig->password, 'dbDatabase' => $dbConfig->database);
     $command = '"' . Config::getInstance()->phpPath . '"  "' . __DIR__ . DIRECTORY_SEPARATOR . 'thread_ignitor.php"';
     foreach ($args as $key => $value) {
         $command .= ' --' . $key . '=' . escapeshellarg($value);
     }
     Console::printDebug('Trying to spawn Thread #' . $threadId . ' using command: ' . PHP_EOL . $command);
     return proc_open($command, $descriptors, $pipes, null, null, array('bypass_shell' => true));
 }
示例#8
0
 function onPlayerConnect($login, $isSpectator)
 {
     $this->hidingGui[$login] = false;
     $this->modals[$login] = array();
     $this->modalShown[$login] = null;
     $this->managedWindow[$login] = null;
     $this->thumbnails[$login] = array();
     $sk = Shortkey::Create($login);
     if (\ManiaLive\Config\Config::getInstance()->enableToggleGUI) {
         $sk->addCallback(Shortkey::F8, array($this, 'toggleGui'));
     }
     $sk->show();
     $this->groupAll->add($login, true);
     if ($isSpectator) {
         $this->groupSpectators->add($login, true);
     } else {
         $this->groupPlayers->add($login, true);
     }
 }
示例#9
0
 protected static function load()
 {
     if (!self::$loaded) {
         $config = \ManiaLive\Config\Config::getInstance();
         $path = Path::getInstance()->getLog(true) . DIRECTORY_SEPARATOR;
         if (!is_dir($path) && !mkdir($path, '0777', true)) {
             throw new \ManiaLive\Application\FatalException(sprintf("The log repository (%s) does not exists and can't be created", Path::getInstance()->getLog(true)));
         }
         self::$loaded = true;
         self::$staticPath = $path;
         self::$staticPrefix = $config->logsPrefix ? $config->logsPrefix . '-' : '';
     }
     return !empty(self::$staticPath);
 }
示例#10
0
 function clearFiles()
 {
     try {
         $login = $this->db->query('SELECT playerLogin FROM Servers S ' . 'INNER JOIN Rents R ON S.idRent = R.id ' . 'WHERE hostname = %s AND port = %d', $this->db->quote(Config::getInstance()->host), Config::getInstance()->port)->fetchScalar();
         $count = $this->db->query('SELECT count(*) ' . 'FROM Rents ' . 'WHERE DATE_ADD(rentDate, INTERVAL duration HOUR) > NOW() ' . 'AND playerLogin = %s', $this->db->quote($login))->fetchScalar();
         $filesPath = realpath(\ManiaLive\Config\Config::getInstance()->dedicatedPath) . DIRECTORY_SEPARATOR . 'UserData' . DIRECTORY_SEPARATOR . 'Maps' . DIRECTORY_SEPARATOR;
         if ($count && file_exists($filesPath . '$uploaded' . DIRECTORY_SEPARATOR . $login)) {
             $maps = scandir($filesPath . '$uploaded' . DIRECTORY_SEPARATOR . $login);
             foreach ($maps as $map) {
                 if ($map != '..' && $map != '.') {
                     unlink($filesPath . '$uploaded' . DIRECTORY_SEPARATOR . $login . DIRECTORY_SEPARATOR . $map);
                 }
             }
             rmdir($filesPath . '$uploaded' . DIRECTORY_SEPARATOR . $login);
         }
     } catch (\Exception $e) {
         \ManiaLive\Application\ErrorHandling::displayAndLogError($e);
     }
 }
示例#11
0
 protected static function load()
 {
     if (!self::$loaded) {
         $config = \ManiaLive\Config\Config::getInstance();
         if (!is_dir($config->logsPath)) {
             if (mkdir($config->logsPath, '0777', true)) {
                 self::$loaded = true;
                 self::$staticPath = $config->logsPath . '/';
                 self::$staticPrefix = $config->logsPrefix ? $config->logsPrefix . '-' : '';
             }
         } else {
             self::$loaded = true;
             self::$staticPath = $config->logsPath . '/';
             self::$staticPrefix = $config->logsPrefix ? $config->logsPrefix . '-' : '';
         }
     }
     return !empty(self::$staticPath);
 }