From 2d9b70184748d56f6b7dc8fd79184312053d3502 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 28 Dec 2012 01:02:22 +0100 Subject: [PATCH 01/12] pthreads dependency --- common/dependencies.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/dependencies.php b/common/dependencies.php index 462fcf0eb..32c7fb53a 100644 --- a/common/dependencies.php +++ b/common/dependencies.php @@ -54,6 +54,11 @@ if(!extension_loaded("sockets")){ ++$errors; } +if(!extension_loaded("pthreads")){ + console("[ERROR] Unable to find pthreads extension. [https://github.com/krakjoe/pthreads]", true, true, 0); + ++$errors; +} + if(!extension_loaded("curl")){ console("[ERROR] Unable to find cURL extension", true, true, 0); ++$errors; From aefa34187ba7ecdc4faf02190b9dd81f08deada7 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 28 Dec 2012 02:09:43 +0100 Subject: [PATCH 02/12] Updated README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 44dfba37f..cb767e1a9 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,10 @@ Check the wiki! https://github.com/shoghicp/PocketMine-MP/wiki ## Third-party Libraries Used - +* __[PHP cURL](http://php.net/manual/en/book.curl.php)__ +* __[PHP Sockets](http://php.net/manual/en/book.sockets.php)__ +* __[PHP SQLite3](http://php.net/manual/en/book.sqlite3.php)__ +* __[PHP pthreads](https://github.com/krakjoe/pthreads)__ by _[krakjoe](https://github.com/krakjoe)_: Threading for PHP - Share Nothing, Do Everything * __[PHP NBT](https://github.com/TheFrozenFire/PHP-NBT-Decoder-Encoder/blob/master/nbt.class.php)__ by _[TheFrozenFire](https://github.com/TheFrozenFire)_: Class for reading in NBT-format files * __[Math_BigInteger](http://phpseclib.sourceforge.net/math/intro.html)__ by _[phpseclib](http://phpseclib.sourceforge.net/)_: Pure-PHP arbitrary precission integer arithmetic library * __[Spyc](https://github.com/mustangostang/spyc/blob/master/Spyc.php)__ by _[Vlad Andersen](https://github.com/mustangostang)_: A simple YAML loader/dumper class for PHP \ No newline at end of file From 3409f873bebb691697b12b46c9b231591fd8a8b9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 28 Dec 2012 04:59:45 +0100 Subject: [PATCH 03/12] Updated README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb767e1a9..6a20e55f8 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,13 @@ along with this program. If not, see . # PocketMine-MP -Github repo: https://github.com/shoghicp/PocketMine-MP +PocketMine-MP is a Server for Minecraft Pocket Edition done in PHP. It has a Plugin API that enables a developer to extend it and add new features, or change default ones. -Server (and client) Minecraft Pocket Edition library written in PHP. -Currently a work in progress, and used to document http://www.wiki.vg/Pocket_Minecraft_Protocol +The entire server is done in PHP, and has been tested, profiled and optimized to run smoothly. -Check the wiki! https://github.com/shoghicp/PocketMine-MP/wiki +[Go to Wiki for more information](https://github.com/shoghicp/PocketMine-MP/wiki) + +[FAQ: Frequently Asked Questions](https://github.com/shoghicp/PocketMine-MP/wiki/Frequently-Asked-Questions) **Project Status: `ALPHA`** From 0c498e96a3d446a2cd726f29f1a1cb31ddce1389 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 28 Dec 2012 14:44:56 +0100 Subject: [PATCH 04/12] Removed bedrock --- classes/Data.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Data.class.php b/classes/Data.class.php index ed9e25f2d..8ab8f494b 100644 --- a/classes/Data.class.php +++ b/classes/Data.class.php @@ -81,7 +81,7 @@ class Material{ ); static $unbreakable = array( 0 => true, - 7 => true, + //7 => true, 8 => true, 9 => true, 10 => true, From 0b683c6b0ee38606f057339d4a7227628cb27208 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 28 Dec 2012 15:09:35 +0100 Subject: [PATCH 05/12] Updated directory structure --- .gitignore | 6 ++-- data/How To Import Maps.txt | 2 -- server.php | 4 +-- {classes => src}/API/BlockAPI.php | 0 {classes => src}/API/ChatAPI.php | 0 {classes => src}/API/ConsoleAPI.php | 0 {classes => src}/API/EntityAPI.php | 0 {classes => src}/API/LevelAPI.php | 0 {classes => src}/API/PlayerAPI.php | 6 ++-- {classes => src}/API/PluginAPI.php | 6 ++-- {classes => src}/API/ServerAPI.php | 32 +++++++++---------- {classes => src}/API/TimeAPI.php | 0 {classes => src/classes}/BigInteger.class.php | 0 .../classes}/ChunkParser.class.php | 0 .../classes}/CustomPacketHandler.class.php | 0 {classes => src/classes}/Data.class.php | 0 {classes => src/classes}/Entity.class.php | 0 {classes => src/classes}/Generator.class.php | 0 {classes => src/classes}/Java.class.php | 0 .../classes}/MinecraftInterface.class.php | 0 {classes => src/classes}/NBT.class.php | 0 {classes => src/classes}/Packet.class.php | 0 {classes => src/classes}/Player.class.php | 0 .../classes}/PocketMinecraftServer.class.php | 0 .../SerializedPacketHandler.class.php | 0 {classes => src/classes}/Spyc.class.php | 0 .../classes}/SuperflatGenerator.class.php | 0 {classes => src/classes}/UDPSocket.class.php | 0 {classes => src/classes}/Utils.class.php | 0 {common => src/common}/config.php | 4 +-- {common => src/common}/default.properties | 0 {common => src/common}/dependencies.php | 2 +- {common => src/common}/functions.php | 0 {misc => src/misc}/block/plant/Sapling.php | 0 .../generator/object/tree/SmallTreeObject.php | 0 .../generator/object/tree/TreeObject.php | 0 {pstruct => src/pstruct}/4.php | 0 {pstruct => src/pstruct}/5.php | 0 {pstruct => src/pstruct}/RakNet.php | 0 {pstruct => src/pstruct}/dataName.php | 0 {pstruct => src/pstruct}/packetName.php | 0 41 files changed, 30 insertions(+), 32 deletions(-) delete mode 100644 data/How To Import Maps.txt rename {classes => src}/API/BlockAPI.php (100%) rename {classes => src}/API/ChatAPI.php (100%) rename {classes => src}/API/ConsoleAPI.php (100%) rename {classes => src}/API/EntityAPI.php (100%) rename {classes => src}/API/LevelAPI.php (100%) rename {classes => src}/API/PlayerAPI.php (96%) rename {classes => src}/API/PluginAPI.php (96%) rename {classes => src}/API/ServerAPI.php (92%) rename {classes => src}/API/TimeAPI.php (100%) rename {classes => src/classes}/BigInteger.class.php (100%) rename {classes => src/classes}/ChunkParser.class.php (100%) rename {classes => src/classes}/CustomPacketHandler.class.php (100%) rename {classes => src/classes}/Data.class.php (100%) rename {classes => src/classes}/Entity.class.php (100%) rename {classes => src/classes}/Generator.class.php (100%) rename {classes => src/classes}/Java.class.php (100%) rename {classes => src/classes}/MinecraftInterface.class.php (100%) rename {classes => src/classes}/NBT.class.php (100%) rename {classes => src/classes}/Packet.class.php (100%) rename {classes => src/classes}/Player.class.php (100%) rename {classes => src/classes}/PocketMinecraftServer.class.php (100%) rename {classes => src/classes}/SerializedPacketHandler.class.php (100%) rename {classes => src/classes}/Spyc.class.php (100%) rename {classes => src/classes}/SuperflatGenerator.class.php (100%) rename {classes => src/classes}/UDPSocket.class.php (100%) rename {classes => src/classes}/Utils.class.php (100%) rename {common => src/common}/config.php (89%) rename {common => src/common}/default.properties (100%) rename {common => src/common}/dependencies.php (98%) rename {common => src/common}/functions.php (100%) rename {misc => src/misc}/block/plant/Sapling.php (100%) rename {misc => src/misc}/world/generator/object/tree/SmallTreeObject.php (100%) rename {misc => src/misc}/world/generator/object/tree/TreeObject.php (100%) rename {pstruct => src/pstruct}/4.php (100%) rename {pstruct => src/pstruct}/5.php (100%) rename {pstruct => src/pstruct}/RakNet.php (100%) rename {pstruct => src/pstruct}/dataName.php (100%) rename {pstruct => src/pstruct}/packetName.php (100%) diff --git a/.gitignore b/.gitignore index a84f67b76..7b8cce590 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -data/players/* -data/maps/* -data/plugins/* +players/* +worlds/* +plugins/* *.log server.properties white-list.txt diff --git a/data/How To Import Maps.txt b/data/How To Import Maps.txt deleted file mode 100644 index 1f6370c78..000000000 --- a/data/How To Import Maps.txt +++ /dev/null @@ -1,2 +0,0 @@ -To import a Pocket Edition Map, drop to the folder "maps" -the chunk.dat, level.dat and entities.dat from the savegame file. \ No newline at end of file diff --git a/server.php b/server.php index e9fc7bd52..853f902ae 100644 --- a/server.php +++ b/server.php @@ -12,9 +12,9 @@ the Free Software Foundation, either version 3 of the License, or */ -require_once("common/dependencies.php"); +require_once("src/common/dependencies.php"); require_once("classes/PocketMinecraftServer.class.php"); -require_once("classes/API/ServerAPI.php"); +require_once("API/ServerAPI.php"); while(true){ $server = new ServerAPI(); diff --git a/classes/API/BlockAPI.php b/src/API/BlockAPI.php similarity index 100% rename from classes/API/BlockAPI.php rename to src/API/BlockAPI.php diff --git a/classes/API/ChatAPI.php b/src/API/ChatAPI.php similarity index 100% rename from classes/API/ChatAPI.php rename to src/API/ChatAPI.php diff --git a/classes/API/ConsoleAPI.php b/src/API/ConsoleAPI.php similarity index 100% rename from classes/API/ConsoleAPI.php rename to src/API/ConsoleAPI.php diff --git a/classes/API/EntityAPI.php b/src/API/EntityAPI.php similarity index 100% rename from classes/API/EntityAPI.php rename to src/API/EntityAPI.php diff --git a/classes/API/LevelAPI.php b/src/API/LevelAPI.php similarity index 100% rename from classes/API/LevelAPI.php rename to src/API/LevelAPI.php diff --git a/classes/API/PlayerAPI.php b/src/API/PlayerAPI.php similarity index 96% rename from classes/API/PlayerAPI.php rename to src/API/PlayerAPI.php index db01cc4ad..e42908fae 100644 --- a/classes/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -189,7 +189,7 @@ class PlayerAPI{ } public function getOffline($name){ - if(!file_exists(FILE_PATH."data/players/".$name.".dat")){ + if(!file_exists(FILE_PATH."players/".$name.".dat")){ console("[NOTICE] Player data not found for \"".$name."\", creating new profile"); $data = array( "spawn" => array( @@ -203,7 +203,7 @@ class PlayerAPI{ ); $this->saveOffline($name, $data); }else{ - $data = unserialize(file_get_contents(FILE_PATH."data/players/".$name.".dat")); + $data = unserialize(file_get_contents(FILE_PATH."players/".$name.".dat")); } $this->server->handle("api.player.offline.get", $data); return $data; @@ -211,6 +211,6 @@ class PlayerAPI{ public function saveOffline($name, $data){ $this->server->handle("api.player.offline.save", $data); - file_put_contents(FILE_PATH."data/players/".str_replace("/", "", $name).".dat", serialize($data)); + file_put_contents(FILE_PATH."players/".str_replace("/", "", $name).".dat", serialize($data)); } } \ No newline at end of file diff --git a/classes/API/PluginAPI.php b/src/API/PluginAPI.php similarity index 96% rename from classes/API/PluginAPI.php rename to src/API/PluginAPI.php index 020bd6294..e9e600e2a 100644 --- a/classes/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -115,7 +115,7 @@ class PluginAPI extends stdClass{ if($p === false){ return false; } - $path = FILE_PATH."data/plugins/".$p[1]["name"]."/"; + $path = FILE_PATH."plugins/".$p[1]["name"]."/"; $this->plugins[$p[1]["class"]][1]["path"] = $path; if(!file_exists($path."config.yml")){ @mkdir($path, 0777); @@ -155,11 +155,11 @@ class PluginAPI extends stdClass{ public function loadAll(){ console("[INFO] Loading Plugins..."); - $dir = dir(FILE_PATH."data/plugins/"); + $dir = dir(FILE_PATH."plugins/"); while(false !== ($file = $dir->read())){ if($file !== "." and $file !== ".."){ if(strtolower(substr($file, -3)) === "php"){ - $this->load(FILE_PATH."data/plugins/" . $file); + $this->load(FILE_PATH."plugins/" . $file); } } } diff --git a/classes/API/ServerAPI.php b/src/API/ServerAPI.php similarity index 92% rename from classes/API/ServerAPI.php rename to src/API/ServerAPI.php index 67873e84f..5bff0f626 100644 --- a/classes/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -79,13 +79,13 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run if(!file_exists(FILE_PATH."server.properties")){ console("[NOTICE] No server.properties found, using default settings"); - copy(FILE_PATH."common/default.properties", FILE_PATH."server.properties"); + copy(FILE_PATH."src/common/default.properties", FILE_PATH."server.properties"); } console("[DEBUG] Checking data folders...", true, true, 2); - @mkdir(FILE_PATH."data/players/", 0777, true); - @mkdir(FILE_PATH."data/maps/", 0777); - @mkdir(FILE_PATH."data/plugins/", 0777); + @mkdir(FILE_PATH."players/", 0777, true); + @mkdir(FILE_PATH."worlds/", 0777); + @mkdir(FILE_PATH."plugins/", 0777); console("[DEBUG] Loading server.properties...", true, true, 2); $this->parseProperties(); @@ -138,17 +138,17 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run } } - if(file_exists(FILE_PATH."data/maps/level.dat")){ + if(file_exists(FILE_PATH."worlds/level.dat")){ console("[NOTICE] Detected unimported map data. Importing..."); - $this->importMap(FILE_PATH."data/maps/", true); + $this->importMap(FILE_PATH."worlds/", true); } $this->server->mapName = $this->getProperty("level-name"); - $this->server->mapDir = FILE_PATH."data/maps/".$this->server->mapName."/"; + $this->server->mapDir = FILE_PATH."worlds/".$this->server->mapName."/"; if($this->server->mapName === false or trim($this->server->mapName) === "" or !file_exists($this->server->mapDir."chunks.dat")){ if($this->server->mapName === false or trim($this->server->mapName) === ""){ $this->server->mapName = "world"; } - $this->server->mapDir = FILE_PATH."data/maps/".$this->server->mapName."/"; + $this->server->mapDir = FILE_PATH."worlds/".$this->server->mapName."/"; $generator = "SuperflatGenerator"; if($this->getProperty("generator") !== false and class_exists($this->getProperty("generator"))){ $generator = $this->getProperty("generator"); @@ -168,7 +168,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run //Autoload all default APIs console("[INFO] Loading default APIs"); - $dir = dir(FILE_PATH."classes/API/"); + $dir = dir(FILE_PATH."src/API/"); while(false !== ($file = $dir->read())){ if($file !== "." and $file !== ".."){ $API = basename($file, ".php"); @@ -317,24 +317,24 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run 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."data/maps/".$lvName, 0777); - file_put_contents(FILE_PATH."data/maps/".$lvName."level.dat", serialize($level)); + @mkdir(FILE_PATH."worlds/".$lvName, 0777); + file_put_contents(FILE_PATH."worlds/".$lvName."level.dat", serialize($level)); $entities = parseNBTData($nbt->loadFile($dir."entities.dat")); - file_put_contents(FILE_PATH."data/maps/".$lvName."entities.dat", serialize($entities["Entities"])); + file_put_contents(FILE_PATH."worlds/".$lvName."entities.dat", serialize($entities["Entities"])); if(!isset($entities["TileEntities"])){ $entities["TileEntities"] = array(); } - file_put_contents(FILE_PATH."data/maps/".$lvName."tileEntities.dat", serialize($entities["TileEntities"])); + file_put_contents(FILE_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."data/maps/".$lvName."chunks.dat"); + rename($dir."chunks.dat", FILE_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."data/maps/".$lvName."chunks.dat"); + copy($dir."chunks.dat", FILE_PATH."worlds/".$lvName."chunks.dat"); } if($this->getProperty("level-name") === false){ console("[INFO] Setting default level to \"".$level["LevelName"]."\""); @@ -370,7 +370,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run public function loadAPI($name, $class, $dir = false){ if($dir === false){ - $dir = FILE_PATH."classes/API/"; + $dir = FILE_PATH."src/API/"; } $file = $dir.$class.".php"; if(!file_exists($file)){ diff --git a/classes/API/TimeAPI.php b/src/API/TimeAPI.php similarity index 100% rename from classes/API/TimeAPI.php rename to src/API/TimeAPI.php diff --git a/classes/BigInteger.class.php b/src/classes/BigInteger.class.php similarity index 100% rename from classes/BigInteger.class.php rename to src/classes/BigInteger.class.php diff --git a/classes/ChunkParser.class.php b/src/classes/ChunkParser.class.php similarity index 100% rename from classes/ChunkParser.class.php rename to src/classes/ChunkParser.class.php diff --git a/classes/CustomPacketHandler.class.php b/src/classes/CustomPacketHandler.class.php similarity index 100% rename from classes/CustomPacketHandler.class.php rename to src/classes/CustomPacketHandler.class.php diff --git a/classes/Data.class.php b/src/classes/Data.class.php similarity index 100% rename from classes/Data.class.php rename to src/classes/Data.class.php diff --git a/classes/Entity.class.php b/src/classes/Entity.class.php similarity index 100% rename from classes/Entity.class.php rename to src/classes/Entity.class.php diff --git a/classes/Generator.class.php b/src/classes/Generator.class.php similarity index 100% rename from classes/Generator.class.php rename to src/classes/Generator.class.php diff --git a/classes/Java.class.php b/src/classes/Java.class.php similarity index 100% rename from classes/Java.class.php rename to src/classes/Java.class.php diff --git a/classes/MinecraftInterface.class.php b/src/classes/MinecraftInterface.class.php similarity index 100% rename from classes/MinecraftInterface.class.php rename to src/classes/MinecraftInterface.class.php diff --git a/classes/NBT.class.php b/src/classes/NBT.class.php similarity index 100% rename from classes/NBT.class.php rename to src/classes/NBT.class.php diff --git a/classes/Packet.class.php b/src/classes/Packet.class.php similarity index 100% rename from classes/Packet.class.php rename to src/classes/Packet.class.php diff --git a/classes/Player.class.php b/src/classes/Player.class.php similarity index 100% rename from classes/Player.class.php rename to src/classes/Player.class.php diff --git a/classes/PocketMinecraftServer.class.php b/src/classes/PocketMinecraftServer.class.php similarity index 100% rename from classes/PocketMinecraftServer.class.php rename to src/classes/PocketMinecraftServer.class.php diff --git a/classes/SerializedPacketHandler.class.php b/src/classes/SerializedPacketHandler.class.php similarity index 100% rename from classes/SerializedPacketHandler.class.php rename to src/classes/SerializedPacketHandler.class.php diff --git a/classes/Spyc.class.php b/src/classes/Spyc.class.php similarity index 100% rename from classes/Spyc.class.php rename to src/classes/Spyc.class.php diff --git a/classes/SuperflatGenerator.class.php b/src/classes/SuperflatGenerator.class.php similarity index 100% rename from classes/SuperflatGenerator.class.php rename to src/classes/SuperflatGenerator.class.php diff --git a/classes/UDPSocket.class.php b/src/classes/UDPSocket.class.php similarity index 100% rename from classes/UDPSocket.class.php rename to src/classes/UDPSocket.class.php diff --git a/classes/Utils.class.php b/src/classes/Utils.class.php similarity index 100% rename from classes/Utils.class.php rename to src/classes/Utils.class.php diff --git a/common/config.php b/src/common/config.php similarity index 89% rename from common/config.php rename to src/common/config.php index 82248598f..f6d71707e 100644 --- a/common/config.php +++ b/src/common/config.php @@ -32,8 +32,8 @@ error_reporting(E_ALL ^ E_NOTICE); ini_set("allow_url_fopen", 1); ini_set("display_errors", 1); ini_set('default_charset', 'utf-8'); -define("FILE_PATH", dirname(__FILE__)."/../"); -set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH . PATH_SEPARATOR . FILE_PATH . "/classes/"); +define("FILE_PATH", dirname(__FILE__)."/../../"); +set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH . PATH_SEPARATOR . FILE_PATH . "/src/" . PATH_SEPARATOR . FILE_PATH . "/src/classes/"); ini_set("memory_limit", "256M"); define("CURRENT_PROTOCOL", 5); define("CURRENT_VERSION", 1); diff --git a/common/default.properties b/src/common/default.properties similarity index 100% rename from common/default.properties rename to src/common/default.properties diff --git a/common/dependencies.php b/src/common/dependencies.php similarity index 98% rename from common/dependencies.php rename to src/common/dependencies.php index 32c7fb53a..886c9ce81 100644 --- a/common/dependencies.php +++ b/src/common/dependencies.php @@ -90,6 +90,6 @@ require_once("classes/SerializedPacketHandler.class.php"); require_once("classes/CustomPacketHandler.class.php"); require_once("classes/MinecraftInterface.class.php"); require_once("classes/BigInteger.class.php"); -require_all("misc/"); +require_all(FILE_PATH . "src/misc/"); ?> \ No newline at end of file diff --git a/common/functions.php b/src/common/functions.php similarity index 100% rename from common/functions.php rename to src/common/functions.php diff --git a/misc/block/plant/Sapling.php b/src/misc/block/plant/Sapling.php similarity index 100% rename from misc/block/plant/Sapling.php rename to src/misc/block/plant/Sapling.php diff --git a/misc/world/generator/object/tree/SmallTreeObject.php b/src/misc/world/generator/object/tree/SmallTreeObject.php similarity index 100% rename from misc/world/generator/object/tree/SmallTreeObject.php rename to src/misc/world/generator/object/tree/SmallTreeObject.php diff --git a/misc/world/generator/object/tree/TreeObject.php b/src/misc/world/generator/object/tree/TreeObject.php similarity index 100% rename from misc/world/generator/object/tree/TreeObject.php rename to src/misc/world/generator/object/tree/TreeObject.php diff --git a/pstruct/4.php b/src/pstruct/4.php similarity index 100% rename from pstruct/4.php rename to src/pstruct/4.php diff --git a/pstruct/5.php b/src/pstruct/5.php similarity index 100% rename from pstruct/5.php rename to src/pstruct/5.php diff --git a/pstruct/RakNet.php b/src/pstruct/RakNet.php similarity index 100% rename from pstruct/RakNet.php rename to src/pstruct/RakNet.php diff --git a/pstruct/dataName.php b/src/pstruct/dataName.php similarity index 100% rename from pstruct/dataName.php rename to src/pstruct/dataName.php diff --git a/pstruct/packetName.php b/src/pstruct/packetName.php similarity index 100% rename from pstruct/packetName.php rename to src/pstruct/packetName.php From 8abc36acd4d52cb11e0ae9805e77990642bc1d0b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 28 Dec 2012 15:12:46 +0100 Subject: [PATCH 06/12] Changed files --- server.php => PocketMine-MP.php | 0 src/API/ConsoleAPI.php | 2 +- input.php => src/input.php | 0 start.cmd | 4 ++-- start.sh | 4 ++-- 5 files changed, 5 insertions(+), 5 deletions(-) rename server.php => PocketMine-MP.php (100%) rename input.php => src/input.php (100%) diff --git a/server.php b/PocketMine-MP.php similarity index 100% rename from server.php rename to PocketMine-MP.php diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index a0c2a3521..16d208702 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -30,7 +30,7 @@ class ConsoleAPI{ function __construct(PocketMinecraftServer $server){ $this->help = array(); $this->server = $server; - $this->input = fopen(FILE_PATH."console.in", "w+b"); + $this->input = fopen(FILE_PATH."src/console.in", "w+b"); $this->last = microtime(true); } diff --git a/input.php b/src/input.php similarity index 100% rename from input.php rename to src/input.php diff --git a/start.cmd b/start.cmd index 83a18c2e4..abdd99898 100644 --- a/start.cmd +++ b/start.cmd @@ -26,7 +26,7 @@ if not "%PHPOUTPUT%"=="1" ( echo [ERROR] Couldn't find PHP binary in PATH. ping 127.0.0.1 -n 3 -w 1000>nul ) else ( -START /B CMD /C CALL php server.php -START /B /WAIT php input.php 1 +START /B CMD /C CALL php PocketMine-MP.php +START /B /WAIT php src/input.php 1 ping 127.0.0.1 -n 5 -w 1000>nul ) \ No newline at end of file diff --git a/start.sh b/start.sh index ee771133f..7275fbcc7 100644 --- a/start.sh +++ b/start.sh @@ -1,3 +1,3 @@ #!/bin/bash -php server.php & -cat>console.in \ No newline at end of file +php PocketMine-MP.php & +cat > src/console.in \ No newline at end of file From b5c191530ab3da37c78eb9acbc9707e57d6e6cb9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 28 Dec 2012 15:27:49 +0100 Subject: [PATCH 07/12] Updated folders --- .gitignore | 2 +- src/API/ConsoleAPI.php | 2 +- src/API/ServerAPI.php | 18 +++++++++--------- src/classes/PocketMinecraftServer.class.php | 2 +- src/common/functions.php | 2 +- src/{ => common}/input.php | 2 +- start.cmd | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) rename src/{ => common}/input.php (91%) diff --git a/.gitignore b/.gitignore index 7b8cce590..fd7fa6bac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,11 @@ players/* worlds/* plugins/* +logs/* *.log server.properties white-list.txt banned-ips.txt -console.in ################# ## Eclipse diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index 16d208702..866504bd5 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -30,7 +30,7 @@ class ConsoleAPI{ function __construct(PocketMinecraftServer $server){ $this->help = array(); $this->server = $server; - $this->input = fopen(FILE_PATH."src/console.in", "w+b"); + $this->input = fopen(FILE_PATH."logs/console.in", "w+b"); $this->last = microtime(true); } diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 5bff0f626..e21934ac5 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -30,9 +30,14 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run private $server, $config, $apiList = array(); function __construct(){ console("[INFO] Starting ServerAPI server handler..."); - file_put_contents(FILE_PATH."packets.log", ""); - file_put_contents(FILE_PATH."console.in", ""); - if(!file_exists(FILE_PATH."test.bin.log") or md5_file(FILE_PATH."test.bin.log") !== TEST_MD5){ + console("[DEBUG] Checking data folders...", true, true, 2); + @mkdir(FILE_PATH."logs/", 0777, true); + @mkdir(FILE_PATH."players/", 0777); + @mkdir(FILE_PATH."worlds/", 0777); + @mkdir(FILE_PATH."plugins/", 0777); + file_put_contents(FILE_PATH."logs/packets.log", ""); + file_put_contents(FILE_PATH."logs/console.in", ""); + if(!file_exists(FILE_PATH."logs/test.bin.log") or md5_file(FILE_PATH."logs/test.bin.log") !== TEST_MD5){ console("[NOTICE] Executing integrity tests..."); console("[INFO] OS: ".PHP_OS.", ".Utils::getOS()); console("[INFO] uname -a: ".php_uname("a")); @@ -60,7 +65,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run $test .= Utils::writeLong($str->hashCode()); $test .= Utils::writeDataArray(array("a", "b", "c", "\xff\xff\xff\xff")); $test .= Utils::hexToStr("012334567890"); - file_put_contents(FILE_PATH."test.bin.log", $test); + file_put_contents(FILE_PATH."logs/test.bin.log", $test); if(md5($test) !== TEST_MD5){ console("[ERROR] Test error, please send your console.log + test.bin.log to the Github repo"); die(); @@ -82,11 +87,6 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run copy(FILE_PATH."src/common/default.properties", FILE_PATH."server.properties"); } - console("[DEBUG] Checking data folders...", true, true, 2); - @mkdir(FILE_PATH."players/", 0777, true); - @mkdir(FILE_PATH."worlds/", 0777); - @mkdir(FILE_PATH."plugins/", 0777); - console("[DEBUG] Loading server.properties...", true, true, 2); $this->parseProperties(); define("DEBUG", $this->config["debug"]); diff --git a/src/classes/PocketMinecraftServer.class.php b/src/classes/PocketMinecraftServer.class.php index 30cdcdaa9..a660a737a 100644 --- a/src/classes/PocketMinecraftServer.class.php +++ b/src/classes/PocketMinecraftServer.class.php @@ -30,7 +30,7 @@ class PocketMinecraftServer extends stdClass{ private $database, $interface, $evCnt, $handCnt, $events, $handlers, $version, $serverType, $lastTick; function __construct($name, $gamemode = 1, $seed = false, $protocol = CURRENT_PROTOCOL, $port = 19132, $serverID = false, $version = CURRENT_VERSION){ $this->port = (int) $port; //19132 - 19135 - console("[INFO] PocketMine-MP ".MAJOR_VERSION." by @shoghicp, LGPL License. http://bit.ly/TbrimG", true, true, 0); + console("[INFO] PocketMine-MP ".MAJOR_VERSION." by @shoghicp, LGPL License", true, true, 0); console("[INFO] Starting Minecraft PE Server at *:".$this->port); if($this->port < 19132 or $this->port > 19135){ console("[WARNING] You've selected a not-standard port. Normal port range is from 19132 to 19135 included"); diff --git a/src/common/functions.php b/src/common/functions.php index 3380213e7..ce9d05630 100644 --- a/src/common/functions.php +++ b/src/common/functions.php @@ -170,7 +170,7 @@ function logg($message, $name, $EOL = true, $level = 2, $close = false){ $fpointers = array(); } if(!isset($fpointers[$name])){ - $fpointers[$name] = fopen(FILE_PATH."/".$name.".log", "ab"); + $fpointers[$name] = fopen(FILE_PATH."logs/".$name.".log", "ab"); } fwrite($fpointers[$name], $message); if($close === true){ diff --git a/src/input.php b/src/common/input.php similarity index 91% rename from src/input.php rename to src/common/input.php index 1e9107a84..9e1f2aaad 100644 --- a/src/input.php +++ b/src/common/input.php @@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or */ -$fp = fopen(dirname(__FILE__)."/console.in","wb"); +$fp = fopen(dirname(__FILE__)."/../../logs/console.in","wb"); while(true){ $l = fgets(STDIN); fwrite($fp, $l); diff --git a/start.cmd b/start.cmd index abdd99898..8e15e3e23 100644 --- a/start.cmd +++ b/start.cmd @@ -27,6 +27,6 @@ echo [ERROR] Couldn't find PHP binary in PATH. ping 127.0.0.1 -n 3 -w 1000>nul ) else ( START /B CMD /C CALL php PocketMine-MP.php -START /B /WAIT php src/input.php 1 +START /B /WAIT php src/common/input.php 1 ping 127.0.0.1 -n 5 -w 1000>nul ) \ No newline at end of file From 8a0c5e465545a678e5e828248ebde9813cddc46a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 28 Dec 2012 16:33:16 +0100 Subject: [PATCH 08/12] Scheduled update for entities --- README.md | 2 +- src/classes/Entity.class.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6a20e55f8..a12a42027 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,6 @@ The entire server is done in PHP, and has been tested, profiled and optimized to * __[PHP Sockets](http://php.net/manual/en/book.sockets.php)__ * __[PHP SQLite3](http://php.net/manual/en/book.sqlite3.php)__ * __[PHP pthreads](https://github.com/krakjoe/pthreads)__ by _[krakjoe](https://github.com/krakjoe)_: Threading for PHP - Share Nothing, Do Everything -* __[PHP NBT](https://github.com/TheFrozenFire/PHP-NBT-Decoder-Encoder/blob/master/nbt.class.php)__ by _[TheFrozenFire](https://github.com/TheFrozenFire)_: Class for reading in NBT-format files +* __[PHP NBT](https://github.com/TheFrozenFire/PHP-NBT-Decoder-Encoder/blob/master/nbt.class.php)__ by _[TheFrozenFire](https://github.com/TheFrozenFire)_: Class for reading in NBT-format files (modified to handle Little-Endian files) * __[Math_BigInteger](http://phpseclib.sourceforge.net/math/intro.html)__ by _[phpseclib](http://phpseclib.sourceforge.net/)_: Pure-PHP arbitrary precission integer arithmetic library * __[Spyc](https://github.com/mustangostang/spyc/blob/master/Spyc.php)__ by _[Vlad Andersen](https://github.com/mustangostang)_: A simple YAML loader/dumper class for PHP \ No newline at end of file diff --git a/src/classes/Entity.class.php b/src/classes/Entity.class.php index 8c50069a7..6145a9996 100644 --- a/src/classes/Entity.class.php +++ b/src/classes/Entity.class.php @@ -33,8 +33,8 @@ define("ENTITY_ITEM", 3); define("ENTITY_PAINTING", 4); class Entity extends stdClass{ - var $eid, $type, $name, $x, $y, $z, $yaw, $pitch, $dead, $data, $class, $attach, $metadata, $closed, $player; - + var $eid, $type, $name, $x, $y, $z, $yaw, $pitch, $dead, $data, $class, $attach, $metadata, $closed, $player, $onTick; + private $ev, $server; function __construct($server, $eid, $class, $type = 0, $data = array()){ $this->server = $server; $this->eid = (int) $eid; @@ -49,6 +49,7 @@ class Entity extends stdClass{ $this->closed = false; $this->name = ""; $this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");"); + $this->ev = $this->server->event("server.tick", array($this, "update")); $this->metadata = array(); $this->x = isset($this->data["x"]) ? $this->data["x"]:0; $this->y = isset($this->data["y"]) ? $this->data["y"]:0; @@ -74,6 +75,10 @@ class Entity extends stdClass{ } } + public function update(){ + + } + public function getDirection(){ $rotation = ($this->yaw - 90) % 360; if ($rotation < 0) { @@ -147,6 +152,7 @@ class Entity extends stdClass{ if($this->closed === false){ $this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";"); $this->server->trigger("entity.remove", $this->eid); + $this->server->deleteEvent($this->ev); $this->closed = true; } } From ca54acd09b21a6e10b3a0c7b3ea19a5e92c0dda4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sat, 29 Dec 2012 02:19:54 +0100 Subject: [PATCH 09/12] Removed example folder (added those examples to the wiki) --- example/ExamplePlugin.php | 34 ------------ example/ReactorAsWater.php | 46 ---------------- example/SpawnChanger.php | 105 ------------------------------------- 3 files changed, 185 deletions(-) delete mode 100644 example/ExamplePlugin.php delete mode 100644 example/ReactorAsWater.php delete mode 100644 example/SpawnChanger.php diff --git a/example/ExamplePlugin.php b/example/ExamplePlugin.php deleted file mode 100644 index 7a32f1553..000000000 --- a/example/ExamplePlugin.php +++ /dev/null @@ -1,34 +0,0 @@ -api = $api; - } - - public function init(){ - $this->api->console->register("example", "Example command", array($this, "handleCommand")); - } - - public function __destruct(){ - - } - - public function handleCommand($cmd, $arg){ - switch($cmd){ - case "example": - console("EXAMPLE!!!"); - break; - } - } - -} \ No newline at end of file diff --git a/example/ReactorAsWater.php b/example/ReactorAsWater.php deleted file mode 100644 index 3315b0382..000000000 --- a/example/ReactorAsWater.php +++ /dev/null @@ -1,46 +0,0 @@ -api = $api; - } - - public function init(){ - $this->api->addHandler("player.block.action", array($this, "handle"), 15); //Priority higher that API - $this->api->addHandler("player.equipment.change", array($this, "handle"), 15); - } - - public function __destruct(){ - - } - - public function handle(&$data, $event){ - switch($event){ - case "player.equipment.change": - if($data["block"] === 247){ - $this->api->player->getByEID($data["eid"])->eventHandler("[ReactorAsWater] Placing water", "server.chat"); - $data["block"] = 9; - $data["meta"] = 0; - } - break; - case "player.block.action": - if($data["block"] === 247){ //nether reactor - $data["block"] = 9; //water source - $data["meta"] = 0; - } - break; - } - } - -} \ No newline at end of file diff --git a/example/SpawnChanger.php b/example/SpawnChanger.php deleted file mode 100644 index 37b41670d..000000000 --- a/example/SpawnChanger.php +++ /dev/null @@ -1,105 +0,0 @@ -api = $api; - } - - public function init(){ - $spawn = $this->api->level->getSpawn(); - $this->path = $this->api->plugin->createConfig($this, array( - "spawnX" => $spawn["x"], - "spawnY" => $spawn["y"], - "spawnZ" => $spawn["z"], - "custom-spawn" => false, - "force-spawn" => false, - )); - $this->config = $this->api->plugin->readYAML($this->path."config.yml"); - if($this->config["custom-spawn"] === false){ - $this->config["spawnX"] = $spawn["x"]; - $this->config["spawnY"] = $spawn["y"]; - $this->config["spawnZ"] = $spawn["z"]; - $this->api->plugin->writeYAML($this->path."config.yml", $this->config); - } - $this->api->addHandler("api.player.offline.get", array($this, "handle"), 15); - $this->api->console->register("spawnchanger", "SpawnChanger init point managing", array($this, "command")); - $this->api->console->register("spawn", "Teleports to spawn", array($this, "command")); - } - - public function __destruct(){ - - } - - public function command($cmd, $args){ - switch($cmd){ - case "spawnchanger": - switch(strtolower(array_shift($args))){ - case "force": - $l = array_shift($args); - if($l != "0" and $l != "1"){ - console("[SpawnChanger] Usage: /spawnchanger force <1 | 0>"); - }else{ - $this->config["force-spawn"] = $l == "0" ? false:true; - if($this->config["force-spawn"] === true){ - console("[SpawnChanger] Forced spawn point"); - }else{ - console("[SpawnChanger] Freed pawn point"); - } - $this->api->plugin->writeYAML($this->path."config.yml", $this->config); - } - break; - case "set": - $z = array_pop($args); - $y = array_pop($args); - $x = array_pop($args); - if($x === null or $y === null or $z === null){ - console("[SpawnChanger] Usage: /spawnchanger set "); - }else{ - $this->config["custom-spawn"] = true; - $this->config["spawnX"] = (float) $x; - $this->config["spawnY"] = (float) $y; - $this->config["spawnZ"] = (float) $z; - console("[SpawnChanger] Spawn point set at X ".$this->config["spawnX"]." Y ".$this->config["spawnY"]." Z ".$this->config["spawnZ"]); - $this->api->plugin->writeYAML($this->path."config.yml", $this->config); - } - break; - default: - console("[SpawnChanger] Always spawn player in spawn point: /spawnchanger force <1 | 0>"); - console("[SpawnChanger] Set the spawn point: /spawnchanger set "); - break; - } - break; - case "spawn": - if($this->api->player->tppos(implode(" ", $args), $this->config["spawnX"], $this->config["spawnY"], $this->config["spawnZ"]) !== false){ - console("[SpawnChanger] Teleported to spawn!"); - }else{ - console("[SpawnChanger] Usage: /spawn "); - } - break; - } - } - - public function handle(&$data, $event){ - switch($event){ - case "api.player.offline.get": - if($this->config["force-spawn"] === true){ - $data["spawn"]["x"] = $this->config["spawnX"]; - $data["spawn"]["y"] = $this->config["spawnY"]; - $data["spawn"]["z"] = $this->config["spawnZ"]; - } - break; - } - } - -} \ No newline at end of file From 470352cd31ab93b73a100837f4e042985f26346b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sat, 29 Dec 2012 02:27:51 +0100 Subject: [PATCH 10/12] Bedrock *again* --- src/classes/Data.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/Data.class.php b/src/classes/Data.class.php index 8ab8f494b..ed9e25f2d 100644 --- a/src/classes/Data.class.php +++ b/src/classes/Data.class.php @@ -81,7 +81,7 @@ class Material{ ); static $unbreakable = array( 0 => true, - //7 => true, + 7 => true, 8 => true, 9 => true, 10 => true, From c959e1471820fdbada332f433da6cc7228f4c382 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sat, 29 Dec 2012 02:30:20 +0100 Subject: [PATCH 11/12] Cancel unallowed break/place events --- src/API/BlockAPI.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index f20c5394f..721c9dfe6 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -44,13 +44,24 @@ class BlockAPI{ $this->server->addHandler("player.block.action", array($this, "blockAction"), 1); } + private function cancelAction($block){ + $this->server->trigger("world.block.change", array( + "x" => $block[2][0], + "y" => $block[2][1], + "z" => $block[2][2], + "block" => $block[0], + "meta" => $block[1], + )); + return false; + } + public function blockBreak($data, $event){ if($event !== "player.block.break"){ return; } $target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]); if(isset(Material::$unbreakable[$target[0]])){ - return false; + return $this->cancelAction($target); } $drop = array( $target[0], //Block @@ -247,7 +258,10 @@ class BlockAPI{ } if($cancelPlace === true){ - return false; + $this->cancelAction($target); + BlockFace::setPosition($data, $data["face"]); + $target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]); + return $this->cancelAction($target); } $replace = false; @@ -275,13 +289,13 @@ class BlockAPI{ $block = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]); if($replace === false and !isset(Material::$replaceable[$block[0]])){ - return false; + return $this->cancelAction($block); } if(isset(Material::$placeable[$data["block"]])){ $data["block"] = Material::$placeable[$data["block"]] === true ? $data["block"]:Material::$placeable[$data["block"]]; }else{ - return false; + return $this->cancelAction($block); } $direction = $this->server->api->entity->get($data["eid"])->getDirection(); From 4c34cdaa61118f40ec50c6d90855c737af4b574d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sat, 29 Dec 2012 02:31:19 +0100 Subject: [PATCH 12/12] Removed pthreads dependency for merge --- src/common/dependencies.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/dependencies.php b/src/common/dependencies.php index 886c9ce81..36df079d5 100644 --- a/src/common/dependencies.php +++ b/src/common/dependencies.php @@ -54,10 +54,10 @@ if(!extension_loaded("sockets")){ ++$errors; } -if(!extension_loaded("pthreads")){ +/*if(!extension_loaded("pthreads")){ console("[ERROR] Unable to find pthreads extension. [https://github.com/krakjoe/pthreads]", true, true, 0); ++$errors; -} +}*/ if(!extension_loaded("curl")){ console("[ERROR] Unable to find cURL extension", true, true, 0);