diff --git a/application/configs/authentication.xml b/application/configs/authentication.xml
deleted file mode 100644
index 4bcf7639..00000000
--- a/application/configs/authentication.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
- steeffeen
- kremsy
-
-
-
-
-
diff --git a/application/configs/database.xml b/application/configs/database.xml
deleted file mode 100644
index c945a251..00000000
--- a/application/configs/database.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
- localhost
- 3306
-
-
- maniacontrol
- kjhgvhbjnfih2394ugnjk
-
-
- maniacontrol_dev
-
-
diff --git a/application/core/Admin/AuthenticationManager.php b/application/core/Admin/AuthenticationManager.php
index aecbbadc..00ae9bcd 100644
--- a/application/core/Admin/AuthenticationManager.php
+++ b/application/core/Admin/AuthenticationManager.php
@@ -48,7 +48,6 @@ class AuthenticationManager {
* @return bool
*/
private function loadConfig() {
- $config = FileUtil::loadConfig('authentication.xml');
$mysqli = $this->maniaControl->database->mysqli;
// Remove all MasterAdmins
@@ -61,8 +60,8 @@ class AuthenticationManager {
return false;
}
$adminLevel = self::AUTH_LEVEL_SUPERADMIN;
- $xAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
- $adminStatement->bind_param('ii', $adminLevel, $xAdminLevel);
+ $masterAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
+ $adminStatement->bind_param('ii', $adminLevel, $masterAdminLevel);
$adminStatement->execute();
if ($adminStatement->error) {
trigger_error($adminStatement->error);
@@ -70,7 +69,7 @@ class AuthenticationManager {
$adminStatement->close();
// Set MasterAdmins
- $xAdmins = $config->masteradmins->xpath('login');
+ $masterAdmins = $this->maniaControl->config->masteradmins->xpath('login');
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`,
`authLevel`
@@ -83,13 +82,10 @@ class AuthenticationManager {
trigger_error($mysqli->error, E_USER_ERROR);
return false;
}
- $adminStatement->bind_param('si', $login, $xAdminLevel);
+ $adminStatement->bind_param('si', $login, $masterAdminLevel);
$success = true;
- foreach ($xAdmins as $xAdmin) {
- /**
- * @noinspection PhpUnusedLocalVariableInspection
- */
- $login = (string) $xAdmin;
+ foreach ($masterAdmins as $masterAdmin) {
+ $login = (string) $masterAdmin;
$adminStatement->execute();
if ($adminStatement->error) {
trigger_error($adminStatement->error);
diff --git a/application/core/Database.php b/application/core/Database.php
index 03a45831..26df54d6 100644
--- a/application/core/Database.php
+++ b/application/core/Database.php
@@ -17,7 +17,6 @@ class Database {
* Private properties
*/
private $maniaControl = null;
- private $config = null;
/**
* Construct database connection
@@ -25,27 +24,16 @@ class Database {
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
- // Load config
- $this->config = FileUtil::loadConfig('database.xml');
-
// Get mysql server information
- $host = $this->config->xpath('host');
- $port = $this->config->xpath('port');
- $user = $this->config->xpath('user');
- $pass = $this->config->xpath('pass');
+ $host = $this->maniaControl->config->database->xpath('host');
+ $port = $this->maniaControl->config->database->xpath('port');
+ $user = $this->maniaControl->config->database->xpath('user');
+ $pass = $this->maniaControl->config->database->xpath('pass');
- if (!$host) {
- 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 (!$pass) {
- trigger_error("Invalid database configuration (pass).", E_USER_ERROR);
- }
+ if (!$host) 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 (!$pass) trigger_error("Invalid database configuration (pass).", E_USER_ERROR);
$host = (string) $host[0];
$port = (int) $port[0];
@@ -76,18 +64,16 @@ class Database {
* @return bool
*/
private function initDatabase() {
- $dbName = $this->config->xpath('database');
+ $dbName = $this->maniaControl->config->database->xpath('db_name');
if (!$dbName) {
trigger_error("Invalid database configuration (database).", E_USER_ERROR);
return false;
}
- $dbName = (string) $dbName[0];
+ $dbName = (string) $dbName[0];
// Try to connect
$result = $this->mysqli->select_db($dbName);
- if ($result) {
- return true;
- }
+ if ($result) return true;
// Create database
$databaseQuery = "CREATE DATABASE ?;";
diff --git a/application/core/FileUtil.php b/application/core/FileUtil.php
index 65c820c4..fa3503bc 100644
--- a/application/core/FileUtil.php
+++ b/application/core/FileUtil.php
@@ -8,6 +8,7 @@ namespace ManiaControl;
* @author steeffeen & kremsy
*/
abstract class FileUtil {
+
/**
* Load a remote file
*
@@ -21,18 +22,18 @@ abstract class FileUtil {
}
$urlData = parse_url($url);
$port = (isset($urlData['port']) ? $urlData['port'] : 80);
-
+
$fsock = fsockopen($urlData['host'], $port);
stream_set_timeout($fsock, 3);
-
+
$query = 'GET ' . $urlData['path'] . ' HTTP/1.0' . PHP_EOL;
$query .= 'Host: ' . $urlData['host'] . PHP_EOL;
$query .= 'Content-Type: ' . $contentType . PHP_EOL;
$query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL;
$query .= PHP_EOL;
-
+
fwrite($fsock, $query);
-
+
$buffer = '';
$info = array('timed_out' => false);
while (!feof($fsock) && !$info['timed_out']) {
@@ -40,26 +41,27 @@ abstract class FileUtil {
$info = stream_get_meta_data($fsock);
}
fclose($fsock);
-
+
if ($info['timed_out'] || !$buffer) {
return null;
}
if (substr($buffer, 9, 3) != "200") {
return null;
}
-
+
$result = explode("\r\n\r\n", $buffer, 2);
-
+
if (count($result) < 2) {
return null;
}
-
+
return $result[1];
}
+
/**
* Load config xml-file
*
- * @param string $fileName
+ * @param string $fileName
* @return \SimpleXMLElement
*/
public static function loadConfig($fileName) {
@@ -78,7 +80,7 @@ abstract class FileUtil {
/**
* Return file name cleared from special characters
*
- * @param string $fileName
+ * @param string $fileName
* @return string
*/
public static function getClearedFileName($fileName) {
diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php
index d4a97eb9..e45c0bcb 100644
--- a/application/core/ManiaControl.php
+++ b/application/core/ManiaControl.php
@@ -74,6 +74,7 @@ class ManiaControl implements CommandListener {
public $authenticationManager = null;
public $callbackManager = null;
public $chat = null;
+ public $config = null;
public $configurator = null;
/**
*
@@ -102,6 +103,9 @@ class ManiaControl implements CommandListener {
public function __construct() {
$this->log('Loading ManiaControl v' . self::VERSION . '...');
+ // Load config
+ $this->config = FileUtil::loadConfig('server.xml');
+
// Load ManiaControl Modules
$this->database = new Database($this);
$this->callbackManager = new CallbackManager($this);
@@ -329,10 +333,10 @@ class ManiaControl implements CommandListener {
// Load remote client
$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);
$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);
$port = (string) $port[0];
@@ -343,10 +347,10 @@ class ManiaControl implements CommandListener {
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);
$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);
$pass = (string) $pass[0];
diff --git a/application/core/Server/Server.php b/application/core/Server/Server.php
index d7054fe2..894232fc 100644
--- a/application/core/Server/Server.php
+++ b/application/core/Server/Server.php
@@ -22,11 +22,6 @@ class Server implements CallbackListener {
*/
const TABLE_SERVERS = 'mc_servers';
- /**
- * Public Properties
- */
- public $config = null;
-
/**
* Private Properties
*/
@@ -44,9 +39,6 @@ class Server implements CallbackListener {
$this->maniaControl = $maniaControl;
$this->initTables();
- // Load config
- $this->config = FileUtil::loadConfig('server.xml');
-
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');