Added option to change the DATA_PATH via CLI argument data-path=<directory>

This commit is contained in:
Shoghi Cervantes Pueyo 2013-03-05 12:43:35 +01:00
parent c60e15a682
commit a3e141672a
6 changed files with 34 additions and 33 deletions

View File

@ -37,10 +37,10 @@ class BanAPI{
public function init(){
console("[INFO] Loading authentication lists...");
$this->whitelist = new Config(FILE_PATH."white-list.txt", CONFIG_LIST);
$this->bannedIPs = new Config(FILE_PATH."banned-ips.txt", CONFIG_LIST);
$this->banned = new Config(FILE_PATH."banned.txt", CONFIG_LIST);
$this->ops = new Config(FILE_PATH."ops.txt", CONFIG_LIST);
$this->whitelist = new Config(DATA_PATH."white-list.txt", CONFIG_LIST);
$this->bannedIPs = new Config(DATA_PATH."banned-ips.txt", CONFIG_LIST);
$this->banned = new Config(DATA_PATH."banned.txt", CONFIG_LIST);
$this->ops = new Config(DATA_PATH."ops.txt", CONFIG_LIST);
$this->server->api->console->register("banip", "Manages IP Banning", array($this, "commandHandler"));
$this->server->api->console->register("ban", "Manages Bannning", array($this, "commandHandler"));
$this->server->api->console->register("kick", "Kicks a player", array($this, "commandHandler"));
@ -138,7 +138,7 @@ class BanAPI{
$output .= "Player \"$user\" added to white-list\n";
break;
case "reload":
$this->whitelist = new Config(FILE_PATH."white-list.txt", CONFIG_LIST);
$this->whitelist = new Config(DATA_PATH."white-list.txt", CONFIG_LIST);
break;
case "list":
$output .= "White-list: ".implode(", ", $this->whitelist->getAll(true))."\n";
@ -178,7 +178,7 @@ class BanAPI{
$output .= "IP \"$ip\" added to ban list\n";
break;
case "reload":
$this->bannedIPs = new Config(FILE_PATH."banned-ips.txt", CONFIG_LIST);
$this->bannedIPs = new Config(DATA_PATH."banned-ips.txt", CONFIG_LIST);
break;
case "list":
$output .= "IP ban list: ".implode(", ", $this->bannedIPs->getAll(true))."\n";
@ -216,7 +216,7 @@ class BanAPI{
$output .= "Player \"$user\" added to ban list\n";
break;
case "reload":
$this->banned = new Config(FILE_PATH."banned.txt", CONFIG_LIST);
$this->banned = new Config(DATA_PATH."banned.txt", CONFIG_LIST);
break;
case "list":
$output .= "Ban list: ".implode(", ", $this->banned->getAll(true))."\n";

View File

@ -265,7 +265,7 @@ class PlayerAPI{
}
public function getOffline($name){
if(!file_exists(FILE_PATH."players/".$name.".dat")){
if(!file_exists(DATA_PATH."players/".$name.".dat")){
console("[NOTICE] Player data not found for \"".$name."\", creating new profile");
$data = array(
"spawn" => array(
@ -281,7 +281,7 @@ class PlayerAPI{
);
$this->saveOffline($name, $data);
}else{
$data = unserialize(file_get_contents(FILE_PATH."players/".$name.".dat"));
$data = unserialize(file_get_contents(DATA_PATH."players/".$name.".dat"));
}
if($this->server->gamemode === 1){
$data["health"] = 20;
@ -292,6 +292,6 @@ class PlayerAPI{
public function saveOffline($name, $data){
$this->server->handle("api.player.offline.save", $data);
file_put_contents(FILE_PATH."players/".str_replace("/", "", $name).".dat", serialize($data));
file_put_contents(DATA_PATH."players/".str_replace("/", "", $name).".dat", serialize($data));
}
}

View File

@ -117,7 +117,7 @@ class PluginAPI extends stdClass{
if($p === false){
return false;
}
$path = FILE_PATH."plugins/".$p[1]["name"]."/";
$path = DATA_PATH."plugins/".$p[1]["name"]."/";
$this->plugins[$p[1]["class"]][1]["path"] = $path;
return $path;
}
@ -127,7 +127,7 @@ class PluginAPI extends stdClass{
if($p === false){
return false;
}
$path = FILE_PATH."plugins/".$p[1]["name"]."/";
$path = DATA_PATH."plugins/".$p[1]["name"]."/";
@mkdir($path);
$this->plugins[$p[1]["class"]][1]["path"] = $path;
$cnf = new Config($path."config.yml", CONFIG_YAML, $default);
@ -163,11 +163,11 @@ class PluginAPI extends stdClass{
public function loadAll(){
console("[INFO] Loading Plugins...");
$dir = dir(FILE_PATH."plugins/");
$dir = dir(DATA_PATH."plugins/");
while(false !== ($file = $dir->read())){
if($file{0} !== "."){
if(strtolower(substr($file, -3)) === "php"){
$this->load(FILE_PATH."plugins/" . $file);
$this->load(DATA_PATH."plugins/" . $file);
}
}
}

View File

@ -42,13 +42,13 @@ class ServerAPI{
}
public function load(){
@mkdir(FILE_PATH."logs/", 0777, true);
@mkdir(FILE_PATH."players/", 0777);
@mkdir(FILE_PATH."worlds/", 0777);
@mkdir(FILE_PATH."plugins/", 0777);
@mkdir(DATA_PATH."logs/", 0777, true);
@mkdir(DATA_PATH."players/", 0777);
@mkdir(DATA_PATH."worlds/", 0777);
@mkdir(DATA_PATH."plugins/", 0777);
console("[INFO] Starting ServerAPI server handler...");
file_put_contents(FILE_PATH."logs/packets.log", "");
if(!file_exists(FILE_PATH."logs/test.bin.log") or md5_file(FILE_PATH."logs/test.bin.log") !== TEST_MD5){
file_put_contents(DATA_PATH."logs/packets.log", "");
if(!file_exists(DATA_PATH."logs/test.bin.log") or md5_file(DATA_PATH."logs/test.bin.log") !== TEST_MD5){
console("[NOTICE] Executing tests...");
console("[INFO] OS: ".PHP_OS.", ".Utils::getOS());
console("[INFO] uname -a: ".php_uname("a"));
@ -74,7 +74,7 @@ class ServerAPI{
$test .= Utils::writeInt($str->hashCode());
$test .= Utils::writeDataArray(array("a", "b", "c", "\xff\xff\xff\xff"));
$test .= Utils::hexToStr("012334567890");
file_put_contents(FILE_PATH."logs/test.bin.log", $test);
file_put_contents(DATA_PATH."logs/test.bin.log", $test);
$md5 = md5($test);
console("[INFO] MD5 of test: ".$md5);
if($md5 !== TEST_MD5){
@ -84,7 +84,7 @@ class ServerAPI{
}
console("[DEBUG] Loading server.properties...", true, true, 2);
$this->config = new Config(FILE_PATH . "server.properties", CONFIG_PROPERTIES, array(
$this->config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES, array(
"server-name" => "Minecraft Server",
"description" => "Server made using PocketMine-MP",
"motd" => "Welcome @username to this server!",
@ -162,17 +162,17 @@ class ServerAPI{
}
}
if(file_exists(FILE_PATH."worlds/level.dat")){
if(file_exists(DATA_PATH."worlds/level.dat")){
console("[NOTICE] Detected unimported map data. Importing...");
$this->importMap(FILE_PATH."worlds/", true);
$this->importMap(DATA_PATH."worlds/", true);
}
$this->server->mapName = $this->getProperty("level-name");
$this->server->mapDir = FILE_PATH."worlds/".$this->server->mapName."/";
$this->server->mapDir = DATA_PATH."worlds/".$this->server->mapName."/";
if($this->server->mapName === false or trim($this->server->mapName) === "" or (!file_exists($this->server->mapDir."chunks.dat") and !file_exists($this->server->mapDir."chunks.dat.gz"))){
if($this->server->mapName === false or trim($this->server->mapName) === ""){
$this->server->mapName = "world";
}
$this->server->mapDir = FILE_PATH."worlds/".$this->server->mapName."/";
$this->server->mapDir = DATA_PATH."worlds/".$this->server->mapName."/";
$generator = "SuperflatGenerator";
if($this->getProperty("generator") !== false and class_exists($this->getProperty("generator"))){
$generator = $this->getProperty("generator");
@ -356,24 +356,24 @@ class ServerAPI{
console("[DEBUG] Importing map \"".$level["LevelName"]."\" gamemode ".$level["GameType"]." with seed ".$level["RandomSeed"], true, true, 2);
unset($level["Player"]);
$lvName = $level["LevelName"]."/";
@mkdir(FILE_PATH."worlds/".$lvName, 0777);
file_put_contents(FILE_PATH."worlds/".$lvName."level.dat", serialize($level));
@mkdir(DATA_PATH."worlds/".$lvName, 0777);
file_put_contents(DATA_PATH."worlds/".$lvName."level.dat", serialize($level));
$entities = parseNBTData($nbt->loadFile($dir."entities.dat"));
file_put_contents(FILE_PATH."worlds/".$lvName."entities.dat", serialize($entities["Entities"]));
file_put_contents(DATA_PATH."worlds/".$lvName."entities.dat", serialize($entities["Entities"]));
if(!isset($entities["TileEntities"])){
$entities["TileEntities"] = array();
}
file_put_contents(FILE_PATH."worlds/".$lvName."tileEntities.dat", serialize($entities["TileEntities"]));
file_put_contents(DATA_PATH."worlds/".$lvName."tileEntities.dat", serialize($entities["TileEntities"]));
console("[DEBUG] Imported ".count($entities["Entities"])." Entities and ".count($entities["TileEntities"])." TileEntities", true, true, 2);
if($remove === true){
rename($dir."chunks.dat", FILE_PATH."worlds/".$lvName."chunks.dat");
rename($dir."chunks.dat", DATA_PATH."worlds/".$lvName."chunks.dat");
unlink($dir."level.dat");
@unlink($dir."level.dat_old");
@unlink($dir."player.dat");
unlink($dir."entities.dat");
}else{
copy($dir."chunks.dat", FILE_PATH."worlds/".$lvName."chunks.dat");
copy($dir."chunks.dat", DATA_PATH."worlds/".$lvName."chunks.dat");
}
if($this->getProperty("level-name") === false){
console("[INFO] Setting default level to \"".$level["LevelName"]."\"");

View File

@ -29,6 +29,7 @@ the Free Software Foundation, either version 3 of the License, or
require_once(dirname(__FILE__)."/config.php");
require_once(FILE_PATH."/src/functions.php");
/***REM_END***/
define(DATA_PATH, realpath(arg("data-path", FILE_PATH))."/");
if(strpos(strtoupper(php_uname("s")), "WIN") === false or arg("enable-ansi", false) === true){
define("ENABLE_ANSI", true);

View File

@ -225,7 +225,7 @@ function logg($message, $name, $EOL = true, $level = 2, $close = false){
$fpointers = array();
}
if(!isset($fpointers[$name]) or $fpointers[$name] === false){
$fpointers[$name] = @fopen(FILE_PATH."logs/".$name.".log", "ab");
$fpointers[$name] = @fopen(DATA_PATH."logs/".$name.".log", "ab");
}
@fwrite($fpointers[$name], $message);
if($close === true){