From d8951b725561d09489ecf7d12a5ef4ee6b657654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Mon, 23 Jun 2014 16:14:47 +0200 Subject: [PATCH] handle socket exception on connect --- application/core/ManiaControl.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index 7025bf9f..c71f3518 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -283,6 +283,15 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener { $this->requestQuit("ManiaControl Shutdown requested by '{$player->login}'!"); } + /** + * Request ManiaControl to quit + * + * @param mixed $message + */ + public function requestQuit($message = true) { + $this->requestQuitMessage = $message; + } + /** * Run ManiaControl */ @@ -336,8 +345,11 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener { try { $this->client = Connection::factory($this->server->config->host, $this->server->config->port, self::SCRIPT_TIMEOUT, $this->server->config->user, $this->server->config->pass, self::API_VERSION); - } catch (AuthenticationException $e) { - $message = "Couldn't authenticate on Server with User '{$this->server->config->user}' & Pass '{$this->server->config->pass}'! " . $e->getMessage(); + } catch (TransportException $exception) { + $message = "Couldn't connect to the server: '{$exception->getMessage()}'"; + $this->quit($message, true); + } catch (AuthenticationException $exception) { + $message = "Couldn't authenticate on Server with User '{$this->server->config->user}' & Pass '{$this->server->config->pass}'! " . $exception->getMessage(); $this->quit($message, true); } @@ -401,13 +413,4 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener { public function handleServerStopCallback() { $this->requestQuit('The Server has been shut down!'); } - - /** - * Request ManiaControl to quit - * - * @param mixed $message - */ - public function requestQuit($message = true) { - $this->requestQuitMessage = $message; - } }