Use Chat::formatMessage in Players/*

This commit is contained in:
Alexander Nell 2020-05-30 22:42:39 +02:00
parent 06f24a1bfb
commit 74dc8182bf
4 changed files with 352 additions and 219 deletions

View File

@ -165,11 +165,11 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId, $calledByAdmin = true) { public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId, $calledByAdmin = true) {
if ($calledByAdmin) { if ($calledByAdmin) {
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin); $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_TEAM)) { if (!$admin) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
return false; return false;
} }
if (!$admin) { if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_TEAM)) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
return false; return false;
} }
} }
@ -183,52 +183,54 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
if (!$this->forcePlayerToPlay($adminLogin, $targetLogin, true, false, $calledByAdmin)) { if (!$this->forcePlayerToPlay($adminLogin, $targetLogin, true, false, $calledByAdmin)) {
return false; return false;
} }
} catch (FaultException $exception) { } catch (FaultException $e) {
if ($calledByAdmin) { $this->maniaControl->getChat()->sendException($e, $adminLogin);
$this->maniaControl->getChat()->sendException($exception, $admin);
}
} }
} }
try { try {
$this->maniaControl->getClient()->forcePlayerTeam($target->login, $teamId); $this->maniaControl->getClient()->forcePlayerTeam($target->login, $teamId);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $e) {
$this->forcePlayerToPlay($adminLogin, $targetLogin); $this->forcePlayerToPlay($adminLogin, $targetLogin);
return false; return false;
} catch (UnknownPlayerException $exception) { } catch (UnknownPlayerException $e) {
$this->maniaControl->getChat()->sendException($e, $adminLogin);
return false;
} catch (GameModeException $e) {
$this->maniaControl->getChat()->sendException($e, $adminLogin);
return false;
}
$message = false;
$teamName = '';
if ($teamId === self::TEAM_BLUE) {
$teamName = '$00fBlue';
} elseif ($teamId === self::TEAM_RED) {
$teamName = '$f00Red';
}
if ($teamName) {
if ($calledByAdmin) { if ($calledByAdmin) {
$this->maniaControl->getChat()->sendException($exception, $admin); $message = $this->maniaControl->getChat()->formatMessage(
} '%s %s forced %s into the %s-Team!',
return false; $admin->getAuthLevelName(),
} catch (GameModeException $exception) { $admin,
if ($calledByAdmin) { $target,
$this->maniaControl->getChat()->sendException($exception, $admin); $teamName
} );
return false; } else {
} $message = $this->maniaControl->getChat()->formatMessage(
'%s got forced %s into the %s-Team!',
$chatMessage = false; $target,
$teamName
if ($calledByAdmin) { );
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
if ($teamId === self::TEAM_BLUE) {
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' into the Blue-Team!';
} else if ($teamId === self::TEAM_RED) {
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' into the Red-Team!';
}
} else {
if ($teamId === self::TEAM_BLUE) {
$chatMessage = $target->getEscapedNickname() . ' got forced into the Blue-Team!';
} else if ($teamId === self::TEAM_RED) {
$chatMessage = $target->getEscapedNickname() . ' got forced into the Red-Team!';
} }
} }
if (!$chatMessage) { if ($message) {
return false; $this->maniaControl->getChat()->sendInformation($message);
Logger::logInfo($chatMessage, true);
} }
$this->maniaControl->getChat()->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true);
return true; return true;
} }
@ -260,24 +262,20 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
try { try {
$this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_PLAYER); $this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_PLAYER);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $e) {
if ($calledByAdmin) { $this->maniaControl->getChat()->sendException($e, $adminLogin);
$this->maniaControl->getChat()->sendException($exception, $admin);
}
return false; return false;
} catch (UnknownPlayerException $exception) { } catch (UnknownPlayerException $e) {
if ($calledByAdmin) { $this->maniaControl->getChat()->sendException($e, $adminLogin);
$this->maniaControl->getChat()->sendException($exception, $admin);
}
return false; return false;
} }
if ($userIsAbleToSelect) { if ($userIsAbleToSelect) {
try { try {
$this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE); $this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $e) {
if ($calledByAdmin) { if ($calledByAdmin) {
$this->maniaControl->getChat()->sendException($exception, $admin); $this->maniaControl->getChat()->sendException($e, $admin);
} }
return false; return false;
} }
@ -286,13 +284,20 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
// Announce force // Announce force
if ($displayAnnouncement) { if ($displayAnnouncement) {
if ($calledByAdmin) { if ($calledByAdmin) {
$chatMessage = $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Play!'; $message = $this->maniaControl->getChat()->formatMessage(
'%s %s forced %s to Play!',
$admin->getAuthLevelName(),
$admin,
$target
);
} else { } else {
$chatMessage = $target->getEscapedNickname() . ' got forced to Play!'; $message = $this->maniaControl->getChat()->formatMessage(
'%s got forced to Play!',
$target
);
} }
$this->maniaControl->getChat()->sendInformation($message);
$this->maniaControl->getChat()->sendInformation($chatMessage);
} }
return true; return true;
@ -312,12 +317,12 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true, $calledByAdmin = true) { public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true, $calledByAdmin = true) {
if ($calledByAdmin) { if ($calledByAdmin) {
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin); $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC)) { if (!$admin) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
return false; return false;
} }
if (!$admin) { if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC)) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
return false; return false;
} }
} }
@ -330,21 +335,27 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
try { try {
$this->maniaControl->getClient()->forceSpectator($target->login, $spectatorState); $this->maniaControl->getClient()->forceSpectator($target->login, $spectatorState);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $e) {
if ($calledByAdmin) { $this->maniaControl->getChat()->sendException($e, $adminLogin);
$this->maniaControl->getChat()->sendException($exception, $admin->login);
}
return false; return false;
} }
if ($calledByAdmin) { if ($calledByAdmin) {
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel); $message = $this->maniaControl->getChat()->formatMessage(
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Spectator!'; '%s %s forced %s to Spectator!',
$admin->getAuthLevelName(),
$admin,
$target
);
} else { } else {
$chatMessage = $target->getEscapedNickname() . ' got forced to Spectator!'; $message = $this->maniaControl->getChat()->formatMessage(
'%s got forced to Spectator!',
$target
);
} }
$this->maniaControl->getChat()->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); $this->maniaControl->getChat()->sendInformation($message);
Logger::logInfo($message, true);
if ($releaseSlot) { if ($releaseSlot) {
// Free player slot // Free player slot
@ -375,8 +386,8 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
return false; return false;
} }
} }
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
if (!$target) { if (!$target) {
return false; return false;
} }
@ -384,19 +395,30 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
try { try {
$this->maniaControl->getClient()->unIgnore($targetLogin); $this->maniaControl->getClient()->unIgnore($targetLogin);
} catch (NotInListException $e) { } catch (NotInListException $e) {
$this->maniaControl->getChat()->sendError('Player is not ignored!', $adminLogin); $message = $this->maniaControl->getChat()->formatMessage(
'%s is not muted!',
$player
);
$this->maniaControl->getChat()->sendError($message, $adminLogin);
return false; return false;
} }
if ($calledByAdmin) { if ($calledByAdmin) {
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel); $message = $this->maniaControl->getChat()->formatMessage(
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' un-muted ' . $target->getEscapedNickname() . '!'; '%s %s un-muted %s!',
$admin->getAuthLevelName(),
$admin,
$target
);
} else { } else {
$chatMessage = $target->getEscapedNickname() . ' got un-muted!'; $message = $this->maniaControl->getChat()->formatMessage(
'%s got un-muted!',
$target
);
} }
$this->maniaControl->getChat()->sendInformation($chatMessage); $this->maniaControl->getChat()->sendInformation($message);
Logger::logInfo($chatMessage, true); Logger::logInfo($message, true);
return true; return true;
} }
@ -418,8 +440,8 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
return false; return false;
} }
} }
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
if (!$target) { if (!$target) {
return false; return false;
} }
@ -427,20 +449,30 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
try { try {
$this->maniaControl->getClient()->ignore($targetLogin); $this->maniaControl->getClient()->ignore($targetLogin);
} catch (AlreadyInListException $e) { } catch (AlreadyInListException $e) {
$this->maniaControl->getChat()->sendError("Player already ignored!", $adminLogin); $message = $this->maniaControl->getChat()->formatMessage(
'%s is already muted!',
$player
);
$this->maniaControl->getChat()->sendError($message, $adminLogin);
return false; return false;
} }
// Announce warning
if ($calledByAdmin) { if ($calledByAdmin) {
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel); $message = $this->maniaControl->getChat()->formatMessage(
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' muted ' . $target->getEscapedNickname() . '!'; '%s %s muted %s!',
$admin->getAuthLevelName(),
$admin,
$target
);
} else { } else {
$chatMessage = $target->getEscapedNickname() . ' got muted!'; $message = $this->maniaControl->getChat()->formatMessage(
'%s got muted!',
$target
);
} }
$this->maniaControl->getChat()->sendInformation($chatMessage); $this->maniaControl->getChat()->sendInformation($message);
Logger::logInfo($chatMessage, true); Logger::logInfo($message, true);
return true; return true;
} }
@ -464,7 +496,6 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
} }
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin); $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
if (!$target) { if (!$target) {
return false; return false;
} }
@ -527,16 +558,22 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
// Display manialink // Display manialink
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $target); $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $target);
// Announce warning
if ($calledByAdmin) { if ($calledByAdmin) {
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel); $message = $this->maniaControl->getChat()->formatMessage(
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' warned ' . $target->getEscapedNickname() . '!'; '%s %s warned %s!',
$admin->getAuthLevelName(),
$admin,
$target
);
} else { } else {
$chatMessage = $target->getEscapedNickname() . ' got an administrative warning!'; $message = $this->maniaControl->getChat()->formatMessage(
'%s got warned!',
$target
);
} }
$this->maniaControl->getChat()->sendInformation($chatMessage); $this->maniaControl->getChat()->sendInformation($message);
Logger::log($chatMessage, true); Logger::log($message, true);
return true; return true;
} }
@ -570,37 +607,37 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
try { try {
$this->maniaControl->getClient()->disconnectFakePlayer($target->login); $this->maniaControl->getClient()->disconnectFakePlayer($target->login);
} catch (PlayerStateException $e) { } catch (PlayerStateException $e) {
if ($calledByAdmin) { $this->maniaControl->getChat()->sendException($e, $adminLogin);
$this->maniaControl->getChat()->sendException($e, $admin);
}
return false; return false;
} catch (UnknownPlayerException $e) { //TODO check why it's actually needed, but there was a crash at this place } catch (UnknownPlayerException $e) {
if ($calledByAdmin) { $this->maniaControl->getChat()->sendException($e, $adminLogin);
$this->maniaControl->getChat()->sendException($e, $admin);
}
return false; return false;
} }
} else { } else {
try { try {
$this->maniaControl->getClient()->kick($target->login, $message); $this->maniaControl->getClient()->kick($target->login, $message);
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
if ($calledByAdmin) { $this->maniaControl->getChat()->sendException($e, $adminLogin);
$this->maniaControl->getChat()->sendException($e, $admin);
}
return false; return false;
} }
} }
// Announce kick
if ($calledByAdmin) { if ($calledByAdmin) {
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel); $message = $this->maniaControl->getChat()->formatMessage(
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' kicked ' . $target->getEscapedNickname() . '!'; '%s %s kicked %s!',
$admin->getAuthLevelName(),
$admin,
$target
);
} else { } else {
$chatMessage = $target->getEscapedNickname() . ' got kicked!'; $message = $this->maniaControl->getChat()->formatMessage(
'%s got kicked!',
$target
);
} }
$this->maniaControl->getChat()->sendInformation($chatMessage); $this->maniaControl->getChat()->sendInformation($message);
Logger::logInfo($chatMessage, true); Logger::logInfo($message, true);
return true; return true;
} }
@ -639,12 +676,14 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
return; return;
} }
$message = $this->maniaControl->getChat()->formatMessage(
// Announce ban '%s %s banned %s!',
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel); $admin->getAuthLevelName(),
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' banned ' . $target->getEscapedNickname() . '!'; $admin,
$this->maniaControl->getChat()->sendInformation($chatMessage); $target
Logger::logInfo($chatMessage, true); );
$this->maniaControl->getChat()->sendInformation($message);
Logger::logInfo($message, true);
} }
/** /**
@ -679,35 +718,52 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
return; return;
} }
// Announce ban $message = $this->maniaControl->getChat()->formatMessage(
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel); '%s %s unbanned %s!',
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' unbanned ' . $targetLogin . '!'; $admin->getAuthLevelName(),
$this->maniaControl->getChat()->sendInformation($chatMessage); $admin,
Logger::logInfo($chatMessage, true); $target
);
$this->maniaControl->getChat()->sendInformation($message);
Logger::logInfo($message, true);
} }
/** /**
* Grands the Player an Authorization Level * Grands the Player an Authorization Level
* *
* @api * @api
* @deprecated
* @param string $adminLogin * @param string $adminLogin
* @param string $targetLogin * @param string $targetLogin
* @param int $authLevel * @param int $authLevel
*/ */
public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) { public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) {
$this->grantAuthLevel($adminLogin, $targetLogin, $authLevel);
}
/**
* Grants the Player an Authorization Level
*
* @api
* @deprecated
* @param string $adminLogin
* @param string $targetLogin
* @param int $authLevel
*/
public function grantAuthLevel($adminLogin, $targetLogin, $authLevel) {
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin); $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin); $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
if (!$admin || !$target) { if (!$admin || !$target) {
return; return;
} }
$authLevelName = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($authLevel); $authLevelName = AuthenticationManager::getAuthLevelName($authLevel);
if (!$this->maniaControl->getAuthenticationManager()->checkRight($admin, $authLevel + 1)) { if (!AuthenticationManager::checkRight($admin, $authLevel + 1)) {
$this->maniaControl->getChat()->sendError("You don't have the permission to add a {$authLevelName}!", $admin); $this->maniaControl->getChat()->sendError("You do not have the permission to add a {$authLevelName}!", $admin);
return; return;
} }
if ($this->maniaControl->getAuthenticationManager()->checkRight($target, $authLevel)) { if (AuthenticationManager::checkRight($target, $authLevel)) {
$this->maniaControl->getChat()->sendError("This Player is already {$authLevelName}!", $admin); $this->maniaControl->getChat()->sendError("This Player is already {$authLevelName}!", $admin);
return; return;
} }
@ -718,11 +774,14 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
return; return;
} }
// Announce granting $message = $this->maniaControl->getChat()->formatMessage(
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel); "%s %s added %s as {$authLevelName}!",
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as $< ' . $authLevelName . '$>!'; $admin->getAuthLevelName(),
$this->maniaControl->getChat()->sendInformation($chatMessage); $admin,
Logger::logInfo($chatMessage, true); $target
);
$this->maniaControl->getChat()->sendInformation($message);
Logger::logInfo($message, true);
} }
/** /**
@ -739,14 +798,13 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
return; return;
} }
if (!$this->maniaControl->getAuthenticationManager()->checkRight($admin, $target->authLevel + 1)) { if ($admin->authLevel <= $target->authLevel) {
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($target->authLevel); $this->maniaControl->getChat()->sendError("You cannot revoke the Rights of a {$target->getAuthLevelName()}!", $admin);
$this->maniaControl->getChat()->sendError("You can't revoke the Rights of a {$title}!", $admin);
return; return;
} }
if ($this->maniaControl->getAuthenticationManager()->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) { if (AuthenticationManager::checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
$this->maniaControl->getChat()->sendError("MasterAdmins can't be removed!", $admin); $this->maniaControl->getChat()->sendError("MasterAdmins cannot be removed!", $admin);
return; return;
} }
@ -756,11 +814,13 @@ class PlayerActions implements EchoListener, CommunicationListener, UsageInforma
return; return;
} }
// Announce revoke $message = $this->maniaControl->getChat()->formatMessage(
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel); "%s %s revoked the Rights of %s!",
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' revoked the Rights of ' . $target->getEscapedNickname() . '!'; $admin->getAuthLevelName(),
$this->maniaControl->getChat()->sendInformation($chatMessage); $admin,
Logger::logInfo($chatMessage, true); $target
);
$this->maniaControl->getChat()->sendInformation($message);
Logger::logInfo($message, true);
} }
} }

View File

@ -45,6 +45,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
// Admin commands // Admin commands
$this->maniaControl->getCommandManager()->registerCommandListener(array('balance', 'teambalance', 'autoteambalance'), $this, 'command_TeamBalance', true, 'Balances the teams.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('balance', 'teambalance', 'autoteambalance'), $this, 'command_TeamBalance', true, 'Balances the teams.');
$this->maniaControl->getCommandManager()->registerCommandListener('warn', $this, 'command_Warn', true, 'Warns a player from the server.');
$this->maniaControl->getCommandManager()->registerCommandListener('kick', $this, 'command_Kick', true, 'Kicks player from the server.'); $this->maniaControl->getCommandManager()->registerCommandListener('kick', $this, 'command_Kick', true, 'Kicks player from the server.');
$this->maniaControl->getCommandManager()->registerCommandListener('ban', $this, 'command_Ban', true, 'Bans a player from the server.'); $this->maniaControl->getCommandManager()->registerCommandListener('ban', $this, 'command_Ban', true, 'Bans a player from the server.');
$this->maniaControl->getCommandManager()->registerCommandListener('unban', $this, 'command_UnBan', true, 'Unbans a player from the server.'); $this->maniaControl->getCommandManager()->registerCommandListener('unban', $this, 'command_UnBan', true, 'Unbans a player from the server.');
@ -112,7 +113,11 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
return; return;
} }
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' balanced Teams!'); $message = $this->maniaControl->getChat()->formatMessage(
'%s balanced Teams!',
$player
);
$this->maniaControl->getChat()->sendInformation($message);
} }
/** /**
@ -122,22 +127,27 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_Kick(array $chat, Player $player) { public function command_Kick(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_KICK_PLAYER) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_KICK_PLAYER)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2], 3); $params = explode(' ', $chat[1][2], 3);
if (count($params) <= 1) { if (count($params) <= 1) {
$this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//kick login'", $player->login); $message = $this->maniaControl->getChat()->formatMessage(
'No Login given! Example: %s',
'//kick login'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
$message = ''; $message = '';
if (isset($params[2])) { if (isset($params[2])) {
$message = $params[2]; $message = $params[2];
} }
$this->maniaControl->getPlayerManager()->getPlayerActions()->kickPlayer($player->login, $targetLogin, $message); $this->maniaControl->getPlayerManager()->getPlayerActions()->kickPlayer($player, $targetLogin, $message);
} }
/** /**
@ -147,22 +157,27 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_Ban(array $chat, Player $player) { public function command_Ban(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_BAN_PLAYER) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_BAN_PLAYER)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2], 3); $params = explode(' ', $chat[1][2], 3);
if (count($params) <= 1) { if (count($params) <= 1) {
$this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//ban login'", $player->login); $message = $this->maniaControl->getChat()->formatMessage(
'No Login given! Example: %s',
'//ban login'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
$message = ''; $message = '';
if (isset($params[2])) { if (isset($params[2])) {
$message = $params[2]; $message = $params[2];
} }
$this->maniaControl->getPlayerManager()->getPlayerActions()->banPlayer($player->login, $targetLogin, $message); $this->maniaControl->getPlayerManager()->getPlayerActions()->banPlayer($player, $targetLogin, $message);
} }
/** /**
@ -172,18 +187,23 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_UnBan(array $chat, Player $player) { public function command_UnBan(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_BAN_PLAYER) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_BAN_PLAYER)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2], 3); $params = explode(' ', $chat[1][2], 3);
if (count($params) <= 1) { if (count($params) <= 1) {
$this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//ban login'", $player->login); $message = $this->maniaControl->getChat()->formatMessage(
'No Login given! Example: %s',
'//unban login'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
$this->maniaControl->getPlayerManager()->getPlayerActions()->unBanPlayer($player->login, $targetLogin); $this->maniaControl->getPlayerManager()->getPlayerActions()->unBanPlayer($player, $targetLogin);
} }
/** /**
@ -193,13 +213,23 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_Warn(array $chatCallback, Player $player) { public function command_Warn(array $chatCallback, Player $player) {
$params = explode(' ', $chatCallback[1][2], 3); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_WARN_PLAYER)) {
if (count($params) <= 1) { $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
$this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//warn login'", $player->login);
return; return;
} }
$params = explode(' ', $chatCallback[1][2], 3);
if (count($params) <= 1) {
$message = $this->maniaControl->getChat()->formatMessage(
'No Login given! Example: %s',
'//warn login'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return;
}
$targetLogin = $params[1]; $targetLogin = $params[1];
$this->maniaControl->getPlayerManager()->getPlayerActions()->warnPlayer($player->login, $targetLogin); $this->maniaControl->getPlayerManager()->getPlayerActions()->warnPlayer($player, $targetLogin);
} }
/** /**
@ -209,23 +239,27 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_ForceSpectator(array $chat, Player $player) { public function command_ForceSpectator(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_SPEC) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_SPEC)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (count($params) <= 1) { if (count($params) <= 1) {
$this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//forcespec login'", $player->login); $message = $this->maniaControl->getChat()->formatMessage(
'No Login given! Example: %s',
'//forcespec login'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return; return;
} }
$targetLogin = $params[1];
$targetLogin = $params[1];
if (isset($params[2]) && is_numeric($params[2])) { if (isset($params[2]) && is_numeric($params[2])) {
$type = (int) $params[2]; $type = intval($params[2]);
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToSpectator($player->login, $targetLogin, $type); $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToSpectator($player, $targetLogin, $type);
} else { } else {
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToSpectator($player->login, $targetLogin); $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToSpectator($player, $targetLogin);
} }
} }
@ -236,25 +270,29 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_ForcePlay(array $chat, Player $player) { public function command_ForcePlay(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (!isset($params[1])) { if (!isset($params[1])) {
$this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//forceplay login'", $player->login); $message = $this->maniaControl->getChat()->formatMessage(
'No Login given! Example: %s',
'//forceplay login'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return; return;
} }
$targetLogin = $params[1];
$targetLogin = $params[1];
$type = 2; $type = 2;
if (isset($params[2]) && is_numeric($params[2])) { if (isset($params[2]) && is_numeric($params[2])) {
$type = (int) $params[2]; $type = intval($params[2]);
} }
$selectable = ($type === 2); $selectable = ($type === 2);
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToPlay($player->login, $targetLogin, $selectable); $this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToPlay($player, $targetLogin, $selectable);
} }
/** /**
@ -264,19 +302,23 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_ForceBlue(array $chat, Player $player) { public function command_ForceBlue(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (!isset($params[1])) { if (!isset($params[1])) {
$this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//forceblue login'", $player->login); $message = $this->maniaControl->getChat()->formatMessage(
'No Login given! Example: %s',
'//forceblue login'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return; return;
} }
$targetLogin = $params[1];
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($player->login, $targetLogin, PlayerActions::TEAM_BLUE); $targetLogin = $params[1];
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($player, $targetLogin, PlayerActions::TEAM_BLUE);
} }
/** /**
@ -286,19 +328,23 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_ForceRed(array $chat, Player $player) { public function command_ForceRed(array $chat, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (!isset($params[1])) { if (!isset($params[1])) {
$this->maniaControl->getChat()->sendUsageInfo("No Login given! Example: '//forcered login'", $player->login); $message = $this->maniaControl->getChat()->formatMessage(
'No Login given! Example: %s',
'//forcered login'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return; return;
} }
$targetLogin = $params[1];
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($player->login, $targetLogin, PlayerActions::TEAM_RED); $targetLogin = $params[1];
$this->maniaControl->getPlayerManager()->getPlayerActions()->forcePlayerToTeam($player, $targetLogin, PlayerActions::TEAM_RED);
} }
/** /**
@ -308,11 +354,11 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_AddFakePlayers(array $chatCallback, Player $player) { public function command_AddFakePlayers(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_ADD_BOT) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_ADD_BOT)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$amount = 1; $amount = 1;
$messageParts = explode(' ', $chatCallback[1][2]); $messageParts = explode(' ', $chatCallback[1][2]);
if (isset($messageParts[1]) && is_numeric($messageParts[1])) { if (isset($messageParts[1]) && is_numeric($messageParts[1])) {
@ -325,7 +371,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
} }
$this->maniaControl->getChat()->sendSuccess('Fake players connected!', $player); $this->maniaControl->getChat()->sendSuccess('Fake players connected!', $player);
} catch (UnavailableFeatureException $e) { } catch (UnavailableFeatureException $e) {
$this->maniaControl->getChat()->sendSuccess('Error while connecting a Fake-Player.', $player); $this->maniaControl->getChat()->sendError('Error while connecting a Fake-Player.', $player);
} }
} }
@ -336,11 +382,11 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* @param Player $player * @param Player $player
*/ */
public function command_RemoveFakePlayers(array $chatCallback, Player $player) { public function command_RemoveFakePlayers(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_ADD_BOT) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_ADD_BOT)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
$this->maniaControl->getClient()->disconnectFakePlayer('*'); $this->maniaControl->getClient()->disconnectFakePlayer('*');
$this->maniaControl->getChat()->sendSuccess('Fake players disconnected!', $player); $this->maniaControl->getChat()->sendSuccess('Fake players disconnected!', $player);
} }
@ -349,32 +395,52 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
* Handle //mute Command * Handle //mute Command
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $admin * @param Player $player
*/ */
public function command_MutePlayer(array $chatCallback, Player $admin) { public function command_MutePlayer(array $chatCallback, Player $player) {
$commandParts = explode(' ', $chatCallback[1][2]); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_MUTE_PLAYER)) {
if (count($commandParts) <= 1) { $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
$this->maniaControl->getChat()->sendUsageInfo("No login specified! Example: '//mute login'", $admin);
return; return;
} }
$commandParts = explode(' ', $chatCallback[1][2]);
if (count($commandParts) <= 1) {
$message = $this->maniaControl->getChat()->formatMessage(
'No Login given! Example: %s',
'//mute login'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return;
}
$targetLogin = $commandParts[1]; $targetLogin = $commandParts[1];
$this->maniaControl->getPlayerManager()->getPlayerActions()->mutePlayer($admin->login, $targetLogin); $this->maniaControl->getPlayerManager()->getPlayerActions()->mutePlayer($player, $targetLogin);
} }
/** /**
* Handle //unmute Command * Handle //unmute Command
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $admin * @param Player $player
*/ */
public function command_UnmutePlayer(array $chatCallback, Player $admin) { public function command_UnmutePlayer(array $chatCallback, Player $player) {
$commandParts = explode(' ', $chatCallback[1][2]); if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, PlayerActions::SETTING_PERMISSION_MUTE_PLAYER)) {
if (count($commandParts) <= 1) { $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
$this->maniaControl->getChat()->sendUsageInfo("No login specified! Example: '//unmute login'", $admin);
return; return;
} }
$commandParts = explode(' ', $chatCallback[1][2]);
if (count($commandParts) <= 1) {
$message = $this->maniaControl->getChat()->formatMessage(
'No Login given! Example: %s',
'//unmute login'
);
$this->maniaControl->getChat()->sendUsageInfo($message, $player);
return;
}
$targetLogin = $commandParts[1]; $targetLogin = $commandParts[1];
$this->maniaControl->getPlayerManager()->getPlayerActions()->unMutePlayer($admin->login, $targetLogin); $this->maniaControl->getPlayerManager()->getPlayerActions()->unMutePlayer($player, $targetLogin);
} }
/** /**

View File

@ -714,13 +714,13 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
break; break;
case self::ACTION_ADD_AS_MASTER: case self::ACTION_ADD_AS_MASTER:
case self::ACTION_ADD_AS_SUPER: case self::ACTION_ADD_AS_SUPER:
$this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_SUPERADMIN); $this->maniaControl->getPlayerManager()->getPlayerActions()->grantAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
break; break;
case self::ACTION_ADD_AS_ADMIN: case self::ACTION_ADD_AS_ADMIN:
$this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->getPlayerManager()->getPlayerActions()->grantAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_ADMIN);
break; break;
case self::ACTION_ADD_AS_MOD: case self::ACTION_ADD_AS_MOD:
$this->maniaControl->getPlayerManager()->getPlayerActions()->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->getPlayerManager()->getPlayerActions()->grantAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_MODERATOR);
break; break;
case self::ACTION_REVOKE_RIGHTS: case self::ACTION_REVOKE_RIGHTS:
$this->maniaControl->getPlayerManager()->getPlayerActions()->revokeAuthLevel($adminLogin, $targetLogin); $this->maniaControl->getPlayerManager()->getPlayerActions()->revokeAuthLevel($adminLogin, $targetLogin);
@ -737,7 +737,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$votesPlugin->defineVote('forcespec', 'Force ' . $target->getEscapedNickname() . ' Spec', true, $startMessage); $votesPlugin->defineVote('forcespec', 'Force ' . $target->getEscapedNickname() . ' Spec', true, $startMessage);
$votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) { $votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) {
$this->maniaControl->getChat()->sendInformation('$sVote successful -> Player ' . $target->getEscapedNickname() . ' forced to Spectator!'); $message = $this->maniaControl->getChat()->formatMessage(
'Vote successful -> %s forced to Spectator!',
$target
);
$this->maniaControl->getChat()->sendSuccess($message);
$votesPlugin->undefineVote('forcespec'); $votesPlugin->undefineVote('forcespec');
try { try {
@ -761,10 +765,14 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$votesPlugin->defineVote('kick', 'Kick ' . $target->getEscapedNickname(), true, $startMessage); $votesPlugin->defineVote('kick', 'Kick ' . $target->getEscapedNickname(), true, $startMessage);
$votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) { $votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) {
$this->maniaControl->getChat()->sendInformation('$sVote successful -> ' . $target->getEscapedNickname() . ' got Kicked!'); $message = $this->maniaControl->getChat()->formatMessage(
'Vote successful -> %s got kicked!',
$target
);
$this->maniaControl->getChat()->sendSuccess($message);
$votesPlugin->undefineVote('kick'); $votesPlugin->undefineVote('kick');
$message = '$39F You got kicked due to a Public Vote!$z '; $message = '$39FYou got kicked due to a Public Vote!';
try { try {
$this->maniaControl->getClient()->kick($target->login, $message); $this->maniaControl->getClient()->kick($target->login, $message);
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
@ -780,7 +788,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$neededPage = (int) substr($action, strlen(self::ACTION_PAGING_CHUNKS)); $neededPage = (int) substr($action, strlen(self::ACTION_PAGING_CHUNKS));
$this->showPlayerList($player, $neededPage - 1); $this->showPlayerList($player, $neededPage - 1);
} }
} }
} }

View File

@ -42,7 +42,6 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis
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_COLORING = 'Enable Join & Leave Coloring';
const SETTING_JOIN_LEAVE_LOGIN = 'Enable Join & Leave Login';
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';
@ -95,7 +94,6 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis
// Settings // Settings
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_JOIN_LEAVE_COLORING, false); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_JOIN_LEAVE_COLORING, false);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_JOIN_LEAVE_LOGIN, 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);
@ -375,8 +373,8 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis
return; return;
} }
$played = Formatter::formatTimeH(time() - $player->joinTime); $playTime = Formatter::formatTimeH(time() - $player->joinTime);
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}"; $logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$playTime}";
Logger::logInfo($logMessage, true); Logger::logInfo($logMessage, true);
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)
@ -387,13 +385,13 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis
$color = $this->maniaControl->getColorManager()->getColorByPlayer($player); $color = $this->maniaControl->getColorManager()->getColorByPlayer($player);
} }
$nickname = Formatter::escapeText('$fff' . $player->nickname); $authName = $player->getAuthLevelName();
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_LOGIN)) { $message = $this->maniaControl->getChat()->formatMessage(
$nickname .= 'Login: ' . Formatter::escapeText('$fff' . $player->login); "{$color}{$authName} %s has left after %s!",
} $player,
$playTime
$authname = AuthenticationManager::getAuthLevelName($player->authLevel); );
$this->maniaControl->getChat()->sendChat("{$color}{$authname} {$nickname} has left after \$<\$fff{$played}\$>!"); $this->maniaControl->getChat()->sendChat($message);
} }
//Destroys stored PlayerData, after all Disconnect Callbacks got Handled //Destroys stored PlayerData, after all Disconnect Callbacks got Handled
@ -504,24 +502,26 @@ class PlayerManager implements CallbackListener, TimerListener, CommunicationLis
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_COLORING)) { if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_COLORING)) {
$color = $this->maniaControl->getColorManager()->getColorByPlayer($player); $color = $this->maniaControl->getColorManager()->getColorByPlayer($player);
} }
$nickname = Formatter::escapeText('$fff' . $player->nickname);
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_LOGIN)) {
$nickname .= 'Login: ' . Formatter::escapeText('$fff' . $player->login);
}
$authname = AuthenticationManager::getAuthLevelName($player->authLevel); $authName = $player->getAuthLeveName();
$nation = '$<$fff' . $player->getCountry() . '$>';
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->isFakePlayer()) {
$chatMessage = "{$color}{$authname} {$nickname} Nation: {$nation} joined!"; $message = $this->maniaControl->getChat()->formatMessage(
$this->maniaControl->getChat()->sendChat($chatMessage); "{$color}{$authName} %s Nation: %s joined!",
$player,
$player->getCountry()
);
$this->maniaControl->getChat()->sendChat($message);
} else if ($player->isSpectator && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES_SPECTATOR)) { } else if ($player->isSpectator && $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_JOIN_LEAVE_MESSAGES_SPECTATOR)) {
$chatMessage = "{$color}{$authname} {$nickname} Nation: {$nation} joined as Spectator!"; $message = $this->maniaControl->getChat()->formatMessage(
$this->maniaControl->getChat()->sendChat($chatMessage); "{$color}{$authName} %s Nation: %s joined as Spectator!",
$player,
$player->getCountry()
);
$this->maniaControl->getChat()->sendChat($message);
} }
$this->maniaControl->getChat()->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login); $this->maniaControl->getChat()->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player);
$logMessage = "Player joined: {$player->login} / {$player->nickname} Nation: {$nation} IP: {$player->ipAddress}"; $logMessage = "Player joined: {$player->login} / {$player->nickname} Nation: {$nation} IP: {$player->ipAddress}";
Logger::logInfo($logMessage, true); Logger::logInfo($logMessage, true);