Moved and Improved Shutdown Command
This commit is contained in:
parent
6c56938ddd
commit
accf5617e2
@ -122,6 +122,7 @@ class ManiaControl implements CommandListener {
|
||||
// Register for commands
|
||||
$this->commandManager->registerCommandListener('version', $this, 'command_Version');
|
||||
$this->commandManager->registerCommandListener('restart', $this, 'command_Restart', true);
|
||||
$this->commandManager->registerCommandListener('shutdown', $this, 'command_Shutdown', true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,8 +191,21 @@ class ManiaControl implements CommandListener {
|
||||
$this->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$this->log($player->login . ' requested ManiaControl Restart.');
|
||||
$this->restart();
|
||||
$this->restart("ManiaControl Restart requested by '{$player->login}'!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //shutdown command
|
||||
*
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_Shutdown(array $chat, Player $player) {
|
||||
if (!$this->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
|
||||
$this->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$this->quit("ManiaControl Shutdown requested by '{$player->login}'!");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -199,27 +213,26 @@ class ManiaControl implements CommandListener {
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function quit($message = '') {
|
||||
// Log quit reason
|
||||
if ($message) {
|
||||
$this->log($message);
|
||||
public function quit($message = null) {
|
||||
if ($message) $this->log($message);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PHP Process Shutdown
|
||||
*/
|
||||
public function handleShutdown() {
|
||||
// OnShutdown callback
|
||||
$this->callbackManager->triggerCallback(CallbackManager::CB_MC_ONSHUTDOWN, array(CallbackManager::CB_MC_ONSHUTDOWN));
|
||||
|
||||
if ($this->client) {
|
||||
// Announce quit
|
||||
$this->chat->sendInformation('ManiaControl shutting down.');
|
||||
|
||||
// Hide manialinks
|
||||
$this->client->query('SendHideManialinkPage');
|
||||
}
|
||||
|
||||
// Shutdown
|
||||
if ($this->client) {
|
||||
// Close connection
|
||||
$this->client->Terminate();
|
||||
}
|
||||
|
||||
$this->log('Quitting ManiaControl!');
|
||||
exit();
|
||||
@ -236,7 +249,6 @@ class ManiaControl implements CommandListener {
|
||||
|
||||
// Announce restart
|
||||
$this->chat->sendInformation('Restarting ManiaControl...');
|
||||
$this->log('Restarting ManiaControl...');
|
||||
if ($message) $this->log($message);
|
||||
|
||||
// Hide widgets
|
||||
@ -245,6 +257,8 @@ class ManiaControl implements CommandListener {
|
||||
// Close connection
|
||||
$this->client->Terminate();
|
||||
|
||||
$this->log('Restarting ManiaControl!');
|
||||
|
||||
// Execute start script in background
|
||||
if ($this->getOS(self::OS_UNIX)) {
|
||||
$command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &';
|
||||
@ -271,7 +285,7 @@ class ManiaControl implements CommandListener {
|
||||
$this->connect();
|
||||
|
||||
// Register shutdown handler
|
||||
register_shutdown_function(array($this, 'quit'));
|
||||
register_shutdown_function(array($this, 'handleShutdown'));
|
||||
|
||||
// Loading finished
|
||||
$this->log('Loading completed!');
|
||||
|
@ -39,7 +39,6 @@ class ServerCommands implements CallbackListener, CommandListener {
|
||||
$this->maniaControl->commandManager->registerCommandListener('setmaxplayers', $this, 'command_SetMaxPlayers', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('setmaxspectators', $this, 'command_SetMaxSpectators', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('setspecpwd', $this, 'command_SetSpecPwd', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('shutdown', $this, 'command_Shutdown',true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('shutdownserver', $this, 'command_ShutdownServer', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('systeminfo', $this, 'command_SystemInfo', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('hideserver', $this, 'command_HideServer', true);
|
||||
@ -90,20 +89,6 @@ class ServerCommands implements CallbackListener, CommandListener {
|
||||
$this->maniaControl->chat->sendInformation($message, $player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //shutdown command
|
||||
*
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_Shutdown(array $chat, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->quit("ManiaControl shutdown requested by '{$player->login}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //shutdownserver command
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user