2014-01-17 18:58:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Server;
|
|
|
|
|
2014-01-31 00:04:40 +01:00
|
|
|
use ManiaControl\Callbacks\TimerListener;
|
2014-01-17 18:58:15 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class reports Usage
|
|
|
|
*
|
|
|
|
* @author steeffeen & kremsy
|
|
|
|
*/
|
2014-01-31 00:04:40 +01:00
|
|
|
class UsageReporter implements TimerListener {
|
2014-01-17 18:58:15 +01:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
const UPDATE_MINUTE_COUNT = 10;
|
|
|
|
const SETTING_DISABLE_USAGE_REPORTING = 'Disable Usage Reporting';
|
|
|
|
/**
|
|
|
|
* Private Properties
|
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Server Settings Instance
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
//TODO setting
|
2014-01-31 00:04:40 +01:00
|
|
|
|
|
|
|
$this->maniaControl->timerManager->registerTimerListening($this, 'reportUsage', 1000 * 60 * self::UPDATE_MINUTE_COUNT);
|
2014-01-17 18:58:15 +01:00
|
|
|
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DISABLE_USAGE_REPORTING, false);
|
|
|
|
}
|
|
|
|
|
2014-01-31 00:04:40 +01:00
|
|
|
/**
|
|
|
|
* Reports Usage every xx Minutes
|
|
|
|
*
|
|
|
|
* @param $time
|
|
|
|
*/
|
|
|
|
public function reportUsage($time) {
|
|
|
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DISABLE_USAGE_REPORTING)) {
|
2014-01-17 18:58:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-31 00:04:40 +01:00
|
|
|
$properties = array();
|
|
|
|
$properties['MC_Version'] = ManiaControl::VERSION;
|
|
|
|
$properties['OperatingSystem'] = php_uname();
|
|
|
|
$properties['PHPVersion'] = phpversion();
|
|
|
|
$properties['ServerLogin'] = $this->maniaControl->server->login;
|
|
|
|
$properties['TitleId'] = $this->maniaControl->server->titleId;
|
|
|
|
$properties['ServerName'] = $this->maniaControl->server->getName();
|
|
|
|
$properties['PlayerCount'] = count($this->maniaControl->playerManager->getPlayers());
|
|
|
|
$properties['MaxPlayers'] = $this->maniaControl->client->getMaxPlayers();
|
2014-01-17 18:58:15 +01:00
|
|
|
|
2014-01-31 00:04:40 +01:00
|
|
|
$json = json_encode($properties);
|
|
|
|
$info = base64_encode($json);
|
2014-01-17 18:58:15 +01:00
|
|
|
|
2014-02-08 15:13:59 +01:00
|
|
|
//TODO make on website
|
2014-02-08 15:15:21 +01:00
|
|
|
/* $this->maniaControl->fileReader->loadFile("url/webservice?info=" . $info, function ($response, $error) {
|
|
|
|
if ($error) {
|
|
|
|
$this->maniaControl->log("Error while Sending data: " . $error);
|
|
|
|
}
|
|
|
|
});*/
|
2014-01-17 18:58:15 +01:00
|
|
|
}
|
|
|
|
}
|