performed code formatting
This commit is contained in:
@ -60,25 +60,38 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Settings
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ENABLE_UPDATECHECK, true);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AUTO_UPDATE, true);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_UPDATECHECK_INTERVAL, 1);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_UPDATECHECK_CHANNEL, $this->getUpdateChannels());
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PERFORM_BACKUPS, true);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_ENABLE_UPDATECHECK, true);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_AUTO_UPDATE, true);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_UPDATECHECK_INTERVAL, 1);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_UPDATECHECK_CHANNEL, $this->getUpdateChannels());
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_PERFORM_BACKUPS, true);
|
||||
|
||||
// Callbacks
|
||||
$updateInterval = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_UPDATECHECK_INTERVAL);
|
||||
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval);
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
||||
$updateInterval = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_UPDATECHECK_INTERVAL);
|
||||
$this->maniaControl->getTimerManager()
|
||||
->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval);
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
||||
|
||||
// Permissions
|
||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_UPDATECHECK, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->definePermissionLevel(self::SETTING_PERMISSION_UPDATECHECK, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
|
||||
// Chat commands
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true, 'Checks if there is a core update.');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true, 'Performs the core update.');
|
||||
$this->maniaControl->getCommandManager()
|
||||
->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true, 'Checks if there is a core update.');
|
||||
$this->maniaControl->getCommandManager()
|
||||
->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true, 'Performs the core update.');
|
||||
|
||||
// Children
|
||||
$this->pluginUpdateManager = new PluginUpdateManager($maniaControl);
|
||||
@ -107,7 +120,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* Perform Hourly Update Check
|
||||
*/
|
||||
public function hourlyUpdateCheck() {
|
||||
$updateCheckEnabled = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ENABLE_UPDATECHECK);
|
||||
$updateCheckEnabled = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_ENABLE_UPDATECHECK);
|
||||
if (!$updateCheckEnabled) {
|
||||
$this->setCoreUpdateData();
|
||||
} else {
|
||||
@ -140,7 +154,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
$updateChannel = $this->getCurrentUpdateChannelSetting();
|
||||
$url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel;
|
||||
|
||||
$this->maniaControl->getFileReader()->loadFile($url, function ($dataJson, $error) use (&$function) {
|
||||
$this->maniaControl->getFileReader()
|
||||
->loadFile($url, function ($dataJson, $error) use (&$function) {
|
||||
if ($error) {
|
||||
Logger::logError('Error on UpdateCheck: ' . $error);
|
||||
return;
|
||||
@ -161,7 +176,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentUpdateChannelSetting() {
|
||||
$updateChannel = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_UPDATECHECK_CHANNEL);
|
||||
$updateChannel = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_UPDATECHECK_CHANNEL);
|
||||
$updateChannel = strtolower($updateChannel);
|
||||
if (!in_array($updateChannel, $this->getUpdateChannels())) {
|
||||
$updateChannel = self::CHANNEL_RELEASE;
|
||||
@ -259,7 +275,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
return false;
|
||||
}
|
||||
|
||||
$version = $this->maniaControl->getClient()->getVersion();
|
||||
$version = $this->maniaControl->getClient()
|
||||
->getVersion();
|
||||
if ($updateData->minDedicatedBuild > $version->build) {
|
||||
// Server not compatible
|
||||
return false;
|
||||
@ -272,7 +289,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* Check if an automatic Update should be performed
|
||||
*/
|
||||
public function checkAutoUpdate() {
|
||||
$autoUpdate = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_AUTO_UPDATE);
|
||||
$autoUpdate = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_AUTO_UPDATE);
|
||||
if (!$autoUpdate) {
|
||||
// Auto update turned off
|
||||
return;
|
||||
@ -281,7 +299,9 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
// No update available
|
||||
return;
|
||||
}
|
||||
if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) > 0) {
|
||||
if ($this->maniaControl->getPlayerManager()
|
||||
->getPlayerCount(false) > 0
|
||||
) {
|
||||
// Server not empty
|
||||
return;
|
||||
}
|
||||
@ -299,7 +319,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
if (!$this->coreUpdateData) {
|
||||
$message = 'Update failed: No update Data available!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return false;
|
||||
@ -311,39 +332,45 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
if (!FileUtil::checkWritePermissions($directories)) {
|
||||
$message = 'Update not possible: Incorrect File System Permissions!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return false;
|
||||
}
|
||||
|
||||
$performBackup = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PERFORM_BACKUPS);
|
||||
$performBackup = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_PERFORM_BACKUPS);
|
||||
if ($performBackup && !BackupUtil::performFullBackup()) {
|
||||
$message = 'Creating Backup before Update failed!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
}
|
||||
|
||||
$updateData = $this->coreUpdateData;
|
||||
$this->maniaControl->getFileReader()->loadFile($updateData->url, function ($updateFileContent, $error) use (
|
||||
$this->maniaControl->getFileReader()
|
||||
->loadFile($updateData->url, function ($updateFileContent, $error) use (
|
||||
$updateData, &$player
|
||||
) {
|
||||
if (!$updateFileContent || $error) {
|
||||
$message = "Update failed: Couldn't load Update zip! {$error}";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
|
||||
$tempDir = FileUtil::getTempFolder();
|
||||
$tempDir = FileUtil::getTempFolder();
|
||||
if (!$tempDir) {
|
||||
$message = "Update failed: Can't save Update zip!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
@ -354,7 +381,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
if (!$bytes || $bytes <= 0) {
|
||||
$message = "Update failed: Couldn't save Update zip!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
@ -365,7 +393,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
if ($result !== true) {
|
||||
$message = "Update failed: Couldn't open Update Zip. ({$result})";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
unlink($updateFileName);
|
||||
@ -382,7 +411,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
|
||||
$message = 'Update finished!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
|
||||
@ -415,14 +445,18 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
return;
|
||||
}
|
||||
// Announce available update
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, self::SETTING_PERMISSION_UPDATE)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isNightlyUpdateChannel()) {
|
||||
$this->maniaControl->getChat()->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login);
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login);
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
|
||||
}
|
||||
}
|
||||
|
||||
@ -442,19 +476,24 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handle_CheckUpdate(array $chatCallback, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATECHECK)) {
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, self::SETTING_PERMISSION_UPDATECHECK)
|
||||
) {
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
|
||||
if (!$this->checkUpdateData($updateData)) {
|
||||
$this->maniaControl->getChat()->sendInformation('No Update available!', $player->login);
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation('No Update available!', $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->checkUpdateDataBuildVersion($updateData)) {
|
||||
$this->maniaControl->getChat()->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login);
|
||||
$this->maniaControl->getChat()
|
||||
->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -463,16 +502,20 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
$buildDate = $this->getNightlyBuildDate();
|
||||
if ($buildDate) {
|
||||
if ($updateData->isNewerThan($buildDate)) {
|
||||
$this->maniaControl->getChat()->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login);
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login);
|
||||
return;
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login);
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login);
|
||||
}
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login);
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login);
|
||||
}
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
|
||||
}
|
||||
|
||||
$this->coreUpdateData = $updateData;
|
||||
@ -486,18 +529,23 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handle_CoreUpdate(array $chatCallback, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, self::SETTING_PERMISSION_UPDATE)
|
||||
) {
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
|
||||
if (!$updateData) {
|
||||
$this->maniaControl->getChat()->sendError('Update is currently not possible!', $player);
|
||||
$this->maniaControl->getChat()
|
||||
->sendError('Update is currently not possible!', $player);
|
||||
return;
|
||||
}
|
||||
if (!$this->checkUpdateDataBuildVersion($updateData)) {
|
||||
$this->maniaControl->getChat()->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player);
|
||||
$this->maniaControl->getChat()
|
||||
->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user