From 5d6f8d047ceae8d8e9e4ee4524c5cddbf8334de3 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 13 May 2017 23:52:51 +0200 Subject: [PATCH] CommunicationManager added Coreupdate --- core/Communication/CommunicationMethods.php | 3 +++ core/Update/UpdateManager.php | 28 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/Communication/CommunicationMethods.php b/core/Communication/CommunicationMethods.php index 063e458b..9810fa1f 100644 --- a/core/Communication/CommunicationMethods.php +++ b/core/Communication/CommunicationMethods.php @@ -16,6 +16,9 @@ interface CommunicationMethods { */ const RESTART_MANIA_CONTROL = "ManiaControl.Restart"; + /** Update the ManiaControl Core */ + const UPDATE_MANIA_CONTROL_CORE = "UpdateManager.CoreUpdate"; + /** Grands an Authentication Level on a Player * Required Parameters * - login (login of the player) diff --git a/core/Update/UpdateManager.php b/core/Update/UpdateManager.php index 2baee855..2e585ae0 100644 --- a/core/Update/UpdateManager.php +++ b/core/Update/UpdateManager.php @@ -6,6 +6,9 @@ use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Commands\CommandListener; +use ManiaControl\Communication\CommunicationAnswer; +use ManiaControl\Communication\CommunicationListener; +use ManiaControl\Communication\CommunicationMethods; use ManiaControl\Files\AsyncHttpRequest; use ManiaControl\Files\BackupUtil; use ManiaControl\Files\FileUtil; @@ -21,7 +24,7 @@ use ManiaControl\Players\PlayerManager; * @copyright 2014-2017 ManiaControl Team * @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 */ @@ -80,6 +83,12 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener // Children $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; } + $this->checkAndHandleCoreUpdate($player); + } + + /** + * Handle CoreUpdate Asnyc + * + * @param null $player + */ + private function checkAndHandleCoreUpdate($player = null) { $this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) { if (!$updateData) { - $this->maniaControl->getChat()->sendError('Update is currently not possible!', $player); + if ($player) { + $this->maniaControl->getChat()->sendError('Update is currently not possible!', $player); + } return; } if (!$this->checkUpdateDataBuildVersion($updateData)) { - $this->maniaControl->getChat()->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player); + if ($player) { + $this->maniaControl->getChat()->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player); + } return; }