From 0205880f99ad28c054352a95cba1a0ea8d053573 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sun, 25 Nov 2012 20:27:33 +0100 Subject: [PATCH] better custom packet handling --- classes/CustomPacketHandler.class.php | 19 ++++++++++++++++++- classes/Packet.class.php | 20 +++++++++++++++----- classes/PocketMinecraftClient.class.php | 8 ++++---- classes/PocketMinecraftServer.class.php | 4 +++- classes/SerializedPacketHandler.class.php | 6 ------ classes/Session.class.php | 18 ++++++++++++++++-- pstruct/dataName.php | 3 ++- pstruct/packetName.php | 8 ++++---- 8 files changed, 62 insertions(+), 24 deletions(-) diff --git a/classes/CustomPacketHandler.class.php b/classes/CustomPacketHandler.class.php index 719649ef9..2ebce5fb5 100644 --- a/classes/CustomPacketHandler.class.php +++ b/classes/CustomPacketHandler.class.php @@ -78,7 +78,24 @@ class CustomPacketHandler{ $this->data["time"] = Utils::readInt($this->get(4)); }else{ $this->raw .= Utils::writeInt($this->data["time"]); - } + } + break; + case 0x87: + if($this->c === false){ + $this->data["seed"] = $this->get(8); + $this->data["unknown1"] = $this->get(4); + $this->data["unknown2"] = $this->get(4); + $this->data["spawnX"] = Utils::readFloat($this->get(4)); + $this->data["spawnY"] = Utils::readFloat($this->get(4)); + $this->data["spawnZ"] = Utils::readFloat($this->get(4)); + }else{ + $this->raw .= $this->data["seed"]; + $this->raw .= "\x00\x00\x00\x01\x00\x00\x00\x05"; + $this->raw .= "\x43\x00\x80\x00\x42\x82\x00\x00\x43\x00\x80\x00"; + /*$this->raw .= Utils::writeFloat($this->data["spawnX"]); + $this->raw .= Utils::writeFloat($this->data["spawnY"]); + $this->raw .= Utils::writeFloat($this->data["spawnZ"]);*/ + } break; case 0x09: if($this->c === false){ diff --git a/classes/Packet.class.php b/classes/Packet.class.php index 7c165a69d..b31961ea2 100644 --- a/classes/Packet.class.php +++ b/classes/Packet.class.php @@ -71,11 +71,21 @@ class Packet{ } break; case "customData": - $reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true); - $this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3)); - $this->addRaw(Utils::writeTriad($this->data[$field]["count"])); - $this->addRaw(chr($this->data[$field]["id"])); - $this->addRaw($reply->raw); + switch($this->data[1]){ + case 0x40: + $reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true); + $this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3)); + $this->addRaw(Utils::writeTriad($this->data[$field]["count"])); + $this->addRaw(chr($this->data[$field]["id"])); + $this->addRaw($reply->raw); + break; + case 0x00: + $reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true); + $this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3)); + $this->addRaw(chr($this->data[$field]["id"])); + $this->addRaw($reply->raw); + break; + } break; case "magic": $this->addRaw(MAGIC); diff --git a/classes/PocketMinecraftClient.class.php b/classes/PocketMinecraftClient.class.php index a7dad1cfb..048452396 100644 --- a/classes/PocketMinecraftClient.class.php +++ b/classes/PocketMinecraftClient.class.php @@ -114,7 +114,7 @@ class PocketMinecraftClient{ $serverID = $data[1]; $this->send(0x84, array( $this->counter[0], - 0x40, + 0x00, array( "id" => 0x09, "clientID" => $this->clientID, @@ -132,7 +132,7 @@ class PocketMinecraftClient{ case 0x00: $this->send(0x84, array( $this->counter[0], - 0x40, + 0x00, array( "id" => 0x00, "payload" => $data["payload"], @@ -143,7 +143,7 @@ class PocketMinecraftClient{ case 0x10: $this->send(0x84, array( $this->counter[0], - 0x40, + 0x00, array( "id" => 0x13, "port" => 19132, @@ -154,7 +154,7 @@ class PocketMinecraftClient{ ++$this->counter[0]; $this->send(0x84, array( $this->counter[0], - 0x40, + 0x00, array( "id" => 0x82, "username" => $this->username, diff --git a/classes/PocketMinecraftServer.class.php b/classes/PocketMinecraftServer.class.php index c5f0a0753..e0b9c4a41 100644 --- a/classes/PocketMinecraftServer.class.php +++ b/classes/PocketMinecraftServer.class.php @@ -28,13 +28,15 @@ the Free Software Foundation, either version 3 of the License, or require_once("classes/Session.class.php"); class PocketMinecraftServer{ - protected $interface, $protocol, $entities, $player, $cnt, $events, $username, $version, $clients, $serverType; + var $seed, $protocol; + protected $interface, $entities, $player, $cnt, $events, $username, $version, $clients, $serverType; function __construct($username, $protocol = CURRENT_PROTOCOL, $version = CURRENT_VERSION){ //$this->player = new Player($username); $this->version = (int) $version; $this->username = $username; $this->cnt = 1; $this->serverID = substr(Utils::generateKey(), 0, 8); + $this->seed = "\x4f\xf0\x2d\x84\x00\x00\x00\x00"; $this->events = array("disabled" => array()); $this->actions = array(); $this->clients = array(); diff --git a/classes/SerializedPacketHandler.class.php b/classes/SerializedPacketHandler.class.php index cba7ae7cc..d03106dc6 100644 --- a/classes/SerializedPacketHandler.class.php +++ b/classes/SerializedPacketHandler.class.php @@ -77,12 +77,6 @@ class SerializedPacketHandler{ } $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; } } diff --git a/classes/Session.class.php b/classes/Session.class.php index 11480ef0d..19d2dc6f7 100644 --- a/classes/Session.class.php +++ b/classes/Session.class.php @@ -86,9 +86,9 @@ class Session{ $this->close("client disconnect"); break; case 0x09: - $this->send(0x84, array( + $this->send(0x88, array( $this->counter[0], - 0x40, + 0x00, array( "id" => 0x10, "count" => 0, @@ -98,10 +98,24 @@ class Session{ )); ++$this->counter[0]; break; + case 0x82: $this->username = $data["username"]; console("[INFO] User ".$this->username." connected from ".$this->ip.":".$this->port); + $this->send(0x84, array( + $this->counter[0], + 0x00, + array( + "id" => 0x87, + "seed" => $this->server->seed, + "spawnX" => 0, + "spawnY" => 100, + "spawnZ" => 0, + ), + )); + ++$this->counter[0]; break; + } break; case 0x8c: diff --git a/pstruct/dataName.php b/pstruct/dataName.php index 5dfe91161..d268b8254 100644 --- a/pstruct/dataName.php +++ b/pstruct/dataName.php @@ -35,7 +35,8 @@ $dataName = array( 0x83 => "LoginStatus", 0x84 => "Ready", 0x85 => "Message", - 0x66 => "SetTime", + 0x86 => "SetTime", + 0x87 => "StartGame", 0x93 => "MoveEntity_PosRot", diff --git a/pstruct/packetName.php b/pstruct/packetName.php index 061f00e55..375259cc5 100644 --- a/pstruct/packetName.php +++ b/pstruct/packetName.php @@ -34,10 +34,10 @@ $packetName = array( 0x1a => "ID_INCOMPATIBLE_PROTOCOL_VERSION", //RakNet 0x1c => "ID_UNCONNECTED_PONG", //RakNet 0x1d => "ID_ADVERTISE_SYSTEM", //RakNet - 0x80 => "Unknown", //Minecraft Implementation - 0x84 => "Data Packet", //Minecraft Implementation - 0x88 => "Unknown", //Minecraft Implementation - 0x8c => "Unknown", //Minecraft Implementation + 0x80 => "Custom Packet", //Minecraft Implementation + 0x84 => "Custom Packet", //Minecraft Implementation + 0x88 => "Custom Packet", //Minecraft Implementation + 0x8c => "Custom Packet", //Minecraft Implementation 0xa0 => "Unknown", //Minecraft Implementation 0xc0 => "ACK", //Minecraft Implementation ); \ No newline at end of file