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
|
// Register for commands
|
||||||
$this->commandManager->registerCommandListener('version', $this, 'command_Version');
|
$this->commandManager->registerCommandListener('version', $this, 'command_Version');
|
||||||
$this->commandManager->registerCommandListener('restart', $this, 'command_Restart', true);
|
$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);
|
$this->authenticationManager->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->log($player->login . ' requested ManiaControl Restart.');
|
$this->restart("ManiaControl Restart requested by '{$player->login}'!");
|
||||||
$this->restart();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* @param string $message
|
||||||
*/
|
*/
|
||||||
public function quit($message = '') {
|
public function quit($message = null) {
|
||||||
// Log quit reason
|
if ($message) $this->log($message);
|
||||||
if ($message) {
|
exit();
|
||||||
$this->log($message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle PHP Process Shutdown
|
||||||
|
*/
|
||||||
|
public function handleShutdown() {
|
||||||
// OnShutdown callback
|
// OnShutdown callback
|
||||||
$this->callbackManager->triggerCallback(CallbackManager::CB_MC_ONSHUTDOWN, array(CallbackManager::CB_MC_ONSHUTDOWN));
|
$this->callbackManager->triggerCallback(CallbackManager::CB_MC_ONSHUTDOWN, array(CallbackManager::CB_MC_ONSHUTDOWN));
|
||||||
|
|
||||||
if ($this->client) {
|
|
||||||
// Announce quit
|
// Announce quit
|
||||||
$this->chat->sendInformation('ManiaControl shutting down.');
|
$this->chat->sendInformation('ManiaControl shutting down.');
|
||||||
|
|
||||||
// Hide manialinks
|
// Hide manialinks
|
||||||
$this->client->query('SendHideManialinkPage');
|
$this->client->query('SendHideManialinkPage');
|
||||||
}
|
|
||||||
|
|
||||||
// Shutdown
|
// Close connection
|
||||||
if ($this->client) {
|
|
||||||
$this->client->Terminate();
|
$this->client->Terminate();
|
||||||
}
|
|
||||||
|
|
||||||
$this->log('Quitting ManiaControl!');
|
$this->log('Quitting ManiaControl!');
|
||||||
exit();
|
exit();
|
||||||
@ -236,7 +249,6 @@ class ManiaControl implements CommandListener {
|
|||||||
|
|
||||||
// Announce restart
|
// Announce restart
|
||||||
$this->chat->sendInformation('Restarting ManiaControl...');
|
$this->chat->sendInformation('Restarting ManiaControl...');
|
||||||
$this->log('Restarting ManiaControl...');
|
|
||||||
if ($message) $this->log($message);
|
if ($message) $this->log($message);
|
||||||
|
|
||||||
// Hide widgets
|
// Hide widgets
|
||||||
@ -245,6 +257,8 @@ class ManiaControl implements CommandListener {
|
|||||||
// Close connection
|
// Close connection
|
||||||
$this->client->Terminate();
|
$this->client->Terminate();
|
||||||
|
|
||||||
|
$this->log('Restarting ManiaControl!');
|
||||||
|
|
||||||
// Execute start script in background
|
// Execute start script in background
|
||||||
if ($this->getOS(self::OS_UNIX)) {
|
if ($this->getOS(self::OS_UNIX)) {
|
||||||
$command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &';
|
$command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &';
|
||||||
@ -271,7 +285,7 @@ class ManiaControl implements CommandListener {
|
|||||||
$this->connect();
|
$this->connect();
|
||||||
|
|
||||||
// Register shutdown handler
|
// Register shutdown handler
|
||||||
register_shutdown_function(array($this, 'quit'));
|
register_shutdown_function(array($this, 'handleShutdown'));
|
||||||
|
|
||||||
// Loading finished
|
// Loading finished
|
||||||
$this->log('Loading completed!');
|
$this->log('Loading completed!');
|
||||||
|
@ -34,20 +34,19 @@ class ServerCommands implements CallbackListener, CommandListener {
|
|||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_5_SECOND, $this, 'each5Seconds');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_5_SECOND, $this, 'each5Seconds');
|
||||||
|
|
||||||
// Register for commands
|
// Register for commands
|
||||||
$this->maniaControl->commandManager->registerCommandListener('setpwd', $this, 'command_SetPwd',true);
|
$this->maniaControl->commandManager->registerCommandListener('setpwd', $this, 'command_SetPwd', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('setservername', $this, 'command_SetServerName',true);
|
$this->maniaControl->commandManager->registerCommandListener('setservername', $this, 'command_SetServerName', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('setmaxplayers', $this, 'command_SetMaxPlayers',true);
|
$this->maniaControl->commandManager->registerCommandListener('setmaxplayers', $this, 'command_SetMaxPlayers', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('setmaxspectators', $this, 'command_SetMaxSpectators',true);
|
$this->maniaControl->commandManager->registerCommandListener('setmaxspectators', $this, 'command_SetMaxSpectators', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('setspecpwd', $this, 'command_SetSpecPwd',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('shutdownserver', $this, 'command_ShutdownServer',true);
|
$this->maniaControl->commandManager->registerCommandListener('systeminfo', $this, 'command_SystemInfo', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('systeminfo', $this, 'command_SystemInfo',true);
|
$this->maniaControl->commandManager->registerCommandListener('hideserver', $this, 'command_HideServer', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('hideserver', $this, 'command_HideServer',true);
|
$this->maniaControl->commandManager->registerCommandListener('showserver', $this, 'command_ShowServer', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('showserver', $this, 'command_ShowServer',true);
|
$this->maniaControl->commandManager->registerCommandListener('enablemapdownload', $this, 'command_EnableMapDownload', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('enablemapdownload', $this, 'command_EnableMapDownload',true);
|
$this->maniaControl->commandManager->registerCommandListener('disablemapdownload', $this, 'command_DisableMapDownload', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('disablemapdownload', $this, 'command_DisableMapDownload',true);
|
$this->maniaControl->commandManager->registerCommandListener('enablehorns', $this, 'command_EnableHorns', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('enablehorns', $this, 'command_EnableHorns',true);
|
$this->maniaControl->commandManager->registerCommandListener('disablehorns', $this, 'command_DisableHorns', 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);
|
$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
|
* Handle //shutdownserver command
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user