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