added update channel to usage report

This commit is contained in:
Steffen Schröder 2014-05-04 15:29:01 +02:00
parent 0ce3c8bae6
commit ea2e0b0698

View File

@ -19,8 +19,8 @@ class UsageReporter implements TimerListener {
/* /*
* Constants * Constants
*/ */
const UPDATE_MINUTE_COUNT = 10; const UPDATE_MINUTE_COUNT = 10;
const SETTING_DISABLE_USAGE_REPORTING = 'Disable Usage Reporting'; const SETTING_REPORT_USAGE = 'Report Usage to $lManiaControl.com$l';
/* /*
* Private Properties * Private Properties
@ -34,22 +34,22 @@ class UsageReporter implements TimerListener {
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DISABLE_USAGE_REPORTING, false);
$this->maniaControl->timerManager->registerTimerListening($this, 'reportUsage', 1000 * 60 * self::UPDATE_MINUTE_COUNT);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_REPORT_USAGE, true);
$this->maniaControl->timerManager->registerTimerListening($this, 'reportUsage', 1000 * 60 * self::UPDATE_MINUTE_COUNT);
} }
/** /**
* Reports Usage every xx Minutes * Report Usage every xx Minutes
* *
* @param float $time * @param float $time
*/ */
public function reportUsage($time) { public function reportUsage($time) {
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DISABLE_USAGE_REPORTING)) { if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_REPORT_USAGE)) {
return; return;
} }
$properties = array(); $properties = array();
$properties['ManiaControlVersion'] = ManiaControl::VERSION; $properties['ManiaControlVersion'] = ManiaControl::VERSION;
$properties['OperatingSystem'] = php_uname(); $properties['OperatingSystem'] = php_uname();
@ -57,17 +57,18 @@ class UsageReporter implements TimerListener {
$properties['ServerLogin'] = $this->maniaControl->server->login; $properties['ServerLogin'] = $this->maniaControl->server->login;
$properties['TitleId'] = $this->maniaControl->server->titleId; $properties['TitleId'] = $this->maniaControl->server->titleId;
$properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->client->getServerName()); $properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->client->getServerName());
$properties['UpdateChannel'] = $this->maniaControl->updateManager->getCurrentUpdateChannelSetting();
$properties['PlayerCount'] = $this->maniaControl->playerManager->getPlayerCount(); $properties['PlayerCount'] = $this->maniaControl->playerManager->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->client->getMaxPlayers(); $maxPlayers = $this->maniaControl->client->getMaxPlayers();
$properties['MaxPlayers'] = $maxPlayers["CurrentValue"]; $properties['MaxPlayers'] = $maxPlayers['CurrentValue'];
try { try {
$scriptName = $this->maniaControl->client->getScriptName(); $scriptName = $this->maniaControl->client->getScriptName();
$properties['ScriptName'] = $scriptName["CurrentValue"]; $properties['ScriptName'] = $scriptName['CurrentValue'];
} catch (Exception $e) { } catch (Exception $e) {
if ($e->getMessage() == 'Not in script mode.') { if ($e->getMessage() == 'Not in script mode.') {
$properties['ScriptName'] = ''; $properties['ScriptName'] = '';
@ -93,10 +94,10 @@ class UsageReporter implements TimerListener {
$info = base64_encode($json); $info = base64_encode($json);
$self = $this; $self = $this;
$this->maniaControl->fileReader->loadFile(ManiaControl::URL_WEBSERVICE . "/usagereport?info=" . urlencode($info), function ($response, $error) use (&$self) { $this->maniaControl->fileReader->loadFile(ManiaControl::URL_WEBSERVICE . '/usagereport?info=' . urlencode($info), function ($response, $error) use (&$self) {
$response = json_decode($response); $response = json_decode($response);
if ($error || !$response) { if ($error || !$response) {
$self->maniaControl->log("Error while Sending data: " . $error); $self->maniaControl->log('Error while Sending data: ' . $error);
} }
}); });
} }