Removed seed and spawn from server.properties

This commit is contained in:
Shoghi Cervantes Pueyo 2012-12-24 13:26:52 +01:00
parent 30a13fb1b4
commit 022e25ff05
4 changed files with 22 additions and 38 deletions

View File

@ -90,7 +90,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
console("[DEBUG] Loading server.properties...", true, true, 2); console("[DEBUG] Loading server.properties...", true, true, 2);
$this->parseProperties(); $this->parseProperties();
define("DEBUG", $this->config["debug"]); define("DEBUG", $this->config["debug"]);
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), $this->getProperty("seed"), CURRENT_PROTOCOL, $this->getProperty("port"), $this->getProperty("server-id")); $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, CURRENT_PROTOCOL, $this->getProperty("port"), $this->getProperty("server-id"));
$this->server->api = $this; $this->server->api = $this;
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){ if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
console("[INFO] Checking for new server version"); console("[INFO] Checking for new server version");
@ -130,21 +130,9 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
} }
$this->gen->init(); $this->gen->init();
$this->gen->generate(); $this->gen->generate();
$this->gen->save($this->server->mapDir."chunks.dat"); $this->gen->save($this->server->mapDir, $this->server->mapName);
$this->setProperty("seed", $this->server->seed);
$this->setProperty("level-name", $this->server->mapName); $this->setProperty("level-name", $this->server->mapName);
$this->setProperty("gamemode", 1); $this->setProperty("gamemode", 1);
$s = $this->gen->getSpawn();
$this->setProperty("spawn", array("x" => $s[0], "y" => $s[1], "z" => $s[2]));
$array = array();
file_put_contents($this->server->mapDir."entities.dat", serialize($array));
file_put_contents($this->server->mapDir."tileEntities.dat", serialize($array));
$level = array(
"LevelName" => $this->server->mapName,
"Time" => 0,
"RandomSeed" => $this->server->seed,
);
file_put_contents($this->server->mapDir."level.dat", serialize($level));
} }
$this->loadProperties(); $this->loadProperties();
$this->server->loadMap(); $this->server->loadMap();
@ -220,7 +208,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$this->setProperty("level-name", $level["LevelName"]); $this->setProperty("level-name", $level["LevelName"]);
$this->setProperty("gamemode", $level["GameType"]); $this->setProperty("gamemode", $level["GameType"]);
$this->server->seed = $level["RandomSeed"]; $this->server->seed = $level["RandomSeed"];
$this->setProperty("spawn", array("x" => $level["SpawnX"], "y" => $level["SpawnY"], "z" => $level["SpawnZ"])); $this->server->spawn = array("x" => $level["SpawnX"], "y" => $level["SpawnY"], "z" => $level["SpawnZ"]);
$this->writeProperties(); $this->writeProperties();
} }
console("[INFO] Map \"".$level["LevelName"]."\" importing done!"); console("[INFO] Map \"".$level["LevelName"]."\" importing done!");
@ -261,7 +249,6 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$this->server->motd = $this->config["motd"]; $this->server->motd = $this->config["motd"];
$this->server->gamemode = $this->config["gamemode"]; $this->server->gamemode = $this->config["gamemode"];
$this->server->difficulty = $this->config["difficulty"]; $this->server->difficulty = $this->config["difficulty"];
$this->server->spawn = $this->config["spawn"];
$this->server->whitelist = $this->config["white-list"]; $this->server->whitelist = $this->config["white-list"];
$this->server->reloadConfig(); $this->server->reloadConfig();
} }
@ -269,7 +256,6 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
private function writeProperties(){ private function writeProperties(){
if(is_object($this->server)){ if(is_object($this->server)){
$this->config["seed"] = $this->server->seed;
$this->config["server-id"] = $this->server->serverID; $this->config["server-id"] = $this->server->serverID;
} }
$config = $this->config; $config = $this->config;
@ -277,9 +263,6 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$config["invisible"] = $config["invisible"] === true ? "true":"false"; $config["invisible"] = $config["invisible"] === true ? "true":"false";
$prop = "#Pocket Minecraft PHP server properties\r\n#".date("D M j H:i:s T Y")."\r\n"; $prop = "#Pocket Minecraft PHP server properties\r\n#".date("D M j H:i:s T Y")."\r\n";
foreach($config as $n => $v){ foreach($config as $n => $v){
if($n == "spawn"){
$v = implode(";", $v);
}
$prop .= $n."=".$v."\r\n"; $prop .= $n."=".$v."\r\n";
} }
file_put_contents(FILE_PATH."server.properties", $prop); file_put_contents(FILE_PATH."server.properties", $prop);
@ -324,23 +307,11 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
case "time-per-second": case "time-per-second":
$v = (int) $v; $v = (int) $v;
break; break;
case "seed":
if($v !== false and preg_match("/[^0-9\-]/", $v) > 0){
$str = new Java_String($v);
$v = $str->hashCode();
}else{
$v = (int) $v;
}
break;
case "server-id": case "server-id":
if($v !== false){ if($v !== false){
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v; $v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v;
} }
break; break;
case "spawn":
$v = explode(";", $v);
$v = array("x" => floatval($v[0]), "y" => floatval($v[1]), "z" => floatval($v[2]));
break;
} }
$this->config[$n] = $v; $this->config[$n] = $v;
} }

View File

@ -334,9 +334,23 @@ class Generator{
return $chunk; return $chunk;
} }
public function save($file){ public function save($dir, $name){
@mkdir(dirname($file), 0777, true); @mkdir($dir, 0777, true);
return file_put_contents($file, $this->raw); file_put_contents($dir."chunks.dat", $this->raw);
$s = $this->getSpawn();
$array = array();
file_put_contents($dir."entities.dat", serialize($array));
file_put_contents($dir."tileEntities.dat", serialize($array));
$level = array(
"LevelName" => $name,
"Time" => 0,
"Gamemode" => 1,
"RandomSeed" => $this->seed,
"SpawnX" => $s[0],
"SpawnY" => $s[1],
"SpawnX" => $s[2],
);
file_put_contents($dir."level.dat", serialize($level));
} }
} }

View File

@ -224,6 +224,7 @@ class PocketMinecraftServer extends stdClass{
console("[INFO] Map: ".$this->level["LevelName"]); console("[INFO] Map: ".$this->level["LevelName"]);
$this->time = (int) $this->level["Time"]; $this->time = (int) $this->level["Time"];
$this->seed = (int) $this->level["RandomSeed"]; $this->seed = (int) $this->level["RandomSeed"];
$this->spawn = array("x" => $level["SpawnX"], "y" => $level["SpawnY"], "z" => $level["SpawnZ"]);
$this->level["Time"] = &$this->time; $this->level["Time"] = &$this->time;
console("[INFO] Time: ".$this->time); console("[INFO] Time: ".$this->time);
console("[INFO] Seed: ".$this->seed); console("[INFO] Seed: ".$this->seed);

View File

@ -14,7 +14,5 @@ time-per-second=20
gamemode=1 gamemode=1
difficulty=1 difficulty=1
generator-settings= generator-settings=
seed=false
level-name=false level-name=false
server-id=false server-id=false
spawn=128.5;100;128.5