improved shutdown/quit code

This commit is contained in:
Steffen Schröder 2014-05-29 22:54:43 +02:00
parent 4f8542b854
commit 897630a95c
2 changed files with 12 additions and 9 deletions

View File

@ -6,7 +6,6 @@ use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Files\FileUtil; use ManiaControl\Files\FileUtil;
use ManiaControl\Plugins\PluginManager; use ManiaControl\Plugins\PluginManager;
use ManiaControl\Update\UpdateManager; use ManiaControl\Update\UpdateManager;
use Maniaplanet\DedicatedServer\Connection;
/** /**
* Error and Exception Manager Class * Error and Exception Manager Class
@ -301,10 +300,7 @@ class ErrorHandler {
if ($this->maniaControl->client) { if ($this->maniaControl->client) {
try { try {
// Hide manialinks
$this->maniaControl->client->sendHideManialinkPage(); $this->maniaControl->client->sendHideManialinkPage();
// Close the client connection
Connection::delete($this->maniaControl->client);
} catch (TransportException $e) { } catch (TransportException $e) {
$this->handleException($e, false); $this->handleException($e, false);
} }

View File

@ -177,9 +177,18 @@ class ManiaControl implements CommandListener, TimerListener {
} }
$this->log($message); $this->log($message);
} }
$this->disconnect();
exit(); exit();
} }
/**
* Close the Client Connection
*/
public function disconnect() {
Connection::delete($this->client);
$this->client = null;
}
/** /**
* Check Connection * Check Connection
*/ */
@ -294,7 +303,7 @@ class ManiaControl implements CommandListener, TimerListener {
// Check if the version of the server is high enough // Check if the version of the server is high enough
$version = $this->client->getVersion(); $version = $this->client->getVersion();
if ($version->build < self::MIN_DEDIVERSION) { if ($version->build < self::MIN_DEDIVERSION) {
trigger_error("The Server has Version '{$version->build}', while at least '" . self::MIN_DEDIVERSION . "' is required!", E_USER_ERROR); $this->quit("The Server has Version '{$version->build}', while at least '" . self::MIN_DEDIVERSION . "' is required!", true);
} }
// OnInit callback // OnInit callback
@ -307,12 +316,10 @@ class ManiaControl implements CommandListener, TimerListener {
// AfterInit callback // AfterInit callback
$this->callbackManager->triggerCallback(Callbacks::AFTERINIT); $this->callbackManager->triggerCallback(Callbacks::AFTERINIT);
// Announce ManiaControl
$this->chat->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
// Loading finished // Loading finished
$this->log('Loading completed!'); $this->log('Loading completed!');
$this->log('Link: maniaplanet://#join=' . $this->server->login . '@' . $this->server->titleId); $this->log('Link: maniaplanet://#join=' . $this->server->login . '@' . $this->server->titleId);
$this->chat->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
// Main loop // Main loop
while (!$this->shutdownRequested) { while (!$this->shutdownRequested) {
@ -330,7 +337,7 @@ class ManiaControl implements CommandListener, TimerListener {
// Load remote client // Load remote client
$this->server->loadConfig(); $this->server->loadConfig();
$this->log("Connecting to server at {$this->server->config->host}:{$this->server->config->port}..."); $this->log("Connecting to Server at {$this->server->config->host}:{$this->server->config->port}...");
try { try {
$this->client = Connection::factory($this->server->config->host, $this->server->config->port, self::SCRIPT_TIMEOUT, $this->server->config->login, $this->server->config->pass); $this->client = Connection::factory($this->server->config->host, $this->server->config->port, self::SCRIPT_TIMEOUT, $this->server->config->login, $this->server->config->pass);