refactor codestyle (chaining)

This commit is contained in:
kremsy
2014-08-13 11:05:52 +02:00
parent 699c5951d9
commit 22915bb934
56 changed files with 1572 additions and 3132 deletions

View File

@ -155,26 +155,19 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
$this->pluginManager = new PluginManager($this);
$this->updateManager = new UpdateManager($this);
$this->getErrorHandler()
->init();
$this->getErrorHandler()->init();
// Permissions
$this->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_SHUTDOWN, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
$this->getAuthenticationManager()
->definePermissionLevel(self::SETTING_PERMISSION_RESTART, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
$this->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_SHUTDOWN, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
$this->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_RESTART, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
// Commands
$this->getCommandManager()
->registerCommandListener('version', $this, 'commandVersion', false, 'Shows ManiaControl version.');
$this->getCommandManager()
->registerCommandListener('restart', $this, 'commandRestart', true, 'Restarts ManiaControl.');
$this->getCommandManager()
->registerCommandListener('shutdown', $this, 'commandShutdown', true, 'Shuts ManiaControl down.');
$this->getCommandManager()->registerCommandListener('version', $this, 'commandVersion', false, 'Shows ManiaControl version.');
$this->getCommandManager()->registerCommandListener('restart', $this, 'commandRestart', true, 'Restarts ManiaControl.');
$this->getCommandManager()->registerCommandListener('shutdown', $this, 'commandShutdown', true, 'Shuts ManiaControl down.');
// Check connection every 30 seconds
$this->getTimerManager()
->registerTimerListening($this, 'checkConnection', 1000 * 30);
$this->getTimerManager()->registerTimerListening($this, 'checkConnection', 1000 * 30);
}
/**
@ -410,11 +403,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
* Check connection
*/
public function checkConnection() {
if ($this->getClient()
->getIdleTime() > 180
if ($this->getClient()->getIdleTime() > 180
) {
$this->getClient()
->getServerName();
$this->getClient()->getServerName();
}
}
@ -426,8 +417,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
*/
public function commandVersion(array $chatCallback, Player $player) {
$message = 'This server is using ManiaControl v' . ManiaControl::VERSION . '!';
$this->getChat()
->sendInformation($message, $player);
$this->getChat()->sendInformation($message, $player);
}
/**
@ -437,11 +427,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
* @param Player $player
*/
public function commandRestart(array $chatCallback, Player $player) {
if (!$this->getAuthenticationManager()
->checkPermission($player, self::SETTING_PERMISSION_RESTART)
if (!$this->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_RESTART)
) {
$this->getAuthenticationManager()
->sendNotAllowed($player);
$this->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$this->restart("ManiaControl Restart requested by '{$player->login}'!");
@ -454,21 +442,18 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
*/
public function restart($message = null) {
// Shutdown callback
$this->getCallbackManager()
->triggerCallback(Callbacks::ONSHUTDOWN);
$this->getCallbackManager()->triggerCallback(Callbacks::ONSHUTDOWN);
// Announce restart
if ($message) {
Logger::log($message);
}
$this->getChat()
->sendInformation('Restarting ManiaControl...');
$this->getChat()->sendInformation('Restarting ManiaControl...');
Logger::log('Restarting ManiaControl!');
// Hide widgets
if ($this->getClient()) {
$this->getClient()
->sendHideManialinkPage();
$this->getClient()->sendHideManialinkPage();
}
// Start new instance
@ -485,11 +470,9 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
* @param Player $player
*/
public function commandShutdown(array $chat, Player $player) {
if (!$this->getAuthenticationManager()
->checkPermission($player, self::SETTING_PERMISSION_SHUTDOWN)
if (!$this->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_SHUTDOWN)
) {
$this->getAuthenticationManager()
->sendNotAllowed($player);
$this->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$this->requestQuit("ManiaControl Shutdown requested by '{$player->login}'!");
@ -518,37 +501,28 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
}
// Check if the version of the server is high enough
$version = $this->getClient()
->getVersion();
$version = $this->getClient()->getVersion();
if ($version->build < self::MIN_DEDIVERSION) {
$this->quit("The Server has Version '{$version->build}', while at least '" . self::MIN_DEDIVERSION . "' is required!", true);
}
// Listen for shutdown
$this->getCallbackManager()
->registerCallbackListener(CallbackManager::CB_MP_SERVERSTOP, $this, 'handleServerStopCallback');
$this->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_SERVERSTOP, $this, 'handleServerStopCallback');
// OnInit callback
$this->getCallbackManager()
->triggerCallback(Callbacks::ONINIT);
$this->getCallbackManager()->triggerCallback(Callbacks::ONINIT);
// Load plugins
$this->getPluginManager()
->loadPlugins();
$this->getUpdateManager()
->getPluginUpdateManager()
->checkPluginsUpdate();
$this->getPluginManager()->loadPlugins();
$this->getUpdateManager()->getPluginUpdateManager()->checkPluginsUpdate();
// AfterInit callback
$this->getCallbackManager()
->triggerCallback(Callbacks::AFTERINIT);
$this->getCallbackManager()->triggerCallback(Callbacks::AFTERINIT);
// Loading finished
Logger::log('Loading completed!');
Logger::log('Link: ' . $this->getServer()
->getJoinLink());
$this->getChat()
->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
Logger::log('Link: ' . $this->getServer()->getJoinLink());
$this->getChat()->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
// Main loop
while (!$this->requestQuitMessage) {
@ -564,8 +538,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
*/
private function connect() {
// Load remote client
$serverConfig = $this->getServer()
->loadConfig();
$serverConfig = $this->getServer()->loadConfig();
Logger::log("Connecting to Server at {$serverConfig->host}:{$serverConfig->port}...");
@ -580,12 +553,10 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
}
// Enable callback system
$this->getClient()
->enableCallbacks(true);
$this->getClient()->enableCallbacks(true);
// Wait for server to be ready
if (!$this->getServer()
->waitForStatus(4)
if (!$this->getServer()->waitForStatus(4)
) {
$this->quit("Server couldn't get ready!");
}
@ -594,13 +565,10 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
Logger::log('Server Connection successfully established!');
// Hide old widgets
$this->getClient()
->sendHideManialinkPage();
$this->getClient()->sendHideManialinkPage();
// Enable script callbacks
$this->getServer()
->getScriptManager()
->enableScriptCallbacks();
$this->getServer()->getScriptManager()->enableScriptCallbacks();
}
/**
@ -613,16 +581,14 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener {
set_time_limit(self::SCRIPT_TIMEOUT);
try {
$this->getCallbackManager()
->manageCallbacks();
$this->getCallbackManager()->manageCallbacks();
} catch (TransportException $e) {
Logger::logError('Connection interrupted!');
$this->quit($e->getMessage(), true);
}
// Manage FileReader
$this->getFileReader()
->appendData();
$this->getFileReader()->appendData();
// Yield for next tick
$loopEnd = microtime(true);