Added specific plugin updates in configurator

This commit is contained in:
Max Klaversma 2014-04-16 01:22:31 +02:00 committed by Steffen Schröder
parent e3c4e6048e
commit b4d131404d
2 changed files with 45 additions and 2 deletions

View File

@ -9,6 +9,7 @@ use FML\Controls\Label;
use FML\Controls\Labels\Label_Button; use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text; use FML\Controls\Labels\Label_Text;
use FML\Controls\Quads\Quad_Icons128x32_1; use FML\Controls\Quads\Quad_Icons128x32_1;
use FML\Controls\Quads\Quad_Icons128x128_1;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Script\Script; use FML\Script\Script;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
@ -37,6 +38,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
const ACTION_PREFIX_SETTING = 'PluginMenuSetting'; const ACTION_PREFIX_SETTING = 'PluginMenuSetting';
const ACTION_SETTING_BOOL = 'PluginMenuActionBoolSetting.'; const ACTION_SETTING_BOOL = 'PluginMenuActionBoolSetting.';
const ACTION_BACK_TO_PLUGINS = 'PluginMenu.BackToPlugins'; const ACTION_BACK_TO_PLUGINS = 'PluginMenu.BackToPlugins';
const ACTION_PREFIX_UPDATEPLUGIN = 'PluginMenu.Update.';
const SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS = 'Change Plugin Settings'; const SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS = 'Change Plugin Settings';
/* /*
@ -316,6 +318,16 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$statusChangeButton->setAction(self::ACTION_PREFIX_ENABLEPLUGIN . $pluginClass); $statusChangeButton->setAction(self::ACTION_PREFIX_ENABLEPLUGIN . $pluginClass);
} }
if ($this->maniaControl->updateManager->checkPluginUpdate($pluginClass) != false) {
$quadUpdate = new Quad_Icons128x128_1();
$pluginFrame->add($quadUpdate);
$quadUpdate->setSubStyle($quadUpdate::SUBSTYLE_ProfileVehicle);
$quadUpdate->setX(56);
$quadUpdate->setZ(2);
$quadUpdate->setSize(5, 5);
$quadUpdate->setAction(self::ACTION_PREFIX_UPDATEPLUGIN . $pluginClass);
}
$y -= $entryHeight; $y -= $entryHeight;
if ($index % $pageMaxCount == $pageMaxCount - 1) { if ($index % $pageMaxCount == $pageMaxCount - 1) {
unset($pageFrame); unset($pageFrame);

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Update; namespace ManiaControl\Update;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
@ -11,6 +12,7 @@ use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
use ManiaControl\Plugins\PluginMenu;
/** /**
* Manager checking for ManiaControl Core and Plugin Updates * Manager checking for ManiaControl Core and Plugin Updates
@ -63,6 +65,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$this->maniaControl->timerManager->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval); $this->maniaControl->timerManager->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval);
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'autoUpdate'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'autoUpdate');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
//define Permissions //define Permissions
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
@ -232,6 +235,28 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
} }
} }
/**
* Handle PlayerManialinkPageAnswer callback
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$update = (strpos($actionId, PluginMenu::ACTION_PREFIX_UPDATEPLUGIN) === 0);
$login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login);
if($update) {
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
$newUpdate = $this->checkPluginUpdate($pluginClass);
if($newUpdate != false) {
$newUpdate->pluginClass = $pluginClass;
$this->updatePlugin($newUpdate, $player, true);
}
}
}
/** /**
* Get the Build Date of the local Nightly Build Version * Get the Build Date of the local Nightly Build Version
* *
@ -382,9 +407,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
* *
* @param $pluginData * @param $pluginData
* @param Player $player * @param Player $player
* @param bool $reopen
*/ */
private function updatePlugin($pluginData, Player $player = null) { private function updatePlugin($pluginData, Player $player = null, $reopen = false) {
$this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($updateFileContent, $error) use (&$updateData, &$player, &$pluginData) { $this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($updateFileContent, $error) use (&$updateData, &$player, &$pluginData, &$reopen) {
$this->maniaControl->log('[UPDATE] Now updating '.$pluginData->name.' ...'); $this->maniaControl->log('[UPDATE] Now updating '.$pluginData->name.' ...');
if ($player) { if ($player) {
$this->maniaControl->chat->sendInformation('Now updating '.$pluginData->name.' ...', $player->login); $this->maniaControl->chat->sendInformation('Now updating '.$pluginData->name.' ...', $player->login);
@ -423,6 +449,11 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$this->maniaControl->chat->sendSuccess('Successfully updated '.$pluginData->name.'!', $player->login); $this->maniaControl->chat->sendSuccess('Successfully updated '.$pluginData->name.'!', $player->login);
$this->maniaControl->pluginManager->deactivatePlugin($pluginData->pluginClass); $this->maniaControl->pluginManager->deactivatePlugin($pluginData->pluginClass);
$this->maniaControl->pluginManager->activatePlugin($pluginData->pluginClass); $this->maniaControl->pluginManager->activatePlugin($pluginData->pluginClass);
if ($reopen) {
$menuId = $this->maniaControl->configurator->getMenuId('Plugins');
$this->maniaControl->configurator->reopenMenu($player, $menuId);
}
} }
}); });
} }