add maps over writefile method

This commit is contained in:
kremsy 2014-01-29 22:44:06 +01:00 committed by Steffen Schröder
parent 4dabf459a8
commit cef598cd3e
2 changed files with 31 additions and 22 deletions

View File

@ -278,7 +278,7 @@ class Client
$request = new Request($method, $args); $request = new Request($method, $args);
// Check if request is larger than 512 Kbytes // 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); throw new Exception('transport error - request too large!', -32700);
} }

View File

@ -478,7 +478,6 @@ class MapManager implements CallbackListener {
return array_search($map, $maps); return array_search($map, $maps);
} }
/** /**
* Adds a Map from Mania Exchange * Adds a Map from Mania Exchange
* *
@ -496,20 +495,6 @@ class MapManager implements CallbackListener {
return; 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 // Download the map
if (is_numeric($mapId)) { if (is_numeric($mapId)) {
// Load from MX // Load from MX
@ -545,14 +530,38 @@ class MapManager implements CallbackListener {
// Save map // Save map
$fileName = $mapId . '_' . $mapInfo->name . '.Map.Gbx'; $fileName = $mapId . '_' . $mapInfo->name . '.Map.Gbx';
$fileName = FileUtil::getClearedFileName($fileName); $fileName = FileUtil::getClearedFileName($fileName);
if (!file_put_contents($mapDir . $fileName, $file)) {
// Save error $downloadDirectory = $this->maniaControl->settingManager->getSetting($this, 'MapDownloadDirectory', 'MX');
$this->maniaControl->chat->sendError('Saving map failed!', $login);
return;
}
// Check for valid map
$mapFileName = $downloadDirectory . '/' . $fileName; $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 { try {
$this->maniaControl->client->checkMapForCurrentServerParams($mapFileName); $this->maniaControl->client->checkMapForCurrentServerParams($mapFileName);
} catch(\Exception $e) { } catch(\Exception $e) {