diff --git a/Beu/ChatAdminColorer.php b/Beu/ChatAdminColorer.php new file mode 100644 index 0000000..a224801 --- /dev/null +++ b/Beu/ChatAdminColorer.php @@ -0,0 +1,130 @@ +maniaControl = $maniaControl; + $this->maniaControl->getCallbackManager()->registerCallbackListener('ManiaPlanet.PlayerChat', $this, 'handlePlayerChat'); + try { + $this->maniaControl->getClient()->chatEnableManualRouting(); + $this->enabled = true; + } catch (\Exception $ex) { + $this->enabled = false; + echo "error! \n"; + } + } + + public function handlePlayerChat($callback) { + $args = $callback[1]; + $this->onPlayerChatter($args[0], $args[1], $args[2]); + } + + private function onPlayerChatter($playerUid, $login, $text) { + if ($playerUid != 0 && substr($text, 0, 1) != "/" && $this->enabled) { + $source_player = $this->maniaControl->getPlayerManager()->getPlayer($login); + if ($source_player == null) { + return; + } + $nick = $source_player->nickname; + $authLevel = $source_player->authLevel; + + if ($authLevel > 0) { + $color = $this->maniaControl->getColorManager()->getColorByLevel($authLevel); + } + + try { + // change text color, if admin is defined at admingroups + if ($authLevel > 0) { + $this->chatSendServerMessage('[$<' . $color . $nick . '$>] ' . $text); + } else { + $this->chatSendServerMessage('[' . $nick . '] ' . $text); + } + } catch (\Exception $e) { + echo "error while sending chat message to $login: " . $e->getMessage() . "\n"; + } + } + } + + public function chatSendServerMessage($text) { + $this->maniaControl->getClient()->chatSendServerMessage($text); + } + + /** + * Unload the plugin and its Resources + */ + public function unload() { + $this->maniaControl->getClient()->chatEnableManualRouting(false); + $this->maniaControl->getCallbackManager()->unregisterCallbackListening('ManiaPlanet.OnPlayerChat', $this); + + } +}