From ae3d1d69dafb7ce5ea81d907c81770c4ddf7d8a3 Mon Sep 17 00:00:00 2001 From: Alexander Nell Date: Fri, 28 Feb 2020 17:38:05 +0100 Subject: [PATCH] Added chat colors to roles, only used in Join/Leave messages so far --- core/Chat.php | 77 +++++++++++++++++++++++++++++++--- core/Players/PlayerManager.php | 20 +++++---- 2 files changed, 84 insertions(+), 13 deletions(-) diff --git a/core/Chat.php b/core/Chat.php index 209fb9c3..65c0cce7 100644 --- a/core/Chat.php +++ b/core/Chat.php @@ -26,13 +26,19 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA /* * Constants */ - const SETTING_PUBLIC_PREFIX = 'Public Messages Prefix'; - const SETTING_PRIVATE_PREFIX = 'Privat Messages Prefix'; + 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'; - const SETTING_FORMAT_ERROR = 'Error Format'; const SETTING_FORMAT_USAGEINFO = 'UsageInfo Format'; + const SETTING_PUBLIC_PREFIX = 'Public Messages Prefix'; + const SETTING_PRIVATE_PREFIX = 'Privat Messages Prefix'; const CHAT_BUFFER_SIZE = 200; + /* * Private properties */ @@ -49,12 +55,17 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA $this->maniaControl = $maniaControl; // Settings - $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PUBLIC_PREFIX, '» '); - $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PRIVATE_PREFIX, '»» '); + $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'); - $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_ERROR, '$f30'); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_USAGEINFO, '$f80'); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PUBLIC_PREFIX, '» '); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PRIVATE_PREFIX, '»» '); //Callbacks $this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'onPlayerChat'); @@ -66,6 +77,60 @@ 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/Players/PlayerManager.php b/core/Players/PlayerManager.php index 476174eb..3823ed98 100644 --- a/core/Players/PlayerManager.php +++ b/core/Players/PlayerManager.php @@ -3,6 +3,7 @@ namespace ManiaControl\Players; use ManiaControl\Admin\AdminLists; +use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\Callbacks; @@ -374,10 +375,13 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis $logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}"; Logger::logInfo($logMessage, true); - if (!$player->isSpectator && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer() + 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) ) { - $this->maniaControl->getChat()->sendChat('$0f0$<$fff' . $player->nickname . '$> has left the game'); + $color = $this->maniaControl->getChat()->getColorByPlayer($player); + $authname = AuthenticationManager::getAuthLevelName($player->authLevel); + $nickname = $player->getEscapedNickname(); + $this->maniaControl->getChat()->sendChat("{$color}{$authname} {$nickname} has left after \$fff{$played}!"); } //Destroys stored PlayerData, after all Disconnect Callbacks got Handled @@ -484,20 +488,22 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis //Check if Player finished joining the game if ($player->hasJoinedGame && !$prevJoinState) { + $color = $this->maniaControl->getChat()->getColorByPlayer($player); + $authname = AuthenticationManager::getAuthLevelName($player->authLevel); + $nickname = $player->getEscapedNickname(); + $nation = '$<$fff' . $player->getCountry() . '$>'; if (!$player->isSpectator && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) { - $string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin'); - $chatMessage = '$0f0' . $string[$player->authLevel] . ' $<$fff' . $player->nickname . '$> Nation: $<$fff' . $player->getCountry() . '$> joined!'; + $chatMessage = "{$color}{$authname} {$nickname} Nation: {$nation} joined!"; $this->maniaControl->getChat()->sendChat($chatMessage); } else if ($player->isSpectator && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES_SPECTATOR)) { - $string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin'); - $chatMessage = '$0f0' . $string[$player->authLevel] . ' $<$fff' . $player->nickname . '$> Nation: $<$fff' . $player->getCountry() . '$> joined as Spectator!'; + $chatMessage = "{$color}{$authname} {$nickname} Nation: {$nation} joined as Spectator!"; $this->maniaControl->getChat()->sendChat($chatMessage); } $this->maniaControl->getChat()->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login); - $logMessage = "Player joined: {$player->login} / {$player->nickname} Nation: " . $player->getCountry() . " IP: {$player->ipAddress}"; + $logMessage = "Player joined: {$player->login} / {$player->nickname} Nation: {$nation} IP: {$player->ipAddress}"; Logger::logInfo($logMessage, true); // Increment the Player Join Count