performed code formatting

This commit is contained in:
Steffen Schröder
2014-08-05 02:17:41 +02:00
parent 98b5f132dc
commit 28d2c08936
66 changed files with 4054 additions and 1901 deletions

View File

@ -56,13 +56,20 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$this->maniaControl = $maniaControl;
// ManiaLink Actions
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SHOW, $this, 'handleActionShow');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_NAVIGATE_UP, $this, 'handleNavigateUp');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_NAVIGATE_ROOT, $this, 'handleNavigateRoot');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_OPEN_FOLDER), $this, 'handleOpenFolder');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_INSPECT_FILE), $this, 'handleInspectFile');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_ADD_FILE), $this, 'handleAddFile');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_ERASE_FILE), $this, 'handleEraseFile');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_SHOW, $this, 'handleActionShow');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_NAVIGATE_UP, $this, 'handleNavigateUp');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerListener(self::ACTION_NAVIGATE_ROOT, $this, 'handleNavigateRoot');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_OPEN_FOLDER), $this, 'handleOpenFolder');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_INSPECT_FILE), $this, 'handleInspectFile');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_ADD_FILE), $this, 'handleAddFile');
$this->maniaControl->getManialinkManager()
->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_ERASE_FILE), $this, 'handleEraseFile');
}
/**
@ -95,7 +102,9 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$oldFolderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
$isInMapsFolder = false;
if (!$oldFolderPath) {
$oldFolderPath = $this->maniaControl->getServer()->getDirectory()->getMapsFolder();
$oldFolderPath = $this->maniaControl->getServer()
->getDirectory()
->getMapsFolder();
$isInMapsFolder = true;
}
$folderPath = $oldFolderPath;
@ -106,12 +115,16 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$folderName = basename($newFolderPath);
switch ($folderName) {
case 'Maps':
$mapsDir = dirname($this->maniaControl->getServer()->getDirectory()->getMapsFolder());
$mapsDir = dirname($this->maniaControl->getServer()
->getDirectory()
->getMapsFolder());
$folderDir = dirname($folderPath);
$isInMapsFolder = ($mapsDir === $folderDir);
break;
case 'UserData':
$dataDir = dirname($this->maniaControl->getServer()->getDirectory()->getGameDataFolder());
$dataDir = dirname($this->maniaControl->getServer()
->getDirectory()
->getGameDataFolder());
$folderDir = dirname($folderPath);
if ($dataDir === $folderDir) {
// Prevent navigation out of maps directory
@ -127,11 +140,17 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$script = $maniaLink->getScript();
$paging = new Paging();
$script->addFeature($paging);
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
$frame = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getDefaultListFrame($script, $paging);
$maniaLink->add($frame);
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
$width = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsWidth();
$height = $this->maniaControl->getManialinkManager()
->getStyleManager()
->getListWidgetsHeight();
$index = 0;
$posY = $height / 2 - 10;
$pageFrame = null;
@ -155,7 +174,9 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$directoryLabel = new Label_Text();
$frame->add($directoryLabel);
$dataFolder = $this->maniaControl->getServer()->getDirectory()->getGameDataFolder();
$dataFolder = $this->maniaControl->getServer()
->getDirectory()
->getGameDataFolder();
$directoryText = substr($folderPath, strlen($dataFolder));
$directoryLabel->setPosition($width * -0.41, $height * 0.45)
->setSize($width * 0.85, 4)
@ -182,8 +203,10 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
->setText('No files found.')
->setTranslate(true);
} else {
$canAddMaps = $this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP);
$canEraseMaps = $this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ERASE_MAP);
$canAddMaps = $this->maniaControl->getAuthenticationManager()
->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP);
$canEraseMaps = $this->maniaControl->getAuthenticationManager()
->checkPermission($player, MapManager::SETTING_PERMISSION_ERASE_MAP);
foreach ($mapFiles as $filePath => $fileName) {
$shortFilePath = substr($filePath, strlen($folderPath));
@ -265,7 +288,8 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
->setTranslate(true);
}
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, self::WIDGET_NAME);
$this->maniaControl->getManialinkManager()
->displayWidget($maniaLink, $player, self::WIDGET_NAME);
}
/**
@ -370,40 +394,52 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
$filePath = $folderPath . $fileName;
$mapsFolder = $this->maniaControl->getServer()->getDirectory()->getMapsFolder();
$mapsFolder = $this->maniaControl->getServer()
->getDirectory()
->getMapsFolder();
$relativeFilePath = substr($filePath, strlen($mapsFolder));
// Check for valid map
try {
$this->maniaControl->getClient()->checkMapForCurrentServerParams($relativeFilePath);
$this->maniaControl->getClient()
->checkMapForCurrentServerParams($relativeFilePath);
} catch (InvalidMapException $exception) {
$this->maniaControl->getChat()->sendException($exception, $player);
$this->maniaControl->getChat()
->sendException($exception, $player);
return;
} catch (FileException $exception) {
$this->maniaControl->getChat()->sendException($exception, $player);
$this->maniaControl->getChat()
->sendException($exception, $player);
return;
}
// Add map to map list
try {
$this->maniaControl->getClient()->insertMap($relativeFilePath);
$this->maniaControl->getClient()
->insertMap($relativeFilePath);
} catch (AlreadyInListException $exception) {
$this->maniaControl->getChat()->sendException($exception, $player);
$this->maniaControl->getChat()
->sendException($exception, $player);
return;
}
$map = $this->maniaControl->getMapManager()->fetchMapByFileName($relativeFilePath);
$map = $this->maniaControl->getMapManager()
->fetchMapByFileName($relativeFilePath);
if (!$map) {
$this->maniaControl->getChat()->sendError('Error occurred.', $player);
$this->maniaControl->getChat()
->sendError('Error occurred.', $player);
return;
}
// Message
$message = $player->getEscapedNickname() . ' added ' . $map->getEscapedName() . '!';
$this->maniaControl->getChat()->sendSuccess($message);
$this->maniaControl->getChat()
->sendSuccess($message);
Logger::logInfo($message, true);
// Queue requested Map
$this->maniaControl->getMapManager()->getMapQueue()->addMapToMapQueue($player, $map);
$this->maniaControl->getMapManager()
->getMapQueue()
->addMapToMapQueue($player, $map);
}
/**
@ -418,10 +454,12 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
$filePath = $folderPath . $fileName;
if (@unlink($filePath)) {
$this->maniaControl->getChat()->sendSuccess("Erased {$fileName}!");
$this->maniaControl->getChat()
->sendSuccess("Erased {$fileName}!");
$this->showManiaLink($player);
} else {
$this->maniaControl->getChat()->sendError("Couldn't erase {$fileName}!");
$this->maniaControl->getChat()
->sendError("Couldn't erase {$fileName}!");
}
}
}