From 9dc455774f4e8a4311ebf124858818e5e0e44128 Mon Sep 17 00:00:00 2001 From: Alexander Nell Date: Sun, 26 Apr 2020 09:47:33 +0200 Subject: [PATCH] Disabled //restart , restored backwards compatibility for the backend on restart --- core/Communication/CommunicationMethods.php | 2 ++ core/ManiaControl.php | 25 +++++++++++++++++++++ core/Maps/MapCommands.php | 2 +- core/Utils/SystemUtil.php | 22 +++++++++--------- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/core/Communication/CommunicationMethods.php b/core/Communication/CommunicationMethods.php index 33120016..252c9e75 100644 --- a/core/Communication/CommunicationMethods.php +++ b/core/Communication/CommunicationMethods.php @@ -15,6 +15,8 @@ interface CommunicationMethods { * - message */ const REBOOT_MANIA_CONTROL = "ManiaControl.Reboot"; + /** @deprecated */ + const RESTART_MANIA_CONTROL = "ManiaControl.Restart"; /** Update the ManiaControl Core */ const UPDATE_MANIA_CONTROL_CORE = "UpdateManager.CoreUpdate"; diff --git a/core/ManiaControl.php b/core/ManiaControl.php index c6694d39..e289e2e2 100644 --- a/core/ManiaControl.php +++ b/core/ManiaControl.php @@ -228,6 +228,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, // Commands $this->getCommandManager()->registerCommandListener('version', $this, 'commandVersion', false, 'Shows ManiaControl version.'); $this->getCommandManager()->registerCommandListener('reboot', $this, 'commandReboot', true, 'Reboots ManiaControl.'); + $this->getCommandManager()->registerCommandListener('restart', $this, 'commandRestart', true, 'Restarts ManiaControl.'); $this->getCommandManager()->registerCommandListener('shutdown', $this, 'commandShutdown', true, 'Shuts ManiaControl down.'); // Check connection every 30 seconds @@ -549,6 +550,30 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, $this->reboot("ManiaControl Reboot requested by '{$player->login}'!"); } + /** + * Handle Restart AdminCommand + * + * @param array $chatCallback + * @param Player $player + */ + public function commandRestart(array $chatCallback, Player $player) { + if (!$this->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_REBOOT)) { + $this->getAuthenticationManager()->sendNotAllowed($player); + return; + } + $this->getChat->sendError('The command //restart got disabled, reboot ManiaControl with //reboot instead', $player); + } + + /** + * @deprecated + * Restart ManiaControl + * + * @param string $message + */ + public function restart($message = null) { + $this->reboot($message); + } + /** * Reboot ManiaControl * diff --git a/core/Maps/MapCommands.php b/core/Maps/MapCommands.php index 6226505f..0550c636 100644 --- a/core/Maps/MapCommands.php +++ b/core/Maps/MapCommands.php @@ -51,7 +51,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb // Admin commands $this->maniaControl->getCommandManager()->registerCommandListener(array('nextmap', 'next', 'skip'), $this, 'command_NextMap', true, 'Skips to the next map.'); - $this->maniaControl->getCommandManager()->registerCommandListener(array('restartmap', 'resmap', 'restart', 'res'), $this, 'command_RestartMap', true, 'Restarts the current map.'); + $this->maniaControl->getCommandManager()->registerCommandListener(array('restartmap', 'resmap', 'res'), $this, 'command_RestartMap', true, 'Restarts the current map.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('replaymap', 'replay'), $this, 'command_ReplayMap', true, 'Replays the current map (after the end of the map).'); $this->maniaControl->getCommandManager()->registerCommandListener(array('addmap', 'add'), $this, 'command_AddMap', true, 'Adds map from ManiaExchange.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('removemap', 'removethis'), $this, 'command_RemoveMap', true, 'Removes the current map.'); diff --git a/core/Utils/SystemUtil.php b/core/Utils/SystemUtil.php index d647eff2..9c96b8d5 100644 --- a/core/Utils/SystemUtil.php +++ b/core/Utils/SystemUtil.php @@ -134,13 +134,13 @@ class SystemUtil { } /** - * Restart ManiaControl immediately + * Reboot ManiaControl immediately */ - public static function restart() { + public static function reboot() { if (SystemUtil::isUnix()) { - self::restartUnix(); + self::rebootUnix(); } else { - self::restartWindows(); + self::rebootWindows(); } } @@ -156,9 +156,9 @@ class SystemUtil { /** * Perform restart on Unix */ - private static function restartUnix() { + private static function rebootUnix() { if (!SystemUtil::checkFunctionAvailability('exec')) { - Logger::log("Can't restart ManiaControl because the function 'exec' is disabled!"); + Logger::log("Can't reboot ManiaControl because the function 'exec' is disabled!"); return; } $fileName = null; @@ -169,7 +169,7 @@ class SystemUtil { } $filePath = MANIACONTROL_PATH . $fileName; if (!is_readable($filePath)) { - Logger::log("Can't restart ManiaControl because the file '{$fileName}' doesn't exist or isn't readable!"); + Logger::log("Can't reboot ManiaControl because the file '{$fileName}' doesn't exist or isn't readable!"); return; } $command = 'sh ' . escapeshellarg($filePath) . ' > /dev/null &'; @@ -197,11 +197,11 @@ class SystemUtil { } /** - * Perform restart on Windows + * Perform reboot on Windows */ - private static function restartWindows() { + private static function rebootWindows() { if (!SystemUtil::checkFunctionAvailability('system')) { - Logger::log("Can't restart ManiaControl because the function 'system' is disabled!"); + Logger::log("Can't reboot ManiaControl because the function 'system' is disabled!"); return; } $fileName = null; @@ -212,7 +212,7 @@ class SystemUtil { } $filePath = MANIACONTROL_PATH . $fileName; if (!is_readable($filePath)) { - Logger::log("Can't restart ManiaControl because the file '{$fileName}' doesn't exist or isn't readable!"); + Logger::log("Can't reboot ManiaControl because the file '{$fileName}' doesn't exist or isn't readable!"); return; } $command = escapeshellarg($filePath);