Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -33,9 +33,9 @@ class LibXmlRpcCallbackManager implements CallbackListener {
|
||||
* Handle Script Callbacks
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
* @param mixed $data
|
||||
*/
|
||||
public function handleScriptCallbacks($name, array $data) {
|
||||
public function handleScriptCallbacks($name, $data) {
|
||||
switch ($name) {
|
||||
case 'LibXmlRpc_BeginMatch':
|
||||
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMATCH, $data[0]);
|
||||
|
@ -52,7 +52,7 @@ class Chat {
|
||||
*/
|
||||
public function sendInformation($message, $login = null, $prefix = true) {
|
||||
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_INFORMATION);
|
||||
return $this->sendChat($format . $message, $login);
|
||||
return $this->sendChat($format . $message, $login, $prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +111,7 @@ class Chat {
|
||||
*/
|
||||
public function sendSuccess($message, $login = null, $prefix = true) {
|
||||
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_SUCCESS);
|
||||
return $this->sendChat($format . $message, $login);
|
||||
return $this->sendChat($format . $message, $login, $prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,7 +137,7 @@ class Chat {
|
||||
*/
|
||||
public function sendError($message, $login = null, $prefix = true) {
|
||||
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_ERROR);
|
||||
return $this->sendChat($format . $message, $login);
|
||||
return $this->sendChat($format . $message, $login, $prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,6 +150,6 @@ class Chat {
|
||||
*/
|
||||
public function sendUsageInfo($message, $login = null, $prefix = false) {
|
||||
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_USAGEINFO);
|
||||
return $this->sendChat($format . $message, $login);
|
||||
return $this->sendChat($format . $message, $login, $prefix);
|
||||
}
|
||||
}
|
||||
|
@ -54,10 +54,10 @@ class HelpManager implements CommandListener, CallbackListener {
|
||||
/**
|
||||
* Shows a list of Admin Commands
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_adminHelp(array $chat, Player $player) {
|
||||
public function command_adminHelp(array $chatCallback, Player $player) {
|
||||
$showCommands = array();
|
||||
$registeredMethods = array();
|
||||
foreach (array_reverse($this->adminCommands) as $command) {
|
||||
@ -85,10 +85,10 @@ class HelpManager implements CommandListener, CallbackListener {
|
||||
/**
|
||||
* Shows a list of Player Commands
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_playerHelp(array $chat, Player $player) {
|
||||
public function command_playerHelp(array $chatCallback, Player $player) {
|
||||
$showCommands = array();
|
||||
$registeredMethods = array();
|
||||
foreach (array_reverse($this->playerCommands) as $command) {
|
||||
@ -116,10 +116,10 @@ class HelpManager implements CommandListener, CallbackListener {
|
||||
/**
|
||||
* Shows a ManiaLink list of Player Commands
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_playerHelpAll(array $chat, Player $player) {
|
||||
public function command_playerHelpAll(array $chatCallback, Player $player) {
|
||||
$this->prepareHelpAll($this->playerCommands, $player);
|
||||
}
|
||||
|
||||
@ -237,10 +237,10 @@ class HelpManager implements CommandListener, CallbackListener {
|
||||
/**
|
||||
* Shows a ManiaLink list of Admin Commands
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_adminHelpAll(array $chat, Player $player) {
|
||||
public function command_adminHelpAll(array $chatCallback, Player $player) {
|
||||
$this->prepareHelpAll($this->adminCommands, $player);
|
||||
}
|
||||
|
||||
|
@ -40,20 +40,23 @@ class MigrationHelper {
|
||||
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
$query = "INSERT INTO `" . SettingManager::TABLE_SETTINGS . "` (`class`, `setting`, `type`, `value`, `default`)
|
||||
SELECT ?, `setting`, `type`, `value`, `default` FROM `" . SettingManager::TABLE_SETTINGS . "` WHERE `class` = ?;";
|
||||
$query = "INSERT IGNORE INTO `" . SettingManager::TABLE_SETTINGS . "`
|
||||
(`class`, `setting`, `type`, `value`, `default`)
|
||||
SELECT ?, `setting`, `type`, `value`, `default`
|
||||
FROM `" . SettingManager::TABLE_SETTINGS . "`
|
||||
WHERE `class` = ?;";
|
||||
$statement = $mysqli->prepare($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
$statement->bind_param('ss', $targetClass, $sourceClass);
|
||||
$success = $statement->execute();
|
||||
if ($statement->error) {
|
||||
trigger_error($statement->error);
|
||||
$statement->close();
|
||||
return false;
|
||||
}
|
||||
$success = $statement->execute();
|
||||
$statement->close();
|
||||
return $success;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class ErrorHandler {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const MC_DEBUG_NOTICE = "ManiaControl.DebugNotice";
|
||||
const MC_DEBUG_NOTICE = 'ManiaControl.DebugNotice';
|
||||
const SETTING_RESTART_ON_EXCEPTION = 'Automatically restart on Exceptions';
|
||||
|
||||
/*
|
||||
@ -30,8 +30,8 @@ class ErrorHandler {
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
set_error_handler(array(&$this, 'errorHandler'), -1);
|
||||
set_exception_handler(array(&$this, 'exceptionHandler'));
|
||||
set_error_handler(array(&$this, 'handleError'), -1);
|
||||
set_exception_handler(array(&$this, 'handleException'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,23 +42,26 @@ class ErrorHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* ManiaControl ExceptionHandler
|
||||
* ManiaControl Exception Handler
|
||||
*
|
||||
* @param \Exception $ex
|
||||
* @param bool $shutdown
|
||||
*/
|
||||
public function exceptionHandler(\Exception $ex, $shutdown = true) {
|
||||
// Log exception
|
||||
$message = "[ManiaControl EXCEPTION]: {$ex->getMessage()}";
|
||||
$traceMessage = 'Class: ' . get_class($ex) . PHP_EOL;
|
||||
$traceMessage .= 'Trace:' . PHP_EOL . $ex->getTraceAsString();
|
||||
logMessage($message . PHP_EOL . $traceMessage);
|
||||
public function handleException(\Exception $ex, $shutdown = true) {
|
||||
$message = "[ManiaControl EXCEPTION]: {$ex->getMessage()}";
|
||||
|
||||
$exceptionClass = get_class($ex);
|
||||
$traceString = $ex->getTraceAsString();
|
||||
|
||||
$logMessage = $message . PHP_EOL . 'Class: ' . $exceptionClass . PHP_EOL . 'Trace:' . PHP_EOL . $traceString;
|
||||
logMessage($logMessage);
|
||||
|
||||
if ($this->reportErrors) {
|
||||
$error = array();
|
||||
$error["Type"] = "Exception";
|
||||
$error["Message"] = $message;
|
||||
$error["Backtrace"] = $traceMessage;
|
||||
$error['Type'] = 'Exception';
|
||||
$error['Message'] = $message;
|
||||
$error['Class'] = $exceptionClass;
|
||||
$error['Backtrace'] = $traceString;
|
||||
$error['OperatingSystem'] = php_uname();
|
||||
$error['PHPVersion'] = phpversion();
|
||||
|
||||
@ -79,13 +82,13 @@ class ErrorHandler {
|
||||
$json = json_encode($error);
|
||||
$info = base64_encode($json);
|
||||
|
||||
$url = ManiaControl::URL_WEBSERVICE . "errorreport?error=" . urlencode($info);
|
||||
$url = ManiaControl::URL_WEBSERVICE . 'errorreport?error=' . urlencode($info);
|
||||
$success = FileUtil::loadFile($url);
|
||||
|
||||
if (!json_decode($success)) {
|
||||
logMessage("Exception-Report failed!");
|
||||
logMessage('Exception-Report failed!');
|
||||
} else {
|
||||
logMessage("Exception successfully reported!");
|
||||
logMessage('Exception successfully reported!');
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,45 +114,39 @@ class ErrorHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a Debug Notice to the ManiaControl Website
|
||||
* Trigger a Debug Notice to the ManiaControl Website
|
||||
*
|
||||
* @param $message
|
||||
* @param string $message
|
||||
*/
|
||||
public function triggerDebugNotice($message) {
|
||||
$this->errorHandler(self::MC_DEBUG_NOTICE, $message);
|
||||
$this->handleError(self::MC_DEBUG_NOTICE, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
* ManiaControl Error Handler
|
||||
*
|
||||
* @param $errorNumber
|
||||
* @param $errorString
|
||||
* @param $errorFile
|
||||
* @param $errorLine
|
||||
* @param int $errorNumber
|
||||
* @param string $errorString
|
||||
* @param string $errorFile
|
||||
* @param int $errorLine
|
||||
* @return bool
|
||||
*/
|
||||
public function errorHandler($errorNumber, $errorString, $errorFile = null, $errorLine = -1) {
|
||||
if (error_reporting() === 0) {
|
||||
// Error suppressed
|
||||
return false;
|
||||
}
|
||||
public function handleError($errorNumber, $errorString, $errorFile = null, $errorLine = -1) {
|
||||
$errorTag = $this->getErrorTag($errorNumber);
|
||||
|
||||
$userError = $this->isUserErrorNumber($errorNumber);
|
||||
$message = $errorTag . ': ' . $errorString;
|
||||
$fileLine = $errorFile . ': ' . $errorLine;
|
||||
$traceString = $this->parseBackTrace(debug_backtrace());
|
||||
|
||||
// Log error
|
||||
$errorTag = $this->getErrorTag($errorNumber);
|
||||
$message = $errorTag . ': ' . $errorString;
|
||||
$fileLine = $errorFile . ': ' . $errorLine;
|
||||
$traceMessage = $this->parseBackTrace(debug_backtrace());
|
||||
$logMessage = $message . PHP_EOL . ($userError ? $fileLine : $traceMessage);
|
||||
$logMessage = $message . PHP_EOL . 'File&Line: ' . $fileLine . PHP_EOL . 'Trace: ' . $traceString;
|
||||
logMessage($logMessage);
|
||||
|
||||
if ($this->reportErrors && !$userError) {
|
||||
if ($this->reportErrors && !$this->isUserErrorNumber($errorNumber)) {
|
||||
$error = array();
|
||||
$error["Type"] = "Error";
|
||||
$error["Message"] = $message;
|
||||
$error["FileLine"] = $fileLine;
|
||||
$error["Backtrace"] = $traceMessage;
|
||||
$error['Type'] = 'Error';
|
||||
$error['Message'] = $message;
|
||||
$error['FileLine'] = $fileLine;
|
||||
$error['Backtrace'] = $traceString;
|
||||
$error['OperatingSystem'] = php_uname();
|
||||
$error['PHPVersion'] = phpversion();
|
||||
|
||||
@ -170,13 +167,13 @@ class ErrorHandler {
|
||||
$json = json_encode($error);
|
||||
$info = base64_encode($json);
|
||||
|
||||
$url = ManiaControl::URL_WEBSERVICE . "errorreport?error=" . urlencode($info);
|
||||
$url = ManiaControl::URL_WEBSERVICE . 'errorreport?error=' . urlencode($info);
|
||||
$success = FileUtil::loadFile($url);
|
||||
|
||||
if (!json_decode($success)) {
|
||||
logMessage("Error-Report failed!");
|
||||
logMessage('Error-Report failed!');
|
||||
} else {
|
||||
logMessage("Error successfully reported!");
|
||||
logMessage('Error successfully reported!');
|
||||
}
|
||||
}
|
||||
if ($this->shouldStopExecution($errorNumber)) {
|
||||
@ -186,16 +183,6 @@ class ErrorHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Prefix for the given Error Level
|
||||
*
|
||||
@ -203,45 +190,38 @@ class ErrorHandler {
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorTag($errorLevel) {
|
||||
if ($errorLevel == E_NOTICE) {
|
||||
return '[PHP NOTICE]';
|
||||
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]';
|
||||
}
|
||||
if ($errorLevel == E_WARNING) {
|
||||
return '[PHP WARNING]';
|
||||
}
|
||||
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]';
|
||||
}
|
||||
if ($errorLevel == E_USER_WARNING) {
|
||||
return '[ManiaControl WARNING]';
|
||||
}
|
||||
if ($errorLevel == E_USER_ERROR) {
|
||||
return '[ManiaControl ERROR]';
|
||||
}
|
||||
if ($errorLevel == self::MC_DEBUG_NOTICE) {
|
||||
return '[ManiaControl DEBUG]';
|
||||
}
|
||||
return "[PHP {$errorLevel}]";
|
||||
return "[PHP ERROR '{$errorLevel}']";
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the Debug Backtrace into a String for the Error Report
|
||||
* return string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function parseBackTrace(array $backtrace) {
|
||||
$traceString = 'Trace:';
|
||||
$traceString = '';
|
||||
$stepCount = 0;
|
||||
foreach ($backtrace as $traceStep) {
|
||||
$traceString .= PHP_EOL . '#' . $stepCount . ': ';
|
||||
@ -267,6 +247,16 @@ class ErrorHandler {
|
||||
return $traceString;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if ManiaControl should stop its Execution
|
||||
*
|
||||
@ -276,4 +266,14 @@ class ErrorHandler {
|
||||
private function shouldStopExecution($errorNumber) {
|
||||
return ($errorNumber === E_ERROR || $errorNumber === E_USER_ERROR || $errorNumber === E_FATAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Shutdown was caused by a Fatal Error and report it
|
||||
*/
|
||||
public function handleShutdown() {
|
||||
$error = error_get_last();
|
||||
if ($error && ($error['type'] & E_FATAL)) {
|
||||
$this->handleError($error['type'], $error['message'], $error['file'], $error['line']);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ abstract class BackupUtil {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const FOLDER_NAME_BACKUP = '/backup/';
|
||||
const FOLDER_NAME_BACKUP = 'backup/';
|
||||
|
||||
/**
|
||||
* Perform a Full Backup of ManiaControl
|
||||
@ -32,7 +32,7 @@ abstract class BackupUtil {
|
||||
}
|
||||
$excludes = array('.', '..', 'backup', 'logs', 'ManiaControl.log');
|
||||
$pathInfo = pathInfo(ManiaControlDir);
|
||||
$parentPath = $pathInfo['dirname'] . '/';
|
||||
$parentPath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR;
|
||||
$dirName = $pathInfo['basename'];
|
||||
$backupZip->addEmptyDir($dirName);
|
||||
self::zipDirectory($backupZip, ManiaControlDir, strlen($parentPath), $excludes);
|
||||
@ -72,7 +72,7 @@ abstract class BackupUtil {
|
||||
if (in_array($file, $excludes)) {
|
||||
continue;
|
||||
}
|
||||
$filePath = $folderName . '/' . $file;
|
||||
$filePath = $folderName . DIRECTORY_SEPARATOR . $file;
|
||||
$localPath = substr($filePath, $prefixLength);
|
||||
if (is_file($filePath)) {
|
||||
$zipArchive->addFile($filePath, $localPath);
|
||||
@ -102,11 +102,11 @@ abstract class BackupUtil {
|
||||
return false;
|
||||
}
|
||||
$excludes = array('.', '..');
|
||||
$pathInfo = pathInfo(ManiaControlDir . '/plugins');
|
||||
$parentPath = $pathInfo['dirname'] . '/';
|
||||
$pathInfo = pathInfo(ManiaControlDir . 'plugins');
|
||||
$parentPath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR;
|
||||
$dirName = $pathInfo['basename'];
|
||||
$backupZip->addEmptyDir($dirName);
|
||||
self::zipDirectory($backupZip, ManiaControlDir . '/plugins', strlen($parentPath), $excludes);
|
||||
self::zipDirectory($backupZip, ManiaControlDir . 'plugins', strlen($parentPath), $excludes);
|
||||
$backupZip->close();
|
||||
return true;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ abstract class FileUtil {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const FOLDER_NAME_TEMP = '/temp/';
|
||||
const FOLDER_NAME_TEMP = 'temp/';
|
||||
|
||||
/**
|
||||
* Load a remote file
|
||||
@ -75,7 +75,7 @@ abstract class FileUtil {
|
||||
* @return \SimpleXMLElement
|
||||
*/
|
||||
public static function loadConfig($fileName) {
|
||||
$fileLocation = ManiaControlDir . '/configs/' . $fileName;
|
||||
$fileLocation = ManiaControlDir . 'configs' . DIRECTORY_SEPARATOR . $fileName;
|
||||
if (!file_exists($fileLocation)) {
|
||||
trigger_error("Config file doesn't exist! ({$fileName})");
|
||||
return null;
|
||||
@ -151,4 +151,47 @@ abstract class FileUtil {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to delete the given Plugin Files
|
||||
*
|
||||
* @param mixed $pluginFileNames
|
||||
*/
|
||||
public static function cleanPluginFiles($pluginFileNames) {
|
||||
$pluginFileNames = self::buildFileNamesArray($pluginFileNames);
|
||||
$fileNames = array();
|
||||
foreach ($pluginFileNames as $pluginFileName) {
|
||||
$fileName = 'plugins' . DIRECTORY_SEPARATOR . $pluginFileName;
|
||||
array_push($fileNames, $fileName);
|
||||
}
|
||||
self::cleanFiles($fileNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure we're dealing with an Array of File Names
|
||||
*
|
||||
* @param mixed $fileNamesParam
|
||||
* @return array
|
||||
*/
|
||||
private static function buildFileNamesArray($fileNamesParam) {
|
||||
if (!is_array($fileNamesParam)) {
|
||||
$fileNamesParam = array($fileNamesParam);
|
||||
}
|
||||
return $fileNamesParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to delete the given Files
|
||||
*
|
||||
* @param mixed $fileNames
|
||||
*/
|
||||
public static function cleanFiles($fileNames) {
|
||||
$fileNames = self::buildFileNamesArray($fileNames);
|
||||
foreach ($fileNames as $fileName) {
|
||||
$filePath = ManiaControlDir . $fileName;
|
||||
if (file_exists($filePath) && is_writeable($filePath)) {
|
||||
unlink($filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,10 +223,10 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
// Execute start script in background
|
||||
// TODO: restart the .php script itself ($_SERVER['scriptname'] or something + $argv)
|
||||
if ($this->getOS(self::OS_UNIX)) {
|
||||
$command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &';
|
||||
$command = 'sh ' . escapeshellarg(ManiaControlDir . 'ManiaControl.sh') . ' > /dev/null &';
|
||||
exec($command);
|
||||
} else {
|
||||
$command = escapeshellarg(ManiaControlDir . "\ManiaControl.bat");
|
||||
$command = escapeshellarg(ManiaControlDir . "ManiaControl.bat");
|
||||
system($command); // TODO, windows stucks here as long controller is running
|
||||
}
|
||||
exit();
|
||||
@ -302,11 +302,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
}
|
||||
}
|
||||
|
||||
// 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->errorHandler->handleShutdown();
|
||||
|
||||
// Disable Garbage Collector
|
||||
$this->collectGarbage();
|
||||
@ -376,7 +372,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
$this->log("Connection interrupted!");
|
||||
// TODO remove
|
||||
if ($this->errorHandler) {
|
||||
$this->errorHandler->exceptionHandler($e, false);
|
||||
$this->errorHandler->handleException($e, false);
|
||||
}
|
||||
$this->quit($e->getMessage());
|
||||
}
|
||||
@ -423,7 +419,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
} catch (Exception $e) {
|
||||
// TODO remove
|
||||
if ($this->errorHandler) {
|
||||
$this->errorHandler->triggerDebugNotice("Fatal Exception: " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
|
||||
$this->errorHandler->handleException($e, false);
|
||||
}
|
||||
$this->quit($e->getMessage());
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
||||
$maplist = 'maplist.txt';
|
||||
}
|
||||
|
||||
$maplist = 'MatchSettings/' . $maplist;
|
||||
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist;
|
||||
try {
|
||||
$this->maniaControl->client->saveMatchSettings($maplist);
|
||||
|
||||
@ -299,7 +299,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
||||
$maplist = 'maplist.txt';
|
||||
}
|
||||
|
||||
$maplist = 'MatchSettings/' . $maplist;
|
||||
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR . $maplist;
|
||||
try {
|
||||
$this->maniaControl->client->loadMatchSettings($maplist);
|
||||
|
||||
@ -472,7 +472,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
||||
* @param Map $b
|
||||
* @return mixed
|
||||
*/
|
||||
private function sortByKarma($a, $b) {
|
||||
private function sortByKarma(Map $a, Map $b) {
|
||||
return ($a->karma - $b->karma);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
||||
use FML\ManiaLink;
|
||||
use FML\Script\Features\Paging;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
@ -397,21 +398,33 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
|
||||
$description = 'Switch Directly to Map: $<' . $map->name . '$>';
|
||||
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
||||
// Switch Map Voting
|
||||
$switchLabel = new Label_Button();
|
||||
$mapFrame->add($switchLabel);
|
||||
$switchLabel->setX($width / 2 - 10);
|
||||
$switchLabel->setZ(0.2);
|
||||
$switchLabel->setSize(3, 3);
|
||||
$switchLabel->setTextSize(2);
|
||||
$switchLabel->setText('»');
|
||||
$switchLabel->setTextColor('0f0');
|
||||
|
||||
$switchLabel->setAction(self::ACTION_START_SWITCH_VOTE . '.' . ($id - 1));
|
||||
|
||||
$description = 'Start Map-Switch Vote: $<' . $map->name . '$>';
|
||||
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
}
|
||||
if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
||||
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
||||
// Switch Map Voting for Admins
|
||||
$switchQuad = new Quad_UIConstruction_Buttons();
|
||||
$mapFrame->add($switchQuad);
|
||||
$switchQuad->setX($width / 2 - 20);
|
||||
$switchQuad->setZ(0.2);
|
||||
$switchQuad->setSubStyle($switchQuad::SUBSTYLE_Validate_Step2);
|
||||
$switchQuad->setSize(3.8, 3.8);
|
||||
$switchQuad->setAction(self::ACTION_START_SWITCH_VOTE . '.' . ($id - 1));
|
||||
$description = 'Start Map-Switch Vote: $<' . $map->name . '$>';
|
||||
$switchQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
} else {
|
||||
// Switch Map Voting for Player
|
||||
$switchLabel = new Label_Button();
|
||||
$mapFrame->add($switchLabel);
|
||||
$switchLabel->setX($width / 2 - 10);
|
||||
$switchLabel->setZ(0.2);
|
||||
$switchLabel->setSize(3, 3);
|
||||
$switchLabel->setTextSize(2);
|
||||
$switchLabel->setText('»');
|
||||
$switchLabel->setTextColor('0f0');
|
||||
$switchLabel->setAction(self::ACTION_START_SWITCH_VOTE . '.' . ($id - 1));
|
||||
$description = 'Start Map-Switch Vote: $<' . $map->name . '$>';
|
||||
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
}
|
||||
}
|
||||
|
||||
// Display Karma bar
|
||||
|
@ -252,9 +252,9 @@ class MapManager implements CallbackListener {
|
||||
|
||||
// Download the file
|
||||
$self->maniaControl->fileReader->loadFile($mapInfo->downloadurl, function ($file, $error) use (&$self, &$login, &$mapInfo, &$update) {
|
||||
if (!$file) {
|
||||
if (!$file || $error) {
|
||||
// Download error
|
||||
$self->maniaControl->chat->sendError('Download failed!', $login);
|
||||
$self->maniaControl->chat->sendError("Download failed: '{$error}'!", $login);
|
||||
return;
|
||||
}
|
||||
$self->processMapFile($file, $mapInfo, $login, $update);
|
||||
@ -284,9 +284,9 @@ class MapManager implements CallbackListener {
|
||||
$fileName = FileUtil::getClearedFileName($fileName);
|
||||
|
||||
$downloadFolderName = $this->maniaControl->settingManager->getSetting($this, 'MapDownloadDirectory', 'MX');
|
||||
$relativeMapFileName = $downloadFolderName . '/' . $fileName;
|
||||
$relativeMapFileName = $downloadFolderName . DIRECTORY_SEPARATOR . $fileName;
|
||||
$mapDir = $this->maniaControl->client->getMapsDirectory();
|
||||
$downloadDirectory = $mapDir . '/' . $downloadFolderName . '/';
|
||||
$downloadDirectory = $mapDir . DIRECTORY_SEPARATOR . $downloadFolderName . DIRECTORY_SEPARATOR;
|
||||
$fullMapFileName = $downloadDirectory . $fileName;
|
||||
|
||||
// Check if it can get written locally
|
||||
|
@ -82,20 +82,19 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Clears the map-queue via admin command clearmap queue
|
||||
*
|
||||
* @param array $chat
|
||||
* @param \ManiaControl\Players\Player $admin
|
||||
* @internal param \ManiaControl\Players\Player $player
|
||||
* @param array $chatCallback
|
||||
* @param Player $admin
|
||||
*/
|
||||
public function command_ClearMapQueue(array $chat, Player $admin) {
|
||||
public function command_ClearMapQueue(array $chatCallback, Player $admin) {
|
||||
$this->clearMapQueue($admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Map Queue
|
||||
* Clear the Map Queue
|
||||
*
|
||||
* @param $admin
|
||||
* @param Player $admin
|
||||
*/
|
||||
public function clearMapQueue($admin) {
|
||||
public function clearMapQueue(Player $admin) {
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
||||
return;
|
||||
@ -121,11 +120,11 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Handles the mapqueue/jukebox command
|
||||
*
|
||||
* @param array $chat
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_MapQueue(array $chat, Player $player) {
|
||||
$chatCommands = explode(' ', $chat[1][2]);
|
||||
public function command_MapQueue(array $chatCallback, Player $player) {
|
||||
$chatCommands = explode(' ', $chatCallback[1][2]);
|
||||
|
||||
if (isset($chatCommands[1])) {
|
||||
if ($chatCommands[1] == ' ' || $chatCommands[1] == 'list') {
|
||||
@ -143,9 +142,9 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Shows current mapqueue in the chat
|
||||
*
|
||||
* @param $player
|
||||
* @param Player $player
|
||||
*/
|
||||
public function showMapQueue($player) {
|
||||
public function showMapQueue(Player $player) {
|
||||
if (count($this->queuedMaps) == 0) {
|
||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
||||
return;
|
||||
@ -164,9 +163,9 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Shows current mapqueue in a manialink
|
||||
*
|
||||
* @param $player
|
||||
* @param Player $player
|
||||
*/
|
||||
public function showMapQueueManialink($player) {
|
||||
public function showMapQueueManialink(Player $player) {
|
||||
if (count($this->queuedMaps) == 0) {
|
||||
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
|
||||
return;
|
||||
@ -192,10 +191,10 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Adds map as first map in queue (for /replay)
|
||||
*
|
||||
* @param $player
|
||||
* @param $map
|
||||
* @param Player $player
|
||||
* @param Map $map
|
||||
*/
|
||||
public function addFirstMapToMapQueue($player, $map) {
|
||||
public function addFirstMapToMapQueue(Player $player, Map $map) {
|
||||
if ($map) {
|
||||
if (array_key_exists($map->uid, $this->queuedMaps)) {
|
||||
unset($this->queuedMaps[$map->uid]);
|
||||
@ -208,8 +207,8 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Adds a Map to the map-queue
|
||||
*
|
||||
* @param $login
|
||||
* @param $uid
|
||||
* @param string $login
|
||||
* @param string $uid
|
||||
*/
|
||||
public function addMapToMapQueue($login, $uid) {
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
@ -270,9 +269,8 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Revmoes a Map from the Map queue
|
||||
*
|
||||
* @param \ManiaControl\Players\Player $player
|
||||
* @param $uid
|
||||
* @internal param $login
|
||||
* @param Player $player
|
||||
* @param string $uid
|
||||
*/
|
||||
public function removeFromMapQueue(Player $player, $uid) {
|
||||
if (!isset($this->queuedMaps[$uid])) {
|
||||
@ -360,7 +358,7 @@ class MapQueue implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Returns the next Map if the next map is a queuedmap or null if it's not
|
||||
*
|
||||
* @return null
|
||||
* @return Map
|
||||
*/
|
||||
public function getNextMap() {
|
||||
return $this->nextMap;
|
||||
|
@ -14,7 +14,6 @@ use ManiaControl\Formatter;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Statistics\StatisticManager;
|
||||
use Maniaplanet\DedicatedServer\Structures\Player;
|
||||
|
||||
/**
|
||||
* Player Detailed Page
|
||||
|
@ -22,7 +22,6 @@ use ManiaControl\Formatter;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use Maniaplanet\DedicatedServer\Structures\Player;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerIsNotSpectatorException;
|
||||
use MCTeam\CustomVotesPlugin;
|
||||
|
@ -154,7 +154,7 @@ class PluginManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the plugin is running
|
||||
* Check if the Plugin is currently running
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @return bool
|
||||
@ -165,7 +165,7 @@ class PluginManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Save plugin status in database
|
||||
* Save Plugin Status in Database
|
||||
*
|
||||
* @param string $className
|
||||
* @param bool $active
|
||||
@ -203,7 +203,7 @@ class PluginManager {
|
||||
* @return array
|
||||
*/
|
||||
public function loadPlugins() {
|
||||
$pluginsDirectory = ManiaControlDir . '/plugins/';
|
||||
$pluginsDirectory = ManiaControlDir . 'plugins' . DIRECTORY_SEPARATOR;
|
||||
|
||||
$classesBefore = get_declared_classes();
|
||||
$this->loadPluginFiles($pluginsDirectory);
|
||||
@ -259,7 +259,7 @@ class PluginManager {
|
||||
|
||||
$dirPath = $directory . $pluginFile;
|
||||
if (is_dir($dirPath)) {
|
||||
$this->loadPluginFiles($dirPath . '/');
|
||||
$this->loadPluginFiles($dirPath . DIRECTORY_SEPARATOR);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -245,6 +245,8 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$pluginUpdates = $this->maniaControl->updateManager->pluginUpdateManager->getPluginsUpdates();
|
||||
|
||||
usort($pluginClasses, function ($a, $b) {
|
||||
/** @var Plugin $a */
|
||||
/** @var Plugin $b */
|
||||
return strcmp($a::getName(), $b::getName());
|
||||
});
|
||||
|
||||
|
@ -257,7 +257,7 @@ class Server implements CallbackListener {
|
||||
if (!$dataDirectory) {
|
||||
return null;
|
||||
}
|
||||
return "{$dataDirectory}Maps/";
|
||||
return "{$dataDirectory}Maps".DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,26 +71,24 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
}
|
||||
$this->maniaControl->log($message);
|
||||
|
||||
$self = $this;
|
||||
$this->maniaControl->pluginManager->fetchPluginList(function ($data, $error) use (&$self, &$player) {
|
||||
|
||||
$self = $this;
|
||||
$maniaControl = $this->maniaControl;
|
||||
$this->maniaControl->pluginManager->fetchPluginList(function ($data, $error) use (&$self, &$maniaControl, &$player) {
|
||||
if (!$data || $error) {
|
||||
$message = 'Error while checking Plugins for newer Versions!';
|
||||
if ($player) {
|
||||
$self->maniaControl->chat->sendError($message, $player);
|
||||
$maniaControl->chat->sendError($message, $player);
|
||||
}
|
||||
$self->maniaControl->log($message);
|
||||
$maniaControl->log($message);
|
||||
return;
|
||||
}
|
||||
|
||||
$pluginsData = $self->parsePluginsData($data);
|
||||
$pluginClasses = $self->maniaControl->pluginManager->getPluginClasses();
|
||||
$pluginClasses = $maniaControl->pluginManager->getPluginClasses();
|
||||
$pluginUpdates = array();
|
||||
|
||||
foreach ($pluginClasses as $pluginClass) {
|
||||
/**
|
||||
* @var Plugin $pluginClass
|
||||
*/
|
||||
/** @var Plugin $pluginClass */
|
||||
$pluginId = $pluginClass::getId();
|
||||
if (!isset($pluginsData[$pluginId])) {
|
||||
continue;
|
||||
@ -102,25 +100,25 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
$pluginUpdates[$pluginId] = $pluginData;
|
||||
$message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})";
|
||||
if ($player) {
|
||||
$self->maniaControl->chat->sendSuccess($message, $player);
|
||||
$maniaControl->chat->sendSuccess($message, $player);
|
||||
}
|
||||
$self->maniaControl->log($message);
|
||||
$maniaControl->log($message);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($pluginUpdates)) {
|
||||
$message = 'Plugins Update Check completed: All Plugins are up-to-date!';
|
||||
if ($player) {
|
||||
$self->maniaControl->chat->sendSuccess($message, $player);
|
||||
$maniaControl->chat->sendSuccess($message, $player);
|
||||
}
|
||||
$self->maniaControl->log($message);
|
||||
$maniaControl->log($message);
|
||||
} else {
|
||||
$updatesCount = count($pluginUpdates);
|
||||
$message = "Plugins Update Check completed: There are {$updatesCount} Updates available!";
|
||||
if ($player) {
|
||||
$self->maniaControl->chat->sendSuccess($message, $player);
|
||||
$maniaControl->chat->sendSuccess($message, $player);
|
||||
}
|
||||
$self->maniaControl->log($message);
|
||||
$maniaControl->log($message);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -242,6 +240,14 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
|
||||
$self = $this;
|
||||
$this->maniaControl->fileReader->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (&$self, &$pluginUpdateData, &$player, &$update) {
|
||||
if (!$updateFileContent || $error) {
|
||||
$message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!";
|
||||
if ($player) {
|
||||
$self->maniaControl->chat->sendInformation($message, $player);
|
||||
}
|
||||
$self->maniaControl->log($message);
|
||||
return;
|
||||
}
|
||||
$actionNoun = ($update ? 'Update' : 'Install');
|
||||
$actionVerb = ($update ? 'Updating' : 'Installing');
|
||||
$actionVerbDone = ($update ? 'updated' : 'installed');
|
||||
@ -276,7 +282,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
return;
|
||||
}
|
||||
|
||||
$zip->extractTo(ManiaControlDir . '/plugins/');
|
||||
$zip->extractTo(ManiaControlDir . 'plugins' . DIRECTORY_SEPARATOR);
|
||||
$zip->close();
|
||||
unlink($updateFileName);
|
||||
FileUtil::removeTempFolder();
|
||||
|
@ -214,7 +214,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
*/
|
||||
public function getNightlyBuildDate() {
|
||||
if (!$this->currentBuildDate) {
|
||||
$nightlyBuildDateFile = ManiaControlDir . '/core/nightly_build.txt';
|
||||
$nightlyBuildDateFile = ManiaControlDir . 'core' . DIRECTORY_SEPARATOR . 'nightly_build.txt';
|
||||
if (file_exists($nightlyBuildDateFile)) {
|
||||
$this->currentBuildDate = file_get_contents($nightlyBuildDateFile);
|
||||
}
|
||||
@ -282,7 +282,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
|
||||
$this->maniaControl->log("Starting Update to Version v{$this->coreUpdateData->version}...");
|
||||
|
||||
$directories = array('/core/', '/plugins/');
|
||||
$directories = array('core', 'plugins');
|
||||
if (!FileUtil::checkWritePermissions($directories)) {
|
||||
$message = 'Update not possible: Incorrect File System Permissions!';
|
||||
if ($player) {
|
||||
@ -303,6 +303,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
|
||||
$self = $this;
|
||||
$this->maniaControl->fileReader->loadFile($this->coreUpdateData->url, function ($updateFileContent, $error) use (&$self, &$updateData, &$player) {
|
||||
if (!$updateFileContent || !$error) {
|
||||
$message = "Update failed: Couldn't load Update zip!";
|
||||
if ($player) {
|
||||
$self->maniaControl->chat->sendError($message, $player);
|
||||
}
|
||||
logMessage($message);
|
||||
return;
|
||||
}
|
||||
|
||||
$tempDir = FileUtil::getTempFolder();
|
||||
$updateFileName = $tempDir . basename($updateData->url);
|
||||
|
||||
@ -353,7 +362,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* @return bool
|
||||
*/
|
||||
private function setNightlyBuildDate($date) {
|
||||
$nightlyBuildDateFile = ManiaControlDir . '/core/nightly_build.txt';
|
||||
$nightlyBuildDateFile = ManiaControlDir . 'core' . DIRECTORY_SEPARATOR . 'nightly_build.txt';
|
||||
$success = (bool)file_put_contents($nightlyBuildDateFile, $date);
|
||||
$this->currentBuildDate = $date;
|
||||
return $success;
|
||||
|
Reference in New Issue
Block a user