public function preFilter()
 {
     $config = \DedicatedManager\Config::getInstance();
     if ($config->maniaConnect) {
         $this->isAdmin = in_array($this->session->login, $config->admins);
     }
 }
 /**
  * @param string $configFile
  * @param mixed[] $options
  * @return int
  * @throws \Exception
  */
 function start($configFile, array $options = array())
 {
     $config = \DedicatedManager\Config::getInstance();
     $isWindows = stripos(PHP_OS, 'WIN') === 0;
     if ($isWindows) {
         $startCommand = 'START php.exe bootstrapper.php';
     } else {
         $startCommand = 'php bootstrapper.php';
     }
     $startCommand .= ' --manialive_cfg=' . escapeshellarg($configFile . '.ini');
     foreach ($options as $key => $value) {
         $startCommand .= ' --' . $key . '=' . escapeshellarg($value);
     }
     if (!$isWindows) {
         $startCommand .= ' &';
     }
     // Getting current PIDs
     $currentPids = $this->getPIDs();
     // Starting dedicated
     $procHandle = proc_open($startCommand, array(), $pipes, $config->manialivePath);
     proc_close($procHandle);
     // Getting its PID
     $diffPids = array_diff($this->getPIDs(), $currentPids);
     if (!$diffPids) {
         throw new \Exception('Can\'t start dedicated server.');
     }
     return reset($diffPids);
 }
示例#3
0
 function index()
 {
     $service = new \DedicatedManager\Services\ConfigFileService();
     $this->response->configFiles = $service->getList();
     $service = new \DedicatedManager\Services\MatchSettingsFileService();
     $this->response->matchFiles = $service->getList();
     if (\DedicatedManager\Config::getInstance()->manialivePath) {
         $service = new \DedicatedManager\Services\ManialiveFileService();
         $this->response->manialiveFiles = $service->getList();
     }
 }
