From a8069ad874af514e7892a6d427371522b958c0ac Mon Sep 17 00:00:00 2001 From: beu Date: Fri, 21 Mar 2025 11:55:27 +0100 Subject: [PATCH] add Fast Kick plugin --- .gitignore | 3 +- Beu/FastKick.php | 239 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 Beu/FastKick.php diff --git a/.gitignore b/.gitignore index 0434a9e..07e6ee6 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ !Beu/ReloadDevTool.php !Beu/SimpleChatColorer.php !Beu/SimpleSkinsRemover.php -!Beu/SmallTextOverlay.php \ No newline at end of file +!Beu/SmallTextOverlay.php +!Beu/FastKick.php \ No newline at end of file diff --git a/Beu/FastKick.php b/Beu/FastKick.php new file mode 100644 index 0000000..6e5796e --- /dev/null +++ b/Beu/FastKick.php @@ -0,0 +1,239 @@ +maniaControl = $maniaControl; + + $this->maniaControl->getCommandManager()->registerCommandListener(['fkick', 'fk', 'fastkick'], $this, 'handleFastKick', true); + + $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_CLOSE, $this, 'handleClose'); + $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener('/^'. self::ACTION_KICK .'/', $this, 'handleKick'); + } + + /** + * handle Fast Kick command + * + * @param array $structure + * @param Player $adminPlayer + * @return void + */ + public function handleFastKick(array $structure, Player $adminPlayer) { + if (!$this->maniaControl->getAuthenticationManager()->checkPermission($adminPlayer, PlayerActions::SETTING_PERMISSION_KICK_PLAYER)) { + $this->maniaControl->getAuthenticationManager()->sendNotAllowed($adminPlayer); + return; + } + + $params = explode(' ', $structure[1][2], 3); + if (count($params) <= 1 || $params[1] === '') { + $message = $this->maniaControl->getChat()->formatMessage( + 'No player name given! Example: %s', + $params[0] .' ' + ); + $this->maniaControl->getChat()->sendUsageInfo($message, $adminPlayer); + return; + } + + $target = $params[1]; + + $players = $this->maniaControl->getPlayerManager()->getPlayers(); + + $indexedList = []; + foreach ($players as $player) { + similar_text($target, $player->nickname, $percent); + $indexedList[intval($percent)][] = $player; + } + krsort($indexedList); + + $manialink = new ManiaLink(self::MANIALINK_ID); + + $parentFrame = new Frame(); + $manialink->addChild($parentFrame); + $parentFrame->setPosition(-150., -35., 100.); + + $background = new Quad(); + $parentFrame->addChild($background); + $background->setHorizontalAlign(Quad::LEFT); + $background->setVerticalAlign(Quad::TOP); + $background->setBackgroundColor('000000'); + $background->setOpacity(0.7); + $background->setSize(60., 25.); + $background->setZ(-1.); + + $closeButton = new Quad_Icons64x64_1(); + $parentFrame->addChild($closeButton); + $closeButton->setPosition(58., -2.); + $closeButton->setSize(6, 6); + $closeButton->setSubStyle($closeButton::SUBSTYLE_QuitRace); + $closeButton->setAction(self::ACTION_CLOSE); + + $headerName = new Label(); + $parentFrame->addChild($headerName); + $headerName->setPosition(1., -3); + $headerName->setHorizontalAlign($headerName::LEFT); + $headerName->setTextFont('GameFontExtraBold'); + $headerName->setTextColor('ffffff'); + $headerName->setTextSize(1.5); + $headerName->setText('Player Name'); + + $headerMatching = new Label(); + $parentFrame->addChild($headerMatching); + $headerMatching->setPosition(40., -3); + $headerMatching->setHorizontalAlign($headerMatching::CENTER); + $headerMatching->setTextFont('GameFontExtraBold'); + $headerMatching->setTextColor('ffffff'); + $headerMatching->setTextSize(1.5); + $headerMatching->setText('Matching'); + + $count = 1; + $posY = -7.; + foreach ($indexedList as $percent => $players) { + foreach ($players as $player) { + $frame = new Frame(); + $parentFrame->addChild($frame); + $frame->setY($posY); + + $name = new Label(); + $frame->addChild($name); + $name->setX(1.5); + $name->setSize(30., 3.5); + $name->setHorizontalAlign($name::LEFT); + $name->setTextFont('GameFontSemiBold'); + $name->setTextColor('ffffff'); + $name->setTextSize(1.2); + $name->setText($player->nickname); + + $matching = new Label(); + $frame->addChild($matching); + $matching->setX(40.); + $matching->setHorizontalAlign($name::CENTER); + $matching->setTextFont('GameFontSemiBold'); + $matching->setTextColor('ffffff'); + $matching->setTextSize(1.2); + $matching->setText($percent . '%'); + + $kickButton = new Quad(); + $frame->addChild($kickButton); + $kickButton->setX(57.); + $kickButton->setSize(4, 4); + $kickButton->setStyle('UICommon64_2'); + $kickButton->setSubStyle('UserDelete_light'); + $kickButton->setAction(self::ACTION_KICK . '.' . $player->login); + + $posY += -3.8; + $count++; + if ($count > 5) break 2; + } + } + + $this->maniaControl->getManialinkManager()->sendManialink($manialink, $adminPlayer, ToggleUIFeature: false); + } + + public function handleClose(array $structure, Player $adminPlayer) { + $this->maniaControl->getManialinkManager()->hideManialink(self::MANIALINK_ID, $adminPlayer); + } + + public function handleKick(array $structure, Player $adminPlayer) { + if (!$this->maniaControl->getAuthenticationManager()->checkPermission($adminPlayer, PlayerActions::SETTING_PERMISSION_KICK_PLAYER)) { + $this->maniaControl->getAuthenticationManager()->sendNotAllowed($adminPlayer); + return; + } + $targetLogin = explode('.', $structure[1][2])[1]; + + $targetPlayer = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin); + Logger::log("========================= Fast kick info: ===="); + Logger::log(json_encode($targetPlayer)); + Logger::log(json_encode($this->maniaControl->getClient()->getNetworkStats())); + + $this->maniaControl->getPlayerManager()->getPlayerActions()->kickPlayer($adminPlayer, $targetLogin); + $this->maniaControl->getManialinkManager()->hideManialink(self::MANIALINK_ID, $adminPlayer); + } + + /** + * Unload the plugin and its Resources + */ + public function unload() {} +} \ No newline at end of file