From cef598cd3e8aae2aa70df0d5607d8896aaa21003 Mon Sep 17 00:00:00 2001 From: kremsy Date: Wed, 29 Jan 2014 22:44:06 +0100 Subject: [PATCH] add maps over writefile method --- .../DedicatedServer/Xmlrpc/Client.php | 2 +- application/core/Maps/MapManager.php | 51 +++++++++++-------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/application/core/Maniaplanet/DedicatedServer/Xmlrpc/Client.php b/application/core/Maniaplanet/DedicatedServer/Xmlrpc/Client.php index 4abd28b5..ec469061 100644 --- a/application/core/Maniaplanet/DedicatedServer/Xmlrpc/Client.php +++ b/application/core/Maniaplanet/DedicatedServer/Xmlrpc/Client.php @@ -278,7 +278,7 @@ class Client $request = new Request($method, $args); // Check if request is larger than 512 Kbytes - if ($request->getLength() > 512*1024-8) + if ($request->getLength() > 1024*1024-8) //TODO changed temporary to 1024 * 1024 { throw new Exception('transport error - request too large!', -32700); } diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 55996c69..d6e34480 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -478,7 +478,6 @@ class MapManager implements CallbackListener { return array_search($map, $maps); } - /** * Adds a Map from Mania Exchange * @@ -496,20 +495,6 @@ class MapManager implements CallbackListener { return; } - if (!is_dir($mapDir)) { - trigger_error("ManiaControl doesn't have have access to the maps directory in '{$mapDir}'."); - $this->maniaControl->chat->sendError("ManiaControl doesn't have access to the maps directory.", $login); - return; - } - $downloadDirectory = $this->maniaControl->settingManager->getSetting($this, 'MapDownloadDirectory', 'MX'); - // Create download directory if necessary - if (!is_dir($mapDir . $downloadDirectory) && !mkdir($mapDir . $downloadDirectory)) { - trigger_error("ManiaControl doesn't have to rights to save maps in '{$mapDir}{$downloadDirectory}'."); - $this->maniaControl->chat->sendError("ManiaControl doesn't have the rights to save maps.", $login); - return; - } - $mapDir .= $downloadDirectory . '/'; - // Download the map if (is_numeric($mapId)) { // Load from MX @@ -545,14 +530,38 @@ class MapManager implements CallbackListener { // Save map $fileName = $mapId . '_' . $mapInfo->name . '.Map.Gbx'; $fileName = FileUtil::getClearedFileName($fileName); - if (!file_put_contents($mapDir . $fileName, $file)) { - // Save error - $this->maniaControl->chat->sendError('Saving map failed!', $login); - return; - } - // Check for valid map + + $downloadDirectory = $this->maniaControl->settingManager->getSetting($this, 'MapDownloadDirectory', 'MX'); + $mapFileName = $downloadDirectory . '/' . $fileName; + //Check if it can get locally Written + if (is_dir($mapDir)) { + // Create download directory if necessary + if (!is_dir($mapDir . $downloadDirectory) && !mkdir($mapDir . $downloadDirectory)) { + trigger_error("ManiaControl doesn't have to rights to save maps in '{$mapDir}{$downloadDirectory}'."); + $this->maniaControl->chat->sendError("ManiaControl doesn't have the rights to save maps.", $login); + return; + } + + $mapDir .= $downloadDirectory . '/'; + + if (!file_put_contents($mapDir . $fileName, $file)) { + // Save error + $this->maniaControl->chat->sendError('Saving map failed!', $login); + return; + } + //Write via Write File Method + } else { + try { + $this->maniaControl->client->writeFileFromString($mapFileName, $file); + } catch(\Exception $e) { + $this->maniaControl->chat->sendError("Map is too big for a remote save.", $login); + return; + } + } + + // Check for valid map try { $this->maniaControl->client->checkMapForCurrentServerParams($mapFileName); } catch(\Exception $e) {