From ff7a61c7aea66644332a82aec116f7fce808dd59 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 23 Nov 2012 14:34:58 +0100 Subject: [PATCH] Packet names --- classes/CustomPacketHandler.class.php | 10 +++++++ classes/MinecraftInterface.class.php | 6 +++-- classes/PocketMinecraftClient.class.php | 2 +- classes/Session.class.php | 17 ++++++++++-- pstruct/dataName.php | 35 +++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 pstruct/dataName.php diff --git a/classes/CustomPacketHandler.class.php b/classes/CustomPacketHandler.class.php index 35bfc2e94..b6b86d573 100644 --- a/classes/CustomPacketHandler.class.php +++ b/classes/CustomPacketHandler.class.php @@ -161,6 +161,16 @@ class CustomPacketHandler{ $this->raw .= "\x00\xae\x21\x4e"; } break; + case 0x15: + //null + break; + case 0x00: + if($this->c === false){ + $this->data["payload"] = $this->get(8); + }else{ + $this->raw .= $this->data["payload"]; + } + break; } } diff --git a/classes/MinecraftInterface.class.php b/classes/MinecraftInterface.class.php index 4cff3d24c..1c2a7366f 100644 --- a/classes/MinecraftInterface.class.php +++ b/classes/MinecraftInterface.class.php @@ -26,15 +26,17 @@ the Free Software Foundation, either version 3 of the License, or */ class MinecraftInterface{ - var $pstruct, $name, $server, $protocol, $client, $buffer; + var $pstruct, $name, $server, $protocol, $client, $buffer, $dataName; function __construct($server, $protocol = CURRENT_PROTOCOL, $port = 25565, $listen = false, $client = true){ $this->server = new Socket($server, $port, (bool) $listen); $this->protocol = (int) $protocol; require("pstruct/RakNet.php"); require("pstruct/packetName.php"); + require("pstruct/dataName.php"); $this->pstruct = $pstruct; $this->name = $packetName; + $this->dataName = $dataName; $this->buffer = array(); $this->client = (bool) $client; $this->start = microtime(true); @@ -53,7 +55,7 @@ class MinecraftInterface{ protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){ if(LOG === true and DEBUG >= 2){ - $p = "[".(microtime(true) - $this->start)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".$this->name[$pid]." (0x".Utils::strTohex(chr($pid)).") [lenght ".strlen($raw)."]".PHP_EOL; + $p = "[".(microtime(true) - $this->start)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".(isset($data["id"]) ? "DATA ".$this->dataName[$pid]:$this->name[$pid])." (0x".Utils::strTohex(chr($pid)).") [lenght ".strlen($raw)."]".PHP_EOL; $p .= Utils::hexdump($raw); if(is_array($data)){ foreach($data as $i => $d){ diff --git a/classes/PocketMinecraftClient.class.php b/classes/PocketMinecraftClient.class.php index 8b7955c09..6d6b9975f 100644 --- a/classes/PocketMinecraftClient.class.php +++ b/classes/PocketMinecraftClient.class.php @@ -152,7 +152,7 @@ class PocketMinecraftClient{ ++$this->counter[0]; break; case 0x86: - console("[DEBUG] Time: ".$data["time"], true, true, 3); + console("[DEBUG] Time: ".$data["time"], true, true, 2); break; } break; diff --git a/classes/Session.class.php b/classes/Session.class.php index 70536cdb6..11480ef0d 100644 --- a/classes/Session.class.php +++ b/classes/Session.class.php @@ -47,10 +47,10 @@ class Session{ } } - public function close(){ + public function close($reason = "timeout"){ $this->server->deleteEvent("onTick", $this->eventID); $this->connected = false; - console("[DEBUG] Session with ".$this->ip.":".$this->port." closed due to timeout", true, true, 2); + console("[DEBUG] Session with ".$this->ip.":".$this->port." closed due to ".$reason, true, true, 2); } public function handle($pid, &$data){ @@ -72,6 +72,19 @@ class Session{ $this->send(0xc0, array(1, true, $data[0])); } switch($data["id"]){ + /*case 0x00: + $this->send(0x84, array( + $this->counter[0], + 0x40, + array( + "payload" => $data["payload"], + ), + )); + ++$this->counter[0]; + break;*/ + case 0x15: + $this->close("client disconnect"); + break; case 0x09: $this->send(0x84, array( $this->counter[0], diff --git a/pstruct/dataName.php b/pstruct/dataName.php new file mode 100644 index 000000000..5fb96f0cc --- /dev/null +++ b/pstruct/dataName.php @@ -0,0 +1,35 @@ + "KeepAlive", + 0x09 => "ClientHandshake", + 0x10 => "ServerHandshake", + 0x13 => "ClientConnect", + 0x15 => "ClientDisconnect", + 0x82 => "LoginPacket", +); \ No newline at end of file