fixed //checkupdate

This commit is contained in:
Steffen Schröder 2014-04-29 23:53:55 +02:00
parent 200f199c06
commit ab375e636e

View File

@ -41,7 +41,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
* Private Properties * Private Properties
*/ */
private $maniaControl = null; private $maniaControl = null;
/** @var UpdateData $coreUpdateData */ /**
*
* @var UpdateData $coreUpdateData
*/
private $coreUpdateData = null; private $coreUpdateData = null;
private $currentBuildDate = ""; private $currentBuildDate = "";
@ -105,7 +108,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$updateChannel = $maniaControl->settingManager->getSetting($self, UpdateManager::SETTING_UPDATECHECK_CHANNEL); $updateChannel = $maniaControl->settingManager->getSetting($self, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
if ($updateChannel != UpdateManager::CHANNEL_NIGHTLY) { if ($updateChannel != UpdateManager::CHANNEL_NIGHTLY) {
$maniaControl->log('New ManiaControl Version ' . $updateData->version . ' available!'); $maniaControl->log('New ManiaControl Version ' . $updateData->version . ' available!');
} else { }
else {
$maniaControl->log('New Nightly Build (' . $updateData->releaseDate . ') available!'); $maniaControl->log('New Nightly Build (' . $updateData->releaseDate . ') available!');
} }
$self->setCoreUpdateData($updateData); $self->setCoreUpdateData($updateData);
@ -134,7 +138,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL); $updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL);
if ($updateChannel != self::CHANNEL_NIGHTLY) { if ($updateChannel != self::CHANNEL_NIGHTLY) {
$this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login); $this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
} else { }
else {
$this->maniaControl->chat->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login); $this->maniaControl->chat->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login);
} }
} }
@ -178,7 +183,6 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$this->performCoreUpdate($this->coreUpdateData); $this->performCoreUpdate($this->coreUpdateData);
} }
/** /**
* Handle //checkupdate command * Handle //checkupdate command
* *
@ -191,27 +195,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return; return;
} }
$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL); $updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL);
if ($updateChannel != self::CHANNEL_NIGHTLY) { if ($updateChannel === self::CHANNEL_NIGHTLY) {
// Check update and send result message
$self = $this;
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self, &$player) {
if (!$updateData) {
$self->maniaControl->chat->sendInformation('No Update available!', $player->login);
return;
}
$version = $self->maniaControl->client->getVersion();
if ($updateData->minDedicatedBuild > $version->build) {
$self->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login);
return;
}
$self->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
});
} else {
// Special nightly channel updating // Special nightly channel updating
$self = $this; $self = $this;
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self, &$player) { $this->checkCoreUpdateAsync(function ($updateData) use(&$self, &$player) {
if (!$updateData) { if (!$updateData) {
$self->maniaControl->chat->sendInformation('No Update available!', $player->login); $self->maniaControl->chat->sendInformation('No Update available!', $player->login);
return; return;
@ -231,11 +218,32 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return; return;
} }
$self->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->releaseDate . ') available, current build: ' . $self->currentBuildDate . '!', $player->login); $self->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->releaseDate . ') available, current build: ' . $self->currentBuildDate . '!', $player->login);
} else { }
else {
$self->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->releaseDate . ') available!', $player->login); $self->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->releaseDate . ') available!', $player->login);
} }
}, true); }, true);
} }
else {
// Check update and send result message
$self = $this;
$this->checkCoreUpdateAsync(function ($updateData) use(&$self, &$player) {
if (!$updateData) {
$self->maniaControl->chat->sendInformation('No Update available!', $player->login);
return;
}
$version = $self->maniaControl->client->getVersion();
if ($updateData->minDedicatedBuild > $version->build) {
$self->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login);
return;
}
$self->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
});
}
} }
/** /**
@ -255,7 +263,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN)); $pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
if ($pluginClass == 'All') { if ($pluginClass == 'All') {
$this->checkPluginsUpdate($player); $this->checkPluginsUpdate($player);
} else { }
else {
$newUpdate = $this->checkPluginUpdate($pluginClass); $newUpdate = $this->checkPluginUpdate($pluginClass);
if ($newUpdate != false) { if ($newUpdate != false) {
$newUpdate->pluginClass = $pluginClass; $newUpdate->pluginClass = $pluginClass;
@ -404,7 +413,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
foreach ($outdatedPlugins as $plugin) { foreach ($outdatedPlugins as $plugin) {
$self->updatePlugin($plugin, $player); $self->updatePlugin($plugin, $player);
} }
} else { }
else {
$self->maniaControl->log('[UPDATE] Checking plugins: COMPLETE, all plugins are up-to-date!'); $self->maniaControl->log('[UPDATE] Checking plugins: COMPLETE, all plugins are up-to-date!');
if ($player) { if ($player) {
$self->maniaControl->chat->sendInformation('Checking plugins: COMPLETE, all plugins are up-to-date!', $player->login); $self->maniaControl->chat->sendInformation('Checking plugins: COMPLETE, all plugins are up-to-date!', $player->login);
@ -423,7 +433,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if (is_object($pluginClass)) { if (is_object($pluginClass)) {
$pluginClass = get_class($pluginClass); $pluginClass = get_class($pluginClass);
} }
/** @var Plugin $pluginClass */ /**
*
* @var Plugin $pluginClass
*/
$pluginId = $pluginClass::getId(); $pluginId = $pluginClass::getId();
$url = ManiaControl::URL_WEBSERVICE . 'plugins?id=' . $pluginId; $url = ManiaControl::URL_WEBSERVICE . 'plugins?id=' . $pluginId;
$dataJson = FileUtil::loadFile($url); $dataJson = FileUtil::loadFile($url);
@ -459,7 +472,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$pluginsWS[$plugin->id] = $plugin; $pluginsWS[$plugin->id] = $plugin;
} }
/** @var Plugin $pluginClass */ /**
*
* @var Plugin $pluginClass
*/
foreach ($this->maniaControl->pluginManager->getPluginClasses() as $pluginClass) { foreach ($this->maniaControl->pluginManager->getPluginClasses() as $pluginClass) {
$pluginId = $pluginClass::getId(); $pluginId = $pluginClass::getId();
if (array_key_exists($pluginId, $pluginsWS)) { if (array_key_exists($pluginId, $pluginsWS)) {
@ -602,7 +618,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
continue; continue;
} }
/** @var Plugin $className */ /**
*
* @var Plugin $className
*/
$self->maniaControl->pluginManager->addPluginClass($className); $self->maniaControl->pluginManager->addPluginClass($className);
$className::prepare($self->maniaControl); $className::prepare($self->maniaControl);
@ -641,7 +660,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
*/ */
private function checkCoreUpdateAsync($function, $ignoreVersion = false) { private function checkCoreUpdateAsync($function, $ignoreVersion = false) {
$updateChannel = $this->getCurrentUpdateChannelSetting(); $updateChannel = $this->getCurrentUpdateChannelSetting();
$url = ManiaControl::URL_WEBSERVICE . 'versions?update=1&current=1&channel=' . $updateChannel; $url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel;
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use(&$function, $ignoreVersion) { $this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use(&$function, $ignoreVersion) {
$versions = json_decode($dataJson); $versions = json_decode($dataJson);
@ -650,10 +669,11 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
} }
$updateData = new UpdateData($versions[0]); $updateData = new UpdateData($versions[0]);
if (!$ignoreVersion && $updateData->version <= ManiaControl::VERSION) { if (!$ignoreVersion && $updateData->version <= ManiaControl::VERSION) {
return; call_user_func($function, null);
} }
else {
call_user_func($function, $updateData); call_user_func($function, $updateData);
}
}); });
} }