single config file

This commit is contained in:
Steffen Schröder 2014-01-06 14:22:48 +01:00
parent 5d4cf86f61
commit 2c5a7a52e2
7 changed files with 37 additions and 86 deletions

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configure Server Administrators -->
<authentication-config>
<!-- MasterAdmins that can't be removed ingame -->
<masteradmins>
<login>steeffeen</login>
<login>kremsy</login>
</masteradmins>
<!-- You can add other admins and moderators ingame -->
</authentication-config>

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configure the MySQL Database used by ManiaControl -->
<database-config>
<!-- MySQL Server -->
<host>localhost</host>
<port>3306</port>
<!-- MySQL User -->
<user>maniacontrol</user>
<pass>kjhgvhbjnfih2394ugnjk</pass>
<!-- Database Name -->
<database>maniacontrol_dev</database>
</database-config>

View File

@ -48,7 +48,6 @@ class AuthenticationManager {
* @return bool * @return bool
*/ */
private function loadConfig() { private function loadConfig() {
$config = FileUtil::loadConfig('authentication.xml');
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
// Remove all MasterAdmins // Remove all MasterAdmins
@ -61,8 +60,8 @@ class AuthenticationManager {
return false; return false;
} }
$adminLevel = self::AUTH_LEVEL_SUPERADMIN; $adminLevel = self::AUTH_LEVEL_SUPERADMIN;
$xAdminLevel = self::AUTH_LEVEL_MASTERADMIN; $masterAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
$adminStatement->bind_param('ii', $adminLevel, $xAdminLevel); $adminStatement->bind_param('ii', $adminLevel, $masterAdminLevel);
$adminStatement->execute(); $adminStatement->execute();
if ($adminStatement->error) { if ($adminStatement->error) {
trigger_error($adminStatement->error); trigger_error($adminStatement->error);
@ -70,7 +69,7 @@ class AuthenticationManager {
$adminStatement->close(); $adminStatement->close();
// Set MasterAdmins // Set MasterAdmins
$xAdmins = $config->masteradmins->xpath('login'); $masterAdmins = $this->maniaControl->config->masteradmins->xpath('login');
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` ( $adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`, `login`,
`authLevel` `authLevel`
@ -83,13 +82,10 @@ class AuthenticationManager {
trigger_error($mysqli->error, E_USER_ERROR); trigger_error($mysqli->error, E_USER_ERROR);
return false; return false;
} }
$adminStatement->bind_param('si', $login, $xAdminLevel); $adminStatement->bind_param('si', $login, $masterAdminLevel);
$success = true; $success = true;
foreach ($xAdmins as $xAdmin) { foreach ($masterAdmins as $masterAdmin) {
/** $login = (string) $masterAdmin;
* @noinspection PhpUnusedLocalVariableInspection
*/
$login = (string) $xAdmin;
$adminStatement->execute(); $adminStatement->execute();
if ($adminStatement->error) { if ($adminStatement->error) {
trigger_error($adminStatement->error); trigger_error($adminStatement->error);

View File

@ -17,7 +17,6 @@ class Database {
* Private properties * Private properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $config = null;
/** /**
* Construct database connection * Construct database connection
@ -25,27 +24,16 @@ class Database {
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Load config
$this->config = FileUtil::loadConfig('database.xml');
// Get mysql server information // Get mysql server information
$host = $this->config->xpath('host'); $host = $this->maniaControl->config->database->xpath('host');
$port = $this->config->xpath('port'); $port = $this->maniaControl->config->database->xpath('port');
$user = $this->config->xpath('user'); $user = $this->maniaControl->config->database->xpath('user');
$pass = $this->config->xpath('pass'); $pass = $this->maniaControl->config->database->xpath('pass');
if (!$host) { if (!$host) trigger_error("Invalid database configuration (host).", E_USER_ERROR);
trigger_error("Invalid database configuration (host).", E_USER_ERROR); if (!$port) trigger_error("Invalid database configuration (port).", E_USER_ERROR);
} if (!$user) trigger_error("Invalid database configuration (user).", E_USER_ERROR);
if (!$port) { if (!$pass) trigger_error("Invalid database configuration (pass).", E_USER_ERROR);
trigger_error("Invalid database configuration (port).", E_USER_ERROR);
}
if (!$user) {
trigger_error("Invalid database configuration (user).", E_USER_ERROR);
}
if (!$pass) {
trigger_error("Invalid database configuration (pass).", E_USER_ERROR);
}
$host = (string) $host[0]; $host = (string) $host[0];
$port = (int) $port[0]; $port = (int) $port[0];
@ -76,7 +64,7 @@ class Database {
* @return bool * @return bool
*/ */
private function initDatabase() { private function initDatabase() {
$dbName = $this->config->xpath('database'); $dbName = $this->maniaControl->config->database->xpath('db_name');
if (!$dbName) { if (!$dbName) {
trigger_error("Invalid database configuration (database).", E_USER_ERROR); trigger_error("Invalid database configuration (database).", E_USER_ERROR);
return false; return false;
@ -85,9 +73,7 @@ class Database {
// Try to connect // Try to connect
$result = $this->mysqli->select_db($dbName); $result = $this->mysqli->select_db($dbName);
if ($result) { if ($result) return true;
return true;
}
// Create database // Create database
$databaseQuery = "CREATE DATABASE ?;"; $databaseQuery = "CREATE DATABASE ?;";

View File

@ -8,6 +8,7 @@ namespace ManiaControl;
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
abstract class FileUtil { abstract class FileUtil {
/** /**
* Load a remote file * Load a remote file
* *
@ -56,6 +57,7 @@ abstract class FileUtil {
return $result[1]; return $result[1];
} }
/** /**
* Load config xml-file * Load config xml-file
* *

View File

@ -74,6 +74,7 @@ class ManiaControl implements CommandListener {
public $authenticationManager = null; public $authenticationManager = null;
public $callbackManager = null; public $callbackManager = null;
public $chat = null; public $chat = null;
public $config = null;
public $configurator = null; public $configurator = null;
/** /**
* *
@ -102,6 +103,9 @@ class ManiaControl implements CommandListener {
public function __construct() { public function __construct() {
$this->log('Loading ManiaControl v' . self::VERSION . '...'); $this->log('Loading ManiaControl v' . self::VERSION . '...');
// Load config
$this->config = FileUtil::loadConfig('server.xml');
// Load ManiaControl Modules // Load ManiaControl Modules
$this->database = new Database($this); $this->database = new Database($this);
$this->callbackManager = new CallbackManager($this); $this->callbackManager = new CallbackManager($this);
@ -329,10 +333,10 @@ class ManiaControl implements CommandListener {
// Load remote client // Load remote client
$this->client = new \IXR_ClientMulticall_Gbx(); $this->client = new \IXR_ClientMulticall_Gbx();
$host = $this->server->config->xpath('host'); $host = $this->config->server->xpath('host');
if (!$host) trigger_error("Invalid server configuration (host).", E_USER_ERROR); if (!$host) trigger_error("Invalid server configuration (host).", E_USER_ERROR);
$host = (string) $host[0]; $host = (string) $host[0];
$port = $this->server->config->xpath('port'); $port = $this->config->server->xpath('port');
if (!$host) trigger_error("Invalid server configuration (port).", E_USER_ERROR); if (!$host) trigger_error("Invalid server configuration (port).", E_USER_ERROR);
$port = (string) $port[0]; $port = (string) $port[0];
@ -343,10 +347,10 @@ class ManiaControl implements CommandListener {
trigger_error("Couldn't connect to server! " . $this->getClientErrorText(), E_USER_ERROR); trigger_error("Couldn't connect to server! " . $this->getClientErrorText(), E_USER_ERROR);
} }
$login = $this->server->config->xpath('login'); $login = $this->config->server->xpath('login');
if (!$login) trigger_error("Invalid server configuration (login).", E_USER_ERROR); if (!$login) trigger_error("Invalid server configuration (login).", E_USER_ERROR);
$login = (string) $login[0]; $login = (string) $login[0];
$pass = $this->server->config->xpath('pass'); $pass = $this->config->server->xpath('pass');
if (!$pass) trigger_error("Invalid server configuration (password).", E_USER_ERROR); if (!$pass) trigger_error("Invalid server configuration (password).", E_USER_ERROR);
$pass = (string) $pass[0]; $pass = (string) $pass[0];

View File

@ -22,11 +22,6 @@ class Server implements CallbackListener {
*/ */
const TABLE_SERVERS = 'mc_servers'; const TABLE_SERVERS = 'mc_servers';
/**
* Public Properties
*/
public $config = null;
/** /**
* Private Properties * Private Properties
*/ */
@ -44,9 +39,6 @@ class Server implements CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->initTables(); $this->initTables();
// Load config
$this->config = FileUtil::loadConfig('server.xml');
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');