added min and max plugin version in plugin install / update

This commit is contained in:
kremsy 2017-03-31 22:32:12 +02:00
parent bd5e4b922e
commit a0639c477a
2 changed files with 25 additions and 4 deletions

View File

@ -21,6 +21,8 @@ class PluginUpdateData {
public $version = null; public $version = null;
public $zipfile = null; public $zipfile = null;
public $url = null; public $url = null;
public $minManiaControlVersion = null;
public $maxManiaControlVersion = null;
/** /**
* Construct new plugin update data instance * Construct new plugin update data instance
@ -37,6 +39,9 @@ class PluginUpdateData {
$this->version = $updateData->currentVersion->version; $this->version = $updateData->currentVersion->version;
$this->zipfile = $updateData->currentVersion->zipfile; $this->zipfile = $updateData->currentVersion->zipfile;
$this->url = $updateData->currentVersion->url; $this->url = $updateData->currentVersion->url;
$this->minManiaControlVersion = $updateData->currentVersion->min_mc_version;
$this->maxManiaControlVersion = $updateData->currentVersion->max_mc_version;
} }
} }

View File

@ -55,8 +55,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
* @param Player $player * @param Player $player
*/ */
public function handle_CheckPluginsUpdate(array $chatCallback, Player $player) { public function handle_CheckPluginsUpdate(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATECHECK) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATECHECK)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
@ -151,8 +150,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
* @param Player $player * @param Player $player
*/ */
public function handle_PluginsUpdate(array $chatCallback, Player $player) { public function handle_PluginsUpdate(array $chatCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATE) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATE)) {
) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return; return;
} }
@ -241,6 +239,24 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
* @param bool $update * @param bool $update
*/ */
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) { private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
if (ManiaControl::VERSION < $pluginUpdateData->minManiaControlVersion) {
$message = "Your ManiaControl Version v" . ManiaControl::VERSION . " is too old for this Plugin (min Required Version): ' . {$pluginUpdateData->minManiaControlVersion}!";
if ($player) {
$this->maniaControl->getChat()->sendError($message, $player);
}
Logger::logError($message);
return;
}
if ($pluginUpdateData->maxManiaControlVersion != -1 && ManiaControl::VERSION > $pluginUpdateData->maxManiaControlVersion) {
$message = "Your ManiaControl Version v" . ManiaControl::VERSION . " is too new for this Plugin (max Version of the Plugin: ' . {$pluginUpdateData->minManiaControlVersion}!";
if ($player) {
$this->maniaControl->getChat()->sendError($message, $player);
}
Logger::logError($message);
return;
}
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $pluginUpdateData->url); $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $pluginUpdateData->url);
$asyncHttpRequest->setCallable(function ($updateFileContent, $error) use ( $asyncHttpRequest->setCallable(function ($updateFileContent, $error) use (
&$pluginUpdateData, &$player, &$update &$pluginUpdateData, &$player, &$update