diff --git a/application/ManiaControl.php b/application/ManiaControl.php index 12409a48..bd032986 100644 --- a/application/ManiaControl.php +++ b/application/ManiaControl.php @@ -5,6 +5,7 @@ define('LOG_WRITE_CURRENT_FILE', 'ManiaControl.log'); // Write current log to extra file in base dir define('LOG_NAME_USE_DATE', true); // Use current date as suffix for log file name in logs folder define('LOG_NAME_USE_PID', true); // Use current process id as suffix for log file name in logs folder +define('E_FATAL', E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_USER_ERROR); // Define base dir define('ManiaControlDir', __DIR__); diff --git a/application/core/ErrorHandler.php b/application/core/ErrorHandler.php index 14639f99..9c3ff9bf 100644 --- a/application/core/ErrorHandler.php +++ b/application/core/ErrorHandler.php @@ -33,7 +33,7 @@ class ErrorHandler { */ public function exceptionHandler(\Exception $ex) { $message = "[ManiaControl EXCEPTION]: {$ex->getMessage()}" . PHP_EOL; - $message .= "Class: ". get_class($ex) . PHP_EOL; + $message .= "Class: " . get_class($ex) . PHP_EOL; $message .= "Trace: {$ex->getTraceAsString()}" . PHP_EOL; logMessage($message); @@ -57,6 +57,8 @@ class ErrorHandler { if (!json_decode($success)) { logMessage("Exception-Report failed"); + } else { + logMessage("Exception successfully reported!"); } exit(); @@ -101,11 +103,13 @@ class ErrorHandler { $success = FileUtil::loadFile($url); if (!json_decode($success)) { - logMessage("Error-Report failed"); + logMessage("Error-Report failed!"); + } else { + logMessage("Error successfully reported!"); } } - if ($errorNumber == E_ERROR || $errorNumber == E_USER_ERROR) { + if ($errorNumber == E_ERROR || $errorNumber == E_USER_ERROR || $errorNumber == E_FATAL) { logMessage('Stopping execution...'); exit(); } @@ -128,6 +132,15 @@ class ErrorHandler { if ($errorLevel == E_ERROR) { return '[PHP ERROR]'; } + if ($errorLevel == E_CORE_ERROR) { + return '[PHP CORE ERROR]'; + } + if ($errorLevel == E_COMPILE_ERROR) { + return '[PHP COMPILE ERROR]'; + } + if ($errorLevel == E_RECOVERABLE_ERROR) { + return '[PHP RECOVERABLE ERROR]'; + } if ($errorLevel == E_USER_NOTICE) { return '[ManiaControl NOTICE]'; } diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index 31f90230..5ba2ba8e 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -219,10 +219,16 @@ class ManiaControl implements CommandListener { $this->client->sendHideManialinkPage(); } catch(Exception $e) { } - + // Close the client connection $this->client->delete($this->server->ip, $this->server->port); + //Check and Trigger Fatal Errors + $error = error_get_last(); + if ($error && ($error['type'] & E_FATAL)) { + $this->errorHandler->errorHandler($error['type'], $error['message'], $error['file'], $error['line']); + } + $this->log('Quitting ManiaControl!'); exit(); } @@ -284,7 +290,7 @@ class ManiaControl implements CommandListener { // Loading finished $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); // Main loop while(!$this->shutdownRequested) { diff --git a/application/plugins/ServerRanking.php b/application/plugins/ServerRanking.php index 59f7db40..72687e17 100644 --- a/application/plugins/ServerRanking.php +++ b/application/plugins/ServerRanking.php @@ -214,7 +214,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener { $requiredRecords = 3; - $query = 'SELECT playerIndex, COUNT(*) AS Cnt + $query = 'SELECT playerIndex, COUNT(*) AS Cnt FROM ' . LocalRecordsPlugin::TABLE_RECORDS . ' GROUP BY PlayerIndex HAVING Cnt >=' . $requiredRecords;