From 9c4abf49f5d6841d48e853052db3ed800bfc8161 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sat, 20 Oct 2012 16:30:52 +0200 Subject: [PATCH] New packets and fields --- classes/MinecraftInterface.class.php | 7 ++-- classes/PocketMinecraftServer.class.php | 28 ++++++++++----- pstruct/RakNet.php | 46 +++++++++++++------------ pstruct/packetName.php | 20 +++++------ 4 files changed, 57 insertions(+), 44 deletions(-) diff --git a/classes/MinecraftInterface.class.php b/classes/MinecraftInterface.class.php index 2ab13bda9..2fcac65c3 100644 --- a/classes/MinecraftInterface.class.php +++ b/classes/MinecraftInterface.class.php @@ -26,7 +26,7 @@ the Free Software Foundation, either version 3 of the License, or */ class MinecraftInterface{ - var $pstruct, $name, $server, $protocol; + var $pstruct, $name, $server, $protocol, $client; function __construct($server, $protocol = CURRENT_PROTOCOL, $port = 25565, $listen = false, $client = true){ $this->server = new Socket($server, $port, (bool) $listen); @@ -35,6 +35,7 @@ class MinecraftInterface{ require("pstruct/packetName.php"); $this->pstruct = $pstruct; $this->name = $packetName; + $this->client = (bool) $client; } public function close(){ @@ -50,11 +51,11 @@ class MinecraftInterface{ protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){ if(LOG === true and DEBUG >= 2){ - $p = "[".microtime(true)."] [".((($origin === "client" and $client === true) or ($origin === "server" and $client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".$this->name[$pid]." (0x".Utils::strTohex(chr($pid)).") [lenght ".strlen($raw)."]".PHP_EOL; + $p = "[".microtime(true)."] [".((($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 .= hexdump($raw, false, false, true); if(is_array($data)){ foreach($data as $i => $d){ - $p .= $i ." => ".(!is_array($d) ? $this->pstruct[$pid][$i]."(".(($this->pstruct[$pid][$i] === "magic" or substr($this->pstruct[$pid][$i], 0, 7) === "special") ? Utils::strToHex($d):$d).")":$this->pstruct[$pid][$i]."(***)").PHP_EOL; + $p .= $i ." => ".(!is_array($d) ? $this->pstruct[$pid][$i]."(".(($this->pstruct[$pid][$i] === "magic" or substr($this->pstruct[$pid][$i], 0, 7) === "special" or is_int($this->pstruct[$pid][$i])) ? Utils::strToHex($d):$d).")":$this->pstruct[$pid][$i]."(***)").PHP_EOL; } } $p .= PHP_EOL; diff --git a/classes/PocketMinecraftServer.class.php b/classes/PocketMinecraftServer.class.php index ab0c83852..6a1335078 100644 --- a/classes/PocketMinecraftServer.class.php +++ b/classes/PocketMinecraftServer.class.php @@ -81,24 +81,34 @@ class PocketMinecraftServer{ case 0x05: $version = $data[1]; $size = strlen($data[2]); - console("[DEBUG] ".$packet["ip"].":".$packet["port"]." v".$version." handshake (".$size.")", true, true, 2); - $this->send(0x06, array( - MAGIC, - $this->serverID, - 0, - strlen($packet["raw"]), - ), false, $packet["ip"], $packet["port"]); + console("[DEBUG] ".$packet["ip"].":".$packet["port"]." v".$version." MTU Sizing ".$size, true, true, 2); + if($version != 5){ + $this->send(0x1a, array( + 5, + MAGIC, + $this->serverID, + ), false, $packet["ip"], $packet["port"]); + }else{ + $this->send(0x06, array( + MAGIC, + $this->serverID, + 0, + strlen($packet["raw"]), + ), false, $packet["ip"], $packet["port"]); + } break; case 0x07: $port = $data[2]; $MTU = $data[3]; $clientID = $data[4]; //console("[DEBUG] ".$packet["ip"].":".$packet["port"]." v".$version." response (".$size.")", true, true, 2); - $sess2 = Utils::readInt(substr(Utils::generateKey(), 0, 4)); + //$sess2 = Utils::readInt(substr(Utils::generateKey(), 0, 4)); $this->send(0x08, array( MAGIC, $this->serverID, - $data[1], + $packet["port"], + $MTU, + 0, ), false, $packet["ip"], $packet["port"]); break; case 0x84: diff --git a/pstruct/RakNet.php b/pstruct/RakNet.php index 923d05343..11d2cfc20 100644 --- a/pstruct/RakNet.php +++ b/pstruct/RakNet.php @@ -27,55 +27,57 @@ the Free Software Foundation, either version 3 of the License, or $pstruct = array( 0x02 => array( - "double", + "double", //Ping ID "magic", ), 0x05 => array( "magic", - "byte", - "special1", + "byte", //Protocol Version + "special1", //MTU Size Null Lenght ), 0x06 => array( "magic", - 8, - "byte", - "short", + 8, //Server GUID + "byte", //Server Security + "short", //MTU Size ), 0x07 => array( "magic", - 5, - "short", - "short", - 8, + 5, //Security Cookie (idk why it's sent here) + "short", //Server UDP Port + "short", //MTU Size + 8, //Client GUID ), 0x08 => array( "magic", - 8, - 5, + 8, //Server GUID + "short", //Client UDP Port + "short", //MTU Size + "byte", //Security ), - 0x09 => array( - 8, - "double", - "byte", + 0x1a => array( + "byte", //Server Version + "magic", + 8, //Server GUID ), 0x1c => array( - "double", - 8, + "double", //Ping ID + 8, //Server ID "magic", - "string", + "string", //Data ), 0x1d => array( - "double", - 8, + "double", //Ping ID + 8, //Server ID "magic", - "string", + "string", //Data ), 0x84 => array( diff --git a/pstruct/packetName.php b/pstruct/packetName.php index 80b96be96..337201972 100644 --- a/pstruct/packetName.php +++ b/pstruct/packetName.php @@ -26,14 +26,14 @@ the Free Software Foundation, either version 3 of the License, or */ $packetName = array( - 0x02 => "ID_UNCONNECTED_PING_OPEN_CONNECTIONS", - 0x05 => "ID_OPEN_CONNECTION_REQUEST_1", - 0x06 => "ID_OPEN_CONNECTION_REPLY_1", - 0x07 => "ID_OPEN_CONNECTION_REQUEST_2", - 0x08 => "ID_OPEN_CONNECTION_REPLY_2", - 0x09 => "ID_CONNECTION_REQUEST", - 0x1c => "ID_UNCONNECTED_PONG", - 0x1d => "ID_ADVERTISE_SYSTEM", - 0x84 => "Unknown", - 0xc0 => "Unknown", + 0x02 => "ID_UNCONNECTED_PING_OPEN_CONNECTIONS", //RakNet + 0x05 => "ID_OPEN_CONNECTION_REQUEST_1", //RakNet + 0x06 => "ID_OPEN_CONNECTION_REPLY_1", //RakNet + 0x07 => "ID_OPEN_CONNECTION_REQUEST_2", //RakNet + 0x08 => "ID_OPEN_CONNECTION_REPLY_2", //RakNet + 0x1a => "ID_INCOMPATIBLE_PROTOCOL_VERSION", //RakNet + 0x1c => "ID_UNCONNECTED_PONG", //RakNet + 0x1d => "ID_ADVERTISE_SYSTEM", //RakNet + 0x84 => "ID_RESERVED_7", //Minecraft Implementation + 0xc0 => "Unknown", //Minecraft Implementation ); \ No newline at end of file