added support for "-config=" parameter to load another xml file

This commit is contained in:
Steffen Schröder 2014-05-01 20:21:40 +02:00
parent df976a8229
commit 509251c5f7

View File

@ -37,7 +37,7 @@ require_once __DIR__ . '/Libs/curl-easy/autoload.php';
/** /**
* ManiaControl Server Controller for ManiaPlanet Server * ManiaControl Server Controller for ManiaPlanet Server
* *
* @author steeffeen & kremsy * @author ManiaControl Team
* @copyright ManiaControl Copyright © 2014 ManiaControl Team * @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
@ -65,7 +65,10 @@ class ManiaControl implements CommandListener, TimerListener {
public $chat = null; public $chat = null;
public $config = null; public $config = null;
public $configurator = null; public $configurator = null;
/** @var Connection $client */ /**
*
* @var Connection $client
*/
public $client = null; public $client = null;
public $commandManager = null; public $commandManager = null;
public $database = null; public $database = null;
@ -96,8 +99,7 @@ class ManiaControl implements CommandListener, TimerListener {
$this->log('Loading ManiaControl v' . self::VERSION . '...'); $this->log('Loading ManiaControl v' . self::VERSION . '...');
// Load config $this->loadConfig();
$this->config = FileUtil::loadConfig('server.xml');
// Load ManiaControl Modules // Load ManiaControl Modules
$this->callbackManager = new CallbackManager($this); $this->callbackManager = new CallbackManager($this);
@ -134,6 +136,21 @@ class ManiaControl implements CommandListener, TimerListener {
$this->errorHandler->init(); $this->errorHandler->init();
} }
/**
* Load the Config XML-File
*/
private function loadConfig() {
$configId = CommandLineHelper::getParameter('-config');
$configFileName = ($configId ? $configId : 'server.xml');
$this->config = FileUtil::loadConfig($configFileName);
if (!$this->config) {
trigger_error("Error loading Configuration XML-File! ('{$configFileName}')", E_USER_ERROR);
}
if (!$this->config->server->port || $this->config->server->port == 'port') {
trigger_error("Your Configuration File ('{$configFileName}') doesn't seem to be maintained. Please check it again!", E_USER_ERROR);
}
}
/** /**
* Checks connection every xxx Minutes * Checks connection every xxx Minutes
* *
@ -151,11 +168,10 @@ class ManiaControl implements CommandListener, TimerListener {
* @param string $message * @param string $message
*/ */
public function log($message, $stripCodes = false) { public function log($message, $stripCodes = false) {
$date = date("d.M y H:i:s");
if ($stripCodes) { if ($stripCodes) {
$message = Formatter::stripCodes($message); $message = Formatter::stripCodes($message);
} }
logMessage($date . ' ' . $message); logMessage($message);
} }
/** /**
@ -248,7 +264,8 @@ class ManiaControl implements CommandListener, TimerListener {
$this->client->sendHideManialinkPage(); $this->client->sendHideManialinkPage();
// Close the client connection // Close the client connection
$this->client->delete($this->server->ip, $this->server->port); $this->client->delete($this->server->ip, $this->server->port);
} catch(TransportException $e) { }
catch (TransportException $e) {
$this->errorHandler->triggerDebugNotice($e->getMessage() . " File: " . $e->getFile() . " Line: " . $e->getLine()); $this->errorHandler->triggerDebugNotice($e->getMessage() . " File: " . $e->getFile() . " Line: " . $e->getLine());
} }
} }
@ -292,7 +309,8 @@ class ManiaControl implements CommandListener, TimerListener {
if ($this->getOS(self::OS_UNIX)) { if ($this->getOS(self::OS_UNIX)) {
$command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &'; $command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &';
exec($command); exec($command);
} else { }
else {
$command = escapeshellarg(ManiaControlDir . "\ManiaControl.bat"); $command = escapeshellarg(ManiaControlDir . "\ManiaControl.bat");
system($command); // TODO, windows stucks here as long controller is running system($command); // TODO, windows stucks here as long controller is running
} }
@ -348,7 +366,8 @@ class ManiaControl implements CommandListener, TimerListener {
try { try {
// Manager callbacks // Manager callbacks
$this->callbackManager->manageCallbacks(); $this->callbackManager->manageCallbacks();
} catch(TransportException $e) { }
catch (TransportException $e) {
$this->log("Connection interrupted!"); $this->log("Connection interrupted!");
// TODO remove // TODO remove
if ($this->errorHandler) { if ($this->errorHandler) {
@ -357,7 +376,6 @@ class ManiaControl implements CommandListener, TimerListener {
$this->quit($e->getMessage()); $this->quit($e->getMessage());
} }
// Manage FileReader // Manage FileReader
$this->fileReader->appendData(); $this->fileReader->appendData();
@ -392,7 +410,8 @@ class ManiaControl implements CommandListener, TimerListener {
try { try {
$this->client = Connection::factory($this->server->config->host, $this->server->config->port, self::CONNECT_TIMEOUT, $this->server->config->login, $this->server->config->pass); $this->client = Connection::factory($this->server->config->host, $this->server->config->port, self::CONNECT_TIMEOUT, $this->server->config->login, $this->server->config->pass);
} catch(Exception $e) { }
catch (Exception $e) {
trigger_error("Couldn't authenticate on server with user '{$this->server->config->login}'! " . $e->getMessage(), E_USER_ERROR); trigger_error("Couldn't authenticate on server with user '{$this->server->config->login}'! " . $e->getMessage(), E_USER_ERROR);
} }
@ -404,7 +423,8 @@ class ManiaControl implements CommandListener, TimerListener {
if (!$this->server->waitForStatus(4)) { if (!$this->server->waitForStatus(4)) {
trigger_error("Server couldn't get ready!", E_USER_ERROR); trigger_error("Server couldn't get ready!", E_USER_ERROR);
} }
} catch(Exception $e) { }
catch (Exception $e) {
// TODO remove // TODO remove
if ($this->errorHandler) { if ($this->errorHandler) {
$this->errorHandler->triggerDebugNotice("Fatal Exception: " . $e->getMessage() . " Trace: " . $e->getTraceAsString()); $this->errorHandler->triggerDebugNotice("Fatal Exception: " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
@ -425,7 +445,8 @@ class ManiaControl implements CommandListener, TimerListener {
try { try {
$scriptSettings = $this->client->getModeScriptSettings(); $scriptSettings = $this->client->getModeScriptSettings();
} catch(NotInScriptModeException $e) { }
catch (NotInScriptModeException $e) {
return; return;
} }
@ -436,7 +457,8 @@ class ManiaControl implements CommandListener, TimerListener {
$scriptSettings['S_UseScriptCallbacks'] = true; $scriptSettings['S_UseScriptCallbacks'] = true;
try { try {
$this->client->setModeScriptSettings($scriptSettings); $this->client->setModeScriptSettings($scriptSettings);
} catch(Exception $e) { }
catch (Exception $e) {
// TODO temp added 19.04.2014 // TODO temp added 19.04.2014
$this->errorHandler->triggerDebugNotice("Exception line 437 ManiaControl.php " . $e->getMessage()); $this->errorHandler->triggerDebugNotice("Exception line 437 ManiaControl.php " . $e->getMessage());