From c104e21ef06c4e2f7997a22fa3f8a1280ad0d698 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 23 Nov 2012 19:19:58 +0100 Subject: [PATCH] Full Data packet handling --- classes/CustomPacketHandler.class.php | 42 +++------- classes/Packet.class.php | 3 +- classes/PocketMinecraftClient.class.php | 11 +++ classes/SerializedPacketHandler.class.php | 93 +++++++++++++++++++++++ common/dependencies.php | 1 + pstruct/dataName.php | 4 + 6 files changed, 119 insertions(+), 35 deletions(-) create mode 100644 classes/SerializedPacketHandler.class.php diff --git a/classes/CustomPacketHandler.class.php b/classes/CustomPacketHandler.class.php index 5cc21c358..79059381a 100644 --- a/classes/CustomPacketHandler.class.php +++ b/classes/CustomPacketHandler.class.php @@ -49,47 +49,23 @@ class CustomPacketHandler{ $this->offset = 0; $this->c = (bool) $create; switch($pid){ - case 0x60: - case 0x40: - if($this->c === false){ - $this->data["packets"] = array(); - $i = 0; - while($this->offset < strlen($this->raw)){ - if($i > 0){ - $pid = ord($this->get(1)); - } - $len = Utils::readShort($this->get(2), false) >> 3; - $c = Utils::readTriad($this->get(3)); - if($pid === 0x60 and $i === 0){ - $this->data["unknown1"] = $this->get(4); - } - $id = ord($this->get(1)); - $raw = $this->get($len - 1); - $pk = new CustomPacketHandler($id, $raw); - $pk->data["length"] = $len; - $pk->data["id"] = $id; - $pk->data["counter"] = $c; - $pk->data["packetName"] = $pk->name; - $this->data["packets"][] = array($pid, $pk->data, $raw); - if($pid === 0x60 and $i === 0){ - $l = $this->get(3); - if(strlen($l) === 3){ - $this->data["unknown2"] = $this->get(Utils::readTriad($l)); - } - } - ++$i; - } - } - break; case 0x82: if($this->c === false){ $this->data["username"] = $this->get(Utils::readShort($this->get(2), false)); - $this->data["unknown1"] = $this->get(8); + $this->data["unknown1"] = Utils::readInt($this->get(4)); + $this->data["unknown2"] = Utils::readInt($this->get(4)); }else{ $this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"]; $this->raw .= "\x00\x00\x00\x07\x00\x00\x00\x07"; } break; + case 0x85: + if($this->c === false){ + $this->data["message"] = $this->get(ord($this->get(1))); + }else{ + $this->raw .= chr(strlen($this->data["message"])).$this->data["message"]; + } + break; case 0x86: if($this->c === false){ $this->data["time"] = Utils::readInt($this->get(4)); diff --git a/classes/Packet.class.php b/classes/Packet.class.php index 3d9ae82c3..7c165a69d 100644 --- a/classes/Packet.class.php +++ b/classes/Packet.class.php @@ -165,8 +165,7 @@ class Packet{ } break; case "customData": - $d = new CustomPacketHandler($this->data[1], $this->get(true)); - $d->data["packetName"] = $d->name; + $d = new SerializedPacketHandler($this->data[1], $this->get(true)); if(isset($d->data["packets"])){ $this->data["packets"] = $d->data["packets"]; }else{ diff --git a/classes/PocketMinecraftClient.class.php b/classes/PocketMinecraftClient.class.php index ebf90192c..a7dad1cfb 100644 --- a/classes/PocketMinecraftClient.class.php +++ b/classes/PocketMinecraftClient.class.php @@ -129,6 +129,17 @@ class PocketMinecraftClient{ $this->send(0xc0, array(1, true, $data[0])); } switch($data["id"]){ + case 0x00: + $this->send(0x84, array( + $this->counter[0], + 0x40, + array( + "id" => 0x00, + "payload" => $data["payload"], + ), + )); + ++$this->counter[0]; + break; case 0x10: $this->send(0x84, array( $this->counter[0], diff --git a/classes/SerializedPacketHandler.class.php b/classes/SerializedPacketHandler.class.php new file mode 100644 index 000000000..7a742250e --- /dev/null +++ b/classes/SerializedPacketHandler.class.php @@ -0,0 +1,93 @@ +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; + } + + public function __construct($pid, $raw = "", $data = array(), $create = false){ + $this->raw = $raw; + $this->data = $data; + $this->offset = 0; + $this->c = (bool) $create; + switch($pid){ + case 0x60: + case 0x40: + case 0x00: + if($this->c === false){ + $this->data["packets"] = array(); + $i = 0; + while($this->offset < strlen($this->raw)){ + if($i > 0){ + $pid = ord($this->get(1)); + } + + $len = Utils::readShort($this->get(2), false) >> 3; + if($pid !== 0x00){ + $c = Utils::readTriad($this->get(3)); + } + if($pid === 0x60 and $i === 0){ + $this->data["unknown1"] = $this->get(4); + } + $id = ord($this->get(1)); + $raw = $this->get($len - 1); + $pk = new CustomPacketHandler($id, $raw); + $pk->data["length"] = $len; + $pk->data["id"] = $id; + if($pid !== 0x00 and $i === 0){ + $pk->data["counter"] = $c; + } + $pk->data["packetName"] = $pk->name; + $this->data["packets"][] = array($pid, $pk->data, $raw); + if($pid === 0x60 and $i === 0){ + $l = $this->get(3); + if(strlen($l) === 3){ + $this->data["unknown2"] = $this->get(Utils::readTriad($l)); + } + } + ++$i; + } + } + break; + } + } + +} \ No newline at end of file diff --git a/common/dependencies.php b/common/dependencies.php index 390a2a069..b8cb3a2dd 100644 --- a/common/dependencies.php +++ b/common/dependencies.php @@ -72,6 +72,7 @@ if($errors > 0){ require_once("classes/Utils.class.php"); require_once("classes/Socket.class.php"); require_once("classes/Packet.class.php"); +require_once("classes/SerializedPacketHandler.class.php"); require_once("classes/CustomPacketHandler.class.php"); require_once("classes/MinecraftInterface.class.php"); diff --git a/pstruct/dataName.php b/pstruct/dataName.php index ff1a3794e..5dfe91161 100644 --- a/pstruct/dataName.php +++ b/pstruct/dataName.php @@ -36,4 +36,8 @@ $dataName = array( 0x84 => "Ready", 0x85 => "Message", 0x66 => "SetTime", + + 0x93 => "MoveEntity_PosRot", + + 0xa4 => "SetEntityMotion", ); \ No newline at end of file