From b72e036cf755ce553bb031fb1145a0a85fbf1f88 Mon Sep 17 00:00:00 2001 From: kremsy Date: Mon, 23 Dec 2013 21:47:39 +0100 Subject: [PATCH] improved player actions --- application/core/Players/PlayerActions.php | 82 +++++++++++++++++++-- application/core/Players/PlayerCommands.php | 8 +- application/core/Players/PlayerList.php | 12 +-- application/core/Players/PlayerManager.php | 4 +- 4 files changed, 85 insertions(+), 21 deletions(-) diff --git a/application/core/Players/PlayerActions.php b/application/core/Players/PlayerActions.php index 359a275c..cf5ab20e 100644 --- a/application/core/Players/PlayerActions.php +++ b/application/core/Players/PlayerActions.php @@ -3,6 +3,7 @@ namespace ManiaControl\Players; +use ManiaControl\Admin\AuthenticationManager; use ManiaControl\ManiaControl; class PlayerActions { @@ -28,32 +29,97 @@ class PlayerActions { /** * Forces a Player to a certain team * @param $adminLogin - * @param $login + * @param $targetLogin * @param $teamId */ - public function forcePlayerToTeam($adminLogin, $login, $teamId){ - $this->maniaControl->client->query('ForcePlayerTeam', $login, $teamId); //TODO bestätigung und chatnachricht + public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId){ //TODO get used by playercommands + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $target = $this->maniaControl->playerManager->getPlayer($targetLogin); + if($target->isSpectator){ + $success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, self::SPECTATOR_PLAYER); + if (!$success) { + $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); + return; + } + } + + $success = $this->maniaControl->client->query('ForcePlayerTeam', $targetLogin, $teamId); //TODO bestätigung und chatnachricht + + if (!$success) { + $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); + return; + } + + if($teamId == self::BLUE_TEAM) + $this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!'); + else if($teamId == self::RED_TEAM) + $this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!'); } /** * Forces a Player to spectator * @param $adminLogin - * @param $login + * @param $targetLogin * @param int $spectatorState */ - public function forcePlayerToSpectator($adminLogin, $login, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE){ - $this->maniaControl->client->query('ForceSpectator', $login, $spectatorState); //TODO bestätigung und chatnachricht + public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE){ //TODO get used by playercommands + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $target = $this->maniaControl->playerManager->getPlayer($targetLogin); + + $success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState); //TODO bestätigung und chatnachricht + if (!$success) { + $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); + return; + } + + $this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to spectator!'); //TODO add admin title } + /** + * Warn a Player + * @param $adminLogin + * @param $login + * @param string $message + */ public function warnPlayer($adminLogin, $login, $message = ''){ } - public function kickPlayer($adminLogin, $login, $message = ''){ + /** + * Kicks a Player + * @param $adminLogin + * @param $targetLogin + * @param string $message + */ + public function kickPlayer($adminLogin, $targetLogin, $message = ''){ + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $target = $this->maniaControl->playerManager->getPlayer($targetLogin); + + $success = $this->maniaControl->client->query('Kick', $target->login, $message); //TODO bestätigung und chatnachricht + if (!$success) { + $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); + return; + } + $this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!'); //TODO add admin title } - public function banPlayer($adminLogin, $login, $message = ''){ + /** + * Bans a Player + * @param $adminLogin + * @param $targetLogin + * @param string $message + */ + public function banPlayer($adminLogin, $targetLogin, $message = ''){ + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $target = $this->maniaControl->playerManager->getPlayer($targetLogin); + $success = $this->maniaControl->client->query('Ban', $target->login, $message); //TODO bestätigung und chatnachricht + + if (!$success) { + $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); + return; + } + $this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!'); //TODO add admin title } } \ No newline at end of file diff --git a/application/core/Players/PlayerCommands.php b/application/core/Players/PlayerCommands.php index d039922a..d10fb2d5 100644 --- a/application/core/Players/PlayerCommands.php +++ b/application/core/Players/PlayerCommands.php @@ -92,12 +92,8 @@ class PlayerCommands implements CommandListener { if (isset($params[2])) { $message = $params[2]; } - $success = $this->maniaControl->client->query('Kick', $target->login, $message); - if (!$success) { - $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); - return; - } - $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> kicked $<' . $target->nickname . '$>!'); + + $this->maniaControl->playerManager->playerActions->kickPlayer($player->login, $target, $message); } /** diff --git a/application/core/Players/PlayerList.php b/application/core/Players/PlayerList.php index 1e4809a0..985cd926 100644 --- a/application/core/Players/PlayerList.php +++ b/application/core/Players/PlayerList.php @@ -38,12 +38,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { const ACTION_PLAYER_ADV = 'PlayerList.PlayerAdvancedActions'; const ACTION_CLOSE_PLAYER_ADV = 'PlayerList.ClosePlayerAdvWidget'; - const ACTION_WARN_PLAYER = ' PlayerList.WarnPlayer'; - const ACTION_KICK_PLAYER = ' PlayerList.KickPlayer'; - const ACTION_BAN_PLAYER = ' PlayerList.BanPlayer'; - const ACTION_ADD_AS_MASTER = ' PlayerList.PlayerAddAsMaster'; - const ACTION_ADD_AS_ADMIN = ' PlayerList.PlayerAddAsAdmin'; - const ACTION_ADD_AS_MOD = ' PlayerList.PlayerAddAsModerator'; + const ACTION_WARN_PLAYER = 'PlayerList.WarnPlayer'; + const ACTION_KICK_PLAYER = 'PlayerList.KickPlayer'; + const ACTION_BAN_PLAYER = 'PlayerList.BanPlayer'; + const ACTION_ADD_AS_MASTER = 'PlayerList.PlayerAddAsMaster'; + const ACTION_ADD_AS_ADMIN = 'PlayerList.PlayerAddAsAdmin'; + const ACTION_ADD_AS_MOD = 'PlayerList.PlayerAddAsModerator'; /** * Private properties diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index 8da4ad24..8899b1e4 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -176,8 +176,10 @@ class PlayerManager implements CallbackListener { * @param array $callback */ public function playerInfoChanged(array $callback){ - //TODO something on playerjoin not working here (maybe because it get called before player join $player = $this->getPlayer($callback[1][0]['Login']); + if($player == null) + return; + $player->teamId = $callback[1][0]["TeamId"]; $player->isSpectator = $callback[1][0]["SpectatorStatus"]; $player->ladderRank = $callback[1][0]["LadderRanking"];