示例#4
0
 function preFilter()
 {
     parent::preFilter();
     $host = $this->request->get('host');
     $port = $this->request->get('port');
     $service = new \DedicatedManager\Services\ServerService();
     try {
         $this->server = $service->get($host, $port);
         $this->server->fetchDetails();
     } catch (\Exception $e) {
         $this->session->set('error', _('The server is unreachable, maybe it is closed'));
         $this->request->redirectArgList('/');
     }
     if (!$this->isAdmin) {
         $service = new \DedicatedManager\Services\ManagerService();
         if (!$service->isAllowed($host, $port, $this->session->login)) {
             $this->session->set('error', _('You\'re not allowed to edit this server.'));
             $this->request->redirectArgList('/');
         }
     }
     $rm = new \ReflectionMethod($this, $this->request->getAction('index'));
     $comment = $rm->getDocComment();
     if ($this->server->isRelay && $comment && preg_match('/@norelay/u', $comment)) {
         $this->session->set('error', _('Unauthorized action on a relay.'));
         if ($this->request->getReferer() == $this->request->createLink()) {
             $this->request->redirectArgList('..');
         } else {
             $this->request->redirectToReferer();
         }
     }
     $mapDirectory = \DedicatedManager\Config::getInstance()->dedicatedPath . 'UserData/Maps/';
     if (!in_array($this->server->rpcHost, array('127.0.0.1', 'localhost')) && $this->server->connection->getMapsDirectory() != $mapDirectory) {
         if (preg_match('/@local/u', $comment)) {
             $this->session->set('error', _('Unauthorized action on a distant server.'));
             if ($this->request->getReferer() == $this->request->createLink()) {
                 $this->request->redirectArgList('..');
             } else {
                 $this->request->redirectToReferer();
             }
         }
         $this->response->isLocal = false;
     } else {
         $this->response->isLocal = true;
     }
     if (!$comment || !preg_match('/@redirect/u', $comment)) {
         $this->request->registerReferer();
         $this->players = $this->server->connection->getPlayerList(-1, 0);
         $this->options = $this->server->connection->getServerOptions();
         $this->currentMap = $this->server->connection->getCurrentMapInfo();
         if (!$this->server->isRelay) {
             $this->nextMap = $this->server->connection->getNextMapInfo();
         }
     }
 }
 function getList()
 {
     $list = array();
     foreach ($this->titleList as $title) {
         $filenames[$title->idString] = $title->filename;
     }
     $currentDir = getcwd();
     chdir(\DedicatedManager\Config::getInstance()->dedicatedPath . 'UserData/Packs/');
     $files = array();
     foreach (glob('*.[tT][iT][tT][lL][eE].[pP][aA][cC][kK].[gG][bB][xX]') as $file) {
         $key = array_keys($filenames, $file);
         if ($key) {
             $list[] = $this->titleList[end($key)];
         }
     }
     chdir($currentDir);
     return $list;
 }
 /**
  * @param string $filename
  * @param GameInfos $gameInfos
  * @param string[] $maps
  */
 function save($filename, GameInfos $gameInfos, array $maps, array $scriptSettings = array(), $randomize = 0)
 {
     $this->directory = \DedicatedManager\Config::getInstance()->dedicatedPath . 'UserData/Maps/MatchSettings/';
     $dom = new \DOMDocument('1.0', 'utf-8');
     $playlist = simplexml_import_dom($dom->createElement('playlist'));
     $gameSettings = $playlist->addChild('gameinfos');
     $gameSettings->addChild('game_mode', (int) $gameInfos->gameMode);
     $gameSettings->addChild('chat_time', (int) $gameInfos->chatTime);
     $gameSettings->addChild('finishtimeout', (int) $gameInfos->finishTimeout);
     $gameSettings->addChild('allwarmupduration', (int) $gameInfos->allWarmUpDuration);
     $gameSettings->addChild('disablerespawn', $gameInfos->disableRespawn);
     $gameSettings->addChild('forceshowallopponents', $gameInfos->forceShowAllOpponents);
     $gameSettings->addChild('script_name')->{0} = (string) $gameInfos->scriptName;
     $gameSettings->addChild('rounds_pointslimit', (int) $gameInfos->roundsPointsLimit);
     $gameSettings->addChild('rounds_usenewrules', (int) $gameInfos->roundsUseNewRules);
     $gameSettings->addChild('rounds_forcedlaps', (int) $gameInfos->roundsForcedLaps);
     $gameSettings->addChild('rounds_pointslimitnewrules', (int) $gameInfos->roundsPointsLimitNewRules);
     $gameSettings->addChild('team_pointslimit', (int) $gameInfos->teamPointsLimit);
     $gameSettings->addChild('team_maxpoints', (int) $gameInfos->teamMaxPoints);
     $gameSettings->addChild('team_usenewrules', (int) $gameInfos->teamUseNewRules);
     $gameSettings->addChild('team_pointslimitnewrules', (int) $gameInfos->teamPointsLimitNewRules);
     $gameSettings->addChild('timeattack_limit', (int) $gameInfos->timeAttackLimit);
     $gameSettings->addChild('timeattack_synchstartperiod', (int) $gameInfos->timeAttackSynchStartPeriod);
     $gameSettings->addChild('laps_nblaps', (int) $gameInfos->lapsNbLaps);
     $gameSettings->addChild('laps_timelimit', (int) $gameInfos->lapsTimeLimit);
     $gameSettings->addChild('cup_pointslimit', (int) $gameInfos->cupPointsLimit);
     $gameSettings->addChild('cup_roundsperchallenge', (int) $gameInfos->cupRoundsPerMap);
     $gameSettings->addChild('cup_nbwinners', (int) $gameInfos->cupNbWinners);
     $gameSettings->addChild('cup_warmupduration', (int) $gameInfos->cupWarmUpDuration);
     $hotseat = $playlist->addChild('hotseat');
     $hotseat->addChild('game_mode', 0);
     $hotseat->addChild('time_limit', 300000);
     $hotseat->addChild('rounds_count', 5);
     $filter = $playlist->addChild('filter');
     $filter->addChild('is_lan', 1);
     $filter->addChild('is_internet', 1);
     $filter->addChild('is_solo', 0);
     $filter->addChild('sort_index', 1000);
     $filter->addChild('random_map_order', (int) $randomize);
     $filter->addChild('force_default_gamemode', 0);
     $modeScriptSettings = $playlist->addChild('mode_script_settings');
     foreach ($scriptSettings as $scriptSetting) {
         /* @var $scriptSetting ScriptSettings */
         $tmp = $modeScriptSettings->addChild('setting');
         $tmp->addAttribute('name', $scriptSetting->name);
         $tmp->addAttribute('type', $scriptSetting->type);
         $tmp->addAttribute('value', $scriptSetting->default);
     }
     $playlist->addChild('startindex', 0);
     foreach ($maps as $map) {
         $playlist->addChild('map')->addChild('file')->{0} = "" . $map;
     }
     $filename = $this->directory . $filename . '.txt';
     $playlist->asXML($filename);
     return $filename;
 }
 function __construct()
 {
     $config = \DedicatedManager\Config::getInstance();
     $this->mapDirectory = $config->dedicatedPath . 'UserData/Maps/';
 }
 function __construct()
 {
     $this->directory = \DedicatedManager\Config::getInstance()->dedicatedPath . 'UserData/Config/';
     $this->rootTag = '<guestlist>';
 }
