diff --git a/.gitignore b/.gitignore index d578018..29dc9be 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ !MatchManagerSuite !MatchManagerSuite/* !Beu +!Beu/AFKNotifier.php !Beu/ChatAdminColorer.php !Beu/ReloadDevTool.php !Beu/GuestlistManager.php diff --git a/Beu/AFKNotifier.php b/Beu/AFKNotifier.php new file mode 100644 index 0000000..018eff5 --- /dev/null +++ b/Beu/AFKNotifier.php @@ -0,0 +1,122 @@ +maniaControl = $maniaControl; + + $this->maniaControl->getCallbackManager()->registerScriptCallbackListener(self::CB_IsAFK, $this, 'handleIsAFK'); + } + + /** + * Handle when a player disconnects + * + * @param array $data + */ + public function handleIsAFK(array $data) { + $json = json_decode($data[1][0],false); + foreach ($json->accountIds as $accountid) { + $login = $this->getLoginFromAccountID($accountid); + Logger::log("Player " . $login . " has been kicked by the AFK lib"); + + $player = $this->maniaControl->getPlayerManager()->getPlayer($login); + + if ($player !== null) { + $this->maniaControl->getChat()->sendInformation("\$ff9" . $player->nickname . " has been kicked for being AFK"); + } + } + } + + private function getLoginFromAccountID(string $accountid) { + $accountid = str_replace("-","", $accountid); + $login = ""; + foreach(str_split($accountid, 2) as $pair){ + $login .= chr(hexdec($pair)); + } + $login = base64_encode($login); + $login = str_replace("+", "-", str_replace("/","_",$login)); + $login = trim($login,"="); + + return $login; + } + + + /** + * Unload the plugin and its Resources + */ + public function unload() { + + } +}