added maniacontrol restart callback

This commit is contained in:
kremsy 2015-06-26 16:53:41 +02:00
parent 0b02f63309
commit 82e1dd1c65
4 changed files with 14 additions and 2 deletions

View File

@ -16,6 +16,7 @@
- added Method getSpectators() in PlayerManager - added Method getSpectators() in PlayerManager
- added some missing PHP Docs - added some missing PHP Docs
- added some depency libraries as they are used by the Socket Handler - 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 - updated some depency libraries
#Bug Fixes #Bug Fixes

View File

@ -18,6 +18,7 @@ interface Callbacks {
const ONINIT = 'Callbacks.OnInit'; const ONINIT = 'Callbacks.OnInit';
const AFTERINIT = 'Callbacks.AfterInit'; const AFTERINIT = 'Callbacks.AfterInit';
const ONSHUTDOWN = 'Callbacks.OnShutdown'; const ONSHUTDOWN = 'Callbacks.OnShutdown';
const ONRESTART = 'Callbacks.OnRestart';
/** Script Callback: CallbackName, CallbackData */ /** Script Callback: CallbackName, CallbackData */
const SCRIPTCALLBACK = 'Callbacks.ScriptCallback'; const SCRIPTCALLBACK = 'Callbacks.ScriptCallback';

View File

@ -54,6 +54,7 @@ class CommunicationManager implements CallbackListener {
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings'); $this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'initCommunicationManager'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'initCommunicationManager');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONRESTART, $this, 'onShutDown');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONSHUTDOWN, $this, 'onShutDown'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONSHUTDOWN, $this, 'onShutDown');
} }
@ -92,6 +93,12 @@ class CommunicationManager implements CallbackListener {
/** Close all Sockets on maniaControl Shutdown */ /** Close all Sockets on maniaControl Shutdown */
public function onShutDown() { public function onShutDown() {
if ($this->socket && $this->socket->master) {
//Stop the Socket Listening
$this->socket->shutdown();
$this->socket = null;
}
foreach ($this->communications as $communication) { foreach ($this->communications as $communication) {
$this->closeCommunication($communication); $this->closeCommunication($communication);
} }
@ -235,6 +242,7 @@ class CommunicationManager implements CallbackListener {
$this->socket = new Server($this->loop); $this->socket = new Server($this->loop);
$this->socket->on('error', function ($e) { $this->socket->on('error', function ($e) {
$this->maniaControl->chat->sendChat($e);
Logger::log("[CommunicationManager] Socket Error" . $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 = openssl_decrypt($msg, self::ENCRYPTION_METHOD, $password, OPENSSL_RAW_DATA, self::ENCRYPTION_IV);
$data = json_decode($data); $data = json_decode($data);
if ($data == null) { if ($data == null) {
$data = array("error" => true, "data" => "Data is not provided as an valid AES-196-encrypted encrypted JSON"); $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")) { } else if (!property_exists($data, "method") || !property_exists($data, "data")) {

View File

@ -228,7 +228,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
$this->restart($data->message); $this->restart($data->message);
} }
$this->restart(); $this->restart();
}, 5000); }, 3000);
return new CommunicationAnswer(); return new CommunicationAnswer();
}); });
} }
@ -507,6 +507,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
* @param string $message * @param string $message
*/ */
public function restart($message = null) { public function restart($message = null) {
// Trigger callback on Restart
$this->getCallbackManager()->triggerCallback(Callbacks::ONRESTART);
// Announce restart // Announce restart
try { try {
$this->getChat()->sendInformation('Restarting ManiaControl...'); $this->getChat()->sendInformation('Restarting ManiaControl...');