From c97bf236d6d45a4f04bd3fb0a9fd929cba624108 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 7 Dec 2012 22:11:15 +0100 Subject: [PATCH] Fix for unknown map --- classes/PocketMinecraftServer.class.php | 59 ++++++++++++++----------- classes/Session.class.php | 1 + server.php | 1 + 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/classes/PocketMinecraftServer.class.php b/classes/PocketMinecraftServer.class.php index cd7ff83c0..a9938d866 100644 --- a/classes/PocketMinecraftServer.class.php +++ b/classes/PocketMinecraftServer.class.php @@ -28,7 +28,7 @@ the Free Software Foundation, either version 3 of the License, or require_once("classes/Session.class.php"); class PocketMinecraftServer{ - var $seed, $protocol, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond, $responses, $spawn, $entities, $mapDir, $map, $level, $tileEntities; + var $seed, $protocol, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond, $responses, $spawn, $entities, $mapDir, $mapName, $map, $level, $tileEntities; private $database, $interface, $cnt, $events, $version, $serverType, $lastTick; function __construct($name, $gamemode = 1, $seed = false, $protocol = CURRENT_PROTOCOL, $port = 19132, $serverID = false, $version = CURRENT_VERSION){ $this->port = (int) $port; @@ -39,6 +39,7 @@ class PocketMinecraftServer{ $this->version = (int) $version; $this->name = $name; $this->mapDir = false; + $this->mapName = false; $this->map = false; $this->level = false; $this->tileEntities = array(); @@ -161,35 +162,43 @@ class PocketMinecraftServer{ } private function loadMap(){ - $this->level = unserialize(file_get_contents($this->mapDir."level.dat")); - console("[INFO] Map: ".$this->level["LevelName"]); - $this->time = (int) $this->level["Time"]; - $this->level["Time"] = &$this->time; - console("[INFO] Time: ".$this->time); - console("[INFO] Seed: ".$this->seed); - console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative")); - console("[INFO] Loading map..."); - $this->map = new ChunkParser(); - if(!$this->map->loadFile($this->mapDir."chunks.dat")){ - console("[ERROR] Couldn't load the map \"".$this->level["LevelName"]."\"!", true, true, 0); - $this->map = false; + if($this->mapName !== false){ + $this->level = unserialize(file_get_contents($this->mapDir."level.dat")); + console("[INFO] Map: ".$this->level["LevelName"]); + $this->time = (int) $this->level["Time"]; + $this->level["Time"] = &$this->time; + console("[INFO] Time: ".$this->time); + console("[INFO] Seed: ".$this->seed); + console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative")); + console("[INFO] Loading map..."); + $this->map = new ChunkParser(); + if(!$this->map->loadFile($this->mapDir."chunks.dat")){ + console("[ERROR] Couldn't load the map \"".$this->level["LevelName"]."\"!", true, true, 0); + $this->map = false; + }else{ + + } + console("[INFO] Loading entities..."); + $entities = unserialize(file_get_contents($this->mapDir."entities.dat")); + foreach($entities as $entity){ + $this->entities[$this->eidCnt] = new Entity($this->eidCnt, ENTITY_MOB, $entity["id"], $this); + $this->entities[$this->eidCnt]->setPosition($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2], $entity["Rotation"][0], $entity["Rotation"][1]); + $this->entities[$this->eidCnt]->setHealth($entity["Health"]); + ++$this->eidCnt; + } + console("[DEBUG] Loaded ".count($this->entities)." Entities", true, true, 2); + $this->action(1000000 * 60 * 15, '$this->chat(false, "Forcing save...");$this->save();$this->chat(false, "Done");'); }else{ - - } - console("[INFO] Loading entities..."); - $entities = unserialize(file_get_contents($this->mapDir."entities.dat")); - foreach($entities as $entity){ - $this->entities[$this->eidCnt] = new Entity($this->eidCnt, ENTITY_MOB, $entity["id"], $this); - $this->entities[$this->eidCnt]->setPosition($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2], $entity["Rotation"][0], $entity["Rotation"][1]); - $this->entities[$this->eidCnt]->setHealth($entity["Health"]); - ++$this->eidCnt; + console("[INFO] Time: ".$this->time); + console("[INFO] Seed: ".$this->seed); + console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative")); } - console("[DEBUG] Loaded ".count($this->entities)." Entities", true, true, 2); - $this->action(1000000 * 60 * 15, '$this->chat(false, "Forcing save...");$this->save();$this->chat(false, "Done");'); } public function save(){ - file_put_contents($this->mapDir."level.dat", serialize($this->level)); + if($this->mapName !== false){ + file_put_contents($this->mapDir."level.dat", serialize($this->level)); + } } public function start(){ diff --git a/classes/Session.class.php b/classes/Session.class.php index 8e9c3fdee..16d6887bc 100644 --- a/classes/Session.class.php +++ b/classes/Session.class.php @@ -372,6 +372,7 @@ class Session{ console("[DEBUG] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 2); break; case MC_REMOVE_BLOCK: + $this->eventHandler("Blocks broken will not be saved", "onChat"); console("[DEBUG] EID ".$this->eid." broke block at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2); $this->send(0x84, array( $this->counter[0], diff --git a/server.php b/server.php index 756178e82..83a860e42 100644 --- a/server.php +++ b/server.php @@ -135,6 +135,7 @@ $server->description = $config["description"]; $server->motd = $config["motd"]; $server->spawn = $config["spawn"]; $server->whitelist = $config["white-list"]; +$server->mapName = $config["level-name"]; $server->mapDir = FILE_PATH."data/maps/".$config["level-name"]."/"; $server->reloadConfig();