From dc248a69ed9a8ebdc4d95187252645bba0ad1c44 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sun, 23 Feb 2014 15:28:53 +0100 Subject: [PATCH] dedimania update --- application/core/Server/Server.php | 29 +++++-- application/core/Settings/SettingManager.php | 4 +- application/plugins/Dedimania/Dedimania.php | 32 ++----- application/plugins/KarmaTest.php | 88 ++++++++++++++++++++ 4 files changed, 121 insertions(+), 32 deletions(-) create mode 100644 application/plugins/KarmaTest.php diff --git a/application/core/Server/Server.php b/application/core/Server/Server.php index d5ee78ed..83ebf56d 100644 --- a/application/core/Server/Server.php +++ b/application/core/Server/Server.php @@ -5,10 +5,6 @@ namespace ManiaControl\Server; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\ManiaControl; -use ManiaControl\Players\Player; -use Maniaplanet\DedicatedServer\Structures\ServerOptions; -use Maniaplanet\DedicatedServer\Structures\SystemInfos; -use Maniaplanet\DedicatedServer\Structures\Version; use Maniaplanet\DedicatedServer\Xmlrpc\Exception; /** @@ -21,7 +17,7 @@ class Server implements CallbackListener { /** * Constants */ - const TABLE_SERVERS = 'mc_servers'; + const TABLE_SERVERS = 'mc_servers'; const CB_TEAM_MODE_CHANGED = 'ServerCallback.TeamModeChanged'; /** @@ -124,6 +120,29 @@ class Server implements CallbackListener { return true; } + /** + * Gets all Servers from the Database + * + * @return array + */ + public function getAllServers() { + $mysqli = $this->maniaControl->database->mysqli; + $query = "SELECT * FROM `" . self::TABLE_SERVERS . "`"; + $result = $mysqli->query($query); + if (!$result) { + trigger_error($mysqli->error); + return array(); + } + + $servers = array(); + while($row = $result->fetch_object()) { + array_push($servers, $row); + } + $result->close(); + + return $servers; + } + /** * Handle OnInit Callback */ diff --git a/application/core/Settings/SettingManager.php b/application/core/Settings/SettingManager.php index cd020537..49866462 100644 --- a/application/core/Settings/SettingManager.php +++ b/application/core/Settings/SettingManager.php @@ -72,7 +72,7 @@ class SettingManager implements CallbackListener { if ($mysqli->error) { trigger_error($mysqli->error, E_USER_ERROR); } - + // TODO: remove before release $settingTableChangesQuery = "ALTER TABLE `".self::TABLE_SETTINGS."` MODIFY `class` VARCHAR(100) NOT NULL, @@ -81,7 +81,7 @@ class SettingManager implements CallbackListener { if ($mysqli->error) { trigger_error($mysqli->error); } - + return $result && $result2; } diff --git a/application/plugins/Dedimania/Dedimania.php b/application/plugins/Dedimania/Dedimania.php index 099823c1..c08d0776 100644 --- a/application/plugins/Dedimania/Dedimania.php +++ b/application/plugins/Dedimania/Dedimania.php @@ -39,8 +39,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin { const SETTING_WIDGET_WIDTH = 'Widget Width'; const SETTING_WIDGET_LINESCOUNT = 'Widget Displayed Lines Count'; const SETTING_WIDGET_LINEHEIGHT = 'Widget Line Height'; - const SETTING_SERVER_LOGINS = 'Serverlogins, splitted by ;'; - const SETTING_DEDIMANIA_CODES = 'Dedimania Codes, splitted by ;'; + const SETTING_DEDIMANIA_CODE = 'Dedimania Code for '; /** * Private Properties @@ -60,8 +59,10 @@ class Dedimania implements CallbackListener, TimerListener, Plugin { * @return mixed */ public static function prepare(ManiaControl $maniaControl) { - $maniaControl->settingManager->initSetting(get_class(), self::SETTING_SERVER_LOGINS, ''); - $maniaControl->settingManager->initSetting(get_class(), self::SETTING_DEDIMANIA_CODES, ''); + $servers = $maniaControl->server->getAllServers(); + foreach($servers as $server) { + $maniaControl->settingManager->initSetting(get_class(), self::SETTING_DEDIMANIA_CODE . $server->login, ''); + } } /** @@ -100,28 +101,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin { $serverVersion = $this->maniaControl->client->getVersion(); $packMask = substr($this->maniaControl->server->titleId, 2); - $logins = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVER_LOGINS); - $codes = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DEDIMANIA_CODES); - - if ($logins == '' || $codes == '') { - throw new \Exception("No Dedimania Data Specified, check the settings!"); - } - - $logins = explode(";", $logins); - $codes = explode(";", $codes); - - $dedimaniaCode = ""; - foreach($logins as $key => $login) { - if ($login == $serverInfo->login) { - if (!isset($codes[$key])) { - throw new \Exception("No Dedimania Code Specified, check the settings!"); - } - $dedimaniaCode = $codes[$key]; - } - } - + $dedimaniaCode = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DEDIMANIA_CODE . $serverInfo->login); if ($dedimaniaCode == '') { - throw new \Exception("No Valid Serverlogin Specified, check the settings!"); + throw new \Exception("No Dedimania Code Specified, check the settings!"); } $this->dedimaniaData = new DedimaniaData($serverInfo->login, $dedimaniaCode, $serverInfo->path, $packMask, $serverVersion); diff --git a/application/plugins/KarmaTest.php b/application/plugins/KarmaTest.php new file mode 100644 index 00000000..49e5a202 --- /dev/null +++ b/application/plugins/KarmaTest.php @@ -0,0 +1,88 @@ +maniaControl = $maniaControl; + + $serverLogin = $this->maniaControl->server->login; + + } + + /** + * Unload the plugin and its resources + */ + public function unload() { + unset($this->maniaControl); + } + + /** + * Get plugin id + * + * @return int + */ + public static function getId() { + // TODO: Implement getId() method. + } + + /** + * Get Plugin Name + * + * @return string + */ + public static function getName() { + return "karmatest"; + } + + /** + * Get Plugin Version + * + * @return float + */ + public static function getVersion() { + // TODO: Implement getVersion() method. + } + + /** + * Get Plugin Author + * + * @return string + */ + public static function getAuthor() { + // TODO: Implement getAuthor() method. + } + + /** + * Get Plugin Description + * + * @return string + */ + public static function getDescription() { + // TODO: Implement getDescription() method. + } +} \ No newline at end of file