From 415c9f16f4c754edb7fd35937468a91e18282657 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 6 Feb 2014 22:49:13 +0100 Subject: [PATCH] wow. much packet. many code. such classes --- src/network/MinecraftInterface.php | 40 +- src/network/protocol/CustomPacketHandler.php | 876 ------------------ src/network/protocol/DataPacket.php | 115 --- src/network/protocol/ProtocolInfo.php | 188 ++-- .../protocol/packet/AddEntityPacket.php | 56 ++ .../protocol/packet/AddItemEntityPacket.php | 52 ++ src/network/protocol/packet/AddMobPacket.php | 52 ++ .../protocol/packet/AddPaintingPacket.php | 48 + .../protocol/packet/AddPlayerPacket.php | 58 ++ .../packet/AdventureSettingsPacket.php | 37 + src/network/protocol/packet/AnimatePacket.php | 41 + src/network/protocol/packet/ChatPacket.php | 37 + .../protocol/packet/ChunkDataPacket.php | 42 + .../protocol/packet/ClientConnectPacket.php | 41 + .../protocol/packet/ClientHandshakePacket.php | 51 + .../protocol/packet/ContainerClosePacket.php | 38 + .../protocol/packet/ContainerOpenPacket.php | 48 + .../packet/ContainerSetContentPacket.php | 59 ++ .../packet/ContainerSetDataPacket.php | 41 + .../packet/ContainerSetSlotPacket.php | 43 + .../protocol/packet/DisconnectPacket.php | 35 + .../protocol/packet/DropItemPacket.php | 41 + .../protocol/packet/EntityDataPacket.php | 46 + .../protocol/packet/EntityEventPacket.php | 41 + .../protocol/packet/ExplosionPacket.php | 53 ++ .../protocol/packet/HurtArmorPacket.php | 38 + .../protocol/packet/InteractPacket.php | 44 + .../protocol/packet/LevelEventPacket.php | 46 + src/network/protocol/packet/LoginPacket.php | 45 + .../protocol/packet/LoginStatusPacket.php | 38 + src/network/protocol/packet/MessagePacket.php | 41 + .../protocol/packet/MoveEntityPacket.php | 36 + .../packet/MoveEntityPacket_PosRot.php | 48 + .../protocol/packet/MovePlayerPacket.php | 56 ++ src/network/protocol/packet/PingPacket.php | 38 + .../protocol/packet/PlayerActionPacket.php | 47 + .../packet/PlayerArmorEquipmentPacket.php | 47 + .../protocol/packet/PlayerEquipmentPacket.php | 46 + src/network/protocol/packet/PongPacket.php | 41 + src/network/protocol/packet/ReadyPacket.php | 37 + .../protocol/packet/RemoveBlockPacket.php | 43 + .../protocol/packet/RemoveEntityPacket.php | 38 + .../protocol/packet/RemovePlayerPacket.php | 40 + .../protocol/packet/RequestChunkPacket.php | 39 + src/network/protocol/packet/RespawnPacket.php | 47 + .../protocol/packet/RotateHeadPacket.php | 40 + .../protocol/packet/SendInventoryPacket.php | 61 ++ .../protocol/packet/ServerHandshakePacket.php | 57 ++ .../protocol/packet/SetEntityDataPacket.php | 40 + .../protocol/packet/SetEntityMotionPacket.php | 44 + .../protocol/packet/SetHealthPacket.php | 38 + .../packet/SetSpawnPositionPacket.php | 41 + src/network/protocol/packet/SetTimePacket.php | 40 + .../protocol/packet/StartGamePacket.php | 50 + .../protocol/packet/TakeItemEntity.php | 40 + .../protocol/packet/TileEventPacket.php | 46 + src/network/protocol/packet/UnknownPacket.php | 37 + .../protocol/packet/UpdateBlockPacket.php | 45 + src/network/protocol/packet/UseItemPacket.php | 61 ++ src/network/raknet/Packet.php | 343 ------- src/network/raknet/RakNetDataPacket.php | 161 ++++ src/network/raknet/RakNetInfo.php | 159 ---- src/network/raknet/RakNetParser.php | 122 +-- 63 files changed, 2829 insertions(+), 1630 deletions(-) delete mode 100644 src/network/protocol/CustomPacketHandler.php delete mode 100644 src/network/protocol/DataPacket.php create mode 100644 src/network/protocol/packet/AddEntityPacket.php create mode 100644 src/network/protocol/packet/AddItemEntityPacket.php create mode 100644 src/network/protocol/packet/AddMobPacket.php create mode 100644 src/network/protocol/packet/AddPaintingPacket.php create mode 100644 src/network/protocol/packet/AddPlayerPacket.php create mode 100644 src/network/protocol/packet/AdventureSettingsPacket.php create mode 100644 src/network/protocol/packet/AnimatePacket.php create mode 100644 src/network/protocol/packet/ChatPacket.php create mode 100644 src/network/protocol/packet/ChunkDataPacket.php create mode 100644 src/network/protocol/packet/ClientConnectPacket.php create mode 100644 src/network/protocol/packet/ClientHandshakePacket.php create mode 100644 src/network/protocol/packet/ContainerClosePacket.php create mode 100644 src/network/protocol/packet/ContainerOpenPacket.php create mode 100644 src/network/protocol/packet/ContainerSetContentPacket.php create mode 100644 src/network/protocol/packet/ContainerSetDataPacket.php create mode 100644 src/network/protocol/packet/ContainerSetSlotPacket.php create mode 100644 src/network/protocol/packet/DisconnectPacket.php create mode 100644 src/network/protocol/packet/DropItemPacket.php create mode 100644 src/network/protocol/packet/EntityDataPacket.php create mode 100644 src/network/protocol/packet/EntityEventPacket.php create mode 100644 src/network/protocol/packet/ExplosionPacket.php create mode 100644 src/network/protocol/packet/HurtArmorPacket.php create mode 100644 src/network/protocol/packet/InteractPacket.php create mode 100644 src/network/protocol/packet/LevelEventPacket.php create mode 100644 src/network/protocol/packet/LoginPacket.php create mode 100644 src/network/protocol/packet/LoginStatusPacket.php create mode 100644 src/network/protocol/packet/MessagePacket.php create mode 100644 src/network/protocol/packet/MoveEntityPacket.php create mode 100644 src/network/protocol/packet/MoveEntityPacket_PosRot.php create mode 100644 src/network/protocol/packet/MovePlayerPacket.php create mode 100644 src/network/protocol/packet/PingPacket.php create mode 100644 src/network/protocol/packet/PlayerActionPacket.php create mode 100644 src/network/protocol/packet/PlayerArmorEquipmentPacket.php create mode 100644 src/network/protocol/packet/PlayerEquipmentPacket.php create mode 100644 src/network/protocol/packet/PongPacket.php create mode 100644 src/network/protocol/packet/ReadyPacket.php create mode 100644 src/network/protocol/packet/RemoveBlockPacket.php create mode 100644 src/network/protocol/packet/RemoveEntityPacket.php create mode 100644 src/network/protocol/packet/RemovePlayerPacket.php create mode 100644 src/network/protocol/packet/RequestChunkPacket.php create mode 100644 src/network/protocol/packet/RespawnPacket.php create mode 100644 src/network/protocol/packet/RotateHeadPacket.php create mode 100644 src/network/protocol/packet/SendInventoryPacket.php create mode 100644 src/network/protocol/packet/ServerHandshakePacket.php create mode 100644 src/network/protocol/packet/SetEntityDataPacket.php create mode 100644 src/network/protocol/packet/SetEntityMotionPacket.php create mode 100644 src/network/protocol/packet/SetHealthPacket.php create mode 100644 src/network/protocol/packet/SetSpawnPositionPacket.php create mode 100644 src/network/protocol/packet/SetTimePacket.php create mode 100644 src/network/protocol/packet/StartGamePacket.php create mode 100644 src/network/protocol/packet/TakeItemEntity.php create mode 100644 src/network/protocol/packet/TileEventPacket.php create mode 100644 src/network/protocol/packet/UnknownPacket.php create mode 100644 src/network/protocol/packet/UpdateBlockPacket.php create mode 100644 src/network/protocol/packet/UseItemPacket.php delete mode 100644 src/network/raknet/Packet.php create mode 100644 src/network/raknet/RakNetDataPacket.php diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index 9eb7be6b9..efa28e8f0 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -23,36 +23,23 @@ class MinecraftInterface{ public $client; public $bandwidth; private $socket; - private $data; - private $chunked; - private $toChunk; - private $needCheck; + private $packets; function __construct($object, $server, $port = 25565, $listen = false, $client = false, $serverip = "0.0.0.0"){ $this->socket = new UDPSocket($server, $port, (bool) $listen, $serverip); if($this->socket->connected === false){ - console("[ERROR] Couldn't bind to $serverip:".$port, true, true, 0); + console("[SEVERE] Couldn't bind to $serverip:".$port, true, true, 0); exit(1); } $this->bandwidth = array(0, 0, microtime(true)); $this->client = (bool) $client; $this->start = microtime(true); - $this->chunked = array(); - $this->toChunk = array(); - $this->needCheck = array(); - $object->schedule(1, array($this, "checkChunked"), array(), true); + $this->packets = array(); } public function close(){ return $this->socket->close(false); } - protected function getStruct($pid){ - if(isset(Protocol::$raknet[$pid])){ - return Protocol::$raknet[$pid]; - } - return false; - } - public function readPacket(){ $pk = $this->popPacket(); if($this->socket->connected === false){ @@ -73,9 +60,15 @@ class MinecraftInterface{ private function parsePacket($buffer, $source, $port){ $pid = ord($buffer{0}); if(RakNetInfo::isValid($pid)){ - $packet = new RakNetParser($buffer); - @$packet->parse(); - $this->data[] = array($pid, $packet->data, $buffer, $source, $port); + $parser = new RakNetParser($buffer); + if($parser->packet !== false){ + $this->packets[] = array( + "pid" => $pid, + "packet" => $packet, + "ip" => $source, + "port" => $port + ); + } }else{ if(ServerAPI::request()->api->dhandle("server.unknownpacket", array( "pid" => $pid, @@ -92,11 +85,10 @@ class MinecraftInterface{ } public function popPacket(){ - if(count($this->data) > 0){ - $p = each($this->data); - unset($this->data[$p[0]]); - $p = $p[1]; - return array("pid" => $p[0], "data" => $p[1], "raw" => $p[2], "ip" => $p[3], "port" => $p[4]); + if(count($this->packets) > 0){ + $p = each($this->packets); + unset($this->packets[$p[0]]); + return $p[1]; } return false; } diff --git a/src/network/protocol/CustomPacketHandler.php b/src/network/protocol/CustomPacketHandler.php deleted file mode 100644 index 9bd9d9678..000000000 --- a/src/network/protocol/CustomPacketHandler.php +++ /dev/null @@ -1,876 +0,0 @@ -raw, $this->offset); - if($check === true){ - $this->offset = strlen($this->raw); - } - return $data; - } - $data = substr($this->raw, $this->offset, $len); - if($check === true){ - $this->offset += $len; - } - return $data; - } - - private function feof(){ - return !isset($this->raw{$this->offset}); - } - - public function __construct($pid, $raw = "", $data = array(), $create = false){ - $this->raw = $raw; - $this->data = $data; - $this->offset = 0; - $this->c = (bool) $create; - if($pid === false){ - return; - } - switch($pid){ - case MC_PING: - if($this->c === false){ - $this->data["time"] = Utils::readLong($this->get(8)); - }else{ - $this->raw .= Utils::writeLong($this->data["time"]); - } - break; - case MC_PONG: - if($this->c === false){ - $this->data["ptime"] = Utils::readLong($this->get(8)); - $this->data["time"] = Utils::readLong($this->get(8)); - }else{ - $this->raw .= Utils::writeLong($this->data["ptime"]); - $this->raw .= Utils::writeLong($this->data["time"]); - } - break; - case MC_CLIENT_CONNECT: - if($this->c === false){ - $this->data["clientID"] = Utils::readLong($this->get(8)); - $this->data["session"] = Utils::readLong($this->get(8)); - $this->data["unknown2"] = $this->get(1); - }else{ - $this->raw .= Utils::writeLong($this->data["clientID"]); - $this->raw .= Utils::writeLong($this->data["session"]); - $this->raw .= "\x00"; - } - break; - case MC_SERVER_HANDSHAKE: - if($this->c === false){ - $this->data["cookie"] = $this->get(4); // 043f57fe - $this->data["security"] = $this->get(1); - $this->data["port"] = Utils::readShort($this->get(2), false); - $this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 10, $offset); - $this->get($offset); - $this->data["timestamp"] = $this->get(2); - $this->data["session"] = Utils::readLong($this->get(8)); - $this->data["session2"] = Utils::readLong($this->get(8)); - }else{ - $this->raw .= "\x04\x3f\x57\xfe"; - $this->raw .= "\xcd"; - $this->raw .= Utils::writeShort($this->data["port"]); - $this->raw .= Utils::writeDataArray(array( - "\xf5\xff\xff\xf5", - "\xff\xff\xff\xff", - "\xff\xff\xff\xff", - "\xff\xff\xff\xff", - "\xff\xff\xff\xff", - "\xff\xff\xff\xff", - "\xff\xff\xff\xff", - "\xff\xff\xff\xff", - "\xff\xff\xff\xff", - "\xff\xff\xff\xff", - )); - $this->raw .= "\x00\x00"; - $this->raw .= Utils::writeLong($this->data["session"]); - $this->raw .= Utils::writeLong($this->data["session2"]); - } - break; - case MC_CLIENT_HANDSHAKE: - if($this->c === false){ - $this->data["cookie"] = $this->get(4); // 043f57fe - $this->data["security"] = $this->get(1); - $this->data["port"] = Utils::readShort($this->get(2), false); - $this->data["dataArray0"] = $this->get(ord($this->get(1))); - $this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 9, $offset); - $this->get($offset); - $this->data["timestamp"] = $this->get(2); - $this->data["session2"] = Utils::readLong($this->get(8)); - $this->data["session"] = Utils::readLong($this->get(8)); - }else{ - $this->raw .= "\x04\x3f\x57\xfe"; - $this->raw .= "\xed"; - $this->raw .= Utils::writeShort($this->data["port"]); - $w = array_shift($this->data["dataArray"]); - $this->raw .= chr(strlen($w)).$w; - $this->raw .= Utils::writeDataArray($this->data["dataArray"]); - $this->raw .= "\x00\x00"; - $this->raw .= Utils::writeLong($this->data["session2"]); - $this->raw .= Utils::writeLong($this->data["session"]); - } - break; - case MC_SERVER_FULL: - if($this->c === false){ - }else{ - $this->raw .= RAKNET_MAGIC; - $this->raw .= Utils::writeLong($this->data["serverID"]); - } - break; - case MC_DISCONNECT: - //null - break; - case MC_BANNED: - if($this->c === false){ - }else{ - $this->raw .= RAKNET_MAGIC; - $this->raw .= Utils::writeLong($this->data["serverID"]); - } - break; - case MC_LOGIN: - if($this->c === false){ - $this->data["username"] = $this->get(Utils::readShort($this->get(2), false)); - $this->data["protocol1"] = Utils::readInt($this->get(4)); - $this->data["protocol2"] = Utils::readInt($this->get(4)); - $this->data["clientId"] = Utils::readInt($this->get(4)); - $this->data["realms_data"] = $this->get(Utils::readShort($this->get(2), false)); - }else{ - $this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"]; - $this->raw .= Utils::writeInt(CURRENT_PROTOCOL). - Utils::writeInt(CURRENT_PROTOCOL). - Utils::writeInt($this->data["clientId"]); - $this->raw .= Utils::writeShort(strlen($this->data["realms_data"])).$this->data["realms_data"]; - } - break; - case MC_LOGIN_STATUS: - if($this->c === false){ - $this->data["status"] = Utils::readInt($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["status"]); - } - break; - case MC_READY: - if($this->c === false){ - $this->data["status"] = ord($this->get(1)); - }else{ - $this->raw .= chr($this->data["status"]); - } - break; - case MC_CHAT: - if($this->c === false){ - $this->data["player"] = $this->get(Utils::readShort($this->get(2), false)); - $this->data["message"] = $this->get(Utils::readShort($this->get(2), false)); - }else{ - $this->raw .= Utils::writeShort(strlen($this->data["player"])).$this->data["player"]; - $this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"]; - } - break; - case MC_SET_TIME: - if($this->c === false){ - $this->data["time"] = Utils::readInt($this->get(4)); - $this->data["started"] = ord($this->get(1)) & 0x80 > 0; - }else{ - $this->raw .= Utils::writeInt($this->data["time"])."\x80"; - $this->raw .= chr((isset($this->data["started"]) and $this->data["started"] == true) ? 0x80:0x00); - } - break; - case MC_START_GAME: - if($this->c === false){ - $this->data["seed"] = Utils::readInt($this->get(4)); - $this->data["generator"] = Utils::readInt($this->get(4)); - $this->data["gamemode"] = Utils::readInt($this->get(4)); - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readFloat($this->get(4)); - $this->data["y"] = Utils::readFloat($this->get(4)); - $this->data["z"] = Utils::readFloat($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["seed"]); - $this->raw .= Utils::writeInt($this->data["generator"]); - $this->raw .= Utils::writeInt($this->data["gamemode"]); - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeFloat($this->data["x"]); - $this->raw .= Utils::writeFloat($this->data["y"]); - $this->raw .= Utils::writeFloat($this->data["z"]); - } - break; - case MC_ADD_MOB: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["type"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readFloat($this->get(4)); - $this->data["y"] = Utils::readFloat($this->get(4)); - $this->data["z"] = Utils::readFloat($this->get(4)); - $this->data["pitch"] = Utils::readByte($this->get(1)); - $this->data["yaw"] = Utils::readByte($this->get(1)); - $this->data["metadata"] = Utils::readMetadata($this->get(true)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeInt($this->data["type"]); - $this->raw .= Utils::writeFloat($this->data["x"]); - $this->raw .= Utils::writeFloat($this->data["y"]); - $this->raw .= Utils::writeFloat($this->data["z"]); - $this->raw .= Utils::writeByte($this->data["pitch"]); - $this->raw .= Utils::writeByte($this->data["yaw"]); - $this->raw .= Utils::writeMetadata($this->data["metadata"]); - } - break; - case MC_ADD_PLAYER: - if($this->c === false){ - $this->data["clientID"] = Utils::readLong($this->get(8)); - $this->data["username"] = $this->get(Utils::readShort($this->get(2), false)); - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readFloat($this->get(4)); - $this->data["y"] = Utils::readFloat($this->get(4)); - $this->data["z"] = Utils::readFloat($this->get(4)); - $this->data["pitch"] = Utils::readByte($this->get(1)); - $this->data["yaw"] = Utils::readByte($this->get(1)); - $this->data["unknown1"] = Utils::readShort($this->get(2)); - $this->data["unknown2"] = Utils::readShort($this->get(2)); - $this->data["metadata"] = Utils::readMetadata($this->get(true)); - }else{ - $this->raw .= Utils::writeLong($this->data["clientID"]); - $this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"]; - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeFloat($this->data["x"]); - $this->raw .= Utils::writeFloat($this->data["y"]); - $this->raw .= Utils::writeFloat($this->data["z"]); - $this->raw .= Utils::writeByte($this->data["pitch"]); - $this->raw .= Utils::writeByte($this->data["yaw"]); - $this->raw .= Utils::writeShort($this->data["unknown1"]); - $this->raw .= Utils::writeShort($this->data["unknown2"]); - $this->raw .= Utils::writeMetadata($this->data["metadata"]); - } - break; - case MC_REMOVE_PLAYER: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["clientID"] = Utils::readLong($this->get(8)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeLong($this->data["clientID"]); - } - break; - case MC_ADD_ENTITY: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["type"] = ord($this->get(1)); - $this->data["x"] = Utils::readFloat($this->get(4)); - $this->data["y"] = Utils::readFloat($this->get(4)); - $this->data["z"] = Utils::readFloat($this->get(4)); - $this->data["did"] = Utils::readInt($this->get(4)); - if($this->data["did"] > 0){ - $this->data["speedX"] = Utils::readShort($this->get(2)); - $this->data["speedY"] = Utils::readShort($this->get(2)); - $this->data["speedZ"] = Utils::readShort($this->get(2)); - } - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= chr($this->data["type"]); - $this->raw .= Utils::writeFloat($this->data["x"]); - $this->raw .= Utils::writeFloat($this->data["y"]); - $this->raw .= Utils::writeFloat($this->data["z"]); - $this->raw .= Utils::writeInt($this->data["did"]); - if($this->data["did"] > 0){ - $this->raw .= Utils::writeShort($this->data["speedX"]); - $this->raw .= Utils::writeShort($this->data["speedY"]); - $this->raw .= Utils::writeShort($this->data["speedZ"]); - } - } - break; - case MC_REMOVE_ENTITY: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - } - break; - case MC_ADD_ITEM_ENTITY: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["block"] = Utils::readShort($this->get(2), false); - $this->data["stack"] = ord($this->get(1)); - $this->data["meta"] = Utils::readShort($this->get(2), false); - $this->data["x"] = Utils::readFloat($this->get(4)); - $this->data["y"] = Utils::readFloat($this->get(4)); - $this->data["z"] = Utils::readFloat($this->get(4)); - $this->data["yaw"] = Utils::readByte($this->get(1)); - $this->data["pitch"] = Utils::readByte($this->get(1)); - $this->data["roll"] = Utils::readByte($this->get(1)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeShort($this->data["block"]); - $this->raw .= chr($this->data["stack"]); - $this->raw .= Utils::writeShort($this->data["meta"]); - $this->raw .= Utils::writeFloat($this->data["x"]); - $this->raw .= Utils::writeFloat($this->data["y"]); - $this->raw .= Utils::writeFloat($this->data["z"]); - $this->raw .= Utils::writeByte($this->data["yaw"]); - $this->raw .= Utils::writeByte($this->data["pitch"]); - $this->raw .= Utils::writeByte($this->data["roll"]); - } - break; - case MC_TAKE_ITEM_ENTITY: - if($this->c === false){ - $this->data["target"] = Utils::readInt($this->get(4)); - $this->data["eid"] = Utils::readInt($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["target"]); - $this->raw .= Utils::writeInt($this->data["eid"]); - } - break; - case MC_MOVE_ENTITY: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readFloat($this->get(4)); - $this->data["y"] = Utils::readFloat($this->get(4)); - $this->data["z"] = Utils::readFloat($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeFloat($this->data["x"]); - $this->raw .= Utils::writeFloat($this->data["y"]); - $this->raw .= Utils::writeFloat($this->data["z"]); - } - break; - case MC_MOVE_ENTITY_POSROT: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readFloat($this->get(4)); - $this->data["y"] = Utils::readFloat($this->get(4)); - $this->data["z"] = Utils::readFloat($this->get(4)); - $this->data["yaw"] = Utils::readFloat($this->get(4)); - $this->data["pitch"] = Utils::readFloat($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeFloat($this->data["x"]); - $this->raw .= Utils::writeFloat($this->data["y"]); - $this->raw .= Utils::writeFloat($this->data["z"]); - $this->raw .= Utils::writeFloat($this->data["yaw"]); - $this->raw .= Utils::writeFloat($this->data["pitch"]); - } - break; - case MC_ROTATE_HEAD: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["yaw"] = Utils::readFloat($this->get(4)); - $this->data["pitch"] = Utils::readFloat($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeFloat($this->data["yaw"]); - $this->raw .= Utils::writeFloat($this->data["pitch"]); - } - break; - case MC_MOVE_PLAYER: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readFloat($this->get(4)); - $this->data["y"] = Utils::readFloat($this->get(4)); - $this->data["z"] = Utils::readFloat($this->get(4)); - $this->data["yaw"] = Utils::readFloat($this->get(4)); - $this->data["pitch"] = Utils::readFloat($this->get(4)); - $this->data["bodyYaw"] = Utils::readFloat($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeFloat($this->data["x"]); - $this->raw .= Utils::writeFloat($this->data["y"]); - $this->raw .= Utils::writeFloat($this->data["z"]); - $this->raw .= Utils::writeFloat($this->data["yaw"]); - $this->raw .= Utils::writeFloat($this->data["pitch"]); - $this->raw .= Utils::writeFloat($this->data["bodyYaw"]); - } - break; - case MC_PLACE_BLOCK: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["z"] = Utils::readInt($this->get(4)); - $this->data["y"] = ord($this->get(1)); - $this->data["block"] = ord($this->get(1)); - $this->data["meta"] = ord($this->get(1)); - $this->data["face"] = Utils::readByte($this->get(1)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["z"]); - $this->raw .= chr($this->data["y"]); - $this->raw .= chr($this->data["block"]); - $this->raw .= chr($this->data["meta"]); - $this->raw .= chr($this->data["face"]); - } - break; - case MC_REMOVE_BLOCK: //Sent when a player removes a block, not used - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["z"] = Utils::readInt($this->get(4)); - $this->data["y"] = ord($this->get(1)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["z"]); - $this->raw .= chr($this->data["y"]); - } - break; - case MC_UPDATE_BLOCK: - if($this->c === false){ - $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["z"] = Utils::readInt($this->get(4)); - $this->data["y"] = ord($this->get(1)); - $this->data["block"] = ord($this->get(1)); - $this->data["meta"] = ord($this->get(1)); - }else{ - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["z"]); - $this->raw .= chr($this->data["y"]); - $this->raw .= chr($this->data["block"]); - $this->raw .= chr($this->data["meta"]); - } - break; - case MC_ADD_PAINTING: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["y"] = Utils::readInt($this->get(4)); - $this->data["z"] = Utils::readInt($this->get(4)); - $this->data["direction"] = Utils::readInt($this->get(4)); - $this->data["title"] = $this->get(Utils::readShort($this->get(2), false)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["y"]); - $this->raw .= Utils::writeInt($this->data["z"]); - $this->raw .= Utils::writeInt($this->data["direction"]); - $this->raw .= Utils::writeShort(strlen($this->data["title"])).$this->data["title"]; - } - break; - case MC_EXPLOSION: - if($this->c === false){ - $this->data["x"] = Utils::readFloat($this->get(4)); - $this->data["y"] = Utils::readFloat($this->get(4)); - $this->data["z"] = Utils::readFloat($this->get(4)); - $this->data["radius"] = Utils::readFloat($this->get(4)); - $this->data["count"] = Utils::readInt($this->get(4)); - $this->data["records"] = array(); - for($r = 0; $r < $this->data["count"] and !$this->feof(); ++$r){ - $this->data["records"][] = new Vector3(Utils::readByte($this->get(1)), Utils::readByte($this->get(1)), Utils::readByte($this->get(1))); - } - }else{ - $this->raw .= Utils::writeFloat($this->data["x"]); - $this->raw .= Utils::writeFloat($this->data["y"]); - $this->raw .= Utils::writeFloat($this->data["z"]); - $this->raw .= Utils::writeFloat($this->data["radius"]); - $this->data["records"] = (array) $this->data["records"]; - $this->raw .= Utils::writeInt(count($this->data["records"])); - if(count($this->data["records"]) > 0){ - foreach($this->data["records"] as $record){ - $this->raw .= Utils::writeByte($record->x) . Utils::writeByte($record->y) . Utils::writeByte($record->z); - } - } - } - break; - case MC_LEVEL_EVENT: - if($this->c === false){ - $this->data["evid"] = Utils::readShort($this->get(2)); - $this->data["x"] = Utils::readShort($this->get(2)); - $this->data["y"] = Utils::readShort($this->get(2)); - $this->data["z"] = Utils::readShort($this->get(2)); - $this->data["data"] = Utils::readInt($this->get(4)); - }else{ - $this->raw .= Utils::writeShort($this->data["evid"]); - $this->raw .= Utils::writeShort($this->data["x"]); - $this->raw .= Utils::writeShort($this->data["y"]); - $this->raw .= Utils::writeShort($this->data["z"]); - $this->raw .= Utils::writeInt($this->data["data"]); - } - break; - case MC_TILE_EVENT: - if($this->c === false){ - $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["y"] = Utils::readInt($this->get(4)); - $this->data["z"] = Utils::readInt($this->get(4)); - $this->data["case1"] = Utils::readInt($this->get(4)); - $this->data["case2"] = Utils::readInt($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["y"]); - $this->raw .= Utils::writeInt($this->data["z"]); - $this->raw .= Utils::writeInt($this->data["case1"]); - $this->raw .= Utils::writeInt($this->data["case2"]); - } - break; - case MC_ENTITY_EVENT: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["event"] = ord($this->get(1)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= chr($this->data["event"]); - } - break; - case MC_REQUEST_CHUNK: - if($this->c === false){ - $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["z"] = Utils::readInt($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["z"]); - } - break; - case MC_CHUNK_DATA: - if($this->c === false){ - $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["z"] = Utils::readInt($this->get(4)); - $this->data["data"] = $this->get(true); - }else{ - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["z"]); - $this->raw .= $this->data["data"]; - } - break; - case MC_PLAYER_EQUIPMENT: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["block"] = Utils::readShort($this->get(2), false); - $this->data["meta"] = Utils::readShort($this->get(2), false); - $this->data["slot"] = ord($this->get(1)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeShort($this->data["block"]); - $this->raw .= Utils::writeShort($this->data["meta"]); - $this->raw .= chr($this->data["slot"]); - } - break; - case MC_PLAYER_ARMOR_EQUIPMENT: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["slot0"] = ord($this->get(1)); - $this->data["slot1"] = ord($this->get(1)); - $this->data["slot2"] = ord($this->get(1)); - $this->data["slot3"] = ord($this->get(1)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= chr($this->data["slot0"]); - $this->raw .= chr($this->data["slot1"]); - $this->raw .= chr($this->data["slot2"]); - $this->raw .= chr($this->data["slot3"]); - } - break; - case MC_INTERACT: - if($this->c === false){ - $this->data["action"] = Utils::readByte($this->get(1)); - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["target"] = Utils::readInt($this->get(4)); - }else{ - $this->raw .= Utils::writeByte($this->data["action"]); - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeInt($this->data["target"]); - } - break; - case MC_USE_ITEM: - if($this->c === false){ - $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["y"] = Utils::readInt($this->get(4)); - $this->data["z"] = Utils::readInt($this->get(4)); - $this->data["face"] = Utils::readInt($this->get(4)); - $this->data["block"] = Utils::readShort($this->get(2)); - $this->data["meta"] = Utils::readByte($this->get(1)); - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["fx"] = Utils::readFloat($this->get(4)); - $this->data["fy"] = Utils::readFloat($this->get(4)); - $this->data["fz"] = Utils::readFloat($this->get(4)); - $this->data["posX"] = Utils::readFloat($this->get(4)); - $this->data["posY"] = Utils::readFloat($this->get(4)); - $this->data["posZ"] = Utils::readFloat($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["y"]); - $this->raw .= Utils::writeInt($this->data["z"]); - $this->raw .= Utils::writeInt($this->data["face"]); - $this->raw .= Utils::writeShort($this->data["block"]); - $this->raw .= Utils::writeByte($this->data["meta"]); - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeFloat($this->data["fx"]); - $this->raw .= Utils::writeFloat($this->data["fy"]); - $this->raw .= Utils::writeFloat($this->data["fz"]); - $this->raw .= Utils::writeFloat($this->data["posX"]); - $this->raw .= Utils::writeFloat($this->data["posY"]); - $this->raw .= Utils::writeFloat($this->data["posZ"]); - } - break; - case MC_PLAYER_ACTION: - if($this->c === false){ - $this->data["action"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["y"] = Utils::readInt($this->get(4)); - $this->data["z"] = Utils::readInt($this->get(4)); - $this->data["face"] = Utils::readInt($this->get(4)); - $this->data["eid"] = Utils::readInt($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["action"]); - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["y"]); - $this->raw .= Utils::writeInt($this->data["z"]); - $this->raw .= Utils::writeInt($this->data["face"]); - $this->raw .= Utils::writeInt($this->data["eid"]); - } - break; - case MC_SET_ENTITY_DATA: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["metadata"] = Utils::readMetadata($this->get(true)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeMetadata($this->data["metadata"]); - } - break; - case MC_SET_ENTITY_MOTION: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["speedX"] = Utils::readShort($this->get(2)); - $this->data["speedY"] = Utils::readShort($this->get(2)); - $this->data["speedZ"] = Utils::readShort($this->get(2)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeShort($this->data["speedX"]); - $this->raw .= Utils::writeShort($this->data["speedY"]); - $this->raw .= Utils::writeShort($this->data["speedZ"]); - } - break; - case MC_HURT_ARMOR: - if($this->c === false){ - $this->data["health"] = Utils::readByte($this->get(1)); - }else{ - $this->raw .= Utils::writeByte($this->data["health"]); - } - break; - case MC_SET_HEALTH: - if($this->c === false){ - $this->data["health"] = Utils::readByte($this->get(1)); - }else{ - $this->raw .= Utils::writeByte($this->data["health"]); - } - break; - case MC_SET_SPAWN_POSITION: - if($this->c === false){ - $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["z"] = Utils::readInt($this->get(4)); - $this->data["y"] = ord($this->get(1)); - }else{ - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["z"]); - $this->raw .= chr($this->data["y"]); - } - break; - case MC_ANIMATE: - if($this->c === false){ - $this->data["action"] = Utils::readByte($this->get(1)); - $this->data["eid"] = Utils::readInt($this->get(4)); - }else{ - $this->raw .= Utils::writeByte($this->data["action"]); - $this->raw .= Utils::writeInt($this->data["eid"]); - } - break; - case MC_RESPAWN: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["x"] = Utils::readFloat($this->get(4)); - $this->data["y"] = Utils::readFloat($this->get(4)); - $this->data["z"] = Utils::readFloat($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= Utils::writeFloat($this->data["x"]); - $this->raw .= Utils::writeFloat($this->data["y"]); - $this->raw .= Utils::writeFloat($this->data["z"]); - } - break; - case MC_SEND_INVENTORY: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["windowid"] = ord($this->get(1)); - $this->data["count"] = Utils::readShort($this->get(2), false); - $this->data["slots"] = array(); - for($s = 0; $s < $this->data["count"] and !$this->feof(); ++$s){ - $this->data["slots"][$s] = Utils::readSlot($this); - } - if($this->data["windowid"] === 1){ //Armor is also sent - $this->data["armor"] = array( - Utils::readSlot($this), - Utils::readSlot($this), - Utils::readSlot($this), - Utils::readSlot($this) - ); - } - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= chr($this->data["windowid"]); - $this->raw .= Utils::writeShort(count($this->data["slots"])); - foreach($this->data["slots"] as $slot){ - $this->raw .= Utils::writeSlot($slot); - } - if($this->data["windowid"] === 1 and isset($this->data["armor"])){ - $this->raw .= Utils::writeSlot($this->data["armor"][0]); - $this->raw .= Utils::writeSlot($this->data["armor"][1]); - $this->raw .= Utils::writeSlot($this->data["armor"][2]); - $this->raw .= Utils::writeSlot($this->data["armor"][3]); - } - } - break; - case MC_DROP_ITEM: - if($this->c === false){ - $this->data["eid"] = Utils::readInt($this->get(4)); - $this->data["unknown1"] = ord($this->get(1)); - $this->data["block"] = Utils::readShort($this->get(2), false); - $this->data["stack"] = ord($this->get(1)); - $this->data["meta"] = Utils::readShort($this->get(2), false); - }else{ - $this->raw .= Utils::writeInt($this->data["eid"]); - $this->raw .= chr($this->data["unknown1"]); - $this->raw .= Utils::writeShort($this->data["block"]); - $this->raw .= chr($this->data["stack"]); - $this->raw .= Utils::writeShort($this->data["meta"]); - } - break; - case MC_CONTAINER_OPEN: - if($this->c === false){ - $this->data["windowid"] = ord($this->get(1)); - $this->data["type"] = ord($this->get(1)); - $this->data["slots"] = ord($this->get(1)); - - //$this->data["title"] = $this->get(Utils::readShort($this->get(2), false)); - }else{ - $this->raw .= chr($this->data["windowid"]); - $this->raw .= chr($this->data["type"]); - $this->raw .= chr($this->data["slots"]); - $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["y"]); - $this->raw .= Utils::writeInt($this->data["z"]); - } - break; - case MC_CONTAINER_CLOSE: - if($this->c === false){ - $this->data["windowid"] = ord($this->get(1)); - }else{ - $this->raw .= chr($this->data["windowid"]); - } - break; - case MC_CONTAINER_SET_SLOT: - if($this->c === false){ - $this->data["windowid"] = ord($this->get(1)); - $this->data["slot"] = Utils::readShort($this->get(2), false); - $this->data["block"] = Utils::readShort($this->get(2), false); - $this->data["stack"] = ord($this->get(1)); - $this->data["meta"] = Utils::readShort($this->get(2), false); - }else{ - $this->raw .= chr($this->data["windowid"]); - $this->raw .= Utils::writeShort($this->data["slot"]); - $this->raw .= Utils::writeShort($this->data["block"]); - $this->raw .= chr($this->data["stack"]); - $this->raw .= Utils::writeShort($this->data["meta"]); - } - break; - case MC_CONTAINER_SET_CONTENT: - if($this->c === false){ - $this->data["windowid"] = ord($this->get(1)); - $this->data["count"] = Utils::readShort($this->get(2), false); - $this->data["slots"] = array(); - for($s = 0; $s < $this->data["count"] and !$this->feof(); ++$s){ - $this->data["slots"][$s] = Utils::readSlot($this); - } - if($this->data["windowid"] == 0){ - $slots = min(9, Utils::readShort($this->get(2), false)); - $this->data["hotbar"] = array(); - if($slots > 0){ - for($s = 0; $s < $slots; ++$s){ - $this->data["hotbar"][$s] = Utils::readInt($this->get(4)); - } - } - } - }else{ - $this->raw .= chr($this->data["windowid"]); - $this->raw .= Utils::writeShort(count($this->data["slots"])); - foreach($this->data["slots"] as $slot){ - $this->raw .= Utils::writeSlot($slot); - } - if($this->data["windowid"] == 0 and isset($this->data["hotbar"])){ - if(count($this->data["hotbar"]) > 0){ - $this->raw .= Utils::writeShort(count($this->data["hotbar"])); - foreach($this->data["hotbar"] as $slot){ - $this->raw .= Utils::writeInt($slot); - } - } - } - } - break; - case MC_CONTAINER_SET_DATA: - if($this->c === false){ - $this->data["windowid"] = ord($this->get(1)); - $this->data["property"] = Utils::readShort($this->get(2)); - $this->data["value"] = Utils::readShort($this->get(2)); - }else{ - $this->raw .= chr($this->data["windowid"]); - $this->raw .= Utils::writeShort($this->data["property"]); - $this->raw .= Utils::writeShort($this->data["value"]); - } - break; - case MC_CLIENT_MESSAGE: - if($this->c === false){ - $this->data["message"] = $this->get(Utils::readShort($this->get(2), false)); - }else{ - $this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"]; - } - break; - case MC_ADVENTURE_SETTINGS: - if($this->c === false){ - $this->data["flags"] = Utils::readInt($this->get(4)); - }else{ - $this->raw .= Utils::writeInt($this->data["flags"]); - } - break; - case MC_ENTITY_DATA: - if($this->c === false){ - $this->data["x"] = Utils::readShort($this->get(2)); - $this->data["y"] = ord($this->get(1)); - $this->data["z"] = Utils::readShort($this->get(2)); - $this->data["namedtag"] = $this->get(true); - }else{ - $this->raw .= Utils::writeShort($this->data["x"]); - $this->raw .= chr($this->data["y"]); - $this->raw .= Utils::writeShort($this->data["z"]); - $this->raw .= $this->data["namedtag"]; - } - break; - default: - if($this->c === false){ - console("[DEBUG] Received unknown Data Packet ID 0x".dechex($pid), true, true, 2); - }else{ - console("[DEBUG] Sent unknown Data Packet ID 0x".dechex($pid), true, true, 2); - } - break; - } - } - -} \ No newline at end of file diff --git a/src/network/protocol/DataPacket.php b/src/network/protocol/DataPacket.php deleted file mode 100644 index c3c0979c4..000000000 --- a/src/network/protocol/DataPacket.php +++ /dev/null @@ -1,115 +0,0 @@ -decoded = true; - $this->encoded = true; - } - - private function get($len){ - if($len <= 0){ - return ""; - } - if($len === true){ - return substr($this->raw, $this->offset); - } - $this->offset += $len; - return substr($this->raw, $this->offset - $len, $len); - } - - private function getLong($unsigned = false){ - return Utils::readLong($this->get(8), $unsigned); - } - - private function getInt($unsigned = false){ - return Utils::readInt($this->get(4), $unsigned); - } - - private function getShort($unsigned = false){ - return Utils::readShort($this->get(2), $unsigned); - } - - private function getTriad(){ - return Utils::readTriad($this->get(3)); - } - - private function getLTriad(){ - return Utils::readTriad(strrev($this->get(3))); - } - - private function getByte(){ - return ord($this->get(1)); - } - - private function getDataArray($len = 10){ - $data = array(); - for($i = 1; $i <= $len and !$this->feof(); ++$i){ - $data[] = $this->get($this->getTriad()); - } - return $data; - } - - private function feof(){ - return !isset($this->raw{$this->offset}); - } - - public function decode(){ - if(!isset($this->raw{0})){ - return false; - } - $this->offset = 0; - switch($this->id){ - case MC_PING: - $this->timestamp = $this->getLong(); - break; - case MC_PONG: - $this->originalTimestamp = $this->getLong(); - $this->timestamp = $this->getLong(); - break; - case MC_CLIENT_CONNECT: - $this->clientID = $this->getLong(); - $this->session = $this->getLong(); - $this->unknown0 = $this->get(1); - break; - case MC_CLIENT_HANDSHAKE: - $this->cookie = $this->get(4); - $this->security = $this->get(1); - $this->port = $this->getShort(true); - $this->dataArray0 = $this->get($this->getByte()); - $this->dataArray = $this->getDataArray(9); - $this->timestamp = $this->get(2); - $this->session2 = $this->getLong(); - $this->session = $this->getLong(); - break; - default: - return false; - } - $this->encoded = true; - $this->decoded = true; - } -} \ No newline at end of file diff --git a/src/network/protocol/ProtocolInfo.php b/src/network/protocol/ProtocolInfo.php index 58a176e92..2e1595d29 100644 --- a/src/network/protocol/ProtocolInfo.php +++ b/src/network/protocol/ProtocolInfo.php @@ -20,75 +20,141 @@ */ -define("CURRENT_PROTOCOL", 14); +class ProtocolInfo{ -define("MC_PING", 0x00); + const CURRENT_PROTOCOL = 14; + + -define("MC_PONG", 0x03); + const PING_PACKET = 0x00; -define("MC_CLIENT_CONNECT", 0x09); -define("MC_SERVER_HANDSHAKE", 0x10); + const PONG_PACKET = 0x03; -define("MC_CLIENT_HANDSHAKE", 0x13); + const CLIENT_CONNECT_PACKET = 0x09; + const SERVER_HANDSHAKE_PACKET = 0x10; -define("MC_SERVER_FULL", 0x14); -define("MC_DISCONNECT", 0x15); + const CLIENT_HANDSHAKE_PACKET = 0x13; + //const SERVER_FULL_PACKET = 0x14; + const DISCONNECT_PACKET = 0x15; -define("MC_BANNED", 0x17); + //const BANNED_PACKET = 0x17; -define("MC_LOGIN", 0x82); -define("MC_LOGIN_STATUS", 0x83); -define("MC_READY", 0x84); -define("MC_CHAT", 0x85); -define("MC_SET_TIME", 0x86); -define("MC_START_GAME", 0x87); -define("MC_ADD_MOB", 0x88); -define("MC_ADD_PLAYER", 0x89); -define("MC_REMOVE_PLAYER", 0x8a); + const LOGIN_PACKET = 0x82; + const LOGIN_STATUS_PACKET = 0x83; + const READY_PACKET = 0x84; + const MESSAGE_PACKET = 0x85; + const SET_TIME_PACKET = 0x86; + const START_GAME_PACKET = 0x87; + const ADD_MOB_PACKET = 0x88; + const ADD_PLAYER_PACKET = 0x89; + const REMOVE_PLAYER_PACKET = 0x8a; -define("MC_ADD_ENTITY", 0x8c); -define("MC_REMOVE_ENTITY", 0x8d); -define("MC_ADD_ITEM_ENTITY", 0x8e); -define("MC_TAKE_ITEM_ENTITY", 0x8f); -define("MC_MOVE_ENTITY", 0x90); + const ADD_ENTITY_PACKET = 0x8c; + const REMOVE_ENTITY_PACKET = 0x8d; + const ADD_ITEM_ENTITY_PACKET = 0x8e; + const TAKE_ITEM_ENTITY_PACKET = 0x8f; + const MOVE_ENTITY_PACKET = 0x90; -define("MC_MOVE_ENTITY_POSROT", 0x93); -define("MC_ROTATE_HEAD", 0x94); -define("MC_MOVE_PLAYER", 0x95); -define("MC_PLACE_BLOCK", 0x96); -define("MC_REMOVE_BLOCK", 0x97); -define("MC_UPDATE_BLOCK", 0x98); -define("MC_ADD_PAINTING", 0x99); -define("MC_EXPLOSION", 0x9a); -define("MC_LEVEL_EVENT", 0x9b); -define("MC_TILE_EVENT", 0x9c); -define("MC_ENTITY_EVENT", 0x9d); -define("MC_REQUEST_CHUNK", 0x9e); -define("MC_CHUNK_DATA", 0x9f); -define("MC_PLAYER_EQUIPMENT", 0xa0); -define("MC_PLAYER_ARMOR_EQUIPMENT", 0xa1); -define("MC_INTERACT", 0xa2); -define("MC_USE_ITEM", 0xa3); -define("MC_PLAYER_ACTION", 0xa4); + const MOVE_ENTITY_PACKET_POSROT = 0x93; + const ROTATE_HEAD_PACKET = 0x94; + const MOVE_PLAYER_PACKET = 0x95; + //const PLACE_BLOCK_PACKET = 0x96; + const REMOVE_BLOCK_PACKET = 0x97; + const UPDATE_BLOCK_PACKET = 0x98; + const ADD_PAINTING_PACKET = 0x99; + const EXPLOSION_PACKET = 0x9a; + const LEVEL_EVENT_PACKET = 0x9b; + const TILE_EVENT_PACKET = 0x9c; + const ENTITY_EVENT_PACKET = 0x9d; + const REQUEST_CHUNK_PACKET = 0x9e; + const CHUNK_DATA_PACKET = 0x9f; + const PLAYER_EQUIPMENT_PACKET = 0xa0; + const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa1; + const INTERACT_PACKET = 0xa2; + const USE_ITEM_PACKET = 0xa3; + const PLAYER_ACTION_PACKET = 0xa4; -define("MC_HURT_ARMOR", 0xa6); -define("MC_SET_ENTITY_DATA", 0xa7); -define("MC_SET_ENTITY_MOTION", 0xa8); -//define("MC_SET_ENTITY_LINK", 0xa9); -define("MC_SET_HEALTH", 0xaa); -define("MC_SET_SPAWN_POSITION", 0xab); -define("MC_ANIMATE", 0xac); -define("MC_RESPAWN", 0xad); -define("MC_SEND_INVENTORY", 0xae); -define("MC_DROP_ITEM", 0xaf); -define("MC_CONTAINER_OPEN", 0xb0); -define("MC_CONTAINER_CLOSE", 0xb1); -define("MC_CONTAINER_SET_SLOT", 0xb2); -define("MC_CONTAINER_SET_DATA", 0xb3); -define("MC_CONTAINER_SET_CONTENT", 0xb4); -//define("MC_CONTAINER_ACK", 0xb5); -define("MC_CLIENT_MESSAGE", 0xb6); -define("MC_ADVENTURE_SETTINGS", 0xb7); -define("MC_ENTITY_DATA", 0xb8); -//define("MC_PLAYER_INPUT", 0xb9); \ No newline at end of file + const HURT_ARMOR_PACKET = 0xa6; + const SET_ENTITY_DATA_PACKET = 0xa7; + const SET_ENTITY_MOTION_PACKET = 0xa8; + //const SET_ENTITY_LINK_PACKET = 0xa9; + const SET_HEALTH_PACKET = 0xaa; + const SET_SPAWN_POSITION_PACKET = 0xab; + const ANIMATE_PACKET = 0xac; + const RESPAWN_PACKET = 0xad; + const SEND_INVENTORY_PACKET = 0xae; + const DROP_ITEM_PACKET = 0xaf; + const CONTAINER_OPEN_PACKET = 0xb0; + const CONTAINER_CLOSE_PACKET = 0xb1; + const CONTAINER_SET_SLOT_PACKET = 0xb2; + const CONTAINER_SET_DATA_PACKET = 0xb3; + const CONTAINER_SET_CONTENT_PACKET = 0xb4; + //const CONTAINER_ACK_PACKET = 0xb5; + const CHAT_PACKET = 0xb6; + const ADVENTURE_SETTINGS_PACKET = 0xb7; + const ENTITY_DATA_PACKET = 0xb8; + //const PLAYER_INPUT_PACKET = 0xb9; + + public static $packets = array( + -1 => "UnknownPacket", + ProtocolInfo::PING_PACKET => "PingPacket", + ProtocolInfo::PONG_PACKET => "PongPacket", + ProtocolInfo::CLIENT_CONNECT_PACKET => "ClientConnectPacket", + ProtocolInfo::SERVER_HANDSHAKE_PACKET => "ServerHandshakePacket", + ProtocolInfo::DISCONNECT_PACKET => "DisconnectPacket", + ProtocolInfo::LOGIN_PACKET => "LoginPacket", + ProtocolInfo::LOGIN_STATUS_PACKET => "LoginStatusPacket", + ProtocolInfo::READY_PACKET => "ReadyPacket", + ProtocolInfo::MESSAGE_PACKET => "MessagePacket", + ProtocolInfo::SET_TIME_PACKET => "SetTimePacket", + ProtocolInfo::START_GAME_PACKET => "StartGamePacket", + ProtocolInfo::ADD_MOB_PACKET => "AddMobPacket", + ProtocolInfo::ADD_PLAYER_PACKET => "AddPlayerPacket", + ProtocolInfo::REMOVE_PLAYER_PACKET => "RemovePlayerPacket", + ProtocolInfo::ADD_ENTITY_PACKET => "AddEntityPacket", + ProtocolInfo::REMOVE_ENTITY_PACKET => "RemoveEntityPacket", + ProtocolInfo::ADD_ITEM_ENTITY_PACKET => "AddItemEntityPacket", + ProtocolInfo::TAKE_ITEM_ENTITY_PACKET => "TakeItemEntityPacket", + ProtocolInfo::MOVE_ENTITY_PACKET => "MoveEntityPacket", + ProtocolInfo::MOVE_ENTITY_PACKET_POSROT => "MoveEntityPacket_PosRot", + ProtocolInfo::ROTATE_HEAD_PACKET => "RotateHeadPacket", + ProtocolInfo::MOVE_PLAYER_PACKET => "MovePlayerPacket", + ProtocolInfo::REMOVE_BLOCK_PACKET => "RemoveBlockPacket", + ProtocolInfo::UPDATE_BLOCK_PACKET => "UpdateBlockPacket", + ProtocolInfo::ADD_PAINTING_PACKET => "AddPaintingPacket", + ProtocolInfo::EXPLOSION_PACKET => "ExplosionPacket", + ProtocolInfo::LEVEL_EVENT_PACKET => "LevelEventPacket", + ProtocolInfo::TILE_EVENT_PACKET => "TileEventPacket", + ProtocolInfo::ENTITY_EVENT_PACKET => "EntityEventPacket", + ProtocolInfo::REQUEST_CHUNK_PACKET => "RequestChunkPacket", + ProtocolInfo::CHUNK_DATA_PACKET => "ChunkDataPacket", + ProtocolInfo::PLAYER_EQUIPMENT_PACKET => "PlayerEquipmentPacket", + ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET => "PlayerArmorEquipmentPacket", + ProtocolInfo::INTERACT_PACKET => "InteractPacket", + ProtocolInfo::USE_ITEM_PACKET => "UseItemPacket", + ProtocolInfo::PLAYER_ACTION_PACKET => "PlayerActionPacket", + ProtocolInfo::HURT_ARMOR_PACKET => "HurtArmorPacket", + ProtocolInfo::SET_ENTITY_DATA_PACKET => "SetEntityDataPacket", + ProtocolInfo::SET_ENTITY_MOTION_PACKET => "SetEntityMotionPacket", + ProtocolInfo::SET_HEALTH_PACKET => "SetHealthPacket", + ProtocolInfo::SET_SPAWN_POSITION_PACKET => "SetSpawnPositionPacket", + ProtocolInfo::ANIMATE_PACKET => "AnimatePacket", + ProtocolInfo::RESPAWN_PACKET => "RespawnPacket", + ProtocolInfo::SEND_INVENTORY_PACKET => "SendInventoryPacket", + ProtocolInfo::DROP_ITEM_PACKET => "DropItemPacket", + ProtocolInfo::CONTAINER_OPEN_PACKET => "ContainerOpenPacket", + ProtocolInfo::CONTAINER_CLOSE_PACKET => "ContainerClosePacket", + ProtocolInfo::CONTAINER_SET_SLOT_PACKET => "ContainerSetSlotPacket", + ProtocolInfo::CONTAINER_SET_DATA_PACKET => "ContainerSetDataPacket", + ProtocolInfo::CONTAINER_SET_CONTENT_PACKET => "ContainerSetContentPacket", + ProtocolInfo::CHAT_PACKET => "ChatPacket", + ProtocolInfo::ADVENTURE_SETTINGS_PACKET => "AdventureSettingsPacket", + ProtocolInfo::ENTITY_DATA_PACKET => "EntityDataPacket", + ); + +} + +/***REM_START***/ +require_once(FILE_PATH . "src/network/raknet/RakNetDataPacket.php"); +/***REM_END***/ \ No newline at end of file diff --git a/src/network/protocol/packet/AddEntityPacket.php b/src/network/protocol/packet/AddEntityPacket.php new file mode 100644 index 000000000..1f106e6e4 --- /dev/null +++ b/src/network/protocol/packet/AddEntityPacket.php @@ -0,0 +1,56 @@ +reset(); + $this->putInt($this->eid); + $this->putInt($this->type); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putInt($this->did); + if($this->did > 0){ + $this->putShort($this->speedX); + $this->putShort($this->speedY); + $this->putShort($this->speedZ); + } + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AddItemEntityPacket.php b/src/network/protocol/packet/AddItemEntityPacket.php new file mode 100644 index 000000000..adc76c0a7 --- /dev/null +++ b/src/network/protocol/packet/AddItemEntityPacket.php @@ -0,0 +1,52 @@ +reset(); + $this->putInt($this->eid); + $this->putSlot($this->item); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putByte($this->yaw); + $this->putByte($this->pitch); + $this->putByte($this->roll); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AddMobPacket.php b/src/network/protocol/packet/AddMobPacket.php new file mode 100644 index 000000000..3a7f41cbe --- /dev/null +++ b/src/network/protocol/packet/AddMobPacket.php @@ -0,0 +1,52 @@ +reset(); + $this->putInt($this->eid); + $this->putInt($this->type); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putByte($this->yaw); + $this->putByte($this->pitch); + $this->put(Utils::writeMetadata($this->metadata)); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AddPaintingPacket.php b/src/network/protocol/packet/AddPaintingPacket.php new file mode 100644 index 000000000..6d0557ced --- /dev/null +++ b/src/network/protocol/packet/AddPaintingPacket.php @@ -0,0 +1,48 @@ +reset(); + $this->putInt($this->eid); + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + $this->putInt($this->direction); + $this->putString($this->title); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AddPlayerPacket.php b/src/network/protocol/packet/AddPlayerPacket.php new file mode 100644 index 000000000..426ef480e --- /dev/null +++ b/src/network/protocol/packet/AddPlayerPacket.php @@ -0,0 +1,58 @@ +reset(); + $this->putLong($this->clientID); + $this->putString($this->username); + $this->putInt($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putByte($this->yaw); + $this->putByte($this->pitch); + $this->putShort($this->unknown1); + $this->putShort($this->unknown2); + $this->put(Utils::writeMetadata($this->metadata)); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AdventureSettingsPacket.php b/src/network/protocol/packet/AdventureSettingsPacket.php new file mode 100644 index 000000000..b287c9d52 --- /dev/null +++ b/src/network/protocol/packet/AdventureSettingsPacket.php @@ -0,0 +1,37 @@ +putInt($this->flags); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AnimatePacket.php b/src/network/protocol/packet/AnimatePacket.php new file mode 100644 index 000000000..d8266f6a9 --- /dev/null +++ b/src/network/protocol/packet/AnimatePacket.php @@ -0,0 +1,41 @@ +action = $this->getByte(); + $this->eid = $this->getInt(); + } + + public function encode(){ + $this->reset(); + $this->putByte($this->action); + $this->putInt($this->eid); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ChatPacket.php b/src/network/protocol/packet/ChatPacket.php new file mode 100644 index 000000000..f04edef68 --- /dev/null +++ b/src/network/protocol/packet/ChatPacket.php @@ -0,0 +1,37 @@ +putString($this->message); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ChunkDataPacket.php b/src/network/protocol/packet/ChunkDataPacket.php new file mode 100644 index 000000000..0546f55f8 --- /dev/null +++ b/src/network/protocol/packet/ChunkDataPacket.php @@ -0,0 +1,42 @@ +reset(); + $this->putInt($this->x); + $this->putInt($this->z); + $this->put($this->data); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ClientConnectPacket.php b/src/network/protocol/packet/ClientConnectPacket.php new file mode 100644 index 000000000..d5187caad --- /dev/null +++ b/src/network/protocol/packet/ClientConnectPacket.php @@ -0,0 +1,41 @@ +clientID = $this->getLong(); + $this->session = $this->getLong(); + $this->unknown1 = $this->get(1); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ClientHandshakePacket.php b/src/network/protocol/packet/ClientHandshakePacket.php new file mode 100644 index 000000000..2cac9e8d4 --- /dev/null +++ b/src/network/protocol/packet/ClientHandshakePacket.php @@ -0,0 +1,51 @@ +cookie = $this->get(4); + $this->security = $this->get(1); + $this->port = $this->getShort(true); + $this->dataArray0 = $this->get($this->getByte()); + $this->dataArray = $this->getDataArray(9); + $this->timespamp = $this->get(2); + $this->session2 = $this->getLong(); + $this->session = $this->getLong(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerClosePacket.php b/src/network/protocol/packet/ContainerClosePacket.php new file mode 100644 index 000000000..06f5a63db --- /dev/null +++ b/src/network/protocol/packet/ContainerClosePacket.php @@ -0,0 +1,38 @@ +windowid = $this->getInt(); + } + + public function encode(){ + $this->reset(); + $this->putByte($this->windowid); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerOpenPacket.php b/src/network/protocol/packet/ContainerOpenPacket.php new file mode 100644 index 000000000..a1e9f55a6 --- /dev/null +++ b/src/network/protocol/packet/ContainerOpenPacket.php @@ -0,0 +1,48 @@ +reset(); + $this->putByte($this->windowid); + $this->putByte($this->type); + $this->putByte($this->slots); + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerSetContentPacket.php b/src/network/protocol/packet/ContainerSetContentPacket.php new file mode 100644 index 000000000..314355d86 --- /dev/null +++ b/src/network/protocol/packet/ContainerSetContentPacket.php @@ -0,0 +1,59 @@ +windowid = $this->getByte(); + $count = $this->getShort(); + for($s = 0; $s < $count and !$this->feof(); ++$s){ + $this->slots[$s] = $this->getSlot(); + } + if($this->windowid === 0){ + $count = $this->getShort(); + for($s = 0; $s < $count and !$this->feof(); ++$s){ + $this->hotbar[$s] = $this->getInt(); + } + } + } + + public function encode(){ + $this->putByte($this->windowid); + $this->putShort(count($this->slots)); + foreach($this->slots as $slot){ + $this->putSlot($item); + } + if($this->windowid === 0 and count($this->hotbar) > 0){ + $this->putShort(count($this->hotbar)); + foreach($this->hotbar as $slot){ + $this->putInt($slot); + } + } + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerSetDataPacket.php b/src/network/protocol/packet/ContainerSetDataPacket.php new file mode 100644 index 000000000..2a36d2222 --- /dev/null +++ b/src/network/protocol/packet/ContainerSetDataPacket.php @@ -0,0 +1,41 @@ +putByte($this->windowid); + $this->putShort($this->property); + $this->putShort($this->value); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerSetSlotPacket.php b/src/network/protocol/packet/ContainerSetSlotPacket.php new file mode 100644 index 000000000..0ab886d45 --- /dev/null +++ b/src/network/protocol/packet/ContainerSetSlotPacket.php @@ -0,0 +1,43 @@ +windowid = $this->getByte(); + $this->slot = $this->getShort(); + $this->item = $this->getSlot(); + } + + public function encode(){ + $this->putByte($this->windowid); + $this->putShort($this->slot); + $this->putSlot($this->item); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/DisconnectPacket.php b/src/network/protocol/packet/DisconnectPacket.php new file mode 100644 index 000000000..d255d9b5b --- /dev/null +++ b/src/network/protocol/packet/DisconnectPacket.php @@ -0,0 +1,35 @@ +eid = $this->getInt(); + $this->unknown = $this->getByte(); + $this->item = $this->getSlot(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/EntityDataPacket.php b/src/network/protocol/packet/EntityDataPacket.php new file mode 100644 index 000000000..f906814e6 --- /dev/null +++ b/src/network/protocol/packet/EntityDataPacket.php @@ -0,0 +1,46 @@ +x = $this->getShort(); + $this->y = $this->getByte(); + $this->z = $this->getShort(); + $this->namedtag = $this->get(true); + } + + public function encode(){ + $this->putShort($this->x); + $this->putByte($this->y); + $this->putShort($this->z); + $this->put($this->namedtag); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/EntityEventPacket.php b/src/network/protocol/packet/EntityEventPacket.php new file mode 100644 index 000000000..8764de026 --- /dev/null +++ b/src/network/protocol/packet/EntityEventPacket.php @@ -0,0 +1,41 @@ +eid = $this->getInt(); + $this->event = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putByte($this->event); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ExplosionPacket.php b/src/network/protocol/packet/ExplosionPacket.php new file mode 100644 index 000000000..5f0545c3f --- /dev/null +++ b/src/network/protocol/packet/ExplosionPacket.php @@ -0,0 +1,53 @@ +reset(); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putFloat($this->radius); + $this->putInt(@count($this->records)); + if(@count($this->records) > 0){ + foreach($this->records as $record){ + $this->putByte($record->x); + $this->putByte($record->y); + $this->putByte($record->z); + } + } + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/HurtArmorPacket.php b/src/network/protocol/packet/HurtArmorPacket.php new file mode 100644 index 000000000..48a148693 --- /dev/null +++ b/src/network/protocol/packet/HurtArmorPacket.php @@ -0,0 +1,38 @@ +reset(); + $this->putByte($this->health); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/InteractPacket.php b/src/network/protocol/packet/InteractPacket.php new file mode 100644 index 000000000..f1ebd8c43 --- /dev/null +++ b/src/network/protocol/packet/InteractPacket.php @@ -0,0 +1,44 @@ +action = $this->getByte(); + $this->eid = $this->getInt(); + $this->target = $this->getInt(); + } + + public function encode(){ + $this->reset(); + $this->putByte($this->action); + $this->putInt($this->eid); + $this->putInt($this->target); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/LevelEventPacket.php b/src/network/protocol/packet/LevelEventPacket.php new file mode 100644 index 000000000..22a44ab58 --- /dev/null +++ b/src/network/protocol/packet/LevelEventPacket.php @@ -0,0 +1,46 @@ +reset(); + $this->putShort($this->evid); + $this->putShort($this->x); + $this->putShort($this->y); + $this->putShort($this->z); + $this->putInt($this->data); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/LoginPacket.php b/src/network/protocol/packet/LoginPacket.php new file mode 100644 index 000000000..a357a27e6 --- /dev/null +++ b/src/network/protocol/packet/LoginPacket.php @@ -0,0 +1,45 @@ +username = $this->getString(); + $this->protocol1 = $this->getInt(); + $this->protocol2 = $this->getInt(); + $this->clientId = $this->getInt(); + $this->loginData = $this->getString(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/LoginStatusPacket.php b/src/network/protocol/packet/LoginStatusPacket.php new file mode 100644 index 000000000..fce48a7ed --- /dev/null +++ b/src/network/protocol/packet/LoginStatusPacket.php @@ -0,0 +1,38 @@ +reset(); + $this->putInt($this->status); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/MessagePacket.php b/src/network/protocol/packet/MessagePacket.php new file mode 100644 index 000000000..113775104 --- /dev/null +++ b/src/network/protocol/packet/MessagePacket.php @@ -0,0 +1,41 @@ +source = $this->getString(); + $this->message = $this->getString(); + } + + public function encode(){ + $this->reset(); + $this->putString($this->source); + $this->putString($this->message); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/MoveEntityPacket.php b/src/network/protocol/packet/MoveEntityPacket.php new file mode 100644 index 000000000..37086ecf8 --- /dev/null +++ b/src/network/protocol/packet/MoveEntityPacket.php @@ -0,0 +1,36 @@ +reset(); + $this->putInt($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putFloat($this->yaw); + $this->putFloat($this->pitch); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/MovePlayerPacket.php b/src/network/protocol/packet/MovePlayerPacket.php new file mode 100644 index 000000000..3730f69ee --- /dev/null +++ b/src/network/protocol/packet/MovePlayerPacket.php @@ -0,0 +1,56 @@ +eid = $this->getInt(); + $this->x = $this->getFloat(); + $this->y = $this->getFloat(); + $this->z = $this->getFloat(); + $this->yaw = $this->getFloat(); + $this->pitch = $this->getFloat(); + $this->bodyYaw = $this->getFloat(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putFloat($this->yaw); + $this->putFloat($this->pitch); + $this->putFloat($this->bodyYaw); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PingPacket.php b/src/network/protocol/packet/PingPacket.php new file mode 100644 index 000000000..85e01b663 --- /dev/null +++ b/src/network/protocol/packet/PingPacket.php @@ -0,0 +1,38 @@ +time = $this->getLong(); + } + + public function encode(){ + $this->reset(); + $this->putLong($this->time); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerActionPacket.php b/src/network/protocol/packet/PlayerActionPacket.php new file mode 100644 index 000000000..89701b085 --- /dev/null +++ b/src/network/protocol/packet/PlayerActionPacket.php @@ -0,0 +1,47 @@ +action = $this->getInt(); + $this->x = $this->getInt(); + $this->y = $this->getInt(); + $this->z = $this->getInt(); + $this->face = $this->getInt(); + $this->eid = $this->getInt(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php new file mode 100644 index 000000000..b20345420 --- /dev/null +++ b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php @@ -0,0 +1,47 @@ +eid = $this->getInt(); + $this->slots[0] = $this->getByte(); + $this->slots[1] = $this->getByte(); + $this->slots[2] = $this->getByte(); + $this->slots[3] = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putByte($this->slots[0]); + $this->putByte($this->slots[1]); + $this->putByte($this->slots[2]); + $this->putByte($this->slots[3]); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerEquipmentPacket.php b/src/network/protocol/packet/PlayerEquipmentPacket.php new file mode 100644 index 000000000..d194f9921 --- /dev/null +++ b/src/network/protocol/packet/PlayerEquipmentPacket.php @@ -0,0 +1,46 @@ +eid = $this->getInt(); + $this->item = $this->getShort(); + $this->meta = $this->getShort(); + $this->slot = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putShort($this->meta); + $this->putByte($this->slot); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PongPacket.php b/src/network/protocol/packet/PongPacket.php new file mode 100644 index 000000000..453b6514d --- /dev/null +++ b/src/network/protocol/packet/PongPacket.php @@ -0,0 +1,41 @@ +ptime = $this->getLong(); + $this->time = $this->getLong(); + } + + public function encode(){ + $this->reset(); + $this->putLong($this->ptime); + $this->putLong($this->time); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ReadyPacket.php b/src/network/protocol/packet/ReadyPacket.php new file mode 100644 index 000000000..c77fc391b --- /dev/null +++ b/src/network/protocol/packet/ReadyPacket.php @@ -0,0 +1,37 @@ +status = $this->getByte(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RemoveBlockPacket.php b/src/network/protocol/packet/RemoveBlockPacket.php new file mode 100644 index 000000000..f30aa142e --- /dev/null +++ b/src/network/protocol/packet/RemoveBlockPacket.php @@ -0,0 +1,43 @@ +eid = $this->getInt(); + $this->x = $this->getInt(); + $this->y = $this->getInt(); + $this->z = $this->getInt(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RemoveEntityPacket.php b/src/network/protocol/packet/RemoveEntityPacket.php new file mode 100644 index 000000000..70e7f912c --- /dev/null +++ b/src/network/protocol/packet/RemoveEntityPacket.php @@ -0,0 +1,38 @@ +reset(); + $this->putInt($this->eid); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RemovePlayerPacket.php b/src/network/protocol/packet/RemovePlayerPacket.php new file mode 100644 index 000000000..d0727bb20 --- /dev/null +++ b/src/network/protocol/packet/RemovePlayerPacket.php @@ -0,0 +1,40 @@ +reset(); + $this->putInt($this->eid); + $this->putLong($this->clientID); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RequestChunkPacket.php b/src/network/protocol/packet/RequestChunkPacket.php new file mode 100644 index 000000000..8629e0519 --- /dev/null +++ b/src/network/protocol/packet/RequestChunkPacket.php @@ -0,0 +1,39 @@ +x = $this->getInt(); + $this->z = $this->getInt(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RespawnPacket.php b/src/network/protocol/packet/RespawnPacket.php new file mode 100644 index 000000000..f9475efb7 --- /dev/null +++ b/src/network/protocol/packet/RespawnPacket.php @@ -0,0 +1,47 @@ +eid = $this->getInt(); + $this->x = $this->getFloat(); + $this->y = $this->getFloat(); + $this->z = $this->getFloat(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RotateHeadPacket.php b/src/network/protocol/packet/RotateHeadPacket.php new file mode 100644 index 000000000..41ba3d123 --- /dev/null +++ b/src/network/protocol/packet/RotateHeadPacket.php @@ -0,0 +1,40 @@ +reset(); + $this->putInt($this->eid); + $this->putByte($this->yaw); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SendInventoryPacket.php b/src/network/protocol/packet/SendInventoryPacket.php new file mode 100644 index 000000000..250d3abce --- /dev/null +++ b/src/network/protocol/packet/SendInventoryPacket.php @@ -0,0 +1,61 @@ +eid = $this->getInt(); + $this->windowid = $this->getByte(); + $count = $this->getShort(); + for($s = 0; $s < $count and !$this->feof(); ++$s){ + $this->slots[$s] = $this->getSlot(); + } + if($this->windowid === 1){ //Armir is sent + for($s = 0; $s < 4; ++$s){ + $this->armor[$s] = $this->getSlot(); + } + } + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putByte($this->windowid); + $this->putShort(count($this->slots)); + foreach($this->slots as $slot){ + $this->putSlot($slot); + } + if($this->windowid === 1 and count($this->armor) === 4){ + for($s = 0; $s < 4; ++$s){ + $this->putSlot($this->armor[$s]); + } + } + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ServerHandshakePacket.php b/src/network/protocol/packet/ServerHandshakePacket.php new file mode 100644 index 000000000..3077acf91 --- /dev/null +++ b/src/network/protocol/packet/ServerHandshakePacket.php @@ -0,0 +1,57 @@ +reset(); + $this->put("\x04\x3f\x57\xfe"); //cookie + $this->put("\xcd"); //Security flags + $this->putShort($this->port); + $this->putDataArray(array( + "\xf5\xff\xff\xf5", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + )); + $this->put("\x00\x00"); + $this->putLong($this->session); + $this->putLong($this->session2); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SetEntityDataPacket.php b/src/network/protocol/packet/SetEntityDataPacket.php new file mode 100644 index 000000000..be9ed385e --- /dev/null +++ b/src/network/protocol/packet/SetEntityDataPacket.php @@ -0,0 +1,40 @@ +reset(); + $this->putInt($this->eid); + $this->put(Utils::writeMetadata($this->metadata)); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SetEntityMotionPacket.php b/src/network/protocol/packet/SetEntityMotionPacket.php new file mode 100644 index 000000000..dd95bf3cf --- /dev/null +++ b/src/network/protocol/packet/SetEntityMotionPacket.php @@ -0,0 +1,44 @@ +reset(); + $this->putInt($this->eid); + $this->putShort($this->speedX); + $this->putShort($this->speedY); + $this->putShort($this->speedZ); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SetHealthPacket.php b/src/network/protocol/packet/SetHealthPacket.php new file mode 100644 index 000000000..66e8f7b54 --- /dev/null +++ b/src/network/protocol/packet/SetHealthPacket.php @@ -0,0 +1,38 @@ +health = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putByte($this->health); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SetSpawnPositionPacket.php b/src/network/protocol/packet/SetSpawnPositionPacket.php new file mode 100644 index 000000000..2217d0155 --- /dev/null +++ b/src/network/protocol/packet/SetSpawnPositionPacket.php @@ -0,0 +1,41 @@ +putInt($this->x); + $this->putInt($this->z); + $this->putByte($this->y); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SetTimePacket.php b/src/network/protocol/packet/SetTimePacket.php new file mode 100644 index 000000000..09df60f9d --- /dev/null +++ b/src/network/protocol/packet/SetTimePacket.php @@ -0,0 +1,40 @@ +reset(); + $this->putInt($this->time); + $this->putByte($this->started == true ? 0x80:0x00); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/StartGamePacket.php b/src/network/protocol/packet/StartGamePacket.php new file mode 100644 index 000000000..fe3ead723 --- /dev/null +++ b/src/network/protocol/packet/StartGamePacket.php @@ -0,0 +1,50 @@ +reset(); + $this->putInt($this->seed); + $this->putInt($this->generator); + $this->putInt($this->gamemode); + $this->putInt($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/TakeItemEntity.php b/src/network/protocol/packet/TakeItemEntity.php new file mode 100644 index 000000000..0d6f97cd7 --- /dev/null +++ b/src/network/protocol/packet/TakeItemEntity.php @@ -0,0 +1,40 @@ +reset(); + $this->putInt($this->target); + $this->putInt($this->eid); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/TileEventPacket.php b/src/network/protocol/packet/TileEventPacket.php new file mode 100644 index 000000000..16ef18ccf --- /dev/null +++ b/src/network/protocol/packet/TileEventPacket.php @@ -0,0 +1,46 @@ +reset(); + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + $this->putInt($this->case1); + $this->putInt($this->case2); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/UnknownPacket.php b/src/network/protocol/packet/UnknownPacket.php new file mode 100644 index 000000000..38cc28143 --- /dev/null +++ b/src/network/protocol/packet/UnknownPacket.php @@ -0,0 +1,37 @@ +packetID; + } + + public function decode(){ + + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/UpdateBlockPacket.php b/src/network/protocol/packet/UpdateBlockPacket.php new file mode 100644 index 000000000..11095e8ef --- /dev/null +++ b/src/network/protocol/packet/UpdateBlockPacket.php @@ -0,0 +1,45 @@ +putInt($this->x); + $this->putInt($this->z); + $this->putByte($this->y); + $this->putByte($this->block); + $this->putByte($this->meta); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/UseItemPacket.php b/src/network/protocol/packet/UseItemPacket.php new file mode 100644 index 000000000..8ec919b57 --- /dev/null +++ b/src/network/protocol/packet/UseItemPacket.php @@ -0,0 +1,61 @@ +x = $this->getInt(); + $this->y = $this->getInt(); + $this->z = $this->getInt(); + $this->face = $this->getInt(); + $this->item = $this->getShort(); + $this->meta = $this->getShort(); + $this->eid = $this->getInt(); + $this->fx = $this->getFloat(); + $this->fy = $this->getFloat(); + $this->fz = $this->getFloat(); + $this->posX = $this->getFloat(); + $this->posY = $this->getFloat(); + $this->posZ = $this->getFloat(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/raknet/Packet.php b/src/network/raknet/Packet.php deleted file mode 100644 index 578e94685..000000000 --- a/src/network/raknet/Packet.php +++ /dev/null @@ -1,343 +0,0 @@ -pid = $pid; - $this->offset = 1; - $this->raw = $data; - $this->data = array(); - if($data === ""){ - $this->addRaw(chr($pid)); - } - $this->struct = $struct; - } - - public function create($raw = false){ - foreach($this->struct as $field => $type){ - if(!isset($this->data[$field])){ - $this->data[$field] = ""; - } - if($raw === true){ - $this->addRaw($this->data[$field]); - continue; - } - switch($type){ - case "special1": - switch($this->pid){ - case 0x99: - if($this->data[0] >= 2){ - $this->addRaw(Utils::writeShort($this->data[1]["id"])); - $this->addRaw(Utils::writeShort($this->data[1]["index"])); - if($this->data[0] === 2){ - $this->addRaw(Utils::writeShort($this->data[1]["count"])); - $this->addRaw(Utils::writeShort(strlen($this->data[1]["data"])).$this->data[1]["data"]); - } - } - break; - case 0xc0: - case 0xa0: - $payload = ""; - $records = 0; - $pointer = 0; - sort($this->data[$field], SORT_NUMERIC); - $max = count($this->data[$field]); - while($pointer < $max){ - $type = true; - $curr = $start = $this->data[$field][$pointer]; - for($i = $start + 1; $i < $max; ++$i){ - $n = $this->data[$field][$i]; - if(($n - $curr) === 1){ - $curr = $end = $n; - $type = false; - $pointer = $i + 1; - }else{ - break; - } - } - ++$pointer; - if($type === false){ - $payload .= Utils::writeBool(false); - $payload .= strrev(Utils::writeTriad($start)); - $payload .= strrev(Utils::writeTriad($end)); - }else{ - $payload .= Utils::writeBool(true); - $payload .= strrev(Utils::writeTriad($start)); - } - ++$records; - } - $this->addRaw(Utils::writeShort($records) . $payload); - break; - case 0x05: - $this->addRaw($this->data[$field]); - break; - } - break; - case "customData": - $this->addRaw(chr($this->data[1])); - if($this->data[2]["id"] === false){ - $this->addRaw($this->data[2]["raw"]); - }else{ - switch($this->data[1]){ - case 0x40: - $reply = new CustomPacketHandler($this->data[2]["id"], "", $this->data[2], true); - $this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3)); - $this->addRaw(strrev(Utils::writeTriad($this->data[2]["count"]))); - $this->addRaw(chr($this->data[2]["id"])); - $this->addRaw($reply->raw); - break; - case 0x00: - $raw = new CustomPacketHandler($this->data[2]["id"], "", $this->data[2], true); - $raw = $raw->raw; - $this->addRaw(Utils::writeShort((strlen($raw) + 1) << 3)); - $this->addRaw(chr($this->data[2]["id"])); - $this->addRaw($raw); - break; - } - } - - break; - case "magic": - $this->addRaw(RAKNET_MAGIC); - break; - case "float": - $this->addRaw(Utils::writeFloat($this->data[$field])); - break; - case "triad": - $this->addRaw(Utils::writeTriad($this->data[$field])); - break; - case "itriad": - $this->addRaw(strrev(Utils::writeTriad($this->data[$field]))); - break; - case "int": - $this->addRaw(Utils::writeInt($this->data[$field])); - break; - case "double": - $this->addRaw(Utils::writeDouble($this->data[$field])); - break; - case "long": - $this->addRaw(Utils::writeLong($this->data[$field])); - break; - case "bool": - case "boolean": - $this->addRaw(Utils::writeBool($this->data[$field])); - break; - case "ubyte": - case "byte": - $this->addRaw(Utils::writeByte($this->data[$field])); - break; - case "short": - $this->addRaw(Utils::writeShort($this->data[$field])); - break; - case "string": - $this->addRaw(Utils::writeShort(strlen($this->data[$field]))); - $this->addRaw($this->data[$field]); - break; - default: - $this->addRaw(Utils::writeByte($this->data[$field])); - break; - } - } - } - - private function get($len = true){ - if($len === true){ - $data = substr($this->raw, $this->offset); - $this->offset = strlen($this->raw); - return $data; - } - $data = substr($this->raw, $this->offset, $len); - $this->offset += $len; - return $data; - } - - private function feof(){ - return !isset($this->raw{$this->offset}); - } - - protected function addRaw($str){ - $this->raw .= $str; - return $str; - } - - public function parse(){ - foreach($this->struct as $field => $type){ - switch($type){ - case "special1": - switch($this->pid){ - case 0x07: - $this->data[] = $this->get(5); - break; - case 0x99: - if($this->data[0] >= 2){ // - $messageID = Utils::readShort($this->get(2), false); - $messageIndex = Utils::readShort($this->get(2), false); - $this->data[1] = array("id" => $messageID, "index" => $messageIndex); - if($this->data[0] === 2){ - $this->data[1]["count"] = Utils::readShort($this->get(2), false); - $dataLength = Utils::readShort($this->get(2), false); - $this->data[1]["data"] = $this->get($dataLength); - } - } - break; - case 0xc0: - case 0xa0: - $cnt = Utils::readShort($this->get(2), false); - $this->data[$field] = array(); - for($i = 0; $i < $cnt and !$this->feof(); ++$i){ - if(Utils::readBool($this->get(1)) === false){ - $start = Utils::readTriad(strrev($this->get(3))); - $end = min(Utils::readTriad(strrev($this->get(3))), $start + 4096); - for($c = $start; $c <= $end; ++$c){ - $this->data[$field][] = $c; - } - }else{ - $this->data[$field][] = Utils::readTriad(strrev($this->get(3))); - } - } - break; - case 0x05: - $this->data[] = $this->get(true); - break; - } - break; - case "customData": - $raw = $this->get(true); - $len = strlen($raw); - $offset = 0; - $this->data["packets"] = array(); - while($len > $offset){ - $pid = ord($raw{$offset}); - ++$offset; - $reliability = ($pid & 0b11100000) >> 5; - $hasSplit = ($pid & 0b00010000) >> 4; - $length = Utils::readShort(substr($raw, $offset, 2), false); - $offset += 2; - if($reliability === 2 - or $reliability === 3 - or $reliability === 4 - or $reliability === 6 - or $reliability === 7){ - $messageIndex = Utils::readTriad(strrev(substr($raw, $offset, 3))); - $offset += 3; - }else{ - $messageIndex = 0; - } - - if($reliability === 1 - or $reliability === 3 - or $reliability === 4 - or $reliability === 7){ - $orderIndex = Utils::readTriad(strrev(substr($raw, $offset, 3))); - $offset += 3; - $orderChannel = ord($raw{$offset}); //5 bits, 32 values - ++$offset; - }else{ - $orderIndex = 0; - $orderChannel = 0; - } - - if($hasSplit === 1){ - $splitCount = Utils::readInt(substr($raw, $offset, 4)); - $offset += 4; - $splitID = Utils::readShort(substr($raw, $offset, 2)); - $offset += 2; - $splitIndex = Utils::readInt(substr($raw, $offset, 4)); - $offset += 4; - //error! no split packets allowed! - break; - }else{ - $splitCount = 0; - $splitID = 0; - $splitIndex = 0; - } - - if($length == 0 - or $orderChannel >= 32 - or ($hasSplit === 1 and $splitIndex >= $splitCount)){ - continue; - } - $ln = ceil($length / 8); - $id = ord($raw{$offset}); - ++$offset; - $pak = substr($raw, $offset, $ln - 1); - $offset += $ln - 1; - $pk = new CustomPacketHandler($id, $pak); - $pk->data["length"] = $ln; - $pk->data["id"] = $id; - $pk->data["counter"] = $messageIndex; - $pk->data["packetName"] = $pk->name; - $this->data["packets"][] = array($pid, $pk->data, $pak); - } - break; - case "magic": - $this->data[] = $this->get(16); - break; - case "triad": - $this->data[] = Utils::readTriad($this->get(3)); - break; - case "itriad": - $this->data[] = Utils::readTriad(strrev($this->get(3))); - break; - case "int": - $this->data[] = Utils::readInt($this->get(4)); - break; - case "string": - $this->data[] = $this->get(Utils::readShort($this->get(2))); - break; - case "long": - $this->data[] = Utils::readLong($this->get(8)); - break; - case "byte": - $this->data[] = Utils::readByte($this->get(1)); - break; - case "ubyte": - $this->data[] = ord($this->get(1)); - break; - case "float": - $this->data[] = Utils::readFloat($this->get(4)); - break; - case "double": - $this->data[] = Utils::readDouble($this->get(8)); - break; - case "ushort": - $this->data[] = Utils::readShort($this->get(2), false); - break; - case "short": - $this->data[] = Utils::readShort($this->get(2)); - break; - case "bool": - case "boolean": - $this->data[] = Utils::readBool($this->get(1)); - break; - } - } - } - - - - -} \ No newline at end of file diff --git a/src/network/raknet/RakNetDataPacket.php b/src/network/raknet/RakNetDataPacket.php new file mode 100644 index 000000000..707e9326c --- /dev/null +++ b/src/network/raknet/RakNetDataPacket.php @@ -0,0 +1,161 @@ +setBuffer(); + } + + public function setBuffer($buffer = ""){ + $this->buffer = $buffer; + $this->offset = 0; + } + + public function getBuffer(){ + return $this->buffer; + } + + protected function get($len){ + if($len <= 0){ + return ""; + } + if($len === true){ + return substr($this->buffer, $this->offset); + } + $this->offset += $len; + return substr($this->buffer, $this->offset - $len, $len); + } + + protected function put($str){ + $this->buffer .= $str; + } + + protected function getLong($unsigned = false){ + return Utils::readLong($this->get(8), $unsigned); + } + + protected function putLong($v){ + $this->buffer .= Utils::writeLong($v); + } + + protected function getInt($unsigned = false){ + return Utils::readInt($this->get(4), $unsigned); + } + + protected function putInt($v){ + $this->buffer .= Utils::writeInt($v); + } + + protected function getShort($unsigned = false){ + return Utils::readShort($this->get(2), $unsigned); + } + + protected function putShort($v){ + $this->buffer .= Utils::writeShort($v); + } + + protected function getTriad(){ + return Utils::readTriad($this->get(3)); + } + + protected function putTriad($v){ + $this->buffer .= Utils::putTriad($v); + } + + protected function getLTriad(){ + return Utils::readTriad(strrev($this->get(3))); + } + + protected function putLTriad($v){ + $this->buffer .= strrev(Utils::putTriad($v)); + } + + protected function getByte(){ + return ord($this->get(1)); + } + + protected function putByte($v){ + $this->buffer .= chr($v); + } + + protected function getDataArray($len = 10){ + $data = array(); + for($i = 1; $i <= $len and !$this->feof(); ++$i){ + $data[] = $this->get($this->getTriad()); + } + return $data; + } + + protected function putDataArray(array $data = array()){ + foreach($data as $v){ + $this->putTriad(strlen($v)); + $this->put($v); + } + } + + protected function getSlot(){ + $id = $this->getShort(); + $cnt = $this->getByte(); + return BlockAPI::getItem( + $id, + $this->getShort(), + $cnt + ); + } + + protected function putSlot(Item $item){ + $this->putShort($item->getID()); + $this->putByte($item->count); + $this->putShort($item->getMetadata()); + } + + protected function getString(){ + return $this->get($this->getShort(true)); + } + + protected function putString($v){ + $this->putShort(strlen($v)); + $this->put($v); + } + + protected function feof(){ + return !isset($this->buffer{$this->offset}); + } +} \ No newline at end of file diff --git a/src/network/raknet/RakNetInfo.php b/src/network/raknet/RakNetInfo.php index 1365983b5..ca28de7c8 100644 --- a/src/network/raknet/RakNetInfo.php +++ b/src/network/raknet/RakNetInfo.php @@ -91,163 +91,4 @@ class RakNetInfo{ return false; } } -} - -class Protocol{ - public static $raknet = array( - 0x01 => array( - "long", //Ping ID - "magic", - ), - 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", - "special1", //Security Cookie - "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", - "customData", - ), - - - 0x81 => array( - "itriad", - "customData", - ), - - 0x82 => array( - "itriad", - "customData", - ), - - 0x83 => array( - "itriad", - "customData", - ), - - 0x84 => array( - "itriad", - "customData", - ), - - 0x85 => array( - "itriad", - "customData", - ), - - 0x86 => array( - "itriad", - "customData", - ), - - 0x87 => array( - "itriad", - "customData", - ), - - 0x88 => array( - "itriad", - "customData", - ), - - 0x89 => array( - "itriad", - "customData", - ), - - 0x8a => array( - "itriad", - "customData", - ), - - 0x8b => array( - "itriad", - "customData", - ), - - 0x8c => array( - "itriad", - "customData", - ), - - 0x8d => array( - "itriad", - "customData", - ), - - 0x8e => array( - "itriad", - "customData", - ), - - 0x8f => array( - "itriad", - "ubyte", - "customData", - ), - - 0x99 => array( - "byte", - "special1", - ), - - 0xa0 => array( - "special1", - ), - - 0xc0 => array( - "special1", - ), - - ); - } \ No newline at end of file diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index 63c92323b..e33633f07 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -20,7 +20,7 @@ */ class RakNetParser{ - + private $id = -1; private $buffer; private $offset; private $packet; @@ -29,12 +29,17 @@ class RakNetParser{ $this->buffer = $buffer; $this->offset = 0; if(strlen($this->buffer) > 0){ - $this->parse(ord($this->get(1))); + $this->id = ord($this->get(1)); + $this->parse(); }else{ $this->packet = false; } } + public function pid(){ + return (int) $this->pid; + } + private function get($len){ if($len <= 0){ return ""; @@ -71,43 +76,43 @@ class RakNetParser{ return !isset($this->buffer{$this->offset}); } - private function parse($packetID){ - $this->packet = new RakNetPacket($packetID); + private function parse(){ + $this->packet = new RakNetPacket($this->pid()); $this->packet->length = strlen($this->buffer); - switch($packetID){ - case RAKNET_UNCONNECTED_PING: - case RAKNET_UNCONNECTED_PING_OPEN_CONNECTIONS: + switch($this->pid()){ + case RakNetInfo::UNCONNECTED_PING: + case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS: $this->packet->pingID = $this->getLong(); $this->offset += 16; //Magic break; - case RAKNET_OPEN_CONNECTION_REQUEST_1: + case RakNetInfo::OPEN_CONNECTION_REQUEST_1: $this->offset += 16; //Magic $this->packet->structure = $this->getByte(); $this->packet->MTU = strlen($this->get(true)); break; - case RAKNET_OPEN_CONNECTION_REQUEST_2: + case RakNetInfo::OPEN_CONNECTION_REQUEST_2: $this->offset += 16; //Magic $this->packet->security = $this->get(5); $this->packet->port = $this->getShort(false); $this->packet->MTU = $this->getShort(false); $this->packet->clientGUID = $this->getLong(); break; - case RAKNET_DATA_PACKET_0: - case RAKNET_DATA_PACKET_1: - case RAKNET_DATA_PACKET_2: - case RAKNET_DATA_PACKET_3: - case RAKNET_DATA_PACKET_4: - case RAKNET_DATA_PACKET_5: - case RAKNET_DATA_PACKET_6: - case RAKNET_DATA_PACKET_7: - case RAKNET_DATA_PACKET_8: - case RAKNET_DATA_PACKET_9: - case RAKNET_DATA_PACKET_A: - case RAKNET_DATA_PACKET_B: - case RAKNET_DATA_PACKET_C: - case RAKNET_DATA_PACKET_D: - case RAKNET_DATA_PACKET_E: - case RAKNET_DATA_PACKET_F: + case RakNetInfo::DATA_PACKET_0: + case RakNetInfo::DATA_PACKET_1: + case RakNetInfo::DATA_PACKET_2: + case RakNetInfo::DATA_PACKET_3: + case RakNetInfo::DATA_PACKET_4: + case RakNetInfo::DATA_PACKET_5: + case RakNetInfo::DATA_PACKET_6: + case RakNetInfo::DATA_PACKET_7: + case RakNetInfo::DATA_PACKET_8: + case RakNetInfo::DATA_PACKET_9: + case RakNetInfo::DATA_PACKET_A: + case RakNetInfo::DATA_PACKET_B: + case RakNetInfo::DATA_PACKET_C: + case RakNetInfo::DATA_PACKET_D: + case RakNetInfo::DATA_PACKET_E: + case RakNetInfo::DATA_PACKET_F: $this->seqNumber = $this->getLTriad(); $this->data = array(); while(!$this->feof()){ @@ -121,52 +126,65 @@ class RakNetParser{ } private function parseDataPacket(){ - $data = new DataPacket; - $data->pid = $this->getByte(); - $data->reliability = ($data->pid & 0b11100000) >> 5; - $data->hasSplit = ($data->pid & 0b00010000) > 0; - $data->length = (int) ceil($this->getShort() / 8); - if($data->reliability === 2 - or $data->reliability === 3 - or $data->reliability === 4 - or $data->reliability === 6 - or $data->reliability === 7){ - $data->messageIndex = $this->getLTriad(); + $packetFlags = $this->getByte(); + $reliability = ($packetFlags & 0b11100000) >> 5; + $hasSplit = ($packetFlags & 0b00010000) > 0; + $length = (int) ceil($this->getShort() / 8); + if($reliability === 2 + or $reliability === 3 + or $reliability === 4 + or $reliability === 6 + or $reliability === 7){ + $messageIndex = $this->getLTriad(); }else{ - $data->messageIndex = 0; + $messageIndex = 0; } if($reliability === 1 or $reliability === 3 or $reliability === 4 or $reliability === 7){ - $data->orderIndex = $this->getLTriad(); - $data->orderChannel = $this->getByte(); + $orderIndex = $this->getLTriad(); + $orderChannel = $this->getByte(); }else{ - $data->orderIndex = 0; - $data->orderChannel = 0; + $orderIndex = 0; + $orderChannel = 0; } - if($data->hasSplit == true){ - $data->splitCount = $this->getInt(); - $data->splitID = $this->getShort(); - $data->splitIndex = $this->getInt(); + if($hasSplit == true){ + $splitCount = $this->getInt(); + $splitID = $this->getShort(); + $splitIndex = $this->getInt(); //error! no split packets allowed! return false; }else{ - $data->splitCount = 0; - $data->splitID = 0; - $data->splitIndex = 0; + $splitCount = 0; + $splitID = 0; + $splitIndex = 0; } - if($data->length <= 0 - or $this->orderChannel >= 32 + if($length <= 0 + or $orderChannel >= 32 or ($hasSplit === 1 and $splitIndex >= $splitCount)){ return false; } - $data->id = $this->getByte(); - $data->raw = $this->get($len - 1); + $pid = $this->getByte(); + if(isset(ProtocolInfo::$packets[$pid])){ + $data = new ProtocolInfo::$packets[$pid]; + }else{ + $data = new UnknownPacket(); + $data->packetID = $pid; + } + $data->reliability = $reliability; + $data->hasSplit = $hasSplit == true; + $data->messageIndex = $messageIndex; + $data->orderIndex = $orderIndex; + $data->orderChannel = $orderChannel; + $data->splitCount = $splitCount; + $data->splitID = $splitID; + $data->splitIndex = $splitIndex; + $data->setBuffer($this->get($length - 1)); return $data; }