Merge remote-tracking branch 'origin/master'
This commit is contained in:
		| @@ -20,7 +20,7 @@ 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); | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -37,16 +37,16 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 	/* | 	/* | ||||||
| 	 * Public Properties | 	 * Public Properties | ||||||
| 	 */ | 	 */ | ||||||
|  | 	/** @var PluginUpdateManager $pluginUpdateManager */ | ||||||
| 	public $pluginUpdateManager = null; | 	public $pluginUpdateManager = null; | ||||||
|  | 	/** @var UpdateData $coreUpdateData */ | ||||||
|  | 	public $coreUpdateData = null; | ||||||
|  |  | ||||||
| 	/* | 	/* | ||||||
| 	 * Private Properties | 	 * Private Properties | ||||||
| 	 */ | 	 */ | ||||||
|  | 	/** @var ManiaControl $maniaControl */ | ||||||
| 	private $maniaControl = null; | 	private $maniaControl = null; | ||||||
| 	/** |  | ||||||
| 	 * @var UpdateData $coreUpdateData |  | ||||||
| 	 */ |  | ||||||
| 	private $coreUpdateData = null; |  | ||||||
| 	private $currentBuildDate = null; | 	private $currentBuildDate = null; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| @@ -85,7 +85,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 	/** | 	/** | ||||||
| 	 * Perform Hourly Update Check | 	 * Perform Hourly Update Check | ||||||
| 	 * | 	 * | ||||||
| 	 * @param $time | 	 * @param float $time | ||||||
| 	 */ | 	 */ | ||||||
| 	public function hourlyUpdateCheck($time) { | 	public function hourlyUpdateCheck($time) { | ||||||
| 		$updateCheckEnabled = $this->maniaControl->settingManager->getSetting($this, self::SETTING_ENABLEUPDATECHECK); | 		$updateCheckEnabled = $this->maniaControl->settingManager->getSetting($this, self::SETTING_ENABLEUPDATECHECK); | ||||||
| @@ -117,7 +117,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 	 * | 	 * | ||||||
| 	 * @param callable $function | 	 * @param callable $function | ||||||
| 	 */ | 	 */ | ||||||
| 	private function checkCoreUpdateAsync($function) { | 	public function checkCoreUpdateAsync($function) { | ||||||
| 		$updateChannel = $this->getCurrentUpdateChannelSetting(); | 		$updateChannel = $this->getCurrentUpdateChannelSetting(); | ||||||
| 		$url           = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel; | 		$url           = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel; | ||||||
|  |  | ||||||
| @@ -137,7 +137,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 	 * | 	 * | ||||||
| 	 * @return string | 	 * @return string | ||||||
| 	 */ | 	 */ | ||||||
| 	private function getCurrentUpdateChannelSetting() { | 	public function getCurrentUpdateChannelSetting() { | ||||||
| 		$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL); | 		$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL); | ||||||
| 		$updateChannel = strtolower($updateChannel); | 		$updateChannel = strtolower($updateChannel); | ||||||
| 		if (!in_array($updateChannel, array(self::CHANNEL_RELEASE, self::CHANNEL_BETA, self::CHANNEL_NIGHTLY))) { | 		if (!in_array($updateChannel, array(self::CHANNEL_RELEASE, self::CHANNEL_BETA, self::CHANNEL_NIGHTLY))) { | ||||||
| @@ -270,7 +270,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 	 * @param Player $player | 	 * @param Player $player | ||||||
| 	 * @return bool | 	 * @return bool | ||||||
| 	 */ | 	 */ | ||||||
| 	private function performCoreUpdate(Player $player = null) { | 	public function performCoreUpdate(Player $player = null) { | ||||||
| 		if (!$this->coreUpdateData) { | 		if (!$this->coreUpdateData) { | ||||||
| 			$message = 'Update failed: No update Data available!'; | 			$message = 'Update failed: No update Data available!'; | ||||||
| 			if ($player) { | 			if ($player) { | ||||||
| @@ -302,13 +302,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		$self = $this; | 		$self = $this; | ||||||
| 		$this->maniaControl->fileReader->loadFile($this->coreUpdateData->url, function ($updateFileContent, $error) use (&$self, &$updateData, &$player) { | 		$updateData = $this->coreUpdateData; | ||||||
| 			if (!$updateFileContent || !$error) { | 		$maniaControl = $this->maniaControl; | ||||||
| 				$message = "Update failed: Couldn't load Update zip!"; | 		$this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use (&$self, &$maniaControl, &$updateData, &$player) { | ||||||
|  | 			if (!$updateFileContent || $error) { | ||||||
|  | 				$message = "Update failed: Couldn't load Update zip! {$error}"; | ||||||
| 				if ($player) { | 				if ($player) { | ||||||
| 					$self->maniaControl->chat->sendError($message, $player); | 					$maniaControl->chat->sendError($message, $player); | ||||||
| 				} | 				} | ||||||
| 				logMessage($message); | 				$maniaControl->log($message); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| @@ -319,19 +321,20 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 			if (!$bytes || $bytes <= 0) { | 			if (!$bytes || $bytes <= 0) { | ||||||
| 				$message = "Update failed: Couldn't save Update zip!"; | 				$message = "Update failed: Couldn't save Update zip!"; | ||||||
| 				if ($player) { | 				if ($player) { | ||||||
| 					$self->maniaControl->chat->sendError($message, $player); | 					$maniaControl->chat->sendError($message, $player); | ||||||
| 				} | 				} | ||||||
| 				logMessage($message); | 				$maniaControl->log($message); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			$zip    = new \ZipArchive(); | 			$zip    = new \ZipArchive(); | ||||||
| 			$result = $zip->open($updateFileName); | 			$result = $zip->open($updateFileName); | ||||||
| 			if ($result !== true) { | 			if ($result !== true) { | ||||||
| 				trigger_error("Couldn't open Update Zip. ({$result})"); | 				$message = "Update failed: Couldn't open Update Zip. ({$result})"; | ||||||
| 				if ($player) { | 				if ($player) { | ||||||
| 					$self->maniaControl->chat->sendError("Update failed: Couldn't open Update zip!", $player); | 					$maniaControl->chat->sendError($message, $player); | ||||||
| 				} | 				} | ||||||
|  | 				$maniaControl->log($message); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| @@ -345,11 +348,11 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
|  |  | ||||||
| 			$message = 'Update finished!'; | 			$message = 'Update finished!'; | ||||||
| 			if ($player) { | 			if ($player) { | ||||||
| 				$self->maniaControl->chat->sendSuccess($message, $player); | 				$maniaControl->chat->sendSuccess($message, $player); | ||||||
| 			} | 			} | ||||||
| 			$self->maniaControl->log($message); | 			$maniaControl->log($message); | ||||||
|  |  | ||||||
| 			$self->maniaControl->restart(); | 			$maniaControl->restart(); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		return true; | 		return true; | ||||||
| @@ -361,7 +364,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 	 * @param string $date | 	 * @param string $date | ||||||
| 	 * @return bool | 	 * @return bool | ||||||
| 	 */ | 	 */ | ||||||
| 	private function setNightlyBuildDate($date) { | 	public  function setNightlyBuildDate($date) { | ||||||
| 		$nightlyBuildDateFile   = ManiaControlDir . 'core' . DIRECTORY_SEPARATOR . 'nightly_build.txt'; | 		$nightlyBuildDateFile   = ManiaControlDir . 'core' . DIRECTORY_SEPARATOR . 'nightly_build.txt'; | ||||||
| 		$success                = (bool)file_put_contents($nightlyBuildDateFile, $date); | 		$success                = (bool)file_put_contents($nightlyBuildDateFile, $date); | ||||||
| 		$this->currentBuildDate = $date; | 		$this->currentBuildDate = $date; | ||||||
| @@ -411,14 +414,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		$self = $this; | 		$self = $this; | ||||||
| 		$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$self, &$player) { | 		$maniaControl = $this->maniaControl; | ||||||
|  | 		$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$self, &$maniaControl, &$player) { | ||||||
| 			if (!$self->checkUpdateData($updateData)) { | 			if (!$self->checkUpdateData($updateData)) { | ||||||
| 				$self->maniaControl->chat->sendInformation('No Update available!', $player->login); | 				$maniaControl->chat->sendInformation('No Update available!', $player->login); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			if (!$self->checkUpdateDataBuildVersion($updateData)) { | 			if (!$self->checkUpdateDataBuildVersion($updateData)) { | ||||||
| 				$self->maniaControl->chat->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login); | 				$maniaControl->chat->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| @@ -427,16 +431,19 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 				$buildDate = $self->getNightlyBuildDate(); | 				$buildDate = $self->getNightlyBuildDate(); | ||||||
| 				if ($buildDate) { | 				if ($buildDate) { | ||||||
| 					if ($updateData->isNewerThan($buildDate)) { | 					if ($updateData->isNewerThan($buildDate)) { | ||||||
| 						$self->maniaControl->chat->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login); | 						$maniaControl->chat->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login); | ||||||
|  | 						return; | ||||||
| 					} else { | 					} else { | ||||||
| 						$self->maniaControl->chat->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login); | 						$maniaControl->chat->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login); | ||||||
| 					} | 					} | ||||||
| 				} else { | 				} else { | ||||||
| 					$self->maniaControl->chat->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login); | 					$maniaControl->chat->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login); | ||||||
| 				} | 				} | ||||||
| 			} else { | 			} else { | ||||||
| 				$self->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login); | 				$maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			$self->coreUpdateData = $updateData; | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -453,26 +460,18 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		$self = $this; | 		$self = $this; | ||||||
| 		$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$self, &$player) { | 		$maniaControl = $this->maniaControl; | ||||||
|  | 		$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$self, &$maniaControl, &$player) { | ||||||
| 			if (!$updateData) { | 			if (!$updateData) { | ||||||
| 				$self->maniaControl->chat->sendError('Update is currently not possible!', $player->login); | 				$maniaControl->chat->sendError('Update is currently not possible!', $player); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			if (!$self->checkUpdateDataBuildVersion($updateData)) { | 			if (!$self->checkUpdateDataBuildVersion($updateData)) { | ||||||
| 				$self->maniaControl->chat->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player->login); | 				$maniaControl->chat->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			$message = "Starting Update to Version v{$updateData->version}..."; | 			$self->coreUpdateData = $updateData; | ||||||
| 			$self->maniaControl->chat->sendInformation($message, $player->login); |  | ||||||
| 			$self->maniaControl->log($message); |  | ||||||
|  |  | ||||||
| 			$performBackup = $self->maniaControl->settingManager->getSetting($self, UpdateManager::SETTING_PERFORM_BACKUPS); |  | ||||||
| 			if ($performBackup && !BackupUtil::performFullBackup()) { |  | ||||||
| 				$message = 'Creating Backup failed!'; |  | ||||||
| 				$self->maniaControl->chat->sendError($message, $player->login); |  | ||||||
| 				$self->maniaControl->log($message); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			$self->performCoreUpdate($player); | 			$self->performCoreUpdate($player); | ||||||
| 		}); | 		}); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user