added dedibuild to error and usage reporting

This commit is contained in:
kremsy 2017-03-26 13:58:23 +02:00
parent f2ab40a50f
commit d46eb59fb9
5 changed files with 150 additions and 142 deletions

View File

@ -11,7 +11,7 @@
error_reporting(E_ALL); error_reporting(E_ALL);
// Run configuration // 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_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('LOG_NAME_USE_PID', true); // Use current process id as suffix for log file name in logs folder

View File

@ -27,7 +27,7 @@ class ErrorHandler {
* Private properties * Private properties
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
private $handlingError = null; private $handlingError = null;
/** /**
@ -144,6 +144,8 @@ class ErrorHandler {
$report['ManiaControlVersion'] = ManiaControl::VERSION; $report['ManiaControlVersion'] = ManiaControl::VERSION;
} }
$report['DedicatedBuildVersion'] = $this->maniaControl->getDedicatedServerBuildVersion();
$json = json_encode(Formatter::utf8($report)); $json = json_encode(Formatter::utf8($report));
$info = base64_encode($json); $info = base64_encode($json);
@ -235,7 +237,7 @@ class ErrorHandler {
$traceString = ''; $traceString = '';
$stepCount = 0; $stepCount = 0;
foreach ($backtrace as $traceStep) { foreach ($backtrace as $traceStep) {
$skipStep = $this->shouldSkipTraceStep($traceStep); $skipStep = $this->shouldSkipTraceStep($traceStep);
$traceString .= '#' . $stepCount . ': '; $traceString .= '#' . $stepCount . ': ';
if (isset($traceStep['class'])) { if (isset($traceStep['class'])) {
if (!$sourceClass && !$skipStep && !$this->isIgnoredSourceClass($traceStep['class'])) { if (!$sourceClass && !$skipStep && !$this->isIgnoredSourceClass($traceStep['class'])) {
@ -329,7 +331,7 @@ class ErrorHandler {
} else if (is_array($arg)) { } else if (is_array($arg)) {
$string .= 'array(' . $this->parseArgumentsArray($arg) . ')'; $string .= 'array(' . $this->parseArgumentsArray($arg) . ')';
} else { } else {
$type = gettype($arg); $type = gettype($arg);
$string .= $type . '('; $string .= $type . '(';
if (is_string($arg)) { if (is_string($arg)) {
$param = $arg; $param = $arg;
@ -438,6 +440,8 @@ class ErrorHandler {
$report['ManiaControlVersion'] = ManiaControl::VERSION; $report['ManiaControlVersion'] = ManiaControl::VERSION;
} }
$report['DedicatedBuildVersion'] = $this->maniaControl->getDedicatedServerBuildVersion();
$errorReport = json_encode(Formatter::utf8($report)); $errorReport = json_encode(Formatter::utf8($report));
$url = ManiaControl::URL_WEBSERVICE . 'errorreport'; $url = ManiaControl::URL_WEBSERVICE . 'errorreport';

View File

@ -183,6 +183,8 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
/** @var ModeScriptEventManager $modeScriptEventManager */ /** @var ModeScriptEventManager $modeScriptEventManager */
private $modeScriptEventManager = null; private $modeScriptEventManager = null;
private $dedicatedServerBuildVersion = "";
/** /**
* Construct a new ManiaControl instance * Construct a new ManiaControl instance
*/ */
@ -216,7 +218,6 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
$this->pluginManager = new PluginManager($this); $this->pluginManager = new PluginManager($this);
$this->updateManager = new UpdateManager($this); $this->updateManager = new UpdateManager($this);
$this->getErrorHandler()->init(); $this->getErrorHandler()->init();
// Permissions // Permissions
@ -565,6 +566,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
$this->requestQuitMessage = $message; $this->requestQuitMessage = $message;
} }
/** /**
* Run ManiaControl * Run ManiaControl
*/ */
@ -576,9 +578,10 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
$this->connect(); $this->connect();
// Check if the version of the server is high enough // Check if the version of the server is high enough
$version = $this->getClient()->getVersion(); $version = $this->getClient()->getVersion();
if ($version->build < self::MIN_DEDIVERSION) { $this->dedicatedServerBuildVersion = $version->build;
$this->quit("The Server has Version '{$version->build}', while at least '" . self::MIN_DEDIVERSION . "' is required!", true); 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 // Listen for shutdown
@ -651,6 +654,16 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
$this->getServer()->getScriptManager()->enableScriptCallbacks(); $this->getServer()->getScriptManager()->enableScriptCallbacks();
} }
/**
* Get The Build Version of the Dedicated Server
*
* @return string
*/
public function getDedicatedServerBuildVersion() {
return $this->dedicatedServerBuildVersion;
}
/** /**
* Return the server * Return the server
* *

View File

@ -51,19 +51,21 @@ class UsageReporter implements TimerListener {
return; return;
} }
$properties = array(); $properties = array();
$properties['ManiaControlVersion'] = ManiaControl::VERSION; $properties['ManiaControlVersion'] = ManiaControl::VERSION;
$properties['OperatingSystem'] = php_uname(); $properties['OperatingSystem'] = php_uname();
$properties['PHPVersion'] = phpversion(); $properties['PHPVersion'] = phpversion();
$properties['ServerLogin'] = $this->maniaControl->getServer()->login; $properties['ServerLogin'] = $this->maniaControl->getServer()->login;
$properties['TitleId'] = $this->maniaControl->getServer()->titleId; $properties['TitleId'] = $this->maniaControl->getServer()->titleId;
$properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->getClient()->getServerName()); $properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->getClient()->getServerName());
$properties['UpdateChannel'] = $this->maniaControl->getUpdateManager()->getCurrentUpdateChannelSetting(); $properties['UpdateChannel'] = $this->maniaControl->getUpdateManager()->getCurrentUpdateChannelSetting();
$properties['DedicatedBuildVersion'] = $this->maniaControl->getDedicatedServerBuildVersion();
$properties['PlayerCount'] = $this->maniaControl->getPlayerManager()->getPlayerCount(); $properties['PlayerCount'] = $this->maniaControl->getPlayerManager()->getPlayerCount();
$properties['MemoryUsage'] = memory_get_usage(); $properties['MemoryUsage'] = memory_get_usage();
$properties['MemoryPeakUsage'] = memory_get_peak_usage(); $properties['MemoryPeakUsage'] = memory_get_peak_usage();
$maxPlayers = $this->maniaControl->getClient()->getMaxPlayers(); $maxPlayers = $this->maniaControl->getClient()->getMaxPlayers();
$properties['MaxPlayers'] = $maxPlayers['CurrentValue']; $properties['MaxPlayers'] = $maxPlayers['CurrentValue'];

View File

@ -69,7 +69,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* Private properties * Private properties
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
private $updateManialink = false; private $updateManialink = false;
/** @var ManiaLink $manialink */ /** @var ManiaLink $manialink */
private $manialink = null; private $manialink = null;
@ -229,8 +229,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* Open a Mx Karma Session * Open a Mx Karma Session
*/ */
private function mxKarmaOpenSession() { 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; return;
} }
@ -253,26 +252,26 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$this->mxKarma['connectionInProgress'] = true; $this->mxKarma['connectionInProgress'] = true;
$this->maniaControl->getFileReader()->loadFile($query, function ($json, $error) use ($mxKarmaCode) { $this->maniaControl->getFileReader()->loadFile($query, function ($json, $error) use ($mxKarmaCode) {
$this->mxKarma['connectionInProgress'] = false; $this->mxKarma['connectionInProgress'] = false;
if ($error) { if ($error) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error: ' . $error); $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error: ' . $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $json, $data); $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $json, $data);
return; return;
} }
if ($data->success) { if ($data->success) {
$this->mxKarma['session'] = $data->data; $this->mxKarma['session'] = $data->data;
$this->activateSession($mxKarmaCode); $this->activateSession($mxKarmaCode);
} else { } else {
Logger::logError("Error while authenticating on Mania-Exchange Karma"); Logger::logError("Error while authenticating on Mania-Exchange Karma");
// TODO remove temp trigger // TODO remove temp trigger
$this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message); $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message);
$this->mxKarma['connectionInProgress'] = false; $this->mxKarma['connectionInProgress'] = false;
} }
}, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); }, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000);
} }
/** /**
@ -288,32 +287,32 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$query .= '&activationHash=' . urlencode($hash); $query .= '&activationHash=' . urlencode($hash);
$this->maniaControl->getFileReader()->loadFile($query, function ($json, $error) use ($query) { $this->maniaControl->getFileReader()->loadFile($query, function ($json, $error) use ($query) {
$this->mxKarma['connectionInProgress'] = false; $this->mxKarma['connectionInProgress'] = false;
if ($error) { if ($error) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error);
return; return;
} }
$data = json_decode($json); $data = json_decode($json);
if (!$data) { if (!$data) {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data);
return; return;
} }
if ($data->success && $data->data->activated) { if ($data->success && $data->data->activated) {
Logger::log('Successfully authenticated on Mania-Exchange Karma'); Logger::log('Successfully authenticated on Mania-Exchange Karma');
// Fetch the Mx Karma Votes // Fetch the Mx Karma Votes
$this->getMxKarmaVotes(); $this->getMxKarmaVotes();
} else { } else {
if ($data->data->message === 'invalid hash') { if ($data->data->message === 'invalid hash') {
$permission = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getAuthenticationManager(), PluginMenu::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS); $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); $this->maniaControl->getChat()->sendErrorToAdmins("Invalid Mania-Exchange Karma code in Karma Plugin specified!", $permission);
} else { } else {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message, $query); $this->maniaControl->getErrorHandler()->triggerDebugNotice('auth error', $data->data->message, $query);
} }
Logger::logError("Error while activating Mania-Exchange Karma Session: " . $data->data->message); Logger::logError("Error while activating Mania-Exchange Karma Session: " . $data->data->message);
unset($this->mxKarma['session']); unset($this->mxKarma['session']);
} }
}, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000); }, AsynchronousFileReader::CONTENT_TYPE_JSON, 1000);
} }
/** /**
@ -331,8 +330,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* Fetch the mxKarmaVotes for the current map * Fetch the mxKarmaVotes for the current map
*/ */
public function getMxKarmaVotes(Player $player = null) { 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; return;
} }
@ -370,47 +368,45 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
$content = json_encode($properties); $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, $this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_GET_MAP_RATING . '?sessionKey=' . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) use (
$error) use &$player
( ) {
&$player if ($error) {
) { $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error);
if ($error) { return;
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); }
return; $data = json_decode($json);
} if (!$data) {
$data = json_decode($json); $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data);
if (!$data) { return;
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); }
return;
}
if ($data->success) { if ($data->success) {
// Fetch averages if it's for the whole server // Fetch averages if it's for the whole server
if (!$player) { if (!$player) {
$this->mxKarma['voteCount'] = $data->data->votecount; $this->mxKarma['voteCount'] = $data->data->votecount;
$this->mxKarma['voteAverage'] = $data->data->voteaverage; $this->mxKarma['voteAverage'] = $data->data->voteaverage;
$this->mxKarma['modeVoteCount'] = $data->data->modevotecount; $this->mxKarma['modeVoteCount'] = $data->data->modevotecount;
$this->mxKarma['modeVoteAverage'] = $data->data->modevoteaverage; $this->mxKarma['modeVoteAverage'] = $data->data->modevoteaverage;
} }
foreach ($data->data->votes as $votes) { foreach ($data->data->votes as $votes) {
$this->mxKarma['votes'][$votes->login] = $votes->vote; $this->mxKarma['votes'][$votes->login] = $votes->vote;
} }
$this->updateManialink = true; $this->updateManialink = true;
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma); $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_KARMA_MXUPDATED, $this->mxKarma);
Logger::logInfo('MX-Karma Votes successfully fetched!'); Logger::logInfo('MX-Karma Votes successfully fetched!');
} else { } else {
// Problem occurred // Problem occurred
Logger::logError('Error while fetching votes: ' . $data->data->message); Logger::logError('Error while fetching votes: ' . $data->data->message);
if ($data->data->message === 'invalid session') { if ($data->data->message === 'invalid session') {
unset($this->mxKarma['session']); unset($this->mxKarma['session']);
} else { } else {
$this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']); $this->maniaControl->getErrorHandler()->triggerDebugNotice('fetch error', $data->data->message, self::MX_KARMA_GET_MAP_RATING, $this->mxKarma['session']);
} }
} }
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON); }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
} }
/** /**
@ -487,29 +483,28 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$content = json_encode($properties); $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, $this->maniaControl->getFileReader()->postData(self::MX_KARMA_URL . self::MX_KARMA_SAVE_VOTES . "?sessionKey=" . urlencode($this->mxKarma['session']->sessionKey), function ($json, $error) {
$error) { if ($error) {
if ($error) { $this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error);
$this->maniaControl->getErrorHandler()->triggerDebugNotice('mx karma error', $error); return;
return; }
} $data = json_decode($json);
$data = json_decode($json); if (!$data) {
if (!$data) { $this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data);
$this->maniaControl->getErrorHandler()->triggerDebugNotice('parse error', $json, $data); return;
return; }
} if ($data->success) {
if ($data->success) { Logger::logInfo('Votes successfully submitted!');
Logger::logInfo('Votes successfully submitted!'); } else {
} else { // Problem occurred
// Problem occurred Logger::logError("Error while updating votes: '{$data->data->message}'");
Logger::logError("Error while updating votes: '{$data->data->message}'"); if ($data->data->message === "invalid session") {
if ($data->data->message === "invalid session") { unset($this->mxKarma['session']);
unset($this->mxKarma['session']); } else {
} else { $this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']);
$this->maniaControl->getErrorHandler()->triggerDebugNotice('saving error', $data->data->message, self::MX_KARMA_SAVE_VOTES, $this->mxKarma['session']); }
} }
} }, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
}, $content, false, AsynchronousFileReader::CONTENT_TYPE_JSON);
} }
/** /**
@ -595,9 +590,9 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
} }
// Calculate actual voting // Calculate actual voting
$vote -= $voteLow; $vote -= $voteLow;
$voteHigh -= $voteLow; $voteHigh -= $voteLow;
$vote /= $voteHigh; $vote /= $voteHigh;
// Save vote // Save vote
$map = $this->maniaControl->getMapManager()->getCurrentMap(); $map = $this->maniaControl->getMapManager()->getCurrentMap();
@ -754,13 +749,11 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$karmaSettingName = self::buildKarmaSettingName($serverLogin); $karmaSettingName = self::buildKarmaSettingName($serverLogin);
switch ($setting->setting) { switch ($setting->setting) {
case $karmaSettingName: case $karmaSettingName: {
{
$this->mxKarmaOpenSession(); $this->mxKarmaOpenSession();
break; break;
} }
case self::SETTING_WIDGET_ENABLE: case self::SETTING_WIDGET_ENABLE: {
{
if ($setting->value) { if ($setting->value) {
$this->updateManialink = true; $this->updateManialink = true;
$this->handle1Second(time()); $this->handle1Second(time());
@ -803,8 +796,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$voteCount = $votes['count']; $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 // Build karma manialink
$this->buildManialink(); $this->buildManialink();
@ -893,7 +885,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$count = 0; $count = 0;
while ($vote = $result->fetch_object()) { while ($vote = $result->fetch_object()) {
$votes[$vote->vote] = $vote; $votes[$vote->vote] = $vote;
$count += $vote->count; $count += $vote->count;
} }
$votes['count'] = $count; $votes['count'] = $count;
$result->free(); $result->free();
@ -968,13 +960,11 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* @param Map $map * @param Map $map
*/ */
public function importMxKarmaVotes(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; return;
} }
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_IMPORTING) if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_IMPORTING)) {
) {
return; return;
} }
@ -1039,8 +1029,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* Save Mx Karma Votes at MapEnd * Save Mx Karma Votes at MapEnd
*/ */
public function sendMxKarmaVotes(Map $map) { 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; return;
} }