From 96eda851df8fdc51c8edde35d4827ea4c6065604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Tue, 31 Dec 2013 16:01:22 +0100 Subject: [PATCH] Improved Player Actions --- application/core/Players/PlayerActions.php | 245 +++++++++++---------- application/core/Players/PlayerList.php | 56 ++--- 2 files changed, 160 insertions(+), 141 deletions(-) diff --git a/application/core/Players/PlayerActions.php b/application/core/Players/PlayerActions.php index 97d5c9fa..d710ee32 100644 --- a/application/core/Players/PlayerActions.php +++ b/application/core/Players/PlayerActions.php @@ -2,7 +2,6 @@ namespace ManiaControl\Players; - use FML\Controls\Control; use FML\Controls\Frame; use FML\Controls\Labels\Label_Text; @@ -26,114 +25,126 @@ class PlayerActions { */ const BLUE_TEAM = 0; const RED_TEAM = 1; - const SPECTATOR_USER_SELECTABLE = 0; const SPECTATOR_SPECTATOR = 1; const SPECTATOR_PLAYER = 2; const SPECTATOR_BUT_KEEP_SELECTABLE = 3; + /** - * Private properties + * Private Properties */ private $maniaControl = null; + /** + * Create a PlayerActions Instance + * + * @param ManiaControl $maniaControl + */ public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; } /** - * Forces a Player to a certain team - * @param $adminLogin - * @param $targetLogin - * @param $teamId + * Force a Player to a certain Team + * + * @param string $adminLogin + * @param string $targetLogin + * @param int $teamId */ - public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId){ //TODO get used by playercommands + public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) { + // TODO: get used by playercommands $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); + if (!$admin || !$target) return; $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - - if($target->isSpectator){ - $success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, self::SPECTATOR_PLAYER); + + if ($target->isSpectator) { + $success = $this->maniaControl->client->query('ForceSpectator', $target->login, 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 - + + $success = $this->maniaControl->client->query('ForcePlayerTeam', $target->login, $teamId); if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - - if($teamId == self::BLUE_TEAM){ - $this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!'); - $this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' forced player '. Formatter::stripCodes($target->nickname) . ' into the Blue-Team'); - }else if($teamId == self::RED_TEAM){ - $this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!'); - $this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' forced player '. Formatter::stripCodes($target->nickname) . ' into the Red-Team'); + + $chatMessage = false; + if ($teamId == self::BLUE_TEAM) { + $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!'; } + else if ($teamId == self::RED_TEAM) { + $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!'; + } + if (!$chatMessage) return; + $this->maniaControl->chat->sendInformation($chatMessage); + $this->maniaControl->log(Formatter::stripCodes($chatMessage)); } /** - * Forces a Player to spectator - * @param $adminLogin - * @param $targetLogin + * Force a Player to Spectator + * + * @param string $adminLogin + * @param string $targetLogin * @param int $spectatorState */ - public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE){ //TODO get used by playercommands + 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); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - - $success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState); //TODO bestätigung + + $success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState); if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - - $this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to spectator!'); - - // log console message - $this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' forced player '. Formatter::stripCodes($target->nickname) . ' to Spectator'); + + $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Spectator!'; + $this->maniaControl->chat->sendInformation($chatMessage); + $this->maniaControl->log(Formatter::stripCodes($chatMessage)); } /** * Warn a Player - * @param $adminLogin - * @param $targetLogin + * + * @param string $adminLogin + * @param string $targetLogin */ - public function warnPlayer($adminLogin, $targetLogin){ //TODO chatcommand + public function warnPlayer($adminLogin, $targetLogin) { + // TODO: chatcommand $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - + // display warning message $message = '$s$f00This is an administrative warning.{br}{br}$gWhatever you wrote or you have done is against {br} our server\'s policy. {br}Not respecting other players, or{br}using offensive language might result in a{br}$f00kick, or ban $ff0the next time. {br}{br}$gThe server administrators.'; $message = preg_split('/{br}/', $message); - - + $width = 80; $height = 50; $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle(); - + $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); - - //mainframe + + // mainframe $frame = new Frame(); $maniaLink->add($frame); - $frame->setSize($width,$height); + $frame->setSize($width, $height); $frame->setPosition(0, 10); - - //Background Quad + + // Background Quad $backgroundQuad = new Quad(); $frame->add($backgroundQuad); - $backgroundQuad->setSize($width,$height); + $backgroundQuad->setSize($width, $height); $backgroundQuad->setStyles($quadStyle, $quadSubstyle); - + // Add Close Quad (X) $closeQuad = new Quad_Icons64x64_1(); $frame->add($closeQuad); @@ -141,8 +152,8 @@ class PlayerActions { $closeQuad->setSize(6, 6); $closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace); $closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET); - - //Headline Label + + // Headline Label $label = new Label_Text(); $frame->add($label); $label->setHAlign(Control::CENTER); @@ -152,14 +163,14 @@ class PlayerActions { $label->setTextSize(4); $label->setText('Administrative Warning'); $label->setTextColor('F00'); - + $y = $height / 2 - 15; - foreach ($message as &$line){ - //Warn Labels + foreach ($message as &$line) { + // Warn Labels $label = new Label_Text(); $frame->add($label); $label->setHAlign(Control::CENTER); - //$label->setX(-$width / 2 + 5); + // $label->setX(-$width / 2 + 5); $label->setX(0); $label->setY($y); $label->setStyle(Label_Text::STYLE_TextCardMedium); @@ -168,128 +179,132 @@ class PlayerActions { $label->setTextColor('FF0'); $y -= 4; } - - - //render and display xml + + // Display manialink $this->maniaControl->manialinkManager->displayWidget($maniaLink, $target); - - // log console message - $this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' warned player '. Formatter::stripCodes($target->nickname)); - - // show chat message - $this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> warned $<' . $target->nickname . '$>!'); + + $chatMessage = $title . ' $<' . $admin->nickname . '$> warned $<' . $target->nickname . '$>!'; + $this->maniaControl->chat->sendInformation($chatMessage); + $this->maniaControl->log(Formatter::stripCodes($chatMessage)); } - /** * Kicks a Player - * @param $adminLogin - * @param $targetLogin + * + * @param string $adminLogin + * @param string $targetLogin * @param string $message */ - public function kickPlayer($adminLogin, $targetLogin, $message = ''){ + public function kickPlayer($adminLogin, $targetLogin, $message = '') { $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - - if($target->isFakePlayer()) + + if ($target->isFakePlayer()) { $success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login); - else - $success = $this->maniaControl->client->query('Kick', $target->login, $message); //TODO bestätigung + } + else { + $success = $this->maniaControl->client->query('Kick', $target->login, $message); + } + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - $this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!'); - - // log console message - $this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' kicked player '. Formatter::stripCodes($target->nickname)); + + $chatMessage = $title . ' $<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!'; + $this->maniaControl->chat->sendInformation($chatMessage); + $this->maniaControl->log(Formatter::stripCodes($chatMessage)); } /** * Bans a Player - * @param $adminLogin - * @param $targetLogin + * + * @param string $adminLogin + * @param string $targetLogin * @param string $message */ - public function banPlayer($adminLogin, $targetLogin, $message = ''){ + public function banPlayer($adminLogin, $targetLogin, $message = '') { $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - - $success = $this->maniaControl->client->query('Ban', $target->login, $message); //TODO bestätigung - + + $success = $this->maniaControl->client->query('Ban', $target->login, $message); // TODO bestätigung + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - $this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!'); - - // log console message - $this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' banned player '. Formatter::stripCodes($target->nickname)); + + $chatMessage = $title . ' $<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!'; + $this->maniaControl->chat->sendInformation($chatMessage); + $this->maniaControl->log(Formatter::stripCodes($chatMessage)); } /** - * Grands Player an authorization level - * @param $adminLogin - * @param $targetLogin - * @param $authLevel + * Grands the Player an Authorization Level + * + * @param string $adminLogin + * @param string $targetLogin + * @param int $authLevel */ - public function grandAuthLevel($adminLogin, $targetLogin, $authLevel){ + public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) { $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - - if($this->maniaControl->authenticationManager->checkRight($target,$authLevel)){ - $this->maniaControl->chat->sendError('This admin is already ' . $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel), $admin->login); + + if ($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) { + $this->maniaControl->chat->sendError( + 'This Player is already ' . $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel), + $admin->login); return; } - + $authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel); - - if($this->maniaControl->authenticationManager->checkRight($admin,$authLevel) <= $this->maniaControl->authenticationManager->checkRight($target,$authLevel)){ + + if ($this->maniaControl->authenticationManager->checkRight($admin, $authLevel) <= + $this->maniaControl->authenticationManager->checkRight($target, $authLevel)) { $this->maniaControl->chat->sendError('You don\'t have the permission to add a ' . $authLevelName . '!', $admin->login); return; } - + $success = $this->maniaControl->authenticationManager->grantAuthLevel($target, $authLevel); - + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - - $this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> added $<' . $target->nickname . '$> as $< ' . $authLevelName. '$>!'); - - // log console message - $this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' added player '. Formatter::stripCodes($target->nickname) . ' as ' . $authLevelName); + + $chatMessage = $title . ' $<' . $admin->nickname . '$> added $<' . $target->nickname . '$> as $< ' . $authLevelName . '$>!'; + $this->maniaControl->chat->sendInformation($chatMessage); + $this->maniaControl->log(Formatter::stripCodes($chatMessage)); } /** - * Revokes all rights from a Admin - * @param $adminLogin - * @param $targetLogin + * Revokes all Rights from the Player + * + * @param string $adminLogin + * @param string $targetLogin */ - public function revokeAuthLevel($adminLogin, $targetLogin){ + public function revokeAuthLevel($adminLogin, $targetLogin) { $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); - - if($this->maniaControl->authenticationManager->checkRight($target,AuthenticationManager::AUTH_LEVEL_MASTERADMIN)){ + + if ($this->maniaControl->authenticationManager->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) { $this->maniaControl->chat->sendError('MasterAdmins can\'t be removed ', $admin->login); return; } - + $success = $this->maniaControl->authenticationManager->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER); - + if (!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } - - $this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> revokes $<' . $target->nickname . '$> rights!'); - - // log console message - $this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' revokes '. Formatter::stripCodes($target->nickname) . ' rights'); + + $chatMessage = $title . ' $<' . $admin->nickname . '$> revokes the Rights of $<' . $target->nickname . '$>!'; + $this->maniaControl->chat->sendInformation($chatMessage); + $this->maniaControl->log(Formatter::stripCodes($chatMessage)); } -} \ No newline at end of file +} diff --git a/application/core/Players/PlayerList.php b/application/core/Players/PlayerList.php index 8c8a69ff..867156c2 100644 --- a/application/core/Players/PlayerList.php +++ b/application/core/Players/PlayerList.php @@ -160,7 +160,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { // $array = array($i => $x + 5, $listPlayer->nickname => $x + 10, $listPlayer->login => $x + 50, $listPlayer->ladderRank => // $x + 60, $listPlayer->ladderScore => $x + 70, $path => $x + 85); $array = array($i => $x + 5, $listPlayer->nickname => $x + 18, $listPlayer->login => $x + 60, $path => $x + 91); - //$properties = array('profile' => $listPlayer->login, 'script' => $script); + // $properties = array('profile' => $listPlayer->login, 'script' => $script); $this->maniaControl->manialinkManager->labelLine($playerFrame, $array); $playerFrame->setY($y); @@ -238,8 +238,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { $descriptionLabel->setText( $this->maniaControl->authenticationManager->getAuthLevelName($listPlayer->authLevel) . " " . $listPlayer->nickname); $script->addTooltip($rightQuad, $descriptionLabel); - - + // Player Profile Quad $playerQuad = new Quad_UIConstruction_Buttons(); $playerFrame->add($playerQuad); @@ -247,8 +246,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { $playerQuad->setZ(20); $playerQuad->setSubStyle($playerQuad::SUBSTYLE_Author); $playerQuad->setSize(3.8, 3.8); - $script->addProfileButton($playerQuad,$listPlayer->login); - + $script->addProfileButton($playerQuad, $listPlayer->login); + // Description Label $descriptionLabel = new Label(); $frame->add($descriptionLabel); @@ -259,7 +258,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { $descriptionLabel->setVisible(false); $descriptionLabel->setText("View Player profile of " . $listPlayer->nickname); $script->addTooltip($playerQuad, $descriptionLabel); - + switch ($listPlayer->authLevel) { case authenticationManager::AUTH_LEVEL_MASTERADMIN: $rightLabel->setText("MA"); @@ -277,8 +276,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { $rightLabel->setTextColor("fff"); if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) { - - + // Further Player actions Quad $playerQuad = new Quad_Icons64x64_1(); $playerFrame->add($playerQuad); @@ -287,7 +285,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { $playerQuad->setSubStyle($playerQuad::SUBSTYLE_Buddy); $playerQuad->setSize(3.8, 3.8); $playerQuad->setAction(self::ACTION_PLAYER_ADV . "." . $listPlayer->login); - + // Further Player actions Mousover Description $descriptionLabel = new Label(); $frame->add($descriptionLabel); @@ -380,6 +378,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { * @param $login */ public function advancedPlayerWidget(Player $caller, $login) { + if (!$caller) return; $this->playersListShown[$caller->login] = $login; // Show a certain player $this->showPlayerList($caller); // reopen playerlist } @@ -622,48 +621,53 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { public function handleManialinkPageAnswer(array $callback) { $actionId = $callback[1][2]; $actionArray = explode(".", $actionId); + if (count($actionArray) <= 2) { + return; + } + $action = $actionArray[0] . "." . $actionArray[1]; + $adminLogin = $callback[1][1]; + $targetLogin = $actionArray[2]; - // TODO maybe with ids instead of logins, lower network traffic - switch ($actionArray[0] . "." . $actionArray[1]) { + switch ($action) { case self::ACTION_FORCE_BLUE: - $this->maniaControl->playerManager->playerActions->forcePlayerToTeam($callback[1][1], $actionArray[2], - playerActions::BLUE_TEAM); + $this->maniaControl->playerManager->playerActions->forcePlayerToTeam($adminLogin, $targetLogin, + PlayerActions::BLUE_TEAM); break; case self::ACTION_FORCE_RED: - $this->maniaControl->playerManager->playerActions->forcePlayerToTeam($callback[1][1], $actionArray[2], - playerActions::RED_TEAM); + $this->maniaControl->playerManager->playerActions->forcePlayerToTeam($adminLogin, $targetLogin, + PlayerActions::RED_TEAM); break; case self::ACTION_FORCE_SPEC: - $this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($callback[1][1], $actionArray[2], - playerActions::SPECTATOR_BUT_KEEP_SELECTABLE); + $this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($adminLogin, $targetLogin, + PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); break; case self::ACTION_WARN_PLAYER: - $this->maniaControl->playerManager->playerActions->warnPlayer($callback[1][1], $actionArray[2]); + $this->maniaControl->playerManager->playerActions->warnPlayer($adminLogin, $targetLogin); break; case self::ACTION_KICK_PLAYER: - $this->maniaControl->playerManager->playerActions->kickPlayer($callback[1][1], $actionArray[2]); + $this->maniaControl->playerManager->playerActions->kickPlayer($adminLogin, $targetLogin); break; case self::ACTION_BAN_PLAYER: - $this->maniaControl->playerManager->playerActions->banPlayer($callback[1][1], $actionArray[2]); + $this->maniaControl->playerManager->playerActions->banPlayer($adminLogin, $targetLogin); break; case self::ACTION_PLAYER_ADV: - $player = $this->maniaControl->playerManager->getPlayer($callback[1][1]); - $this->advancedPlayerWidget($player, $actionArray[2]); + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $this->advancedPlayerWidget($admin, $targetLogin); break; case self::ACTION_ADD_AS_MASTER: - $this->maniaControl->playerManager->playerActions->grandAuthLevel($callback[1][1], $actionArray[2], + $this->maniaControl->playerManager->playerActions->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_SUPERADMIN); break; case self::ACTION_ADD_AS_ADMIN: - $this->maniaControl->playerManager->playerActions->grandAuthLevel($callback[1][1], $actionArray[2], + $this->maniaControl->playerManager->playerActions->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_ADMIN); break; case self::ACTION_ADD_AS_MOD: - $this->maniaControl->playerManager->playerActions->grandAuthLevel($callback[1][1], $actionArray[2], + $this->maniaControl->playerManager->playerActions->grandAuthLevel($adminLogin, $targetLogin, AuthenticationManager::AUTH_LEVEL_OPERATOR); break; case self::ACTION_REVOKE_RIGHTS: - $this->maniaControl->playerManager->playerActions->revokeAuthLevel($callback[1][1], $actionArray[2]); + $this->maniaControl->playerManager->playerActions->revokeAuthLevel($adminLogin, $targetLogin); break; } }