CommunicationManager added Coreupdate

This commit is contained in:
kremsy 2017-05-13 23:52:51 +02:00
parent af10e2c530
commit 5d6f8d047c
2 changed files with 28 additions and 3 deletions

View File

@ -16,6 +16,9 @@ interface CommunicationMethods {
*/ */
const RESTART_MANIA_CONTROL = "ManiaControl.Restart"; const RESTART_MANIA_CONTROL = "ManiaControl.Restart";
/** Update the ManiaControl Core */
const UPDATE_MANIA_CONTROL_CORE = "UpdateManager.CoreUpdate";
/** Grands an Authentication Level on a Player /** Grands an Authentication Level on a Player
* Required Parameters * Required Parameters
* - login (login of the player) * - login (login of the player)

View File

@ -6,6 +6,9 @@ use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Communication\CommunicationAnswer;
use ManiaControl\Communication\CommunicationListener;
use ManiaControl\Communication\CommunicationMethods;
use ManiaControl\Files\AsyncHttpRequest; use ManiaControl\Files\AsyncHttpRequest;
use ManiaControl\Files\BackupUtil; use ManiaControl\Files\BackupUtil;
use ManiaControl\Files\FileUtil; use ManiaControl\Files\FileUtil;
@ -21,7 +24,7 @@ use ManiaControl\Players\PlayerManager;
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class UpdateManager implements CallbackListener, CommandListener, TimerListener { class UpdateManager implements CallbackListener, CommandListener, TimerListener, CommunicationListener {
/* /*
* Constants * Constants
*/ */
@ -80,6 +83,12 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
// Children // Children
$this->pluginUpdateManager = new PluginUpdateManager($maniaControl); $this->pluginUpdateManager = new PluginUpdateManager($maniaControl);
// Communication Methods
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::UPDATE_MANIA_CONTROL_CORE, $this, function ($data) {
$this->checkAndHandleCoreUpdate();
return new CommunicationAnswer();
});
} }
/** /**
@ -502,13 +511,26 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return; return;
} }
$this->checkAndHandleCoreUpdate($player);
}
/**
* Handle CoreUpdate Asnyc
*
* @param null $player
*/
private function checkAndHandleCoreUpdate($player = null) {
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) { $this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
if (!$updateData) { if (!$updateData) {
if ($player) {
$this->maniaControl->getChat()->sendError('Update is currently not possible!', $player); $this->maniaControl->getChat()->sendError('Update is currently not possible!', $player);
}
return; return;
} }
if (!$this->checkUpdateDataBuildVersion($updateData)) { if (!$this->checkUpdateDataBuildVersion($updateData)) {
if ($player) {
$this->maniaControl->getChat()->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player); $this->maniaControl->getChat()->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player);
}
return; return;
} }