From ae8dc2aed50e2cd202f22a8afea0efa9a44c8200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Mon, 6 Jan 2014 18:09:47 +0100 Subject: [PATCH] player actions and commands improved --- application/core/Players/PlayerActions.php | 43 +++++++++++--- application/core/Players/PlayerCommands.php | 63 +++++++++++++++------ 2 files changed, 83 insertions(+), 23 deletions(-) diff --git a/application/core/Players/PlayerActions.php b/application/core/Players/PlayerActions.php index 102317e8..6e3b0683 100644 --- a/application/core/Players/PlayerActions.php +++ b/application/core/Players/PlayerActions.php @@ -22,8 +22,8 @@ class PlayerActions { /** * Constants */ - const BLUE_TEAM = 0; - const RED_TEAM = 1; + const TEAM_BLUE = 0; + const TEAM_RED = 1; const SPECTATOR_USER_SELECTABLE = 0; const SPECTATOR_SPECTATOR = 1; const SPECTATOR_PLAYER = 2; @@ -43,6 +43,33 @@ class PlayerActions { $this->maniaControl = $maniaControl; } + /** + * Force a Player to Play + * + * @param string $adminLogin + * @param string $targetLogin + * @param int $type + */ + public function forcePlayerToPlay($adminLogin, $targetLogin, $type = 2) { + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + $this->maniaControl->authenticationManager->sendNotAllowed($admin); + return; + } + $target = $this->maniaControl->playerManager->getPlayer($targetLogin); + if (!$target) return; + + $success = $this->maniaControl->client->query('ForceSpectator', $target->login, ($type != 1 ? 0 : 2)); + if (!$success) { + $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); + return; + } + + // Announce force + $chatMessage = '$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Play!'; + $this->maniaControl->chat->sendInformation($chatMessage); + } + /** * Force a Player to a certain Team * @@ -51,10 +78,13 @@ class PlayerActions { * @param int $teamId */ public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) { - // TODO: get used by playercommands $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + $this->maniaControl->authenticationManager->sendNotAllowed($admin); + return; + } $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - if (!$admin || !$target) return; + if (!$target) return; if ($target->isSpectator) { $success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_PLAYER); @@ -72,10 +102,10 @@ class PlayerActions { $chatMessage = false; $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - if ($teamId == self::BLUE_TEAM) { + if ($teamId == self::TEAM_BLUE) { $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!'; } - else if ($teamId == self::RED_TEAM) { + else if ($teamId == self::TEAM_RED) { $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!'; } if (!$chatMessage) return; @@ -92,7 +122,6 @@ class PlayerActions { * @param bool $releaseSlot */ public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) { - // TODO: get used by playercommands $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { $this->maniaControl->authenticationManager->sendNotAllowed($admin); diff --git a/application/core/Players/PlayerCommands.php b/application/core/Players/PlayerCommands.php index 9caafca8..624ce2a5 100644 --- a/application/core/Players/PlayerCommands.php +++ b/application/core/Players/PlayerCommands.php @@ -44,8 +44,9 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { $this->maniaControl->commandManager->registerCommandListener('kick', $this, 'command_Kick', true); $this->maniaControl->commandManager->registerCommandListener('forcespec', $this, 'command_ForceSpectator', true); $this->maniaControl->commandManager->registerCommandListener('forcespectator', $this, 'command_ForceSpectator', true); - $this->maniaControl->commandManager->registerCommandListener('forceplay', $this, 'command_ForcePlayer', true); - $this->maniaControl->commandManager->registerCommandListener('forceplayer', $this, 'command_ForcePlayer', true); + $this->maniaControl->commandManager->registerCommandListener('forceplay', $this, 'command_ForcePlay', true); + $this->maniaControl->commandManager->registerCommandListener('forceblue', $this, 'command_ForceBlue', true); + $this->maniaControl->commandManager->registerCommandListener('forcered', $this, 'command_ForceRed', true); $this->maniaControl->commandManager->registerCommandListener('addbot', $this, 'command_AddFakePlayers', true); $this->maniaControl->commandManager->registerCommandListener('removebot', $this, 'command_RemoveFakePlayers', true); $this->maniaControl->commandManager->registerCommandListener('addbots', $this, 'command_AddFakePlayers', true); @@ -192,35 +193,65 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { * @param array $chat * @param Player $player */ - public function command_ForcePlayer(array $chat, Player $player) { + public function command_ForcePlay(array $chat, Player $player) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { $this->maniaControl->authenticationManager->sendNotAllowed($player); return; } $params = explode(' ', $chat[1][2]); if (!isset($params[1])) { - $this->maniaControl->chat->sendUsageInfo('Usage example: //forceplay login', $player->login); - return; - } - $target = $params[1]; - $target = $this->maniaControl->playerManager->getPlayer($target); - if (!$target) { - $this->maniaControl->chat->sendError("Invalid player login.", $player->login); + $this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forceplay login'", $player->login); return; } + $targetLogin = $params[1]; + $type = 2; if (isset($params[2]) && is_numeric($params[2])) { $type = intval($params[2]); } - $success = $this->maniaControl->client->query('ForceSpectator', $target->login, 2); - if (!$success) { - $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); + $this->maniaControl->playerManager->playerActions->forcePlayerToPlay($player->login, $targetLogin, $type); + } + + /** + * Handle //forceblue command + * + * @param array $chat + * @param Player $player + */ + public function command_ForceBlue(array $chat, Player $player) { + if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + $this->maniaControl->authenticationManager->sendNotAllowed($player); return; } - if ($type != 1) { - $this->maniaControl->client->query('ForceSpectator', $target->login, 0); + $params = explode(' ', $chat[1][2]); + if (!isset($params[1])) { + $this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forceblue login'", $player->login); + return; } - $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to player!'); + $targetLogin = $params[1]; + + $this->maniaControl->playerManager->playerActions->forcePlayerToTeam($player->login, $targetLogin, PlayerActions::TEAM_BLUE); + } + + /** + * Handle //forcered command + * + * @param array $chat + * @param Player $player + */ + public function command_ForceRed(array $chat, Player $player) { + if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + $this->maniaControl->authenticationManager->sendNotAllowed($player); + return; + } + $params = explode(' ', $chat[1][2]); + if (!isset($params[1])) { + $this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forcered login'", $player->login); + return; + } + $targetLogin = $params[1]; + + $this->maniaControl->playerManager->playerActions->forcePlayerToTeam($player->login, $targetLogin, PlayerActions::TEAM_RED); } /**