示例#9
0
<?php

require __DIR__ . '/../Header.php';
$r = ManiaLib\Application\Request::getInstance();
$pingServerList = \DedicatedManager\Config::getInstance()->pingServerList;
?>
<div data-role="page">
	<?php 
echo DedicatedManager\Helpers\Header::save();
?>
	<?php 
echo DedicatedManager\Helpers\Box\Box::detect();
?>
	<div data-role="content">
	<?php 
if ($isAdmin) {
    ?>
		<a href="<?php 
    echo $r->createLinkArgList('/create-server');
    ?>
" data-ajax="false" data-role="button" data-icon="plus"><?php 
    echo _('Start a new server');
    ?>
</a>
		<a href="<?php 
    echo $r->createLinkArgList('/create-server/quick-start/');
    ?>
" data-ajax="false" data-role="button" data-icon="plus"><?php 
    echo _('Quick start a new server');
    ?>
</a>
 function __construct()
 {
     $this->directory = \DedicatedManager\Config::getInstance()->manialivePath . '/config/';
 }
 /**
  * @param string $commandLine
  * @param string $successStr
  * @return int
  * @throws \Exception
  */
 private function doStart($commandLine, $successStr = '...Load succeeds')
 {
     $config = \DedicatedManager\Config::getInstance();
     $time = time();
     $timeout = $time + 20;
     // Getting current PIDs
     $currentPids = $this->getPIDs();
     // Starting dedicated
     $procHandle = proc_open($commandLine, array(), $pipes, $config->dedicatedPath);
     proc_close($procHandle);
     // Getting its PID
     $diffPids = array_diff($this->getPIDs(), $currentPids);
     if (!$diffPids) {
         throw new \Exception('Can\'t start dedicated server.');
     }
     $pid = reset($diffPids);
     // Reading dedicated log while it's written
     $isWindows = stripos(PHP_OS, 'WIN') === 0;
     $logFileName = $config->dedicatedPath . 'Logs/ConsoleLog.' . $pid . '.txt';
     while (!file_exists($logFileName) || filemtime($logFileName) < $time) {
         if (time() > $timeout) {
             throw new \Exception('Can\'t start dedicated server.');
         }
         usleep(200000);
     }
     $tries = 0;
     while (!($logFile = fopen($logFileName, 'r'))) {
         if (++$tries == 5) {
             if ($isWindows) {
                 `TASKKILL /PID {$pid}`;
             } else {
                 `kill -9 {$pid}`;
             }
             throw new \Exception('Unknown error while trying to get XML-RPC port');
         }
     }
     $buffer = '';
     while (true) {
         $line = fgets($logFile);
         if (!$line) {
             if (strpos($buffer, $successStr) !== false) {
                 break;
             }
             if (strpos($buffer, 'Server not running, exiting.') !== false || strpos($buffer, 'This title isn\'t playable.') !== false) {
                 throw new \Exception('Server stopped automatically');
             }
             if (time() > $timeout) {
                 if ($isWindows) {
                     `TASKKILL /PID {$pid}`;
                 } else {
                     `kill -9 {$pid}`;
                 }
                 throw new \Exception('Server stopped automatically');
             }
             if (!$buffer) {
                 fseek($logFile, 0, SEEK_SET);
             } else {
                 fseek($logFile, -1, SEEK_CUR);
             }
             usleep(200000);
             continue;
         }
         if ($line !== "\n") {
             $buffer .= $line;
         }
     }
     fclose($logFile);
     // Checking for errors
     if (preg_match_all('/ERROR:\\s+([^\\.$]+)/um', $buffer, $errors)) {
         if ($isWindows) {
             `TASKKILL /PID {$pid}`;
         } else {
             `kill -9 {$pid}`;
         }
         throw new \Exception(serialize(array_map('ucfirst', $errors[1])));
     }
     // Retrieving XML-RPC port
     if (preg_match('/Listening for xml-rpc commands on port (\\d+)/m', $buffer, $matches)) {
         $port = $matches[1];
     } else {
         throw new \Exception('XML-RPC port not found');
     }
     return $port;
 }
示例#12
0
 function index()
 {
     $this->request->registerReferer();
     $config = \DedicatedManager\Config::getInstance();
     $currentDir = getcwd();
     $errors = array();
     $writables[] = $config->dedicatedPath;
     $writables[] = $config->dedicatedPath . 'Logs/';
     $writables[] = $config->dedicatedPath . 'UserData/Config/';
     $writables[] = $config->dedicatedPath . 'UserData/Maps/MatchSettings/';
     if (file_exists($config->dedicatedPath . 'UserData/Config/')) {
         chdir($config->dedicatedPath . 'UserData/Config/');
         $tmp = glob('*.[tT][xX][tT]');
         $tmp = array_map(function ($f) use($config) {
             return $config->dedicatedPath . 'UserData/Config/' . $f;
         }, $tmp);
         $writables = array_merge($writables, $tmp);
     }
     if (file_exists($config->dedicatedPath . 'UserData/Maps/MatchSettings/')) {
         chdir($config->dedicatedPath . 'UserData/Maps/MatchSettings/');
         $tmp = glob('*.[tT][xX][tT]');
         $tmp = array_map(function ($f) use($config) {
             return $config->dedicatedPath . 'UserData/Maps/MatchSettings/' . $f;
         }, $tmp);
         $writables = array_merge($writables, $tmp);
     }
     if ($config->manialivePath) {
         $writables[] = $config->manialivePath;
         $writables[] = $config->manialivePath . 'config/';
         $writables[] = $config->manialivePath . 'logs/';
         if (file_exists($config->manialivePath . 'config/')) {
             chdir($config->manialivePath . 'config/');
             $tmp = glob('*.[iI][nN][iI]');
             $tmp = array_map(function ($f) use($config) {
                 return $config->manialivePath . 'config/' . $f;
             }, $tmp);
             $writables = array_merge($writables, $tmp);
         }
     }
     chdir($currentDir);
     $executables[] = stripos(PHP_OS, 'win') !== false ? $config->dedicatedPath . 'ManiaPlanetServer.exe' : $config->dedicatedPath . 'ManiaPlanetServer';
     $failed = array_filter(array_merge($writables, $executables), function ($f) {
         return !file_exists($f);
     });
     if ($failed) {
         $errors[] = _('The following files do not exist.') . ' ' . _('Contact the admin to check this.') . '<br/>' . _('File list: ') . '<ul>' . implode('', array_map(function ($f) {
             return '<li>' . $f . '</li>';
         }, $failed)) . '</ul>';
     }
     $failed = array_filter($writables, function ($f) {
         return file_exists($f) && !is_writable($f);
     });
     if ($failed) {
         $errors[] = _('The following folders cannot be written by Apache user.') . ' ' . _('Contact the admin to check this.') . '<br/>' . _('Folder list: ') . '<ul>' . implode('', array_map(function ($f) {
             return '<li>' . $f . '</li>';
         }, $failed)) . '</ul>';
     }
     $failed = array_filter($executables, function ($f) {
         return file_exists($f) && !is_executable($f);
     });
     if ($failed) {
         $errors[] = _('The following files cannot be executed by Apache user.') . ' ' . _('Contact the admin to check this.') . '<br/>' . _('File list: ') . '<ul>' . implode('', array_map(function ($f) {
             return '<li>' . $f . '</li>';
         }, $failed)) . '</ul>';
     }
     if ($errors) {
         $this->session->set('error', $errors);
     }
     $service = new \DedicatedManager\Services\ServerService();
     $this->response->servers = $this->isAdmin ? $service->getLives() : $service->getLivesForManager($this->session->login);
 }
 protected function saveConfiguration(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Saving your configuration in app.ini file</info>');
     $applicationConfig = ApplicationConfig::getInstance();
     $dedicatedManagerConfig = DedicatedManagerConfig::getInstance();
     $webServicesConfig = WSConfig::getInstance();
     $databaseConfig = DatabaseConfig::getInstance();
     $config = "application.namespace = DedicatedManager\n";
     $config .= "application.webapp = true\n";
     $config .= sprintf("application.URL = '%s'\n", $applicationConfig->URL . '/');
     $config .= "DedicatedManager\\Config.maniaConnect = On\n";
     $config .= sprintf("DedicatedManager\\Config.dedicatedPath = '%s'\n", $dedicatedManagerConfig->dedicatedPath . '/');
     foreach ($dedicatedManagerConfig->admins as $admin) {
         $config .= sprintf("DedicatedManager\\Config.admins[] = %s\n", $admin);
     }
     $config .= sprintf("webservices.username = '******'\n", $webServicesConfig->username);
     $config .= sprintf("webservices.password = '******'\n", $webServicesConfig->password);
     $config .= sprintf("database.host = '%s'\n", $databaseConfig->host);
     $config .= sprintf("database.user = '******'\n", $databaseConfig->user);
     $config .= sprintf("database.password = '******'\n", $databaseConfig->password);
     $config .= sprintf("database.database = '%s'\n", $databaseConfig->database);
     $config .= "database.slowQueryLog = true\n";
     file_put_contents('./config/app.ini', $config);
     $output->writeln('<success>Your Dedicated manager is successfully configured</success>');
     $output->writeln(sprintf('<success>You can now access to: %s</success>', $applicationConfig->URL));
 }
示例#14
0
<?php

require __DIR__ . '/../Header.php';
$r = ManiaLib\Application\Request::getInstance();
$hasManiaLive = (bool) \DedicatedManager\Config::getInstance()->manialivePath;
?>
<div data-role="page">
	<?php 
echo DedicatedManager\Helpers\Header::save();
?>
	<?php 
echo DedicatedManager\Helpers\Box\Box::detect();
?>
    <div data-role="content">
		<form action="<?php 
echo $r->createLinkArgList('../delete');
?>
" method="get" data-ajax="false">
			<div data-role="collapsible" data-collapsed="false" data-theme="b">
				<h3><?php 
echo _('Config files');
?>
</h3>
				<fieldset data-role="controlgroup">
				<?php 
foreach ($configFiles as $configFile) {
    ?>
					<?php 
    $id = uniqid('config-', true);
    ?>
					<input type="checkbox" id="<?php 
 /**
  * @param string $scriptName
  * @param string $title
  * @return string[]
  */
 function getFileMapType($scriptName, $title)
 {
     $titleService = new TitleService();
     if ($titleService->isCustomTitle($title)) {
         return $titleService->getMapTypes($title);
     }
     $game = $this->getGame($title);
     if (strstr($scriptName, '/') || strstr($scriptName, '\\')) {
         $scriptDirectory = \DedicatedManager\Config::getInstance()->dedicatedPath . 'UserData/Scripts/';
     } else {
         $scriptDirectory = \DedicatedManager\Config::getInstance()->dedicatedPath . 'UserData/Scripts/Modes/' . $game . '/';
     }
     $scriptContent = file_get_contents($scriptDirectory . $scriptName);
     $scripts = array();
     $files = array();
     if (preg_match('/\\#Extends\\s+"([^"]*)"/ixu', $scriptContent, $files)) {
         $files = explode(',', $files[1]);
         foreach ($files as $file) {
             $scripts = array_merge($this->getFileMapType($file, $title), $scripts);
         }
     }
     $matches = array();
     if (preg_match('/\\#Const\\s+(?:CompatibleChallengeTypes|CompatibleMapTypes)\\s*"([^"]*)"/ixu', $scriptContent, $matches)) {
         $scriptMatches = array();
         preg_match_all('/([^ ,;\\t]+)/ixu', $matches[1], $scriptMatches);
         $scripts = $scriptMatches[1];
         $scripts = array_merge($scriptMatches[1], array_map(function ($s) use($game) {
             return $game . '\\' . trim($s);
         }, $scripts));
     }
     return $scripts;
 }
<?php

require __DIR__ . '/../Header.php';
$r = ManiaLib\Application\Request::getInstance();
$c = \DedicatedManager\Config::getInstance();
?>
<div data-role="page">
	<?php 
require __DIR__ . '/Header.php';
?>
	<div data-role="content">
		<div class="content-primary">
			<form method="get" action="<?php 
echo $r->createLinkArgList('../stop-controllers');
?>
" data-ajax="false">
				<input type="hidden" name="host" value="<?php 
echo $host;
?>
"/>
				<input type="hidden" name="port" value="<?php 
echo $port;
?>
"/>
				<ul data-role="listview" data-inset="true">
					<li data-role="list-divider">
						<?php 
echo _('Running ingame controllers');
?>
					</li>
					<li data-role="fieldcontain">