mapfile erase

This commit is contained in:
kremsy 2014-01-31 15:56:57 +01:00 committed by Steffen Schröder
parent 6d5062b61c
commit 34db6ea31b

View File

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