2014-01-27 20:28:37 +01:00
|
|
|
<?php
|
2014-02-10 22:04:09 +01:00
|
|
|
|
|
|
|
namespace ManiaControl;
|
|
|
|
|
2014-05-29 22:46:38 +02:00
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2014-02-08 19:33:26 +01:00
|
|
|
use ManiaControl\Files\FileUtil;
|
2014-05-15 14:20:44 +02:00
|
|
|
use ManiaControl\Plugins\PluginManager;
|
2014-02-10 22:54:49 +01:00
|
|
|
use ManiaControl\Update\UpdateManager;
|
2014-06-12 15:46:24 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\TransportException;
|
2014-01-27 20:28:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Error and Exception Manager Class
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-01-27 20:28:37 +01:00
|
|
|
*/
|
|
|
|
class ErrorHandler {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-02-17 12:54:31 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2014-05-04 00:16:50 +02:00
|
|
|
const MC_DEBUG_NOTICE = 'ManiaControl.DebugNotice';
|
2014-04-28 14:14:04 +02:00
|
|
|
const SETTING_RESTART_ON_EXCEPTION = 'Automatically restart on Exceptions';
|
2014-05-18 21:17:30 +02:00
|
|
|
const LOG_SUPPRESSED_ERRORS = false;
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-01-27 21:56:49 +01:00
|
|
|
* Private Properties
|
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
2014-06-12 16:59:24 +02:00
|
|
|
private $handlingError = null;
|
2014-01-27 21:56:49 +01:00
|
|
|
|
2014-01-27 20:28:37 +01:00
|
|
|
/**
|
|
|
|
* Construct Error Handler
|
2014-05-29 22:46:38 +02:00
|
|
|
*
|
|
|
|
* @param ManiaControl @maniaControl
|
2014-01-27 20:28:37 +01:00
|
|
|
*/
|
2014-01-27 21:56:49 +01:00
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-05-03 22:21:57 +02:00
|
|
|
set_error_handler(array(&$this, 'handleError'), -1);
|
|
|
|
set_exception_handler(array(&$this, 'handleException'));
|
2014-05-29 22:46:38 +02:00
|
|
|
register_shutdown_function(array(&$this, 'handleShutdown'));
|
2014-01-27 20:28:37 +01:00
|
|
|
}
|
|
|
|
|
2014-04-28 14:14:04 +02:00
|
|
|
/**
|
|
|
|
* Initialize other Error Handler Features
|
|
|
|
*/
|
|
|
|
public function init() {
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_RESTART_ON_EXCEPTION, true);
|
|
|
|
}
|
|
|
|
|
2014-01-27 20:28:37 +01:00
|
|
|
/**
|
2014-05-29 22:46:38 +02:00
|
|
|
* Trigger a Debug Notice to the ManiaControl Website
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
2014-05-29 22:46:38 +02:00
|
|
|
* @param string $message
|
2014-01-27 20:28:37 +01:00
|
|
|
*/
|
2014-05-29 22:46:38 +02:00
|
|
|
public function triggerDebugNotice($message) {
|
|
|
|
$this->handleError(self::MC_DEBUG_NOTICE, $message);
|
|
|
|
}
|
2014-05-04 00:16:50 +02:00
|
|
|
|
2014-05-29 22:46:38 +02:00
|
|
|
/**
|
|
|
|
* ManiaControl Error Handler
|
|
|
|
*
|
|
|
|
* @param int $errorNumber
|
|
|
|
* @param string $errorString
|
|
|
|
* @param string $errorFile
|
|
|
|
* @param int $errorLine
|
|
|
|
* @param array $errorContext
|
|
|
|
* @param bool $onShutdown
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function handleError($errorNumber, $errorString, $errorFile = null, $errorLine = -1, array $errorContext = array(), $onShutdown = false) {
|
|
|
|
$suppressed = (error_reporting() === 0);
|
|
|
|
if ($suppressed && !self::LOG_SUPPRESSED_ERRORS) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-04 00:16:50 +02:00
|
|
|
|
2014-06-12 16:59:24 +02:00
|
|
|
if (!$this->handlingError) {
|
|
|
|
// Reset error handler for safety
|
|
|
|
$this->handlingError = true;
|
|
|
|
set_error_handler(array(&$this, 'handleError'), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build log message
|
2014-05-29 22:46:38 +02:00
|
|
|
$errorTag = $this->getErrorTag($errorNumber);
|
|
|
|
$userError = $this->isUserErrorNumber($errorNumber);
|
|
|
|
$traceSourceClass = null;
|
|
|
|
|
|
|
|
$message = $errorTag . ': ' . $errorString;
|
|
|
|
$fileLine = $errorFile . ': ' . $errorLine;
|
|
|
|
$traceString = $this->parseBackTrace(array_slice(debug_backtrace(), 1), $traceSourceClass);
|
|
|
|
$sourceClass = $this->getSourceClass($errorFile);
|
|
|
|
if (!$sourceClass) {
|
|
|
|
$sourceClass = $traceSourceClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
$logMessage = $message . PHP_EOL . 'File&Line: ' . $fileLine;
|
|
|
|
if (!$userError && !$onShutdown) {
|
|
|
|
$logMessage .= PHP_EOL . 'Trace: ' . PHP_EOL . $traceString;
|
|
|
|
}
|
2014-05-15 13:04:05 +02:00
|
|
|
$this->maniaControl->log($logMessage);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-05-29 22:46:38 +02:00
|
|
|
if (!DEV_MODE && !$userError && !$suppressed) {
|
2014-06-12 16:59:24 +02:00
|
|
|
// Report error
|
2014-05-29 22:46:38 +02:00
|
|
|
$report = array();
|
|
|
|
$report['Type'] = 'Error';
|
|
|
|
$report['Message'] = $message;
|
|
|
|
$report['FileLine'] = $fileLine;
|
|
|
|
$report['SourceClass'] = $sourceClass;
|
|
|
|
$report['PluginId'] = PluginManager::getPluginId($sourceClass);
|
|
|
|
if (!$onShutdown) {
|
|
|
|
$report['Backtrace'] = $traceString;
|
|
|
|
}
|
2014-05-24 21:27:41 +02:00
|
|
|
$report['OperatingSystem'] = php_uname();
|
|
|
|
$report['PHPVersion'] = phpversion();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-02-19 15:44:00 +01:00
|
|
|
if ($this->maniaControl->server) {
|
2014-05-24 21:27:41 +02:00
|
|
|
$report['ServerLogin'] = $this->maniaControl->server->login;
|
2014-02-19 15:44:00 +01:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-02-19 15:44:00 +01:00
|
|
|
if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
|
2014-05-24 21:27:41 +02:00
|
|
|
$report['UpdateChannel'] = $this->maniaControl->settingManager->getSettingValue($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
|
2014-05-29 22:46:38 +02:00
|
|
|
$report['ManiaControlVersion'] = ManiaControl::VERSION . ' ' . $this->maniaControl->updateManager->getNightlyBuildDate();
|
2014-05-02 17:40:47 +02:00
|
|
|
} else {
|
2014-05-24 21:27:41 +02:00
|
|
|
$report['ManiaControlVersion'] = ManiaControl::VERSION;
|
2014-02-19 15:44:00 +01:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-05-24 21:27:41 +02:00
|
|
|
$json = json_encode($report);
|
2014-02-19 15:44:00 +01:00
|
|
|
$info = base64_encode($json);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-05-24 21:49:17 +02:00
|
|
|
$url = ManiaControl::URL_WEBSERVICE . 'errorreport?error=' . urlencode($info);
|
|
|
|
$response = FileUtil::loadFile($url);
|
|
|
|
$success = json_decode($response);
|
|
|
|
if ($success) {
|
2014-05-29 22:46:38 +02:00
|
|
|
logMessage('Error-Report successful!');
|
2014-05-24 21:49:17 +02:00
|
|
|
} else {
|
2014-05-29 22:46:38 +02:00
|
|
|
logMessage('Error-Report failed! ' . print_r($response, true));
|
2014-02-19 15:44:00 +01:00
|
|
|
}
|
2014-02-08 19:33:26 +01:00
|
|
|
}
|
2014-06-12 13:38:08 +02:00
|
|
|
|
|
|
|
if ($this->isFatalError($errorNumber)) {
|
|
|
|
$this->maniaControl->quit('Quitting ManiaControl after Fatal Error.');
|
2014-05-29 22:46:38 +02:00
|
|
|
}
|
2014-06-12 13:38:08 +02:00
|
|
|
|
2014-06-12 16:59:24 +02:00
|
|
|
// Disable safety state
|
|
|
|
$this->handlingError = false;
|
|
|
|
|
2014-05-29 22:46:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-05-29 22:46:38 +02:00
|
|
|
/**
|
|
|
|
* Get the Prefix for the given Error Level
|
|
|
|
*
|
|
|
|
* @param int $errorLevel
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getErrorTag($errorLevel) {
|
|
|
|
switch ($errorLevel) {
|
|
|
|
case E_NOTICE:
|
|
|
|
return '[PHP NOTICE]';
|
|
|
|
case E_WARNING:
|
|
|
|
return '[PHP WARNING]';
|
|
|
|
case E_ERROR:
|
|
|
|
return '[PHP ERROR]';
|
|
|
|
case E_CORE_ERROR:
|
|
|
|
return '[PHP CORE ERROR]';
|
|
|
|
case E_COMPILE_ERROR:
|
|
|
|
return '[PHP COMPILE ERROR]';
|
|
|
|
case E_RECOVERABLE_ERROR:
|
|
|
|
return '[PHP RECOVERABLE ERROR]';
|
|
|
|
case E_USER_NOTICE:
|
|
|
|
return '[ManiaControl NOTICE]';
|
|
|
|
case E_USER_WARNING:
|
|
|
|
return '[ManiaControl WARNING]';
|
|
|
|
case E_USER_ERROR:
|
|
|
|
return '[ManiaControl ERROR]';
|
|
|
|
case self::MC_DEBUG_NOTICE:
|
|
|
|
return '[ManiaControl DEBUG]';
|
2014-04-28 14:14:04 +02:00
|
|
|
}
|
2014-05-29 22:46:38 +02:00
|
|
|
return "[PHP ERROR '{$errorLevel}']";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the given Error Number is a User Error
|
|
|
|
*
|
|
|
|
* @param int $errorNumber
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function isUserErrorNumber($errorNumber) {
|
|
|
|
return ($errorNumber & E_USER_ERROR || $errorNumber & E_USER_WARNING || $errorNumber & E_USER_NOTICE || $errorNumber & E_USER_DEPRECATED);
|
2014-01-27 20:28:37 +01:00
|
|
|
}
|
|
|
|
|
2014-05-15 14:20:44 +02:00
|
|
|
/**
|
|
|
|
* Parse the Debug Backtrace into a String for the Error Report
|
|
|
|
*
|
|
|
|
* @param array $backtrace
|
|
|
|
* @param string $sourceClass
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function parseBackTrace(array $backtrace, &$sourceClass = null) {
|
|
|
|
$traceString = '';
|
|
|
|
$stepCount = 0;
|
|
|
|
foreach ($backtrace as $traceStep) {
|
2014-05-29 22:46:38 +02:00
|
|
|
$traceString .= '#' . $stepCount . ': ';
|
2014-05-15 14:20:44 +02:00
|
|
|
if (isset($traceStep['class'])) {
|
2014-06-14 18:14:01 +02:00
|
|
|
if (!$sourceClass && strpos($traceStep['class'], '\\FaultException') === false) {
|
2014-05-15 14:20:44 +02:00
|
|
|
$sourceClass = $traceStep['class'];
|
|
|
|
}
|
|
|
|
$traceString .= $traceStep['class'];
|
|
|
|
}
|
|
|
|
if (isset($traceStep['type'])) {
|
|
|
|
$traceString .= $traceStep['type'];
|
|
|
|
}
|
|
|
|
if (isset($traceStep['function'])) {
|
|
|
|
$traceString .= $traceStep['function'] . '(';
|
|
|
|
if (isset($traceStep['args'])) {
|
|
|
|
$traceString .= $this->parseArgumentsArray($traceStep['args']);
|
|
|
|
}
|
|
|
|
$traceString .= ')';
|
|
|
|
}
|
|
|
|
if (isset($traceStep['file'])) {
|
|
|
|
$traceString .= ' in File ';
|
|
|
|
$traceString .= $traceStep['file'];
|
|
|
|
}
|
|
|
|
if (isset($traceStep['line'])) {
|
|
|
|
$traceString .= ' on Line ';
|
|
|
|
$traceString .= $traceStep['line'];
|
|
|
|
}
|
2014-05-29 22:46:38 +02:00
|
|
|
$traceString .= PHP_EOL;
|
2014-05-24 22:34:57 +02:00
|
|
|
if (strlen($traceString) > 1300) {
|
|
|
|
// Too long...
|
|
|
|
$traceString .= '...';
|
|
|
|
break;
|
|
|
|
}
|
2014-05-15 14:20:44 +02:00
|
|
|
$stepCount++;
|
|
|
|
}
|
|
|
|
return $traceString;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build a String from an Arguments Array
|
|
|
|
*
|
|
|
|
* @param array $args
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function parseArgumentsArray(array $args) {
|
|
|
|
$string = '';
|
|
|
|
$argsCount = count($args);
|
|
|
|
foreach ($args as $index => $arg) {
|
|
|
|
if (is_object($arg)) {
|
|
|
|
$string .= 'object(' . get_class($arg) . ')';
|
|
|
|
} else if (is_array($arg)) {
|
|
|
|
$string .= 'array(' . $this->parseArgumentsArray($arg) . ')';
|
|
|
|
} else {
|
|
|
|
$type = gettype($arg);
|
2014-06-12 13:38:08 +02:00
|
|
|
$string .= $type . '(';
|
|
|
|
if (is_string($arg)) {
|
2014-06-14 19:31:17 +02:00
|
|
|
$param = iconv('UTF-8', 'UTF-8//IGNORE', substr($arg, 0, 20));
|
|
|
|
$string .= print_r($param, true);
|
2014-06-12 13:38:08 +02:00
|
|
|
} else {
|
2014-06-14 18:56:59 +02:00
|
|
|
$string .= print_r($arg, true);
|
2014-06-12 13:38:08 +02:00
|
|
|
}
|
|
|
|
$string .= ')';
|
2014-05-15 14:20:44 +02:00
|
|
|
}
|
|
|
|
if ($index < $argsCount - 1) {
|
|
|
|
$string .= ', ';
|
|
|
|
}
|
2014-05-24 22:34:57 +02:00
|
|
|
if (strlen($string) > 100) {
|
|
|
|
// Too long...
|
|
|
|
$string .= '...';
|
|
|
|
break;
|
|
|
|
}
|
2014-05-15 14:20:44 +02:00
|
|
|
}
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2014-05-02 17:40:47 +02:00
|
|
|
/**
|
2014-05-29 22:46:38 +02:00
|
|
|
* Get the Source Class via the Error File
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
2014-05-29 22:46:38 +02:00
|
|
|
* @param string $errorFile
|
|
|
|
* @return string
|
2014-05-02 17:40:47 +02:00
|
|
|
*/
|
2014-05-29 22:46:38 +02:00
|
|
|
private function getSourceClass($errorFile) {
|
|
|
|
if (!$errorFile) {
|
|
|
|
return null;
|
2014-05-02 17:40:47 +02:00
|
|
|
}
|
2014-05-29 22:46:38 +02:00
|
|
|
$filePath = substr($errorFile, strlen(ManiaControlDir));
|
|
|
|
$filePath = str_replace('plugins' . DIRECTORY_SEPARATOR, '', $filePath);
|
|
|
|
$filePath = str_replace('core' . DIRECTORY_SEPARATOR, 'ManiaControl\\', $filePath);
|
|
|
|
$className = str_replace('.php', '', $filePath);
|
|
|
|
$className = str_replace(DIRECTORY_SEPARATOR, '\\', $className);
|
|
|
|
if (!class_exists($className, false)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $className;
|
2014-05-02 17:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-12 13:38:08 +02:00
|
|
|
* Test whether the given Error Number represents a Fatal Error
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
2014-05-29 22:46:38 +02:00
|
|
|
* @param int $errorNumber
|
|
|
|
* @return bool
|
2014-05-02 17:40:47 +02:00
|
|
|
*/
|
2014-06-12 13:38:08 +02:00
|
|
|
private function isFatalError($errorNumber) {
|
2014-05-29 22:46:38 +02:00
|
|
|
return ($errorNumber & E_FATAL);
|
2014-05-02 17:40:47 +02:00
|
|
|
}
|
|
|
|
|
2014-01-27 20:28:37 +01:00
|
|
|
/**
|
2014-05-29 22:46:38 +02:00
|
|
|
* Handle PHP Process Shutdown
|
2014-01-27 20:28:37 +01:00
|
|
|
*/
|
2014-05-29 22:46:38 +02:00
|
|
|
public function handleShutdown() {
|
|
|
|
// TODO: skip client-related actions on transport exception (e.g. server down)
|
|
|
|
|
|
|
|
if ($this->maniaControl->callbackManager) {
|
|
|
|
// OnShutdown callback
|
|
|
|
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ONSHUTDOWN);
|
2014-05-06 02:29:48 +02:00
|
|
|
}
|
|
|
|
|
2014-05-29 22:46:38 +02:00
|
|
|
if ($this->maniaControl->chat) {
|
|
|
|
// Announce quit
|
|
|
|
$this->maniaControl->chat->sendInformation('ManiaControl shutting down.');
|
|
|
|
}
|
2014-05-04 00:16:50 +02:00
|
|
|
|
2014-05-29 22:46:38 +02:00
|
|
|
if ($this->maniaControl->client) {
|
|
|
|
try {
|
|
|
|
$this->maniaControl->client->sendHideManialinkPage();
|
|
|
|
} catch (TransportException $e) {
|
|
|
|
$this->handleException($e, false);
|
|
|
|
}
|
2014-05-24 13:57:27 +02:00
|
|
|
}
|
2014-05-04 00:16:50 +02:00
|
|
|
|
2014-05-29 22:46:38 +02:00
|
|
|
// Check if the Shutdown was caused by a Fatal Error and report it
|
|
|
|
$error = error_get_last();
|
|
|
|
if ($error && ($error['type'] & E_FATAL)) {
|
|
|
|
$this->handleError($error['type'], $error['message'], $error['file'], $error['line'], array(), true);
|
2014-05-24 18:31:38 +02:00
|
|
|
}
|
2014-05-29 22:46:38 +02:00
|
|
|
|
|
|
|
$this->maniaControl->quit('Quitting ManiaControl!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ManiaControl Exception Handler
|
|
|
|
*
|
|
|
|
* @param \Exception $exception
|
|
|
|
* @param bool $shutdown
|
|
|
|
*/
|
|
|
|
public function handleException(\Exception $exception, $shutdown = true) {
|
|
|
|
$message = "[ManiaControl EXCEPTION]: {$exception->getMessage()}";
|
|
|
|
|
|
|
|
$exceptionClass = get_class($exception);
|
|
|
|
$sourceClass = null;
|
|
|
|
$traceString = $this->parseBackTrace($exception->getTrace(), $sourceClass);
|
|
|
|
|
|
|
|
$logMessage = $message . PHP_EOL . 'Class: ' . $exceptionClass . PHP_EOL . 'Trace:' . PHP_EOL . $traceString;
|
2014-05-15 13:04:05 +02:00
|
|
|
$this->maniaControl->log($logMessage);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-05-29 22:46:38 +02:00
|
|
|
if (!DEV_MODE) {
|
2014-05-24 21:27:41 +02:00
|
|
|
$report = array();
|
2014-05-29 22:46:38 +02:00
|
|
|
$report['Type'] = 'Exception';
|
2014-05-26 12:57:57 +02:00
|
|
|
$report['Message'] = $message;
|
2014-05-29 22:46:38 +02:00
|
|
|
$report['Class'] = $exceptionClass;
|
|
|
|
$report['FileLine'] = $exception->getFile() . ': ' . $exception->getLine();
|
2014-05-24 21:27:41 +02:00
|
|
|
$report['SourceClass'] = $sourceClass;
|
|
|
|
$report['PluginId'] = PluginManager::getPluginId($sourceClass);
|
2014-05-26 12:57:57 +02:00
|
|
|
$report['Backtrace'] = $traceString;
|
2014-05-24 21:27:41 +02:00
|
|
|
$report['OperatingSystem'] = php_uname();
|
|
|
|
$report['PHPVersion'] = phpversion();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-02-15 19:19:03 +01:00
|
|
|
if ($this->maniaControl->server) {
|
2014-05-24 21:27:41 +02:00
|
|
|
$report['ServerLogin'] = $this->maniaControl->server->login;
|
2014-02-10 15:26:08 +01:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-02-15 19:19:03 +01:00
|
|
|
if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
|
2014-05-24 21:27:41 +02:00
|
|
|
$report['UpdateChannel'] = $this->maniaControl->settingManager->getSettingValue($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
|
2014-05-29 22:46:38 +02:00
|
|
|
$report['ManiaControlVersion'] = ManiaControl::VERSION . ' #' . $this->maniaControl->updateManager->getNightlyBuildDate();
|
2014-05-02 17:40:47 +02:00
|
|
|
} else {
|
2014-05-24 21:27:41 +02:00
|
|
|
$report['ManiaControlVersion'] = ManiaControl::VERSION;
|
2014-02-15 18:26:31 +01:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-05-24 21:27:41 +02:00
|
|
|
$json = json_encode($report);
|
2014-02-08 19:33:26 +01:00
|
|
|
$info = base64_encode($json);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-05-24 21:49:17 +02:00
|
|
|
$url = ManiaControl::URL_WEBSERVICE . 'errorreport?error=' . urlencode($info);
|
|
|
|
$response = FileUtil::loadFile($url);
|
|
|
|
$success = json_decode($response);
|
2014-05-07 21:37:37 +02:00
|
|
|
if ($success) {
|
2014-05-29 22:46:38 +02:00
|
|
|
logMessage('Exception successfully reported!');
|
2014-05-07 21:37:37 +02:00
|
|
|
} else {
|
2014-05-29 22:46:38 +02:00
|
|
|
logMessage('Exception-Report failed! ' . print_r($response, true));
|
2014-02-08 19:33:26 +01:00
|
|
|
}
|
2014-02-10 23:03:25 +01:00
|
|
|
}
|
2014-03-19 14:00:24 +01:00
|
|
|
|
2014-05-29 22:46:38 +02:00
|
|
|
if ($shutdown) {
|
|
|
|
if ($this->shouldRestart()) {
|
|
|
|
$this->maniaControl->restart();
|
|
|
|
}
|
2014-06-12 13:38:08 +02:00
|
|
|
$this->maniaControl->quit('Quitting ManiaControl after Exception.');
|
2014-05-24 13:57:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 17:40:47 +02:00
|
|
|
/**
|
2014-05-29 22:46:38 +02:00
|
|
|
* Test if ManiaControl should restart automatically
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-05-29 22:46:38 +02:00
|
|
|
private function shouldRestart() {
|
|
|
|
if (!$this->maniaControl || !$this->maniaControl->settingManager) {
|
|
|
|
return false;
|
2014-05-03 22:26:49 +02:00
|
|
|
}
|
2014-05-29 22:46:38 +02:00
|
|
|
$setting = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_RESTART_ON_EXCEPTION, true);
|
|
|
|
return $setting;
|
2014-05-03 22:26:49 +02:00
|
|
|
}
|
2014-01-27 20:28:37 +01:00
|
|
|
}
|