From 9a6d07e73b691a3376c9fc9519dd7c0fa587467b Mon Sep 17 00:00:00 2001 From: Max Klaversma Date: Wed, 16 Apr 2014 02:07:17 +0200 Subject: [PATCH] Added temporary chatbased pluginlist command, showing not-installed plugins via WS --- application/core/Update/UpdateManager.php | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/application/core/Update/UpdateManager.php b/application/core/Update/UpdateManager.php index 23a35596..9b33f51c 100644 --- a/application/core/Update/UpdateManager.php +++ b/application/core/Update/UpdateManager.php @@ -75,6 +75,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener $this->maniaControl->commandManager->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true); $this->maniaControl->commandManager->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true); $this->maniaControl->commandManager->registerCommandListener('pluginupdate', $this, 'handle_PluginUpdate', true); + $this->maniaControl->commandManager->registerCommandListener('pluginlist', $this, 'handle_PluginList', true); $this->currentBuildDate = $this->getNightlyBuildDate(); } @@ -347,6 +348,39 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener $this->checkPluginsUpdate($player); } + /** + * Handle //pluginlist command + * + * @param array $chatCallback + * @param Player $player + */ + public function handle_PluginList(array $chatCallback, Player $player) { + if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) { + $this->maniaControl->authenticationManager->sendNotAllowed($player); + return; + } + + $url = ManiaControl::URL_WEBSERVICE . 'plugins'; + $dataJson = FileUtil::loadFile($url); + $pluginList = json_decode($dataJson); + if (!$pluginList || !isset($pluginList[0])) { + $this->maniaControl->chat->sendInformation('Pluginlist could not be retrieved from the Web Services!', $player->login); + } + + $pluginClasses = $this->maniaControl->pluginManager->getPluginClasses(); + $pluginIds = array(); + /** @var Plugin $class */ + foreach($pluginClasses as $class) { + $pluginIds[] = $class::getId(); + } + + foreach($pluginList as $plugin) { + if(!in_array($plugin->id, $pluginIds)) { + $this->maniaControl->chat->sendInformation($plugin->name.' (v'.$plugin->currentVersion->version.') - '.$plugin->description, $player->login); + } + } + } + /** * Checks if there are outdated plugins active. * @param Player $player