From 34db6ea31ba2e1149cd96b5d54b5346733ed7ca8 Mon Sep 17 00:00:00 2001 From: kremsy Date: Fri, 31 Jan 2014 15:56:57 +0100 Subject: [PATCH] mapfile erase --- application/core/Maps/MapManager.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 9b3513d1..8e360cec 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -197,12 +197,15 @@ class MapManager implements CallbackListener { * @param bool $eraseFile * @param bool $message */ - public function removeMap(Player $admin, $uid, $eraseFile = false, $message = true) { //TODO erasefile? + public function removeMap(Player $admin, $uid, $eraseFile = false, $message = true) { $map = $this->maps[$uid]; //Unset the Map everywhere $this->mapQueue->removeFromMapQueue($admin, $map->uid); - $this->mxManager->unsetMap($map->mx->id); + + if ($map->mx != null) { + $this->mxManager->unsetMap($map->mx->id); + } // Remove map try { @@ -213,6 +216,23 @@ class MapManager implements CallbackListener { return; } + if ($eraseFile) { + // Check if ManiaControl can even write to the maps dir + try { + $mapDir = $this->maniaControl->client->getMapsDirectory(); + } catch(\Exception $e) { + trigger_error("Couldn't get map directory. " . $e->getMessage()); + $this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $admin->login); + return; + } + + if (!@unlink($mapDir . $map->fileName)) { + trigger_error("Couldn't remove Map '{$mapDir}{$map->fileName}'."); + $this->maniaControl->chat->sendError("ManiaControl couldn't remove the MapFile.", $admin->login); + return; + } + } + //Show Message if ($message) { $message = '$<' . $admin->nickname . '$> removed $<' . $map->name . '$>!';