From 2bbcbf1d72b5cc1c20e36e04a7698c04a7352006 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sun, 13 Apr 2014 19:05:54 +0200 Subject: [PATCH] permission levels for settings --- .../core/Configurators/Configurator.php | 7 ++++- .../core/Configurators/ScriptSettings.php | 9 ++++++ .../core/Configurators/ServerSettings.php | 28 +++++++++++++------ application/core/Server/UsageReporter.php | 2 ++ application/plugins/WidgetPlugin.php | 11 ++++---- 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/application/core/Configurators/Configurator.php b/application/core/Configurators/Configurator.php index 527199c7..e05cb09c 100644 --- a/application/core/Configurators/Configurator.php +++ b/application/core/Configurators/Configurator.php @@ -40,6 +40,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn const SETTING_MENU_HEIGHT = 'Menu Widget Height'; const SETTING_MENU_STYLE = 'Menu Widget BackgroundQuad Style'; const SETTING_MENU_SUBSTYLE = 'Menu Widget BackgroundQuad Substyle'; + const SETTING_PERMISSION_OPEN_CONFIGURATOR = 'Open Configurator'; /* * Private Properties @@ -68,6 +69,9 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_STYLE, Quad_BgRaceScore2::STYLE); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable); + //Permission for opening + $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_OPEN_CONFIGURATOR, AuthenticationManager::AUTH_LEVEL_ADMIN); + // Register for page answers $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, 'handleSaveConfigAction'); @@ -78,6 +82,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened'); $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget'); + // Create server settings $this->serverSettings = new ServerSettings($maniaControl); $this->addMenu($this->serverSettings); @@ -100,7 +105,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn * @param array $callback */ public function handleConfigCommand(array $callback, Player $player) { - if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_OPEN_CONFIGURATOR)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return; } diff --git a/application/core/Configurators/ScriptSettings.php b/application/core/Configurators/ScriptSettings.php index 71fd332d..554623c9 100644 --- a/application/core/Configurators/ScriptSettings.php +++ b/application/core/Configurators/ScriptSettings.php @@ -9,6 +9,7 @@ use FML\Controls\Label; use FML\Controls\Labels\Label_Text; use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Script\Script; +use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\ManiaControl; @@ -34,6 +35,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener { const CB_SCRIPTSETTINGS_CHANGED = 'ScriptSettings.SettingsChanged'; const TABLE_SCRIPT_SETTINGS = 'mc_scriptsettings'; const SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN = 'Load Stored Script-Settings on Map-Begin'; + const SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS = 'Change Script-Settings'; /* * Private Properties @@ -54,6 +56,9 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener { $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'onBeginMap'); $this->maniaControl->settingManager->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, true); $this->initTables(); + + //Permission for Change Script-Settings + $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN); } /** @@ -303,6 +308,10 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener { * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() */ public function saveConfigData(array $configData, Player $player) { + if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS)) { + $this->maniaControl->authenticationManager->sendNotAllowed($player); + return; + } $prefix = explode(".", $configData[3][0]['Name']); if ($prefix[0] != self::ACTION_PREFIX_SETTING) { diff --git a/application/core/Configurators/ServerSettings.php b/application/core/Configurators/ServerSettings.php index e81ea01e..c26e72ee 100644 --- a/application/core/Configurators/ServerSettings.php +++ b/application/core/Configurators/ServerSettings.php @@ -9,6 +9,7 @@ use FML\Controls\Label; use FML\Controls\Labels\Label_Text; use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Script\Script; +use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\ManiaControl; @@ -17,19 +18,20 @@ use ManiaControl\Players\Player; /** * Class offering a Configurator for Server Settings * - * @author steeffeen & kremsy + * @author steeffeen & kremsy * @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 */ class ServerSettings implements ConfiguratorMenu, CallbackListener { /* * Constants */ - const ACTION_PREFIX_SETTING = 'ServerSettings'; - const ACTION_SETTING_BOOL = 'ServerSettings.ActionBoolSetting.'; - const CB_SERVERSETTING_CHANGED = 'ServerSettings.SettingChanged'; - const CB_SERVERSETTINGS_CHANGED = 'ServerSettings.SettingsChanged'; - const TABLE_SERVER_SETTINGS = 'mc_serversettings'; + const ACTION_PREFIX_SETTING = 'ServerSettings'; + const ACTION_SETTING_BOOL = 'ServerSettings.ActionBoolSetting.'; + const CB_SERVERSETTING_CHANGED = 'ServerSettings.SettingChanged'; + const CB_SERVERSETTINGS_CHANGED = 'ServerSettings.SettingsChanged'; + const TABLE_SERVER_SETTINGS = 'mc_serversettings'; + const SETTING_PERMISSION_CHANGE_SERVER_SETTINGS = 'Change Server-Settings'; /* * Private Properties @@ -48,6 +50,9 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener { // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit'); + + //Permission for Change Script-Settings + $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SERVER_SETTINGS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN); } /** @@ -101,8 +106,8 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener { return false; } $serverSettings = $this->maniaControl->client->getServerOptions()->toArray(); - $applySettings = false; - while ($row = $result->fetch_object()) { + $applySettings = false; + while($row = $result->fetch_object()) { if (!isset($serverSettings[$row->settingName])) { continue; } @@ -257,6 +262,11 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener { * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() */ public function saveConfigData(array $configData, Player $player) { + if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SERVER_SETTINGS)) { + $this->maniaControl->authenticationManager->sendNotAllowed($player); + return; + } + $prefix = explode(".", $configData[3][0]['Name']); if ($prefix[0] != self::ACTION_PREFIX_SETTING) { return; diff --git a/application/core/Server/UsageReporter.php b/application/core/Server/UsageReporter.php index 70189c1a..40971ec4 100644 --- a/application/core/Server/UsageReporter.php +++ b/application/core/Server/UsageReporter.php @@ -7,6 +7,7 @@ use ManiaControl\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Plugins\Plugin; use Maniaplanet\DedicatedServer\Xmlrpc\Exception; +use Maniaplanet\DedicatedServer\Xmlrpc\FatalException; /** * Class reporting ManiaControl Usage for the Server @@ -57,6 +58,7 @@ class UsageReporter implements TimerListener { $properties['ServerLogin'] = $this->maniaControl->server->login; $properties['TitleId'] = $this->maniaControl->server->titleId; $properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->client->getServerName()); + $properties['PlayerCount'] = $this->maniaControl->playerManager->getPlayerCount(); $properties['MemoryUsage'] = memory_get_usage(); $properties['MemoryPeakUsage'] = memory_get_peak_usage(); diff --git a/application/plugins/WidgetPlugin.php b/application/plugins/WidgetPlugin.php index d47df811..b979911f 100644 --- a/application/plugins/WidgetPlugin.php +++ b/application/plugins/WidgetPlugin.php @@ -8,23 +8,22 @@ use FML\Controls\Quads\Quad_Icons64x64_1; use FML\ManiaLink; use FML\Script\Script; use ManiaControl\Callbacks\CallbackListener; -use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\IconManager; +use ManiaControl\Maps\Map; +use ManiaControl\Maps\MapManager; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\Plugin; -use ManiaControl\Maps\MapManager; -use ManiaControl\Maps\Map; /** * ManiaControl Widget Plugin * - * @author steeffeen and kremsy + * @author steeffeen and kremsy * @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 */ class WidgetPlugin implements CallbackListener, TimerListener, Plugin { @@ -248,7 +247,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin { $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $maniaLink = new ManiaLink(self::MLID_CLOCKWIDGET); - $script = $maniaLink->getScript(); + $script = $maniaLink->getScript(); // mainframe $frame = new Frame();