diff --git a/ManiaControl.php b/ManiaControl.php index 0b4e7035..2fbfe8ae 100644 --- a/ManiaControl.php +++ b/ManiaControl.php @@ -11,7 +11,7 @@ error_reporting(E_ALL); // Run configuration -define('DEV_MODE', true); // Development mode to not send error reports etc. +define('DEV_MODE', false); // Development mode to not send error reports etc. 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 diff --git a/core/ErrorHandler.php b/core/ErrorHandler.php index c63c91ac..44bfa519 100644 --- a/core/ErrorHandler.php +++ b/core/ErrorHandler.php @@ -27,7 +27,7 @@ class ErrorHandler { * Private properties */ /** @var ManiaControl $maniaControl */ - private $maniaControl = null; + private $maniaControl = null; private $handlingError = null; /** @@ -144,6 +144,8 @@ class ErrorHandler { $report['ManiaControlVersion'] = ManiaControl::VERSION; } + $report['DedicatedBuildVersion'] = $this->maniaControl->getDedicatedServerBuildVersion(); + $json = json_encode(Formatter::utf8($report)); $info = base64_encode($json); @@ -235,7 +237,7 @@ class ErrorHandler { $traceString = ''; $stepCount = 0; foreach ($backtrace as $traceStep) { - $skipStep = $this->shouldSkipTraceStep($traceStep); + $skipStep = $this->shouldSkipTraceStep($traceStep); $traceString .= '#' . $stepCount . ': '; if (isset($traceStep['class'])) { if (!$sourceClass && !$skipStep && !$this->isIgnoredSourceClass($traceStep['class'])) { @@ -329,7 +331,7 @@ class ErrorHandler { } else if (is_array($arg)) { $string .= 'array(' . $this->parseArgumentsArray($arg) . ')'; } else { - $type = gettype($arg); + $type = gettype($arg); $string .= $type . '('; if (is_string($arg)) { $param = $arg; @@ -438,6 +440,8 @@ class ErrorHandler { $report['ManiaControlVersion'] = ManiaControl::VERSION; } + $report['DedicatedBuildVersion'] = $this->maniaControl->getDedicatedServerBuildVersion(); + $errorReport = json_encode(Formatter::utf8($report)); $url = ManiaControl::URL_WEBSERVICE . 'errorreport'; diff --git a/core/ManiaControl.php b/core/ManiaControl.php index fb572fa7..eb158f05 100644 --- a/core/ManiaControl.php +++ b/core/ManiaControl.php @@ -183,6 +183,8 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, /** @var ModeScriptEventManager $modeScriptEventManager */ private $modeScriptEventManager = null; + private $dedicatedServerBuildVersion = ""; + /** * Construct a new ManiaControl instance */ @@ -216,7 +218,6 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, $this->pluginManager = new PluginManager($this); $this->updateManager = new UpdateManager($this); - $this->getErrorHandler()->init(); // Permissions @@ -565,6 +566,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, $this->requestQuitMessage = $message; } + /** * Run ManiaControl */ @@ -576,9 +578,10 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, $this->connect(); // Check if the version of the server is high enough - $version = $this->getClient()->getVersion(); - if ($version->build < self::MIN_DEDIVERSION) { - $this->quit("The Server has Version '{$version->build}', while at least '" . self::MIN_DEDIVERSION . "' is required!", true); + $version = $this->getClient()->getVersion(); + $this->dedicatedServerBuildVersion = $version->build; + if ($this->dedicatedServerBuildVersion < self::MIN_DEDIVERSION) { + $this->quit("The Server has Version '{$this->dedicatedServerBuildVersion}', while at least '" . self::MIN_DEDIVERSION . "' is required!", true); } // Listen for shutdown @@ -651,6 +654,16 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, $this->getServer()->getScriptManager()->enableScriptCallbacks(); } + /** + * Get The Build Version of the Dedicated Server + * + * @return string + */ + public function getDedicatedServerBuildVersion() { + return $this->dedicatedServerBuildVersion; + } + + /** * Return the server * diff --git a/core/Server/UsageReporter.php b/core/Server/UsageReporter.php index 72bdb0e0..88cb21aa 100644 --- a/core/Server/UsageReporter.php +++ b/core/Server/UsageReporter.php @@ -51,19 +51,21 @@ class UsageReporter implements TimerListener { return; } - $properties = array(); - $properties['ManiaControlVersion'] = ManiaControl::VERSION; - $properties['OperatingSystem'] = php_uname(); - $properties['PHPVersion'] = phpversion(); - $properties['ServerLogin'] = $this->maniaControl->getServer()->login; - $properties['TitleId'] = $this->maniaControl->getServer()->titleId; - $properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->getClient()->getServerName()); - $properties['UpdateChannel'] = $this->maniaControl->getUpdateManager()->getCurrentUpdateChannelSetting(); + $properties = array(); + $properties['ManiaControlVersion'] = ManiaControl::VERSION; + $properties['OperatingSystem'] = php_uname(); + $properties['PHPVersion'] = phpversion(); + $properties['ServerLogin'] = $this->maniaControl->getServer()->login; + $properties['TitleId'] = $this->maniaControl->getServer()->titleId; + $properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->getClient()->getServerName()); + $properties['UpdateChannel'] = $this->maniaControl->getUpdateManager()->getCurrentUpdateChannelSetting(); + $properties['DedicatedBuildVersion'] = $this->maniaControl->getDedicatedServerBuildVersion(); $properties['PlayerCount'] = $this->maniaControl->getPlayerManager()->getPlayerCount(); $properties['MemoryUsage'] = memory_get_usage(); $properties['MemoryPeakUsage'] = memory_get_peak_usage(); + $maxPlayers = $this->maniaControl->getClient()->getMaxPlayers(); $properties['MaxPlayers'] = $maxPlayers['CurrentValue']; diff --git a/plugins/MCTeam/KarmaPlugin.php b/plugins/MCTeam/KarmaPlugin.php index 7f78b334..1796a32f 100644 --- a/plugins/MCTeam/KarmaPlugin.php +++ b/plugins/MCTeam/KarmaPlugin.php @@ -69,7 +69,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { * Private properties */ /** @var ManiaControl $maniaControl */ - private $maniaControl = null; + private $maniaControl = null; private $updateManialink = false; /** @var ManiaLink $manialink */ private $manialink = null; @@ -229,8 +229,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { * Open a Mx Karma Session */ private function mxKarmaOpenSession() { - if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED) - ) { + if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)) { return; } @@ -253,26 +252,26 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $this->mxKarma['connectionInProgress'] = true; $this->maniaControl->getFileReader()->loadFile($query, function ($json, $error) use ($mxKarmaCode) { - $this->mxKarma['connectionInProgress'] = false; - if ($error) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error: ' . $error); - return; - } - $data = json_decode($json); - if (!$data) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $json, $data); - return; - } - if ($data->success) { - $this->mxKarma['session'] = $data->data; - $this->activateSession($mxKarmaCode); - } else { - Logger::logError("Error while authenticating on Mania-Exchange Karma"); - // TODO remove temp trigger - $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message); - $this->mxKarma['connectionInProgress'] = false; - } - }, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); + $this->mxKarma['connectionInProgress'] = false; + if ($error) { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error: ' . $error); + return; + } + $data = json_decode($json); + if (!$data) { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $json, $data); + return; + } + if ($data->success) { + $this->mxKarma['session'] = $data->data; + $this->activateSession($mxKarmaCode); + } else { + Logger::logError("Error while authenticating on Mania-Exchange Karma"); + // TODO remove temp trigger + $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message); + $this->mxKarma['connectionInProgress'] = false; + } + }, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); } /** @@ -288,32 +287,32 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $query .= '&activationHash=' . urlencode($hash); $this->maniaControl->getFileReader()->loadFile($query, function ($json, $error) use ($query) { - $this->mxKarma['connectionInProgress'] = false; - if ($error) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); - return; - } - $data = json_decode($json); - if (!$data) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); - return; - } - if ($data->success && $data->data->activated) { - Logger::log('Successfully authenticated on Mania-Exchange Karma'); + $this->mxKarma['connectionInProgress'] = false; + if ($error) { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); + return; + } + $data = json_decode($json); + if (!$data) { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); + return; + } + if ($data->success && $data->data->activated) { + Logger::log('Successfully authenticated on Mania-Exchange Karma'); - // Fetch the Mx Karma Votes - $this->getMxKarmaVotes(); - } else { - if ($data->data->message === 'invalid hash') { - $permission = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getAuthenticationManager(), PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS); - $this->maniaControl->getChat()->sendErrorToAdmins("Invalid Mania-Exchange Karma code in Karma Plugin specified!", $permission); - } else { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message, $query); - } - Logger::logError("Error while activating Mania-Exchange Karma Session: " . $data->data->message); - unset($this->mxKarma['session']); - } - }, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); + // Fetch the Mx Karma Votes + $this->getMxKarmaVotes(); + } else { + if ($data->data->message === 'invalid hash') { + $permission = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getAuthenticationManager(), PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS); + $this->maniaControl->getChat()->sendErrorToAdmins("Invalid Mania-Exchange Karma code in Karma Plugin specified!", $permission); + } else { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message, $query); + } + Logger::logError("Error while activating Mania-Exchange Karma Session: " . $data->data->message); + unset($this->mxKarma['session']); + } + }, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); } /** @@ -331,8 +330,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { * Fetch the mxKarmaVotes for the current map */ public function getMxKarmaVotes(Player $player = null) { - if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED) - ) { + if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)) { return; } @@ -370,47 +368,45 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } $content = json_encode($properties); - $this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey), function ($json, - $error) use - ( - &$player - ) { - if ($error) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); - return; - } - $data = json_decode($json); - if (!$data) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); - return; - } + $this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) use ( + &$player + ) { + if ($error) { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); + return; + } + $data = json_decode($json); + if (!$data) { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); + return; + } - if ($data->success) { - // Fetch averages if it's for the whole server - if (!$player) { - $this->mxKarma['voteCount'] = $data->data->votecount; - $this->mxKarma['voteAverage'] = $data->data->voteaverage; - $this->mxKarma['modeVoteCount'] = $data->data->modevotecount; - $this->mxKarma['modeVoteAverage'] = $data->data->modevoteaverage; - } + if ($data->success) { + // Fetch averages if it's for the whole server + if (!$player) { + $this->mxKarma['voteCount'] = $data->data->votecount; + $this->mxKarma['voteAverage'] = $data->data->voteaverage; + $this->mxKarma['modeVoteCount'] = $data->data->modevotecount; + $this->mxKarma['modeVoteAverage'] = $data->data->modevoteaverage; + } - foreach ($data->data->votes as $votes) { - $this->mxKarma['votes'][$votes->login] = $votes->vote; - } + foreach ($data->data->votes as $votes) { + $this->mxKarma['votes'][$votes->login] = $votes->vote; + } - $this->updateManialink = true; - $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma); - Logger::logInfo('MX-Karma Votes successfully fetched!'); - } else { - // Problem occurred - Logger::logError('Error while fetching votes: ' . $data->data->message); - if ($data->data->message === 'invalid session') { - unset($this->mxKarma['session']); - } else { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']); - } - } - }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); + $this->updateManialink = true; + $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma); + Logger::logInfo('MX-Karma Votes successfully fetched!'); + } else { + // Problem occurred + Logger::logError('Error while fetching votes: ' . $data->data->message); + if ($data->data->message === 'invalid session') { + unset($this->mxKarma['session']); + } else { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']); + } + } + }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); } /** @@ -487,29 +483,28 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $content = json_encode($properties); - $this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($json, - $error) { - if ($error) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); - return; - } - $data = json_decode($json); - if (!$data) { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); - return; - } - if ($data->success) { - Logger::logInfo('Votes successfully submitted!'); - } else { - // Problem occurred - Logger::logError("Error while updating votes: '{$data->data->message}'"); - if ($data->data->message === "invalid session") { - unset($this->mxKarma['session']); - } else { - $this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']); - } - } - }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); + $this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) { + if ($error) { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); + return; + } + $data = json_decode($json); + if (!$data) { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); + return; + } + if ($data->success) { + Logger::logInfo('Votes successfully submitted!'); + } else { + // Problem occurred + Logger::logError("Error while updating votes: '{$data->data->message}'"); + if ($data->data->message === "invalid session") { + unset($this->mxKarma['session']); + } else { + $this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']); + } + } + }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); } /** @@ -595,9 +590,9 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { } // Calculate actual voting - $vote -= $voteLow; + $vote -= $voteLow; $voteHigh -= $voteLow; - $vote /= $voteHigh; + $vote /= $voteHigh; // Save vote $map = $this->maniaControl->getMapManager()->getCurrentMap(); @@ -754,13 +749,11 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $karmaSettingName = self::buildKarmaSettingName($serverLogin); switch ($setting->setting) { - case $karmaSettingName: - { + case $karmaSettingName: { $this->mxKarmaOpenSession(); break; } - case self::SETTING_WIDGET_ENABLE: - { + case self::SETTING_WIDGET_ENABLE: { if ($setting->value) { $this->updateManialink = true; $this->handle1Second(time()); @@ -803,8 +796,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $voteCount = $votes['count']; } - if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE) - ) { + if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)) { // Build karma manialink $this->buildManialink(); @@ -893,7 +885,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $count = 0; while ($vote = $result->fetch_object()) { $votes[$vote->vote] = $vote; - $count += $vote->count; + $count += $vote->count; } $votes['count'] = $count; $result->free(); @@ -968,13 +960,11 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { * @param Map $map */ public function importMxKarmaVotes(Map $map) { - if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED) - ) { + if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)) { return; } - if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_IMPORTING) - ) { + if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_IMPORTING)) { return; } @@ -1039,8 +1029,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { * Save Mx Karma Votes at MapEnd */ public function sendMxKarmaVotes(Map $map) { - if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED) - ) { + if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)) { return; }