Fix for unknown map

This commit is contained in:
Shoghi Cervantes Pueyo 2012-12-07 22:11:15 +01:00
parent 9e08e48d83
commit c97bf236d6
3 changed files with 36 additions and 25 deletions

View File

@ -28,7 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
require_once("classes/Session.class.php"); require_once("classes/Session.class.php");
class PocketMinecraftServer{ 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; 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){ function __construct($name, $gamemode = 1, $seed = false, $protocol = CURRENT_PROTOCOL, $port = 19132, $serverID = false, $version = CURRENT_VERSION){
$this->port = (int) $port; $this->port = (int) $port;
@ -39,6 +39,7 @@ class PocketMinecraftServer{
$this->version = (int) $version; $this->version = (int) $version;
$this->name = $name; $this->name = $name;
$this->mapDir = false; $this->mapDir = false;
$this->mapName = false;
$this->map = false; $this->map = false;
$this->level = false; $this->level = false;
$this->tileEntities = array(); $this->tileEntities = array();
@ -161,35 +162,43 @@ class PocketMinecraftServer{
} }
private function loadMap(){ private function loadMap(){
$this->level = unserialize(file_get_contents($this->mapDir."level.dat")); if($this->mapName !== false){
console("[INFO] Map: ".$this->level["LevelName"]); $this->level = unserialize(file_get_contents($this->mapDir."level.dat"));
$this->time = (int) $this->level["Time"]; console("[INFO] Map: ".$this->level["LevelName"]);
$this->level["Time"] = &$this->time; $this->time = (int) $this->level["Time"];
console("[INFO] Time: ".$this->time); $this->level["Time"] = &$this->time;
console("[INFO] Seed: ".$this->seed); console("[INFO] Time: ".$this->time);
console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative")); console("[INFO] Seed: ".$this->seed);
console("[INFO] Loading map..."); console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative"));
$this->map = new ChunkParser(); console("[INFO] Loading map...");
if(!$this->map->loadFile($this->mapDir."chunks.dat")){ $this->map = new ChunkParser();
console("[ERROR] Couldn't load the map \"".$this->level["LevelName"]."\"!", true, true, 0); if(!$this->map->loadFile($this->mapDir."chunks.dat")){
$this->map = false; 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{ }else{
console("[INFO] Time: ".$this->time);
} console("[INFO] Seed: ".$this->seed);
console("[INFO] Loading entities..."); console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative"));
$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");');
} }
public function save(){ 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(){ public function start(){

View File

@ -372,6 +372,7 @@ class Session{
console("[DEBUG] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 2); console("[DEBUG] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 2);
break; break;
case MC_REMOVE_BLOCK: 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); 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->send(0x84, array(
$this->counter[0], $this->counter[0],

View File

@ -135,6 +135,7 @@ $server->description = $config["description"];
$server->motd = $config["motd"]; $server->motd = $config["motd"];
$server->spawn = $config["spawn"]; $server->spawn = $config["spawn"];
$server->whitelist = $config["white-list"]; $server->whitelist = $config["white-list"];
$server->mapName = $config["level-name"];
$server->mapDir = FILE_PATH."data/maps/".$config["level-name"]."/"; $server->mapDir = FILE_PATH."data/maps/".$config["level-name"]."/";
$server->reloadConfig(); $server->reloadConfig();