From 269408c71a4bf026832ecda8f45e8290619cd4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Mon, 23 Jun 2014 16:04:00 +0200 Subject: [PATCH] improved error handling on map adding --- application/core/Maps/MapActions.php | 4 ++-- application/core/Maps/MapManager.php | 16 +++++++++++----- application/core/Maps/MapQueue.php | 1 - 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/application/core/Maps/MapActions.php b/application/core/Maps/MapActions.php index 14093411..a9eecb7e 100644 --- a/application/core/Maps/MapActions.php +++ b/application/core/Maps/MapActions.php @@ -19,7 +19,7 @@ class MapActions { private $maniaControl = null; /** - * Create a MapActions Instance + * Construct a Map Actions Instance * * @param ManiaControl $maniaControl */ @@ -43,4 +43,4 @@ class MapActions { } catch (ChangeInProgressException $e) { } } -} \ No newline at end of file +} diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 2001a5e4..178c4245 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -14,6 +14,7 @@ use ManiaControl\ManiaExchange\MXMapInfo; use ManiaControl\Players\Player; use ManiaControl\Utils\Formatter; use Maniaplanet\DedicatedServer\InvalidArgumentException; +use Maniaplanet\DedicatedServer\Xmlrpc\AlreadyInListException; use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\FileException; use Maniaplanet\DedicatedServer\Xmlrpc\IndexOutOfBoundException; @@ -292,14 +293,14 @@ class MapManager implements CallbackListener { $downloadFolderName = $this->maniaControl->settingManager->getSettingValue($this, 'MapDownloadDirectory', 'MX'); $relativeMapFileName = $downloadFolderName . DIRECTORY_SEPARATOR . $fileName; - $mapDir = $this->maniaControl->client->getMapsDirectory(); + $mapDir = $this->maniaControl->server->directory->getMapsFolder(); $downloadDirectory = $mapDir . $downloadFolderName . DIRECTORY_SEPARATOR; $fullMapFileName = $downloadDirectory . $fileName; // Check if it can get written locally if ($this->maniaControl->server->checkAccess($mapDir)) { // Create download directory if necessary - if (!is_dir($downloadDirectory) && !mkdir($downloadDirectory)) { + if (!is_dir($downloadDirectory) && !mkdir($downloadDirectory) || !is_writable($downloadDirectory)) { trigger_error("ManiaControl doesn't have to rights to save maps in '{$downloadDirectory}'."); $this->maniaControl->chat->sendError("ManiaControl doesn't have the rights to save maps.", $login); return; @@ -326,13 +327,18 @@ class MapManager implements CallbackListener { // Check for valid map try { $this->maniaControl->client->checkMapForCurrentServerParams($relativeMapFileName); - } catch (InvalidMapException $e) { - $this->maniaControl->chat->sendException($e, $login); + } catch (InvalidMapException $exception) { + $this->maniaControl->chat->sendException($exception, $login); return; } // Add map to map list - $this->maniaControl->client->insertMap($relativeMapFileName); + try { + $this->maniaControl->client->insertMap($relativeMapFileName); + } catch (AlreadyInListException $exception) { + $this->maniaControl->chat->sendException($exception, $login); + return; + } $this->updateFullMapList(); // Update Mx MapInfo diff --git a/application/core/Maps/MapQueue.php b/application/core/Maps/MapQueue.php index 6ea02c63..d237d4fc 100644 --- a/application/core/Maps/MapQueue.php +++ b/application/core/Maps/MapQueue.php @@ -389,7 +389,6 @@ class MapQueue implements CallbackListener, CommandListener { return $this->nextMap; } - /** * Returns the first Queued Map *