Moved and Improved Shutdown Command

This commit is contained in:
Steffen Schröder 2014-01-01 19:25:51 +01:00
parent 6c56938ddd
commit accf5617e2
2 changed files with 77 additions and 78 deletions

View File

@ -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!');

View File

@ -34,20 +34,19 @@ class ServerCommands implements CallbackListener, CommandListener {
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_5_SECOND, $this, 'each5Seconds');
// Register for commands
$this->maniaControl->commandManager->registerCommandListener('setpwd', $this, 'command_SetPwd',true);
$this->maniaControl->commandManager->registerCommandListener('setservername', $this, 'command_SetServerName',true);
$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);
$this->maniaControl->commandManager->registerCommandListener('showserver', $this, 'command_ShowServer',true);
$this->maniaControl->commandManager->registerCommandListener('enablemapdownload', $this, 'command_EnableMapDownload',true);
$this->maniaControl->commandManager->registerCommandListener('disablemapdownload', $this, 'command_DisableMapDownload',true);
$this->maniaControl->commandManager->registerCommandListener('enablehorns', $this, 'command_EnableHorns',true);
$this->maniaControl->commandManager->registerCommandListener('disablehorns', $this, 'command_DisableHorns',true);
$this->maniaControl->commandManager->registerCommandListener('setpwd', $this, 'command_SetPwd', true);
$this->maniaControl->commandManager->registerCommandListener('setservername', $this, 'command_SetServerName', true);
$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('shutdownserver', $this, 'command_ShutdownServer', true);
$this->maniaControl->commandManager->registerCommandListener('systeminfo', $this, 'command_SystemInfo', true);
$this->maniaControl->commandManager->registerCommandListener('hideserver', $this, 'command_HideServer', true);
$this->maniaControl->commandManager->registerCommandListener('showserver', $this, 'command_ShowServer', true);
$this->maniaControl->commandManager->registerCommandListener('enablemapdownload', $this, 'command_EnableMapDownload', true);
$this->maniaControl->commandManager->registerCommandListener('disablemapdownload', $this, 'command_DisableMapDownload', true);
$this->maniaControl->commandManager->registerCommandListener('enablehorns', $this, 'command_EnableHorns', true);
$this->maniaControl->commandManager->registerCommandListener('disablehorns', $this, 'command_DisableHorns', 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
*