TrackManiaControl/core/Update/UpdateManager.php

586 lines
18 KiB
PHP
Raw Permalink Normal View History

2013-12-17 17:38:44 +01:00
<?php
2014-02-10 22:54:49 +01:00
namespace ManiaControl\Update;
2013-12-17 17:38:44 +01:00
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
2014-01-31 00:04:40 +01:00
use ManiaControl\Callbacks\TimerListener;
2013-12-17 17:38:44 +01:00
use ManiaControl\Commands\CommandListener;
2017-05-13 23:52:51 +02:00
use ManiaControl\Communication\CommunicationAnswer;
use ManiaControl\Communication\CommunicationListener;
use ManiaControl\Communication\CommunicationMethods;
2017-03-30 20:27:57 +02:00
use ManiaControl\Files\AsyncHttpRequest;
2014-05-02 17:50:30 +02:00
use ManiaControl\Files\BackupUtil;
2014-02-10 16:52:16 +01:00
use ManiaControl\Files\FileUtil;
use ManiaControl\Logger;
2014-02-10 22:54:49 +01:00
use ManiaControl\ManiaControl;
2013-12-17 17:38:44 +01:00
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
use ManiaControl\Settings\Setting;
use ManiaControl\Settings\SettingManager;
2013-12-17 17:38:44 +01:00
/**
* Manager checking for ManiaControl Core Updates
2014-05-02 17:50:30 +02:00
*
* @author ManiaControl Team <mail@maniacontrol.com>
2020-01-22 10:39:35 +01:00
* @copyright 2014-2020 ManiaControl Team
2014-05-02 17:50:30 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2013-12-17 17:38:44 +01:00
*/
2017-05-13 23:52:51 +02:00
class UpdateManager implements CallbackListener, CommandListener, TimerListener, CommunicationListener {
2014-01-19 22:32:09 +01:00
/*
2013-12-17 17:38:44 +01:00
* Constants
*/
const CHANNEL_RELEASE = 'release';
const CHANNEL_BETA = 'beta';
const CHANNEL_NIGHTLY = 'nightly';
const SETTING_ENABLE_UPDATECHECK = 'Enable Automatic Core Update Check';
2014-05-02 17:50:30 +02:00
const SETTING_UPDATECHECK_INTERVAL = 'Core Update Check Interval (Hours)';
const SETTING_UPDATECHECK_CHANNEL = 'Core Update Channel (release, beta, nightly)';
const SETTING_PERFORM_BACKUPS = 'Perform Backup before Updating';
const SETTING_AUTO_UPDATE = 'Perform update automatically';
const SETTING_PERMISSION_UPDATE = 'Update Core';
2014-01-31 16:55:01 +01:00
const SETTING_PERMISSION_UPDATECHECK = 'Check Core Update';
const BUILD_DATE_FILE_NAME = 'build_date.txt';
2014-05-02 17:50:30 +02:00
2014-01-19 22:32:09 +01:00
/*
* Private properties
2013-12-17 17:38:44 +01:00
*/
2014-05-04 15:09:11 +02:00
/** @var ManiaControl $maniaControl */
2014-10-24 20:08:21 +02:00
private $maniaControl = null;
private $currentBuildDate = null;
/** @var UpdateData $coreUpdateData */
private $coreUpdateData = null;
2013-12-17 17:38:44 +01:00
2017-04-15 23:00:24 +02:00
/** @var PluginUpdateManager $pluginUpdateManager */
2017-04-14 19:17:40 +02:00
private $pluginUpdateManager = null;
2013-12-17 17:38:44 +01:00
/**
* Construct a new update manager instance
2014-05-02 17:50:30 +02:00
*
2013-12-31 17:17:40 +01:00
* @param ManiaControl $maniaControl
2013-12-17 17:38:44 +01:00
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
2014-05-02 17:50:30 +02:00
// Settings
2014-08-13 11:05:52 +02:00
$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);
2014-05-02 17:50:30 +02:00
// Callbacks
2014-08-13 11:05:52 +02:00
$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');
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged');
2014-05-02 17:50:30 +02:00
// Permissions
2014-08-13 11:05:52 +02:00
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_UPDATECHECK, AuthenticationManager::AUTH_LEVEL_MODERATOR);
2014-05-02 17:50:30 +02:00
// Chat commands
2014-08-13 11:05:52 +02:00
$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.');
2014-05-02 17:50:30 +02:00
// Children
$this->pluginUpdateManager = new PluginUpdateManager($maniaControl);
2017-05-13 23:52:51 +02:00
// Communication Methods
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::UPDATE_MANIA_CONTROL_CORE, $this, function ($data) {
$this->checkAndHandleCoreUpdate();
return new CommunicationAnswer();
});
}
2014-05-18 21:46:10 +02:00
/**
* Get the possible update channels
2014-05-18 21:46:10 +02:00
*
2014-05-27 23:00:39 +02:00
* @return string[]
2014-05-18 21:46:10 +02:00
*/
public function getUpdateChannels() {
// TODO: change default channel on release
return array(self::CHANNEL_BETA, self::CHANNEL_RELEASE, self::CHANNEL_NIGHTLY);
}
/**
* Return the plugin update manager
*
* @return PluginUpdateManager
*/
public function getPluginUpdateManager() {
return $this->pluginUpdateManager;
}
2013-12-17 17:38:44 +01:00
/**
2014-02-10 16:46:41 +01:00
* Perform Hourly Update Check
2013-12-17 17:38:44 +01:00
*/
public function hourlyUpdateCheck() {
2014-08-13 11:05:52 +02:00
$updateCheckEnabled = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ENABLE_UPDATECHECK);
2014-01-28 16:23:50 +01:00
if (!$updateCheckEnabled) {
$this->setCoreUpdateData();
} else {
$this->checkUpdate();
2013-12-17 17:38:44 +01:00
}
}
2014-05-02 17:50:30 +02:00
/**
* Set Core Update Data
*
* @param UpdateData $coreUpdateData
*/
public function setCoreUpdateData(UpdateData $coreUpdateData = null) {
$this->coreUpdateData = $coreUpdateData;
}
/**
* Start an Update Check
*/
public function checkUpdate() {
$this->checkCoreUpdateAsync(array($this, 'handleUpdateCheck'));
}
/**
* Checks a Core Update asynchronously
*
* @param callable $function
*/
2014-05-04 15:09:11 +02:00
public function checkCoreUpdateAsync($function) {
2014-05-02 17:50:30 +02:00
$updateChannel = $this->getCurrentUpdateChannelSetting();
$url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel;
2017-03-30 20:27:57 +02:00
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $url);
$asyncHttpRequest->setContentType(AsyncHttpRequest::CONTENT_TYPE_JSON);
$asyncHttpRequest->setCallable(function ($dataJson, $error) use (&$function) {
2014-08-25 15:33:22 +02:00
if ($error) {
Logger::logError('Error on UpdateCheck: ' . $error);
return;
}
2017-04-15 13:21:49 +02:00
2014-08-25 15:33:22 +02:00
$versions = json_decode($dataJson);
if (!$versions || !isset($versions[0])) {
call_user_func($function);
} else {
$updateData = new UpdateData($versions[0]);
call_user_func($function, $updateData);
}
});
2017-03-30 20:27:57 +02:00
$asyncHttpRequest->getData();
2014-05-02 17:50:30 +02:00
}
/**
* Retrieve the Update Channel Setting
*
* @return string
*/
2014-05-04 15:09:11 +02:00
public function getCurrentUpdateChannelSetting() {
2014-08-13 11:05:52 +02:00
$updateChannel = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_UPDATECHECK_CHANNEL);
2014-05-02 17:50:30 +02:00
$updateChannel = strtolower($updateChannel);
2014-05-18 21:46:10 +02:00
if (!in_array($updateChannel, $this->getUpdateChannels())) {
2014-05-02 17:50:30 +02:00
$updateChannel = self::CHANNEL_RELEASE;
}
return $updateChannel;
}
2013-12-17 17:38:44 +01:00
/**
2014-05-07 21:09:13 +02:00
* Handle the fetched Update Data of the hourly Check
2014-05-02 17:50:30 +02:00
*
* @param UpdateData $updateData
2013-12-17 17:38:44 +01:00
*/
2014-05-07 21:09:13 +02:00
public function handleUpdateCheck(UpdateData $updateData = null) {
if (!$this->checkUpdateData($updateData)) {
// No new update available
2014-01-20 21:54:58 +01:00
return;
}
if (!$this->checkUpdateDataBuildVersion($updateData)) {
// Server incompatible
Logger::logError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!");
2014-01-20 21:54:58 +01:00
return;
}
2014-05-02 17:50:30 +02:00
2014-05-07 21:09:13 +02:00
if ($this->coreUpdateData != $updateData) {
if ($this->isNightlyUpdateChannel()) {
Logger::log("New Nightly Build ({$updateData->releaseDate}) available!");
2014-05-07 21:09:13 +02:00
} else {
Logger::log("New ManiaControl Version {$updateData->version} available!");
2014-05-07 21:09:13 +02:00
}
$this->setCoreUpdateData($updateData);
}
2014-05-02 17:50:30 +02:00
$this->checkAutoUpdate();
2013-12-17 17:38:44 +01:00
}
2014-01-20 21:54:58 +01:00
/**
* Check if the given Update Data has a new Version and fits for the Server
2014-05-02 17:50:30 +02:00
*
* @param UpdateData $updateData
* @return bool
2014-01-20 21:54:58 +01:00
*/
public function checkUpdateData(UpdateData $updateData = null) {
if (!$updateData || !$updateData->url) {
// Data corrupted
return false;
2014-01-20 21:54:58 +01:00
}
2014-05-02 17:50:30 +02:00
$isNightly = $this->isNightlyUpdateChannel();
$buildDate = $this->getBuildDate();
2014-05-02 17:50:30 +02:00
if ($isNightly || $buildDate) {
return $updateData->isNewerThan($buildDate);
2014-04-14 14:38:00 +02:00
}
2014-05-02 17:50:30 +02:00
return ($updateData->version > ManiaControl::VERSION);
2014-01-20 21:54:58 +01:00
}
2014-05-02 17:50:30 +02:00
/**
* Check if ManiaControl is running the Nightly Update Channel
*
* @param string $updateChannel
* @return bool
*/
public function isNightlyUpdateChannel($updateChannel = null) {
if (!$updateChannel) {
$updateChannel = $this->getCurrentUpdateChannelSetting();
}
return ($updateChannel === self::CHANNEL_NIGHTLY);
}
/**
* Get the build date of the local version
2014-05-02 17:50:30 +02:00
*
* @return string
*/
public function getBuildDate() {
2014-05-02 17:50:30 +02:00
if (!$this->currentBuildDate) {
$nightlyBuildDateFile = MANIACONTROL_PATH . 'core' . DIRECTORY_SEPARATOR . self::BUILD_DATE_FILE_NAME;
2014-05-02 17:50:30 +02:00
if (file_exists($nightlyBuildDateFile)) {
$this->currentBuildDate = file_get_contents($nightlyBuildDateFile);
}
}
return $this->currentBuildDate;
}
2013-12-17 17:38:44 +01:00
/**
* Check if the Update Data is compatible with the Server
2014-05-02 17:50:30 +02:00
*
* @param UpdateData $updateData
* @return bool
2013-12-17 17:38:44 +01:00
*/
public function checkUpdateDataBuildVersion(UpdateData $updateData = null) {
if (!$updateData) {
// Data corrupted
return false;
2014-04-29 23:53:55 +02:00
}
2014-05-02 17:50:30 +02:00
2014-08-13 11:05:52 +02:00
$version = $this->maniaControl->getClient()->getVersion();
if ($updateData->minDedicatedBuild > $version->build) {
// Server not compatible
return false;
}
2014-05-02 17:50:30 +02:00
return true;
2014-02-10 21:32:41 +01:00
}
2013-12-31 18:25:07 +01:00
/**
* Check if an automatic Update should be performed
2013-12-31 18:25:07 +01:00
*/
public function checkAutoUpdate() {
2014-08-13 11:05:52 +02:00
$autoUpdate = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_AUTO_UPDATE);
if (!$autoUpdate) {
// Auto update turned off
return;
}
if (!$this->coreUpdateData) {
// No update available
return;
}
2017-03-30 20:27:57 +02:00
if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) > 0) {
// Server not empty
2013-12-31 18:25:07 +01:00
return;
}
2014-05-02 17:50:30 +02:00
$this->performCoreUpdate();
2014-02-10 21:32:41 +01:00
}
2013-12-27 23:26:27 +01:00
/**
* Perform a Core Update
2014-05-02 17:50:30 +02:00
*
* @param Player $player
2013-12-27 23:26:27 +01:00
* @return bool
*/
2014-05-04 15:09:11 +02:00
public function performCoreUpdate(Player $player = null) {
if (!$this->coreUpdateData) {
$message = 'Update failed: No update Data available!';
if ($player) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getChat()->sendError($message, $player);
}
Logger::logError($message);
2014-01-28 16:23:50 +01:00
return false;
}
2014-05-02 17:50:30 +02:00
Logger::log("Starting Update to Version v{$this->coreUpdateData->version}...");
2014-05-02 17:50:30 +02:00
2014-05-03 21:37:28 +02:00
$directories = array('core', 'plugins');
if (!FileUtil::checkWritePermissions($directories)) {
$message = 'Update not possible: Incorrect File System Permissions!';
if ($player) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getChat()->sendError($message, $player);
2013-12-27 23:26:27 +01:00
}
Logger::logError($message);
2014-02-10 21:32:41 +01:00
return false;
2013-12-27 23:26:27 +01:00
}
2014-05-02 17:50:30 +02:00
2014-08-13 11:05:52 +02:00
$performBackup = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PERFORM_BACKUPS);
if ($performBackup && !BackupUtil::performFullBackup()) {
$message = 'Creating Backup before Update failed!';
if ($player) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getChat()->sendError($message, $player);
}
Logger::logError($message);
}
2014-05-02 17:50:30 +02:00
2014-06-17 23:27:28 +02:00
$updateData = $this->coreUpdateData;
2017-03-30 20:27:57 +02:00
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $updateData->url);
$asyncHttpRequest->setCallable(function ($updateFileContent, $error) use (
2014-08-25 15:33:22 +02:00
$updateData, &$player
) {
if (!$updateFileContent || $error) {
$message = "Update failed: Couldn't load Update zip! {$error}";
if ($player) {
$this->maniaControl->getChat()->sendError($message, $player);
}
Logger::logError($message);
return;
}
$tempDir = FileUtil::getTempFolder();
if (!$tempDir) {
$message = "Update failed: Can't save Update zip!";
if ($player) {
$this->maniaControl->getChat()->sendError($message, $player);
}
Logger::logError($message);
return;
}
$updateFileName = $tempDir . basename($updateData->url);
$bytes = file_put_contents($updateFileName, $updateFileContent);
if (!$bytes || $bytes <= 0) {
$message = "Update failed: Couldn't save Update zip!";
if ($player) {
$this->maniaControl->getChat()->sendError($message, $player);
}
Logger::logError($message);
return;
}
$zip = new \ZipArchive();
$result = $zip->open($updateFileName);
if ($result !== true) {
$message = "Update failed: Couldn't open Update Zip. ({$result})";
if ($player) {
$this->maniaControl->getChat()->sendError($message, $player);
}
Logger::logError($message);
unlink($updateFileName);
return;
}
2017-04-15 23:00:24 +02:00
//Don't overwrite the files while testing
if (!defined('PHP_UNIT_TEST')) {
2017-04-15 22:01:27 +02:00
$zip->extractTo(MANIACONTROL_PATH);
}
2017-04-15 23:00:24 +02:00
$zip->close();
unlink($updateFileName);
FileUtil::deleteTempFolder();
// Set the build date
$this->setBuildDate($updateData->releaseDate);
2014-08-25 15:33:22 +02:00
2020-05-30 23:28:39 +02:00
$message = $this->maniaControl->getChat()->formatMessage(
'Update finished! See what we updated with %s!',
'//changelog'
);
2014-08-25 15:33:22 +02:00
if ($player) {
$this->maniaControl->getChat()->sendSuccess($message, $player);
}
Logger::log($message);
2020-04-24 18:51:38 +02:00
$this->maniaControl->reboot();
2014-08-25 15:33:22 +02:00
});
2014-05-02 17:50:30 +02:00
2017-03-30 20:27:57 +02:00
$asyncHttpRequest->getData();
2013-12-27 23:26:27 +01:00
return true;
}
2014-01-28 16:23:50 +01:00
/**
* Set the build date version
2014-05-02 17:50:30 +02:00
*
* @param string $date
* @return bool
2014-01-28 16:23:50 +01:00
*/
public function setBuildDate($date) {
$nightlyBuildDateFile = MANIACONTROL_PATH . 'core' . DIRECTORY_SEPARATOR . self::BUILD_DATE_FILE_NAME;
2014-10-24 20:08:21 +02:00
$success = (bool) file_put_contents($nightlyBuildDateFile, $date);
2014-05-02 17:50:30 +02:00
$this->currentBuildDate = $date;
return $success;
}
/**
* Handle ManiaControl PlayerJoined callback
*
* @param Player $player
*/
public function handlePlayerJoined(Player $player) {
if (!$this->coreUpdateData) {
return;
}
// Announce available update
2017-03-30 20:27:57 +02:00
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
2014-05-02 17:50:30 +02:00
return;
}
2020-05-30 23:28:39 +02:00
$message = '';
2014-05-02 17:50:30 +02:00
if ($this->isNightlyUpdateChannel()) {
2020-05-30 23:28:39 +02:00
$message = $this->maniaControl->getChat()->formatMessage(
'New Nightly Build (%s) available!',
$this->coreUpdateData->releaseDate
);
2014-05-02 17:50:30 +02:00
} else {
2020-05-30 23:28:39 +02:00
$message = $this->maniaControl->getChat()->formatMessage(
'New ManiaControl Version (%s) available!',
$this->coreUpdateData->version
);
2014-01-28 16:23:50 +01:00
}
2020-05-30 23:28:39 +02:00
$this->maniaControl->getChat()->sendInformation($message, $player);
2014-01-28 16:23:50 +01:00
}
2013-12-27 23:26:27 +01:00
/**
2014-05-02 17:50:30 +02:00
* Handle Player Disconnect Callback
*
* @param Player $player
2013-12-27 23:26:27 +01:00
*/
2014-05-02 17:50:30 +02:00
public function handlePlayerDisconnect(Player $player) {
$this->checkAutoUpdate();
}
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
public function handleSettingChanged(Setting $setting) {
if (!$setting->setting != self::SETTING_UPDATECHECK_INTERVAL) {
return;
}
2020-04-21 17:44:41 +02:00
$this->maniaControl->getTimerManager()->updateTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60);
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
}
2014-05-02 17:50:30 +02:00
/**
* Handle //checkupdate command
*
* @param array $chatCallback
* @param Player $player
*/
public function handle_CheckUpdate(array $chatCallback, Player $player) {
2017-03-30 20:27:57 +02:00
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATECHECK)) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
2014-05-02 17:50:30 +02:00
return;
2013-12-27 23:26:27 +01:00
}
2014-05-02 17:50:30 +02:00
2014-06-17 23:27:28 +02:00
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
if (!$this->checkUpdateData($updateData)) {
2020-05-30 23:28:39 +02:00
$this->maniaControl->getChat()->sendInformation('No Update available!', $player);
2014-05-02 17:50:30 +02:00
return;
}
2014-06-17 23:27:28 +02:00
if (!$this->checkUpdateDataBuildVersion($updateData)) {
2020-05-30 23:28:39 +02:00
$message = $this->maniaControl->getChat()->formatMessage(
'Please update your server to %s in order to receive further ManiaControl updates!',
$updateData->minDedicatedBuild
);
$this->maniaControl->getChat()->sendError($message, $player);
2014-05-02 17:50:30 +02:00
return;
}
2014-06-17 23:27:28 +02:00
$isNightly = $this->isNightlyUpdateChannel();
2014-05-02 17:50:30 +02:00
if ($isNightly) {
$buildDate = $this->getBuildDate();
2014-05-02 17:50:30 +02:00
if ($buildDate) {
if ($updateData->isNewerThan($buildDate)) {
2020-05-30 23:28:39 +02:00
$message = $this->maniaControl->getChat()->formatMessage(
'No new Build available! (Current Build: %s)',
$buildDate
);
$this->maniaControl->getChat()->sendInformation($message, $player);
2014-05-02 17:50:30 +02:00
} else {
2020-05-30 23:28:39 +02:00
$message = $this->maniaControl->getChat()->formatMesssage(
'New Nightly Build (%s) available! (Current Build: %s)',
$updateData->releaseDate,
$buildDate
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
2014-05-02 17:50:30 +02:00
}
} else {
2020-05-30 23:28:39 +02:00
$message = $this->maniaControl->getChat()->formatMesssage(
'New Nightly Build (%s) available!',
$updateData->releaseDate
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
2014-05-02 17:50:30 +02:00
}
} else {
2020-05-30 23:28:39 +02:00
$message = $this->maniaControl->getChat()->formatMesssage(
'Update for Version %s available!',
$updateData->version
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
2014-05-02 17:50:30 +02:00
}
2014-05-04 15:14:58 +02:00
2014-06-17 23:27:28 +02:00
$this->coreUpdateData = $updateData;
2014-05-02 17:50:30 +02:00
});
}
/**
* Handle //coreupdate command
*
* @param array $chatCallback
* @param Player $player
*/
public function handle_CoreUpdate(array $chatCallback, Player $player) {
2017-03-30 20:27:57 +02:00
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
2014-05-02 17:50:30 +02:00
return;
}
2017-05-13 23:52:51 +02:00
$this->checkAndHandleCoreUpdate($player);
}
/**
* Handle CoreUpdate Asnyc
*
* @param null $player
*/
private function checkAndHandleCoreUpdate($player = null) {
2014-06-17 23:27:28 +02:00
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
2014-05-02 17:50:30 +02:00
if (!$updateData) {
2017-05-13 23:52:51 +02:00
if ($player) {
$this->maniaControl->getChat()->sendError('Update is currently not possible!', $player);
}
2014-05-02 17:50:30 +02:00
return;
}
2014-06-17 23:27:28 +02:00
if (!$this->checkUpdateDataBuildVersion($updateData)) {
2017-05-13 23:52:51 +02:00
if ($player) {
2020-05-30 23:28:39 +02:00
$this->maniaControl->getChat()->sendError('The Next ManiaControl Update requires a newer Dedicated Server Version!', $player);
2017-05-13 23:52:51 +02:00
}
2014-05-02 17:50:30 +02:00
return;
}
2014-06-17 23:27:28 +02:00
$this->coreUpdateData = $updateData;
2014-05-02 17:50:30 +02:00
2014-06-17 23:27:28 +02:00
$this->performCoreUpdate($player);
2014-05-02 17:50:30 +02:00
});
2013-12-27 23:26:27 +01:00
}
2013-12-17 17:38:44 +01:00
}