diff --git a/changelog.txt b/changelog.txt index b62ce875..b3d4ebd2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -16,6 +16,7 @@ - added Method getSpectators() in PlayerManager - added some missing PHP Docs - added some depency libraries as they are used by the Socket Handler +- added additional Callback which gets triggered on ManiaControl Restart - updated some depency libraries #Bug Fixes diff --git a/core/Callbacks/Callbacks.php b/core/Callbacks/Callbacks.php index 79684657..75b3fab8 100644 --- a/core/Callbacks/Callbacks.php +++ b/core/Callbacks/Callbacks.php @@ -18,6 +18,7 @@ interface Callbacks { const ONINIT = 'Callbacks.OnInit'; const AFTERINIT = 'Callbacks.AfterInit'; const ONSHUTDOWN = 'Callbacks.OnShutdown'; + const ONRESTART = 'Callbacks.OnRestart'; /** Script Callback: CallbackName, CallbackData */ const SCRIPTCALLBACK = 'Callbacks.ScriptCallback'; diff --git a/core/Communication/CommunicationManager.php b/core/Communication/CommunicationManager.php index 7931c143..80c06458 100644 --- a/core/Communication/CommunicationManager.php +++ b/core/Communication/CommunicationManager.php @@ -54,6 +54,7 @@ class CommunicationManager implements CallbackListener { $this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'initCommunicationManager'); + $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONRESTART, $this, 'onShutDown'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONSHUTDOWN, $this, 'onShutDown'); } @@ -92,6 +93,12 @@ class CommunicationManager implements CallbackListener { /** Close all Sockets on maniaControl Shutdown */ public function onShutDown() { + if ($this->socket && $this->socket->master) { + //Stop the Socket Listening + $this->socket->shutdown(); + $this->socket = null; + } + foreach ($this->communications as $communication) { $this->closeCommunication($communication); } @@ -235,6 +242,7 @@ class CommunicationManager implements CallbackListener { $this->socket = new Server($this->loop); $this->socket->on('error', function ($e) { + $this->maniaControl->chat->sendChat($e); Logger::log("[CommunicationManager] Socket Error" . $e); }); @@ -253,7 +261,6 @@ class CommunicationManager implements CallbackListener { $data = openssl_decrypt($msg, self::ENCRYPTION_METHOD, $password, OPENSSL_RAW_DATA, self::ENCRYPTION_IV); $data = json_decode($data); - if ($data == null) { $data = array("error" => true, "data" => "Data is not provided as an valid AES-196-encrypted encrypted JSON"); } else if (!property_exists($data, "method") || !property_exists($data, "data")) { diff --git a/core/ManiaControl.php b/core/ManiaControl.php index 37d43017..9ac3cf8f 100644 --- a/core/ManiaControl.php +++ b/core/ManiaControl.php @@ -228,7 +228,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, $this->restart($data->message); } $this->restart(); - }, 5000); + }, 3000); return new CommunicationAnswer(); }); } @@ -507,6 +507,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, * @param string $message */ public function restart($message = null) { + // Trigger callback on Restart + $this->getCallbackManager()->triggerCallback(Callbacks::ONRESTART); + // Announce restart try { $this->getChat()->sendInformation('Restarting ManiaControl...');