new setting enable join/leave messages for spectators

This commit is contained in:
kremsy 2014-08-14 18:55:45 +02:00
parent 20be0f853b
commit fd722d7105

View File

@ -24,14 +24,15 @@ class PlayerManager implements CallbackListener, TimerListener {
/* /*
* Constants * Constants
*/ */
const CB_PLAYERCONNECT = 'PlayerManagerCallback.PlayerConnect'; const CB_PLAYERCONNECT = 'PlayerManagerCallback.PlayerConnect';
const CB_PLAYERDISCONNECT = 'PlayerManagerCallback.PlayerDisconnect'; const CB_PLAYERDISCONNECT = 'PlayerManagerCallback.PlayerDisconnect';
const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged'; const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged';
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_MESSAGES = 'Enable Join & Leave Messages'; const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages';
const STAT_JOIN_COUNT = 'Joins'; const SETTING_JOIN_LEAVE_MESSAGES_SPECTATOR = 'Enable Join & Leave Messages for Spectators';
const STAT_SERVERTIME = 'Servertime'; const STAT_JOIN_COUNT = 'Joins';
const STAT_SERVERTIME = 'Servertime';
/* /*
* Public properties * Public properties
@ -81,6 +82,7 @@ class PlayerManager implements CallbackListener, TimerListener {
// Settings // Settings
$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);
// Callbacks // Callbacks
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
@ -321,7 +323,8 @@ class PlayerManager implements CallbackListener, TimerListener {
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}"; $logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}";
Logger::logInfo($logMessage, true); Logger::logInfo($logMessage, true);
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES) if (!$player->isSpectator && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()
|| $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'); $this->maniaControl->getChat()->sendChat('$0f0$<$fff' . $player->nickname . '$> has left the game');
} }
@ -410,15 +413,19 @@ class PlayerManager implements CallbackListener, TimerListener {
//Check if Player finished joining the game //Check if Player finished joining the game
if ($player->hasJoinedGame && !$prevJoinState) { if ($player->hasJoinedGame && !$prevJoinState) {
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES) if (!$player->isSpectator && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()
&& !$player->isFakePlayer()
) { ) {
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin'); $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 = '$0f0' . $string[$player->authLevel] . ' $<$fff' . $player->nickname . '$> Nation: $<$fff' . $player->getCountry() . '$> joined!';
$this->maniaControl->getChat()->sendChat($chatMessage); $this->maniaControl->getChat()->sendChat($chatMessage);
$this->maniaControl->getChat()->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login); } 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!';
$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: " . $player->getCountry() . " IP: {$player->ipAddress}";
Logger::logInfo($logMessage, true); Logger::logInfo($logMessage, true);