Move Join-/Leave-Coloring from Chat to Admin/ColorManager, and add setting to disable

This commit is contained in:
Alexander Nell 2020-02-29 15:14:48 +01:00
parent 92e00737b5
commit 165fec3317
4 changed files with 124 additions and 66 deletions

View File

@ -0,0 +1,99 @@
<?php
namespace ManiaControl\Admin;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
/**
* Color Manager Class to give roles different colors
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @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);
}
}

View File

@ -26,11 +26,6 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA
/* /*
* Constants * 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_ERROR = 'Error Format';
const SETTING_FORMAT_INFORMATION = 'Information Format'; const SETTING_FORMAT_INFORMATION = 'Information Format';
const SETTING_FORMAT_SUCCESS = 'Success Format'; const SETTING_FORMAT_SUCCESS = 'Success Format';
@ -55,11 +50,6 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Settings // 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_ERROR, '$f30');
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_FORMAT_INFORMATION, '$fff'); $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_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 * Send an information message to the given login
* *

View File

@ -4,6 +4,7 @@ namespace ManiaControl;
use ManiaControl\Admin\ActionsMenu; use ManiaControl\Admin\ActionsMenu;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Admin\ColorManager;
use ManiaControl\Bills\BillManager; use ManiaControl\Bills\BillManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
@ -93,6 +94,10 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
* @see getChat() * @see getChat()
*/ */
private $chat = null; private $chat = null;
/** @var ColorManager $colorManager
* @see getColorManager()
*/
private $colorManager = null;
/** @var \SimpleXMLElement $config /** @var \SimpleXMLElement $config
* @see getConfig() * @see getConfig()
*/ */
@ -202,6 +207,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
$this->server = new Server($this); $this->server = new Server($this);
$this->authenticationManager = new AuthenticationManager($this); $this->authenticationManager = new AuthenticationManager($this);
$this->playerManager = new PlayerManager($this); $this->playerManager = new PlayerManager($this);
$this->colorManager = new ColorManager($this);
$this->mapManager = new MapManager($this); $this->mapManager = new MapManager($this);
$this->configurator = new Configurator($this); $this->configurator = new Configurator($this);
$this->pluginManager = new PluginManager($this); $this->pluginManager = new PluginManager($this);
@ -451,6 +457,15 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
return $this->playerManager; return $this->playerManager;
} }
/**
* Return the color manager
*
* @return ColorManager
*/
public function getColorManager() {
return $this->colorManager;
}
/** /**
* Return the setting manager * Return the setting manager
* *

View File

@ -41,6 +41,7 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis
const CB_PLAYERINFOSCHANGED = 'PlayerManagerCallback.PlayerInfosChanged'; const CB_PLAYERINFOSCHANGED = 'PlayerManagerCallback.PlayerInfosChanged';
const CB_SERVER_EMPTY = 'PlayerManagerCallback.ServerEmpty'; const CB_SERVER_EMPTY = 'PlayerManagerCallback.ServerEmpty';
const TABLE_PLAYERS = 'mc_players'; 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 = 'Enable Join & Leave Messages';
const SETTING_JOIN_LEAVE_MESSAGES_SPECTATOR = 'Enable Join & Leave Messages for Spectators'; const SETTING_JOIN_LEAVE_MESSAGES_SPECTATOR = 'Enable Join & Leave Messages for Spectators';
const STAT_JOIN_COUNT = 'Joins'; const STAT_JOIN_COUNT = 'Joins';
@ -92,6 +93,7 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis
$this->adminLists = new AdminLists($maniaControl); $this->adminLists = new AdminLists($maniaControl);
// Settings // 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, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES_SPECTATOR, 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) 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) || $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); $authname = AuthenticationManager::getAuthLevelName($player->authLevel);
$nickname = $player->getEscapedNickname(); $nickname = $player->getEscapedNickname();
$this->maniaControl->getChat()->sendChat("{$color}{$authname} {$nickname} has left after \$fff{$played}!"); $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 //Check if Player finished joining the game
if ($player->hasJoinedGame && !$prevJoinState) { 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); $authname = AuthenticationManager::getAuthLevelName($player->authLevel);
$nickname = $player->getEscapedNickname(); $nickname = $player->getEscapedNickname();
$nation = '$<$fff' . $player->getCountry() . '$>'; $nation = '$<$fff' . $player->getCountry() . '$>';