improved transport exception handling
This commit is contained in:
parent
e56c4dccb5
commit
769015c8d8
@ -211,6 +211,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
* @param bool $errorPrefix
|
* @param bool $errorPrefix
|
||||||
*/
|
*/
|
||||||
public function quit($message = null, $errorPrefix = false) {
|
public function quit($message = null, $errorPrefix = false) {
|
||||||
|
if ($this->getClient()) {
|
||||||
if ($this->getCallbackManager()) {
|
if ($this->getCallbackManager()) {
|
||||||
// OnShutdown callback
|
// OnShutdown callback
|
||||||
$this->getCallbackManager()->triggerCallback(Callbacks::ONSHUTDOWN);
|
$this->getCallbackManager()->triggerCallback(Callbacks::ONSHUTDOWN);
|
||||||
@ -221,16 +222,13 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
$this->getChat()->sendInformation('ManiaControl shutting down.');
|
$this->getChat()->sendInformation('ManiaControl shutting down.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getClient()) {
|
// Hide UI
|
||||||
try {
|
|
||||||
$this->getClient()->sendHideManialinkPage();
|
$this->getClient()->sendHideManialinkPage();
|
||||||
} catch (TransportException $e) {
|
|
||||||
$this->getErrorHandler()->handleException($e, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Delete client
|
||||||
Connection::delete($this->getClient());
|
Connection::delete($this->getClient());
|
||||||
$this->client = null;
|
$this->client = null;
|
||||||
|
}
|
||||||
|
|
||||||
SystemUtil::quit($message, $errorPrefix);
|
SystemUtil::quit($message, $errorPrefix);
|
||||||
}
|
}
|
||||||
@ -244,6 +242,24 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
return $this->client;
|
return $this->client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the callback manager
|
||||||
|
*
|
||||||
|
* @return CallbackManager
|
||||||
|
*/
|
||||||
|
public function getCallbackManager() {
|
||||||
|
return $this->callbackManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the chat
|
||||||
|
*
|
||||||
|
* @return Chat
|
||||||
|
*/
|
||||||
|
public function getChat() {
|
||||||
|
return $this->chat;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the error handler
|
* Return the error handler
|
||||||
*
|
*
|
||||||
@ -386,8 +402,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
* Check connection
|
* Check connection
|
||||||
*/
|
*/
|
||||||
public function checkConnection() {
|
public function checkConnection() {
|
||||||
if ($this->getClient()->getIdleTime() > 180
|
if ($this->getClient()->getIdleTime() > 180) {
|
||||||
) {
|
|
||||||
$this->getClient()->getServerName();
|
$this->getClient()->getServerName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -403,15 +418,6 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
$this->getChat()->sendInformation($message, $player);
|
$this->getChat()->sendInformation($message, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the chat
|
|
||||||
*
|
|
||||||
* @return Chat
|
|
||||||
*/
|
|
||||||
public function getChat() {
|
|
||||||
return $this->chat;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle Restart AdminCommand
|
* Handle Restart AdminCommand
|
||||||
*
|
*
|
||||||
@ -419,8 +425,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function commandRestart(array $chatCallback, Player $player) {
|
public function commandRestart(array $chatCallback, Player $player) {
|
||||||
if (!$this->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_RESTART)
|
if (!$this->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_RESTART)) {
|
||||||
) {
|
|
||||||
$this->getAuthenticationManager()->sendNotAllowed($player);
|
$this->getAuthenticationManager()->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -433,19 +438,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
* @param string $message
|
* @param string $message
|
||||||
*/
|
*/
|
||||||
public function restart($message = null) {
|
public function restart($message = null) {
|
||||||
// Shutdown callback
|
|
||||||
$this->getCallbackManager()->triggerCallback(Callbacks::ONSHUTDOWN);
|
|
||||||
|
|
||||||
// Announce restart
|
// Announce restart
|
||||||
if ($message) {
|
|
||||||
Logger::log($message);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$this->getChat()->sendInformation('Restarting ManiaControl...');
|
$this->getChat()->sendInformation('Restarting ManiaControl...');
|
||||||
$this->getClient()->sendHideManialinkPage();
|
Logger::log('Restarting ManiaControl... ' . $message);
|
||||||
} catch (TransportException $exception) {
|
|
||||||
}
|
|
||||||
Logger::log('Restarting ManiaControl!');
|
|
||||||
|
|
||||||
// Start new instance
|
// Start new instance
|
||||||
SystemUtil::restart();
|
SystemUtil::restart();
|
||||||
@ -454,15 +449,6 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
$this->quit('Quitting ManiaControl to restart.');
|
$this->quit('Quitting ManiaControl to restart.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the callback manager
|
|
||||||
*
|
|
||||||
* @return CallbackManager
|
|
||||||
*/
|
|
||||||
public function getCallbackManager() {
|
|
||||||
return $this->callbackManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle Shutdown Command
|
* Handle Shutdown Command
|
||||||
*
|
*
|
||||||
@ -492,12 +478,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
public function run() {
|
public function run() {
|
||||||
Logger::log('Starting ManiaControl v' . self::VERSION . '!');
|
Logger::log('Starting ManiaControl v' . self::VERSION . '!');
|
||||||
|
|
||||||
// Connect to server
|
|
||||||
try {
|
try {
|
||||||
|
// Connect to server
|
||||||
$this->connect();
|
$this->connect();
|
||||||
} catch (TransportException $e) {
|
|
||||||
$this->quit($e->getMessage(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the version of the server is high enough
|
// Check if the version of the server is high enough
|
||||||
$version = $this->getClient()->getVersion();
|
$version = $this->getClient()->getVersion();
|
||||||
@ -530,6 +513,12 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
|
|
||||||
// Shutdown
|
// Shutdown
|
||||||
$this->quit($this->requestQuitMessage);
|
$this->quit($this->requestQuitMessage);
|
||||||
|
|
||||||
|
} catch (TransportException $exception) {
|
||||||
|
Logger::logError('Connection interrupted!');
|
||||||
|
$this->getErrorHandler()->handleException($exception);
|
||||||
|
SystemUtil::quit($exception->getMessage(), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -555,8 +544,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
$this->getClient()->enableCallbacks(true);
|
$this->getClient()->enableCallbacks(true);
|
||||||
|
|
||||||
// Wait for server to be ready
|
// Wait for server to be ready
|
||||||
if (!$this->getServer()->waitForStatus(4)
|
if (!$this->getServer()->waitForStatus(4)) {
|
||||||
) {
|
|
||||||
$this->quit("Server couldn't get ready!");
|
$this->quit("Server couldn't get ready!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,14 +594,10 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
|
|||||||
// Extend script timeout
|
// Extend script timeout
|
||||||
set_time_limit(self::SCRIPT_TIMEOUT);
|
set_time_limit(self::SCRIPT_TIMEOUT);
|
||||||
|
|
||||||
try {
|
// Manage callbacks
|
||||||
$this->getCallbackManager()->manageCallbacks();
|
$this->getCallbackManager()->manageCallbacks();
|
||||||
} catch (TransportException $e) {
|
|
||||||
Logger::logError('Connection interrupted!');
|
|
||||||
$this->quit($e->getMessage(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Manage FileReader
|
// Manage async file reader
|
||||||
$this->getFileReader()->appendData();
|
$this->getFileReader()->appendData();
|
||||||
|
|
||||||
// Yield for next tick
|
// Yield for next tick
|
||||||
|
Loading…
Reference in New Issue
Block a user