diff --git a/PocketMine-MP.php b/PocketMine-MP.php index f80f6ac5c..c6df6792c 100644 --- a/PocketMine-MP.php +++ b/PocketMine-MP.php @@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or */ -require_once(dirname(__FILE__)."/src/common/dependencies.php"); +require_once(dirname(__FILE__)."/src/dependencies.php"); require_once("API/ServerAPI.php"); $server = new ServerAPI(); diff --git a/src/classes/network/MinecraftInterface.php b/src/classes/network/MinecraftInterface.php index 40478612f..a97d63374 100644 --- a/src/classes/network/MinecraftInterface.php +++ b/src/classes/network/MinecraftInterface.php @@ -26,21 +26,11 @@ the Free Software Foundation, either version 3 of the License, or */ class MinecraftInterface{ - var $pstruct; - var $name; - var $client; - var $dataName; + public $client; private $socket; private $data; function __construct($server, $port = 25565, $listen = false, $client = false, $serverip = "0.0.0.0"){ $this->socket = new UDPSocket($server, $port, (bool) $listen, $serverip); - require("protocol/RakNet.php"); - require("protocol/packetName.php"); - require("protocol/current.php"); - require("protocol/dataName.php"); - $this->pstruct = $pstruct; - $this->name = $packetName; - $this->dataName = $dataName; $this->client = (bool) $client; $this->start = microtime(true); } @@ -50,19 +40,19 @@ class MinecraftInterface{ } protected function getStruct($pid){ - if(isset($this->pstruct[$pid])){ - return $this->pstruct[$pid]; + if(isset(Protocol::$raknet[$pid])){ + return Protocol::$raknet[$pid]; } return false; } protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){ if(LOG === true and DEBUG >= 3){ - $p = "[".(microtime(true) - $this->start)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".(isset($data["id"]) ? "MC Packet ".$this->dataName[$pid]:$this->name[$pid])." (0x".Utils::strTohex(chr($pid)).") [length ".strlen($raw)."]".PHP_EOL; + $p = "[".(microtime(true) - $this->start)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".(isset($data["id"]) ? "MC Packet ".Protocol::$dataName[$pid]:Protocol::$packetName[$pid])." (0x".Utils::strTohex(chr($pid)).") [length ".strlen($raw)."]".PHP_EOL; $p .= Utils::hexdump($raw); if(is_array($data)){ foreach($data as $i => $d){ - $p .= $i ." => ".(!is_array($d) ? $this->pstruct[$pid][$i]."(".(($this->pstruct[$pid][$i] === "magic" or substr($this->pstruct[$pid][$i], 0, 7) === "special" or is_int($this->pstruct[$pid][$i])) ? Utils::strToHex($d):Utils::printable($d)).")":$this->pstruct[$pid][$i]."(\"".serialize(array_map("Utils::printable", $d))."\")").PHP_EOL; + $p .= $i ." => ".(!is_array($d) ? Protocol::$raknet[$pid][$i]."(".((Protocol::$raknet[$pid][$i] === "magic" or substr(Protocol::$raknet[$pid][$i], 0, 7) === "special" or is_int(Protocol::$raknet[$pid][$i])) ? Utils::strToHex($d):Utils::printable($d)).")":Protocol::$raknet[$pid][$i]."(\"".serialize(array_map("Utils::printable", $d))."\")").PHP_EOL; } } $p .= PHP_EOL; diff --git a/src/classes/network/protocol.php b/src/classes/network/protocol.php new file mode 100644 index 000000000..12aa10e04 --- /dev/null +++ b/src/classes/network/protocol.php @@ -0,0 +1,346 @@ + "Keep Alive", + + MC_CLIENT_CONNECT => "Client Connect", + MC_SERVER_HANDSHAKE => "Server Handshake", + + MC_CLIENT_HANDSHAKE => "Client Handshake", + + MC_DISCONNECT => "Disconnect", + + 0x18 => "Unknown", + + MC_LOGIN => "Login", + MC_LOGIN_STATUS => "Login Status", + MC_READY => "Ready", + MC_CHAT => "Chat", + MC_SET_TIME => "Set Time", + MC_START_GAME => "Start Game", + + MC_ADD_MOB => "Add Mob", + MC_ADD_PLAYER => "Add Player", + + MC_ADD_ENTITY => "Add Entity", + MC_REMOVE_ENTITY => "Remove Entity", + MC_ADD_ITEM_ENTITY => "Add Item", + MC_TAKE_ITEM_ENTITY => "Take Item", + + MC_MOVE_ENTITY => "Move Entity", + + MC_MOVE_ENTITY_POSROT => "Move Entity PosRot", + MC_MOVE_PLAYER => "Move Player", + MC_PLACE_BLOCK => "Place Block", + MC_REMOVE_BLOCK => "Remove Block", + MC_UPDATE_BLOCK => "Update Block", + MC_ADD_PAINTING => "Add Painting", + MC_EXPLOSION => "Explosion", + + MC_LEVEL_EVENT => "Level Event", + + MC_ENTITY_EVENT => "Entity Event", + MC_REQUEST_CHUNK => "Chunk Request", + MC_CHUNK_DATA => "Chunk Data", + + MC_PLAYER_EQUIPMENT => "Player Equipment", + MC_PLAYER_ARMOR_EQUIPMENT => "Player Armor", + MC_INTERACT => "Interact", + MC_USE_ITEM => "Use Item", + MC_PLAYER_ACTION => "Player Action", + MC_SET_ENTITY_DATA => "Entity Data", + MC_SET_ENTITY_MOTION => "Entity Motion", + MC_HURT_ARMOR => "Hurt Armor", + MC_SET_HEALTH => "Set Health", + MC_SET_SPAWN_POSITION => "Set Spawn Position", + MC_ANIMATE => "Animate", + MC_RESPAWN => "Respawn", + MC_SEND_INVENTORY => "Send Inventory", + MC_DROP_ITEM => "Drop Item", + MC_CONTAINER_OPEN => "Open Container", + MC_CONTAINER_CLOSE => "Close Container", + MC_CONTAINER_SET_SLOT => "Set Container Slot", + + MC_CLIENT_MESSAGE => "Client Message", + MC_SIGN_UPDATE => "Sign Update", + MC_ADVENTURE_SETTINGS => "Adventure Settings", + ); + + public static $packetName = array( + 0x02 => "ID_UNCONNECTED_PING_OPEN_CONNECTIONS", //RakNet + 0x05 => "ID_OPEN_CONNECTION_REQUEST_1", //RakNet + 0x06 => "ID_OPEN_CONNECTION_REPLY_1", //RakNet + 0x07 => "ID_OPEN_CONNECTION_REQUEST_2", //RakNet + 0x08 => "ID_OPEN_CONNECTION_REPLY_2", //RakNet + 0x1a => "ID_INCOMPATIBLE_PROTOCOL_VERSION", //RakNet + 0x1c => "ID_UNCONNECTED_PONG", //RakNet + 0x1d => "ID_ADVERTISE_SYSTEM", //RakNet + 0x80 => "Custom Packet", //Minecraft Implementation + 0x84 => "Custom Packet", //Minecraft Implementation + 0x88 => "Custom Packet", //Minecraft Implementation + 0x8c => "Custom Packet", //Minecraft Implementation + 0xa0 => "NACK", //Minecraft Implementation + 0xc0 => "ACK", //Minecraft Implementation + ); + + public static $raknet = array( + 0x02 => array( + "long", //Ping ID + "magic", + ), + + 0x05 => array( + "magic", + "byte", //Protocol Version + "special1", //MTU Size Null Lenght + ), + + 0x06 => array( + "magic", + "long", //Server GUID + "byte", //Server Security + "short", //MTU Size + ), + + 0x07 => array( + "magic", + 5, //Security Cookie (idk why it's sent here) + "short", //Server UDP Port + "short", //MTU Size + "long", //Client GUID + ), + + 0x08 => array( + "magic", + "long", //Server GUID + "short", //Client UDP Port + "short", //MTU Size + "byte", //Security + ), + + 0x1a => array( + "byte", //Server Version + "magic", + "long", //Server GUID + ), + + 0x1c => array( + "long", //Ping ID + "long", //Server GUID + "magic", + "string", //Data + ), + + 0x1d => array( + "long", //Ping ID + "long", //Server GUID + "magic", + "string", //Data + ), + + 0x80 => array( + "itriad", + "ubyte", + "customData", + ), + + + 0x81 => array( + "itriad", + "ubyte", + "customData", + ), + + 0x82 => array( + "itriad", + "ubyte", + "customData", + ), + + 0x83 => array( + "itriad", + "ubyte", + "customData", + ), + + 0x84 => array( + "itriad", + "ubyte", + "customData", + ), + + 0x85 => array( + "itriad", + "ubyte", + "customData", + ), + + 0x86 => array( + "itriad", + "ubyte", + "customData", + ), + + 0x87 => array( + "itriad", + "ubyte", + "customData", + ), + + 0x88 => array( + "itriad", + "ubyte", + "customData", + ), + + 0x89 => array( + "itriad", + "ubyte", + "customData", + ), + + 0x8a => array( + "itriad", + "ubyte", + "customData", + ), + + 0x8b => array( + "itriad", + "ubyte", + "customData", + ), + + 0x8c => array( + "itriad", + "ubyte", + "customData", + ), + + 0x8d => array( + "itriad", + "ubyte", + "customData", + ), + + 0x8e => array( + "itriad", + "ubyte", + "customData", + ), + + 0x8f => array( + "itriad", + "ubyte", + "customData", + ), + + + + 0xa0 => array( + "short", + "bool", + "itriad", + "special1", + ), + + 0xc0 => array( + "short", + "bool", + "itriad", + "special1", + ), + + ); + +} \ No newline at end of file diff --git a/src/common/config.php b/src/config.php similarity index 96% rename from src/common/config.php rename to src/config.php index bf8c1ac2c..4ad5b081b 100644 --- a/src/common/config.php +++ b/src/config.php @@ -32,7 +32,7 @@ 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__)."/../../"); +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("LOG", true); diff --git a/src/common/dependencies.php b/src/dependencies.php similarity index 98% rename from src/common/dependencies.php rename to src/dependencies.php index 740da1292..7b7c3e820 100644 --- a/src/common/dependencies.php +++ b/src/dependencies.php @@ -26,7 +26,7 @@ the Free Software Foundation, either version 3 of the License, or */ require_once(dirname(__FILE__)."/config.php"); -require_once("common/functions.php"); +require_once(dirname(__FILE__)."/functions.php"); if(strpos(strtoupper(php_uname("s")), "WIN") === false or arg("enable-ansi", false) === true){ define("ENABLE_ANSI", true); }else{ diff --git a/src/common/functions.php b/src/functions.php similarity index 100% rename from src/common/functions.php rename to src/functions.php diff --git a/src/protocol/RakNet.php b/src/protocol/RakNet.php deleted file mode 100644 index b1e66d9bf..000000000 --- a/src/protocol/RakNet.php +++ /dev/null @@ -1,196 +0,0 @@ - array( - "long", //Ping ID - "magic", - ), - - 0x05 => array( - "magic", - "byte", //Protocol Version - "special1", //MTU Size Null Lenght - ), - - 0x06 => array( - "magic", - "long", //Server GUID - "byte", //Server Security - "short", //MTU Size - ), - - 0x07 => array( - "magic", - 5, //Security Cookie (idk why it's sent here) - "short", //Server UDP Port - "short", //MTU Size - "long", //Client GUID - ), - - 0x08 => array( - "magic", - "long", //Server GUID - "short", //Client UDP Port - "short", //MTU Size - "byte", //Security - ), - - 0x1a => array( - "byte", //Server Version - "magic", - "long", //Server GUID - ), - - 0x1c => array( - "long", //Ping ID - "long", //Server GUID - "magic", - "string", //Data - ), - - 0x1d => array( - "long", //Ping ID - "long", //Server GUID - "magic", - "string", //Data - ), - - 0x80 => array( - "itriad", - "ubyte", - "customData", - ), - - - 0x81 => array( - "itriad", - "ubyte", - "customData", - ), - - 0x82 => array( - "itriad", - "ubyte", - "customData", - ), - - 0x83 => array( - "itriad", - "ubyte", - "customData", - ), - - 0x84 => array( - "itriad", - "ubyte", - "customData", - ), - - 0x85 => array( - "itriad", - "ubyte", - "customData", - ), - - 0x86 => array( - "itriad", - "ubyte", - "customData", - ), - - 0x87 => array( - "itriad", - "ubyte", - "customData", - ), - - 0x88 => array( - "itriad", - "ubyte", - "customData", - ), - - 0x89 => array( - "itriad", - "ubyte", - "customData", - ), - - 0x8a => array( - "itriad", - "ubyte", - "customData", - ), - - 0x8b => array( - "itriad", - "ubyte", - "customData", - ), - - 0x8c => array( - "itriad", - "ubyte", - "customData", - ), - - 0x8d => array( - "itriad", - "ubyte", - "customData", - ), - - 0x8e => array( - "itriad", - "ubyte", - "customData", - ), - - 0x8f => array( - "itriad", - "ubyte", - "customData", - ), - - - - 0xa0 => array( - "short", - "bool", - "itriad", - "special1", - ), - - 0xc0 => array( - "short", - "bool", - "itriad", - "special1", - ), - -); \ No newline at end of file diff --git a/src/protocol/current.php b/src/protocol/current.php deleted file mode 100644 index 547a67787..000000000 --- a/src/protocol/current.php +++ /dev/null @@ -1,89 +0,0 @@ - "Keep Alive", - - MC_CLIENT_CONNECT => "Client Connect", - MC_SERVER_HANDSHAKE => "Server Handshake", - - MC_CLIENT_HANDSHAKE => "Client Handshake", - - MC_DISCONNECT => "Disconnect", - - 0x18 => "Unknown", - - MC_LOGIN => "Login", - MC_LOGIN_STATUS => "Login Status", - MC_READY => "Ready", - MC_CHAT => "Chat", - MC_SET_TIME => "Set Time", - MC_START_GAME => "Start Game", - - MC_ADD_MOB => "Add Mob", - MC_ADD_PLAYER => "Add Player", - - MC_ADD_ENTITY => "Add Entity", - MC_REMOVE_ENTITY => "Remove Entity", - MC_ADD_ITEM_ENTITY => "Add Item", - MC_TAKE_ITEM_ENTITY => "Take Item", - - MC_MOVE_ENTITY => "Move Entity", - - MC_MOVE_ENTITY_POSROT => "Move Entity PosRot", - MC_MOVE_PLAYER => "Move Player", - MC_PLACE_BLOCK => "Place Block", - MC_REMOVE_BLOCK => "Remove Block", - MC_UPDATE_BLOCK => "Update Block", - MC_ADD_PAINTING => "Add Painting", - MC_EXPLOSION => "Explosion", - - MC_LEVEL_EVENT => "Level Event", - - MC_ENTITY_EVENT => "Entity Event", - MC_REQUEST_CHUNK => "Chunk Request", - MC_CHUNK_DATA => "Chunk Data", - - MC_PLAYER_EQUIPMENT => "Player Equipment", - MC_PLAYER_ARMOR_EQUIPMENT => "Player Armor", - MC_INTERACT => "Interact", - MC_USE_ITEM => "Use Item", - MC_PLAYER_ACTION => "Player Action", - MC_SET_ENTITY_DATA => "Entity Data", - MC_SET_ENTITY_MOTION => "Entity Motion", - MC_HURT_ARMOR => "Hurt Armor", - MC_SET_HEALTH => "Set Health", - MC_SET_SPAWN_POSITION => "Set Spawn Position", - MC_ANIMATE => "Animate", - MC_RESPAWN => "Respawn", - MC_SEND_INVENTORY => "Send Inventory", - MC_DROP_ITEM => "Drop Item", - MC_CONTAINER_OPEN => "Open Container", - MC_CONTAINER_CLOSE => "Close Container", - MC_CONTAINER_SET_SLOT => "Set Container Slot", - - MC_CLIENT_MESSAGE => "Client Message", - MC_SIGN_UPDATE => "Sign Update", - MC_ADVENTURE_SETTINGS => "Adventure Settings", -); \ No newline at end of file diff --git a/src/protocol/packetName.php b/src/protocol/packetName.php deleted file mode 100644 index c556aa138..000000000 --- a/src/protocol/packetName.php +++ /dev/null @@ -1,43 +0,0 @@ - "ID_UNCONNECTED_PING_OPEN_CONNECTIONS", //RakNet - 0x05 => "ID_OPEN_CONNECTION_REQUEST_1", //RakNet - 0x06 => "ID_OPEN_CONNECTION_REPLY_1", //RakNet - 0x07 => "ID_OPEN_CONNECTION_REQUEST_2", //RakNet - 0x08 => "ID_OPEN_CONNECTION_REPLY_2", //RakNet - 0x1a => "ID_INCOMPATIBLE_PROTOCOL_VERSION", //RakNet - 0x1c => "ID_UNCONNECTED_PONG", //RakNet - 0x1d => "ID_ADVERTISE_SYSTEM", //RakNet - 0x80 => "Custom Packet", //Minecraft Implementation - 0x84 => "Custom Packet", //Minecraft Implementation - 0x88 => "Custom Packet", //Minecraft Implementation - 0x8c => "Custom Packet", //Minecraft Implementation - 0xa0 => "NACK", //Minecraft Implementation - 0xc0 => "ACK", //Minecraft Implementation -); \ No newline at end of file