From 165fec331708fad6625572df48f13b5be19590f0 Mon Sep 17 00:00:00 2001 From: Alexander Nell Date: Sat, 29 Feb 2020 15:14:48 +0100 Subject: [PATCH] Move Join-/Leave-Coloring from Chat to Admin/ColorManager, and add setting to disable --- core/Admin/ColorManager.php | 99 ++++++++++++++++++++++++++++++++++ core/Chat.php | 64 ---------------------- core/ManiaControl.php | 15 ++++++ core/Players/PlayerManager.php | 12 ++++- 4 files changed, 124 insertions(+), 66 deletions(-) create mode 100644 core/Admin/ColorManager.php diff --git a/core/Admin/ColorManager.php b/core/Admin/ColorManager.php new file mode 100644 index 00000000..e6f7da07 --- /dev/null +++ b/core/Admin/ColorManager.php @@ -0,0 +1,99 @@ + + * @copyright 2014-2020 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class ColorManager implements UsageInformationAble { + use UsageInformationTrait; + + /** + * Constants + */ + const SETTING_COLOR_PLAYER = 'Color of Player'; + const SETTING_COLOR_MODERATOR = 'Color of Moderator'; + const SETTING_COLOR_ADMIN = 'Color of Admin'; + const SETTING_COLOR_SUPERADMIN = 'Color of SuperAdmin'; + const SETTING_COLOR_MASTERADMIN = 'Color of MasterAdmin'; + + /* + * Private properties + */ + /** @var ManiaControl $maniaControl */ + private $maniaControl = null; + + public function __construct(ManiaControl $maniaControl) { + $this->maniaControl = $maniaControl; + + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLOR_PLAYER, '$ff0'); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLOR_MODERATOR, '$0f9'); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLOR_ADMIN, '$39f'); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLOR_SUPERADMIN, '$f93'); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLOR_MASTERADMIN, '$f00'); + } + + /** + * Returns the admins color by the authentication level + * + * @param int $authLevel + * @return string + */ + public function getColorByLevel($authLevel) { + switch ($authLevel) { + case AuthenticationManager::AUTH_LEVEL_PLAYER: + return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_PLAYER); + case AuthenticationManager::AUTH_LEVEL_MODERATOR: + return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_MODERATOR); + case AuthenticationManager::AUTH_LEVEL_ADMIN: + return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_ADMIN); + case AuthenticationManager::AUTH_LEVEL_SUPERADMIN: + return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_SUPERADMIN); + case AuthenticationManager::AUTH_LEVEL_MASTERADMIN: + return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_MASTERADMIN); + } + return ''; + } + + /** + * Returns the admins color by the authentication name + * + * @param string $authName + * @return string + */ + public function getColorByName($authName) { + switch ($authLevel) { + case AuthenticationManager::AUTH_NAME_PLAYER: + return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_PLAYER); + case AuthenticationManager::AUTH_NAME_MODERATOR: + return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_MODERATOR); + case AuthenticationManager::AUTH_NAME_ADMIN: + return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_ADMIN); + case AuthenticationManager::AUTH_NAME_SUPERADMIN: + return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_SUPERADMIN); + case AuthenticationManager::AUTH_NAME_MASTERADMIN: + return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_MASTERADMIN); + } + return ''; + } + + /** + * Returns the admins color by the players authentication level + * + * @param Player $player + * @return string + */ + public function getColorByPlayer(Player $player) { + return $this->getColorByLevel($player->authLevel); + } +} \ No newline at end of file diff --git a/core/Chat.php b/core/Chat.php index 65c0cce7..ba49aeec 100644 --- a/core/Chat.php +++ b/core/Chat.php @@ -26,11 +26,6 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA /* * Constants */ - const SETTING_COLOR_PLAYER = 'Color of Player'; - const SETTING_COLOR_MODERATOR = 'Color of Moderator'; - const SETTING_COLOR_ADMIN = 'Color of Admin'; - const SETTING_COLOR_SUPERADMIN = 'Color of SuperAdmin'; - const SETTING_COLOR_MASTERADMIN = 'Color of MasterAdmin'; const SETTING_FORMAT_ERROR = 'Error Format'; const SETTING_FORMAT_INFORMATION = 'Information Format'; const SETTING_FORMAT_SUCCESS = 'Success Format'; @@ -55,11 +50,6 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA $this->maniaControl = $maniaControl; // Settings - $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLOR_PLAYER, '$ff0'); - $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLOR_MODERATOR, '$0f9'); - $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLOR_ADMIN, '$39f'); - $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLOR_SUPERADMIN, '$f93'); - $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_COLOR_MASTERADMIN, '$f00'); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_ERROR, '$f30'); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_INFORMATION, '$fff'); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_SUCCESS, '$0f0'); @@ -77,60 +67,6 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA }); } - /** - * Returns the admins color by the authentication level - * - * @param int $authLevel - * @return string - */ - public function getColorByLevel($authLevel) { - switch ($authLevel) { - case AuthenticationManager::AUTH_LEVEL_PLAYER: - return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_PLAYER); - case AuthenticationManager::AUTH_LEVEL_MODERATOR: - return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_MODERATOR); - case AuthenticationManager::AUTH_LEVEL_ADMIN: - return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_ADMIN); - case AuthenticationManager::AUTH_LEVEL_SUPERADMIN: - return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_SUPERADMIN); - case AuthenticationManager::AUTH_LEVEL_MASTERADMIN: - return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_MASTERADMIN); - } - return ''; - } - - /** - * Returns the admins color by the authentication name - * - * @param string $authName - * @return string - */ - public function getColorByName($authName) { - switch ($authLevel) { - case AuthenticationManager::AUTH_NAME_PLAYER: - return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_PLAYER); - case AuthenticationManager::AUTH_NAME_MODERATOR: - return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_MODERATOR); - case AuthenticationManager::AUTH_NAME_ADMIN: - return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_ADMIN); - case AuthenticationManager::AUTH_NAME_SUPERADMIN: - return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_SUPERADMIN); - case AuthenticationManager::AUTH_NAME_MASTERADMIN: - return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_COLOR_MASTERADMIN); - } - return ''; - } - - /** - * Returns the admins color by the players authentication level - * - * @param Player $player - * @return string - */ - public function getColorByPlayer(Player $player) { - return $this->getColorByLevel($player->authLevel); - } - /** * Send an information message to the given login * diff --git a/core/ManiaControl.php b/core/ManiaControl.php index d959a716..5a4f9b7c 100644 --- a/core/ManiaControl.php +++ b/core/ManiaControl.php @@ -4,6 +4,7 @@ namespace ManiaControl; use ManiaControl\Admin\ActionsMenu; use ManiaControl\Admin\AuthenticationManager; +use ManiaControl\Admin\ColorManager; use ManiaControl\Bills\BillManager; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; @@ -93,6 +94,10 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, * @see getChat() */ private $chat = null; + /** @var ColorManager $colorManager + * @see getColorManager() + */ + private $colorManager = null; /** @var \SimpleXMLElement $config * @see getConfig() */ @@ -202,6 +207,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, $this->server = new Server($this); $this->authenticationManager = new AuthenticationManager($this); $this->playerManager = new PlayerManager($this); + $this->colorManager = new ColorManager($this); $this->mapManager = new MapManager($this); $this->configurator = new Configurator($this); $this->pluginManager = new PluginManager($this); @@ -451,6 +457,15 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, return $this->playerManager; } + /** + * Return the color manager + * + * @return ColorManager + */ + public function getColorManager() { + return $this->colorManager; + } + /** * Return the setting manager * diff --git a/core/Players/PlayerManager.php b/core/Players/PlayerManager.php index 3823ed98..47adb6a0 100644 --- a/core/Players/PlayerManager.php +++ b/core/Players/PlayerManager.php @@ -41,6 +41,7 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis const CB_PLAYERINFOSCHANGED = 'PlayerManagerCallback.PlayerInfosChanged'; const CB_SERVER_EMPTY = 'PlayerManagerCallback.ServerEmpty'; const TABLE_PLAYERS = 'mc_players'; + const SETTING_JOIN_LEAVE_COLORING = 'Enable Join & Leave Coloring'; const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages'; const SETTING_JOIN_LEAVE_MESSAGES_SPECTATOR = 'Enable Join & Leave Messages for Spectators'; const STAT_JOIN_COUNT = 'Joins'; @@ -92,6 +93,7 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis $this->adminLists = new AdminLists($maniaControl); // Settings + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_JOIN_LEAVE_COLORING, false); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES, true); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES_SPECTATOR, true); @@ -378,7 +380,10 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis if (!$player->isSpectator && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES) || $player->isSpectator && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES_SPECTATOR) ) { - $color = $this->maniaControl->getChat()->getColorByPlayer($player); + $color = '$0f0'; + if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_COLORING)) { + $color = $this->maniaControl->getColorManager()->getColorByPlayer($player); + } $authname = AuthenticationManager::getAuthLevelName($player->authLevel); $nickname = $player->getEscapedNickname(); $this->maniaControl->getChat()->sendChat("{$color}{$authname} {$nickname} has left after \$fff{$played}!"); @@ -488,7 +493,10 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis //Check if Player finished joining the game if ($player->hasJoinedGame && !$prevJoinState) { - $color = $this->maniaControl->getChat()->getColorByPlayer($player); + $color = '$0f0'; + if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_COLORING)) { + $color = $this->maniaControl->getColorManager()->getColorByPlayer($player); + } $authname = AuthenticationManager::getAuthLevelName($player->authLevel); $nickname = $player->getEscapedNickname(); $nation = '$<$fff' . $player->getCountry() . '$>';