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 . '$>!';