This commit is contained in:
Shoghi Cervantes 2014-02-19 17:41:12 +01:00
parent be13d0a921
commit 7bdc48509e
14 changed files with 123 additions and 198 deletions

View File

@ -38,10 +38,10 @@ class BanAPI{
}
public function init(){
$this->whitelist = new Config(DATA_PATH."white-list.txt", CONFIG_LIST);//Open whitelist list file
$this->bannedIPs = new Config(DATA_PATH."banned-ips.txt", CONFIG_LIST);//Open Banned IPs list file
$this->banned = new Config(DATA_PATH."banned.txt", CONFIG_LIST);//Open Banned Usernames list file
$this->ops = new Config(DATA_PATH."ops.txt", CONFIG_LIST);//Open list of OPs
$this->whitelist = new Config(DATA_PATH."white-list.txt", Config::LIST);//Open whitelist list file
$this->bannedIPs = new Config(DATA_PATH."banned-ips.txt", Config::LIST);//Open Banned IPs list file
$this->banned = new Config(DATA_PATH."banned.txt", Config::LIST);//Open Banned Usernames list file
$this->ops = new Config(DATA_PATH."ops.txt", Config::LIST);//Open list of OPs
$this->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", array($this, "commandHandler"));
$this->server->api->console->register("ban", "<add|remove|list|reload> [username]", array($this, "commandHandler"));
$this->server->api->console->register("kick", "<player> [reason ...]", array($this, "commandHandler"));
@ -211,7 +211,7 @@ class BanAPI{
$output .= "Player \"$user\" added to white-list\n";
break;
case "reload":
$this->whitelist = new Config(DATA_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";
@ -256,7 +256,7 @@ class BanAPI{
$output .= "IP \"$ip\" added to ban list\n";
break;
case "reload":
$this->bannedIPs = new Config(DATA_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";
@ -294,7 +294,7 @@ class BanAPI{
$output .= "Player \"$user\" added to ban list\n";
break;
case "reload":
$this->banned = new Config(DATA_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

@ -155,12 +155,12 @@ class LevelAPI{
console("[ERROR] Could not load level \"".$name."\"");
return false;
}
$entities = new Config($path."entities.yml", CONFIG_YAML);
$entities = new Config($path."entities.yml", Config::YAML);
if(file_exists($path."tileEntities.yml")){
@rename($path."tileEntities.yml", $path."tiles.yml");
}
$tiles = new Config($path."tiles.yml", CONFIG_YAML);
$blockUpdates = new Config($path."bupdates.yml", CONFIG_YAML);
$tiles = new Config($path."tiles.yml", Config::YAML);
$blockUpdates = new Config($path."bupdates.yml", Config::YAML);
$this->levels[$name] = new Level($level, $entities, $tiles, $blockUpdates, $name);
foreach($entities->getAll() as $entity){
if(!isset($entity["id"])){

View File

@ -502,10 +502,10 @@ class PlayerAPI{
if(!file_exists(DATA_PATH."players/".$iname.".yml")){
console("[NOTICE] Player data not found for \"".$iname."\", creating new profile");
$data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default);
$data = new Config(DATA_PATH."players/".$iname.".yml", Config::YAML, $default);
$data->save();
}else{
$data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default);
$data = new Config(DATA_PATH."players/".$iname.".yml", Config::YAML, $default);
}
if(($data->get("gamemode") & 0x01) === 1){

View File

@ -191,7 +191,7 @@ class PluginAPI extends stdClass{
return false;
}
$path = $this->configPath($plugin);
$cnf = new Config($path."config.yml", CONFIG_YAML, $default);
$cnf = new Config($path."config.yml", Config::YAML, $default);
$cnf->save();
return $path;
}

View File

@ -110,7 +110,7 @@ class ServerAPI{
console("[INFO] Starting Minecraft PE server version ".FORMAT_AQUA.CURRENT_MINECRAFT_VERSION);
console("[INFO] Loading properties...");
$this->config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES, array(
$this->config = new Config(DATA_PATH . "server.properties", Config::PROPERTIES, array(
"server-name" => "Minecraft: PE Server",
"description" => "Server made using PocketMine-MP",
"motd" => "Welcome @player to this server!",

View File

@ -2426,22 +2426,6 @@ class Player{
$this->bufferLen += 6 + $len;
return array();
}
public function isPermissionSet($nodeName){
}
public function hasPermission($nodeName){
return $this->isPermissionSet($nodeName) and PermissionsAPI::hasPermission($nodeName, $this);
}
public function setPermission($nodeName, $boolean){
}
public function unsetPermission($nodeName, $boolean){
}
/**
* @return string

36
src/nbt/NBT.php Normal file
View File

@ -0,0 +1,36 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class NBT{
const MODE_WRITE = 0;
const MODE_OVERWRITE = 1;
const LITTLE_ENDIAN = 0;
const BIG_ENDIAN = 1;
private $buffer;
private $offset;
private $mode = NBT::MODE_WRITE;
public function __construct($buffer, $endianness = NBT::BIG_ENDIAN){
}
}

View File

@ -98,11 +98,11 @@ class PMFLevel extends PMF{
$this->saveData();
@mkdir(dirname($this->file)."/chunks/", 0755);
if(!file_exists(dirname($this->file)."/entities.yml")){
$entities = new Config(dirname($this->file)."/entities.yml", CONFIG_YAML);
$entities = new Config(dirname($this->file)."/entities.yml", Config::YAML);
$entities->save();
}
if(!file_exists(dirname($this->file)."/tiles.yml")){
$tiles = new Config(dirname($this->file)."/tiles.yml", CONFIG_YAML);
$tiles = new Config(dirname($this->file)."/tiles.yml", Config::YAML);
$tiles->save();
}
}

View File

@ -19,14 +19,7 @@
*
*/
define("CONFIG_DETECT", -1); //Detect by file extension
define("CONFIG_PROPERTIES", 0); // .properties
define("CONFIG_CNF", CONFIG_PROPERTIES); // .cnf
define("CONFIG_JSON", 1); // .js, .json
define("CONFIG_YAML", 2); // .yml, .yaml
//define("CONFIG_EXPORT", 3); // .export, .xport
define("CONFIG_SERIALIZED", 4); // .sl
define("CONFIG_LIST", 5); // .txt, .list
/**
* Class Config
@ -34,6 +27,15 @@ define("CONFIG_LIST", 5); // .txt, .list
* Config Class for simple config manipulation of multiple formats.
*/
class Config{
const DETECT = -1; //Detect by file extension
const PROPERTIES = 0; // .properties
const CNF = PROPERTIES; // .cnf
const JSON = 1; // .js, .json
const YAML = 2; // .yml, .yaml
//const EXPORT = 3; // .export, .xport
const SERIALIZED = 4; // .sl
const LIST = 5; // .txt, .list
/**
* @var array
*/
@ -49,23 +51,23 @@ class Config{
/**
* @var integer
*/
private $type = CONFIG_DETECT;
private $type = Config::DETECT;
public static $formats = array(
"properties" => CONFIG_PROPERTIES,
"cnf" => CONFIG_CNF,
"conf" => CONFIG_CNF,
"config" => CONFIG_CNF,
"json" => CONFIG_JSON,
"js" => CONFIG_JSON,
"yml" => CONFIG_YAML,
"yaml" => CONFIG_YAML,
//"export" => CONFIG_EXPORT,
//"xport" => CONFIG_EXPORT,
"sl" => CONFIG_SERIALIZED,
"serialize" => CONFIG_SERIALIZED,
"txt" => CONFIG_LIST,
"list" => CONFIG_LIST,
"properties" => Config::PROPERTIES,
"cnf" => Config::CNF,
"conf" => Config::CNF,
"config" => Config::CNF,
"json" => Config::JSON,
"js" => Config::JSON,
"yml" => Config::YAML,
"yaml" => Config::YAML,
//"export" => Config::EXPORT,
//"xport" => Config::EXPORT,
"sl" => Config::SERIALIZED,
"serialize" => Config::SERIALIZED,
"txt" => Config::LIST,
"list" => Config::LIST,
);
/**
@ -74,8 +76,9 @@ class Config{
* @param array $default
* @param null|boolean $correct
*/
public function __construct($file, $type = CONFIG_DETECT, $default = array(), &$correct = null){
public function __construct($file, $type = Config::DETECT, $default = array(), &$correct = null){
$this->load($file, $type, $default);
$correct = $this->correct;
}
public function reload(){
@ -96,7 +99,7 @@ class Config{
*
* @return boolean
*/
public function load($file, $type = CONFIG_DETECT, $default = array()){
public function load($file, $type = Config::DETECT, $default = array()){
$this->correct = true;
$this->type = (int) $type;
$this->file = $file;
@ -107,7 +110,7 @@ class Config{
$this->config = $default;
$this->save();
}else{
if($this->type === CONFIG_DETECT){
if($this->type === Config::DETECT){
$extension = explode(".", basename($this->file));
$extension = strtolower(trim(array_pop($extension)));
if(isset(Config::$formats[$extension])){
@ -119,21 +122,21 @@ class Config{
if($this->correct === true){
$content = @file_get_contents($this->file);
switch($this->type){
case CONFIG_PROPERTIES:
case CONFIG_CNF:
case Config::PROPERTIES:
case Config::CNF:
$this->parseProperties($content);
break;
case CONFIG_JSON:
case Config::JSON:
$this->config = @json_decode($content, true);
break;
case CONFIG_YAML:
case Config::YAML:
$content = $this->fixYAMLIndexes($content);
$this->config = yaml_parse($content);
break;
case CONFIG_SERIALIZED:
case Config::SERIALIZED:
$this->config = @unserialize($content);
break;
case CONFIG_LIST:
case Config::LIST:
$this->parseList($content);
break;
default:
@ -166,20 +169,20 @@ class Config{
public function save(){
if($this->correct === true){
switch($this->type){
case CONFIG_PROPERTIES:
case CONFIG_CNF:
case Config::PROPERTIES:
case Config::CNF:
$content = $this->writeProperties();
break;
case CONFIG_JSON:
case Config::JSON:
$content = json_encode($this->config, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING);
break;
case CONFIG_YAML:
case Config::YAML:
$content = yaml_emit($this->config, YAML_UTF8_ENCODING);
break;
case CONFIG_SERIALIZED:
case Config::SERIALIZED:
$content = @serialize($this->config);
break;
case CONFIG_LIST:
case Config::LIST:
$content = implode("\r\n", array_keys($this->config));
break;
}

View File

@ -19,7 +19,7 @@
*
*/
class NBT{
class NBTOld{
public $tree = array();
public $binary = b"";
private $offset = 0;

View File

@ -82,7 +82,7 @@ LICENSE;
}
private function generateBaseConfig(){
$config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES);
$config = new Config(DATA_PATH . "server.properties", Config::PROPERTIES);
echo "[?] ".$this->lang->name_your_server." (".self::DEFAULT_NAME."): ";
$config->set("server-name", $this->getInput(self::DEFAULT_NAME));
echo "[*] ".$this->lang->port_warning."\n";
@ -122,13 +122,13 @@ LICENSE;
if($op === ""){
echo "[!] ".$this->lang->op_warning."\n";
}else{
$ops = new Config(DATA_PATH."ops.txt", CONFIG_LIST);
$ops = new Config(DATA_PATH."ops.txt", Config::LIST);
$ops->set($op, true);
$ops->save();
}
echo "[*] ".$this->lang->whitelist_info."\n";
echo "[?] ".$this->lang->whitelist_enable." (y/N): ";
$config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES);
$config = new Config(DATA_PATH . "server.properties", Config::PROPERTIES);
if(strtolower($this->getInput("n")) === "y"){
echo "[!] ".$this->lang->whitelist_warning."\n";
$config->set("white-list", true);
@ -139,7 +139,7 @@ LICENSE;
}
private function networkFunctions(){
$config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES);
$config = new Config(DATA_PATH . "server.properties", Config::PROPERTIES);
echo "[!] ".$this->lang->query_warning1."\n";
echo "[!] ".$this->lang->query_warning2."\n";
echo "[?] ".$this->lang->query_disable." (y/N): ";

View File

@ -20,16 +20,25 @@
*/
class Level{
public $entities, $tiles, $blockUpdates, $nextSave, $players = array(), $level;
public $entities = array();
public $chunkEntities = array();
public $tiles = array();
public $entitiesConfig;
public $tilesConfig;
public $blockUpdatesConfig;
public $nextSave, $players = array(), $level;
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime, $generator;
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
$this->server = ServerAPI::request();
$this->level = $level;
$this->level->level = $this;
$this->entities = $entities;
$this->tiles = $tiles;
$this->blockUpdates = $blockUpdates;
$this->entitiesConfig = $entities;
$this->tilesConfig = $tiles;
$this->blockUpdatesConfig = $blockUpdates;
$this->startTime = $this->time = (int) $this->level->getData("time");
$this->nextSave = $this->startCheck = microtime(true);
$this->nextSave += 90;
@ -58,10 +67,11 @@ class Level{
}
public function useChunk($X, $Z, Player $player){
if(!isset($this->usedChunks[$X.".".$Z])){
$this->usedChunks[$X.".".$Z] = array();
$index = PMFLevel::getIndex($X, $Z);
if(!isset($this->usedChunks[$index])){
$this->usedChunks[$index] = array();
}
$this->usedChunks[$X.".".$Z][$player->CID] = true;
$this->usedChunks[$index][$player->CID] = true;
if(isset($this->level)){
$this->level->loadChunk($X, $Z);
}
@ -74,7 +84,7 @@ class Level{
}
public function freeChunk($X, $Z, Player $player){
unset($this->usedChunks[$X.".".$Z][$player->CID]);
unset($this->usedChunks[PMFLevel::getIndex($X, $Z)][$player->CID]);
}
public function isChunkPopulated($X, $Z){
@ -183,115 +193,7 @@ class Level{
}
if($extra !== false){
$entities = array();
foreach($this->server->api->entity->getAll($this) as $entity){
if($entity->class === ENTITY_MOB){
$entities[] = array(
"id" => $entity->type,
"Color" => @$entity->data["Color"],
"Sheared" => @$entity->data["Sheared"],
"Health" => $entity->health,
"Pos" => array(
0 => $entity->x,
1 => $entity->y,
2 => $entity->z,
),
"Rotation" => array(
0 => $entity->yaw,
1 => $entity->pitch,
),
);
}elseif($entity->class === ENTITY_OBJECT){
if($entity->type === OBJECT_PAINTING){
$entities[] = array(
"id" => $entity->type,
"TileX" => $entity->x,
"TileY" => $entity->y,
"TileZ" => $entity->z,
"Health" => $entity->health,
"Motive" => $entity->data["Motive"],
"Pos" => array(
0 => $entity->x,
1 => $entity->y,
2 => $entity->z,
),
"Rotation" => array(
0 => $entity->yaw,
1 => $entity->pitch,
),
);
}else{
$entities[] = array(
"id" => $entity->type,
"Health" => $entity->health,
"Pos" => array(
0 => $entity->x,
1 => $entity->y,
2 => $entity->z,
),
"Rotation" => array(
0 => $entity->yaw,
1 => $entity->pitch,
),
);
}
}elseif($entity->class === ENTITY_FALLING){
$entities[] = array(
"id" => $entity->type,
"Health" => $entity->health,
"Tile" => $entity->data["Tile"],
"Pos" => array(
0 => $entity->x,
1 => $entity->y,
2 => $entity->z,
),
"Rotation" => array(
0 => 0,
1 => 0,
),
);
}elseif($entity->class === ENTITY_ITEM){
$entities[] = array(
"id" => 64,
"Item" => array(
"id" => $entity->type,
"Damage" => $entity->meta,
"Count" => $entity->stack,
),
"Health" => $entity->health,
"Pos" => array(
0 => $entity->x,
1 => $entity->y,
2 => $entity->z,
),
"Rotation" => array(
0 => 0,
1 => 0,
),
);
}
}
$this->entities->setAll($entities);
$this->entities->save();
$tiles = array();
foreach($this->server->api->tile->getAll($this) as $tile){
$tiles[] = $tile->data;
}
$this->tiles->setAll($tiles);
$this->tiles->save();
$blockUpdates = array();
$updates = $this->server->query("SELECT x,y,z,type,delay FROM blockUpdates WHERE level = '".$this->getName()."';");
if($updates !== false and $updates !== true){
$timeu = microtime(true);
while(($bupdate = $updates->fetchArray(SQLITE3_ASSOC)) !== false){
$bupdate["delay"] = max(1, ($bupdate["delay"] - $timeu) * 20);
$blockUpdates[] = $bupdate;
}
}
$this->blockUpdates->setAll($blockUpdates);
$this->blockUpdates->save();
}

View File

@ -29,9 +29,9 @@ class LevelImport{
if(file_exists($this->path."tileEntities.dat")){ //OldPM
$level = unserialize(file_get_contents($this->path."level.dat"));
console("[INFO] Importing OldPM level \"".$level["LevelName"]."\" to PMF format");
$entities = new Config($this->path."entities.yml", CONFIG_YAML, unserialize(file_get_contents($this->path."entities.dat")));
$entities = new Config($this->path."entities.yml", Config::YAML, unserialize(file_get_contents($this->path."entities.dat")));
$entities->save();
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML, unserialize(file_get_contents($this->path."tileEntities.dat")));
$tiles = new Config($this->path."tiles.yml", Config::YAML, unserialize(file_get_contents($this->path."tileEntities.dat")));
$tiles->save();
}elseif(file_exists($this->path."chunks.dat") and file_exists($this->path."level.dat")){ //Pocket
$nbt = new NBT();
@ -49,9 +49,9 @@ class LevelImport{
}
$tiles = $entities["TileEntities"];
$entities = $entities["Entities"];
$entities = new Config($this->path."entities.yml", CONFIG_YAML, $entities);
$entities = new Config($this->path."entities.yml", Config::YAML, $entities);
$entities->save();
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML, $tiles);
$tiles = new Config($this->path."tiles.yml", Config::YAML, $tiles);
$tiles->save();
}else{
return false;

View File

@ -39,9 +39,9 @@ class WorldGenerator{
"generatorSettings" => $this->generator->getSettings(),
"extra" => ""
));
$entities = new Config($this->path."entities.yml", CONFIG_YAML);
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML);
$blockUpdates = new Config($this->path."bupdates.yml", CONFIG_YAML);
$entities = new Config($this->path."entities.yml", Config::YAML);
$tiles = new Config($this->path."tiles.yml", Config::YAML);
$blockUpdates = new Config($this->path."bupdates.yml", Config::YAML);
$this->level = new Level($level, $entities, $tiles, $blockUpdates, $name);
}