diff --git a/.gitignore b/.gitignore index 7845072..7fd62ba 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ !Beu/GameModeLoader.php !Beu/GuestlistManager.php !Beu/MoreModesTools.php +!Beu/OpenplanetDetector.php !Beu/ReloadDevTool.php !Beu/SimpleChatColorer.php !Beu/SimpleSkinsRemover.php diff --git a/Beu/OpenplanetDetector.php b/Beu/OpenplanetDetector.php new file mode 100644 index 0000000..e08804f --- /dev/null +++ b/Beu/OpenplanetDetector.php @@ -0,0 +1,211 @@ +maniaControl = $maniaControl; + $this->manialink = $this->getManialink(); + + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIGNATURE_BLACKLIST, "DEVMODE", "Comma separated signature banned (Only used is whitelist is empty)"); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIGNATURE_WHITELIST, "", "Comma separated signature allowed."); + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ACTION, [self::ACTION_FORCE_AS_SPEC, self::ACTION_KICK], ""); + + $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); + $this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener('/^Maniacontrol.OpenplanetDetector:/', $this, 'handleOpenplanetSignature'); + + $this->maniaControl->getManialinkManager()->sendManialink($this->manialink); + } + + /** + * handleOpenplanetSignature + * + * @param array $callback + * @param Player $player + * @return void + */ + public function handleOpenplanetSignature(array $callback, Player $player) { + $whitelist = array_filter(explode(',', $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SIGNATURE_WHITELIST))); + $signature = explode(':', $callback[1][2])[1]; + if ($signature === "") $signature = "REGULAR"; + + if (count($whitelist) > 0) { + if (!in_array($signature, $whitelist)) { + $this->triggerAction($player, $signature); + } + } else { + $blacklist = array_filter(explode(',', $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SIGNATURE_BLACKLIST))); + + if (in_array($signature, $blacklist)) { + $this->triggerAction($player, $signature); + } + } + } + + /** + * triggerAction + * + * @param Player $player + * @param string $signature + * @return void + * @throws InvalidArgumentException + */ + private function triggerAction(Player $player, string $signature) { + $this->maniaControl->getChat()->sendInformationToAdmins("Player ". $player->nickname ." has the wrong Openplanet Signature: " . $signature); + Logger::log("Player ". $player->nickname ." has the wrong Openplanet Signature: " . $signature); + + switch ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ACTION)) { + case self::ACTION_FORCE_AS_SPEC: + $this->maniaControl->getClient()->forceSpectator($player->login, 1); + $this->maniaControl->getChat()->sendInformation("Your Openplanet signature is not allowed. Change it and try to re-join the server", $player->login); + break; + case self::ACTION_KICK: + $this->maniaControl->getClient()->kick($player->login, "Your Openplanet signature is not allowed. Change it and try to re-join the server"); + break; + } + } + + /** + * Handle when a player connects + * + * @param Player $player + */ + public function handlePlayerConnect(Player $player) { + $this->maniaControl->getManialinkManager()->sendManialink($this->manialink, $player->login); + } + + /** + * Unload the plugin and its Resources + */ + public function unload() {} + + /** + * getManialink + * + * @return string + */ + private function getManialink() { + return <<<'EOD' + + + + +EOD; + } +}