New packets and fields

This commit is contained in:
Shoghi Cervantes Pueyo 2012-10-20 16:30:52 +02:00
parent 0dc53c2bc1
commit 9c4abf49f5
4 changed files with 57 additions and 44 deletions

View File

@ -26,7 +26,7 @@ the Free Software Foundation, either version 3 of the License, or
*/ */
class MinecraftInterface{ 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){ function __construct($server, $protocol = CURRENT_PROTOCOL, $port = 25565, $listen = false, $client = true){
$this->server = new Socket($server, $port, (bool) $listen); $this->server = new Socket($server, $port, (bool) $listen);
@ -35,6 +35,7 @@ class MinecraftInterface{
require("pstruct/packetName.php"); require("pstruct/packetName.php");
$this->pstruct = $pstruct; $this->pstruct = $pstruct;
$this->name = $packetName; $this->name = $packetName;
$this->client = (bool) $client;
} }
public function close(){ public function close(){
@ -50,11 +51,11 @@ class MinecraftInterface{
protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){ protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){
if(LOG === true and DEBUG >= 2){ 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); $p .= hexdump($raw, false, false, true);
if(is_array($data)){ if(is_array($data)){
foreach($data as $i => $d){ 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; $p .= PHP_EOL;

View File

@ -81,24 +81,34 @@ class PocketMinecraftServer{
case 0x05: case 0x05:
$version = $data[1]; $version = $data[1];
$size = strlen($data[2]); $size = strlen($data[2]);
console("[DEBUG] ".$packet["ip"].":".$packet["port"]." v".$version." handshake (".$size.")", true, true, 2); console("[DEBUG] ".$packet["ip"].":".$packet["port"]." v".$version." MTU Sizing ".$size, true, true, 2);
$this->send(0x06, array( if($version != 5){
MAGIC, $this->send(0x1a, array(
$this->serverID, 5,
0, MAGIC,
strlen($packet["raw"]), $this->serverID,
), false, $packet["ip"], $packet["port"]); ), false, $packet["ip"], $packet["port"]);
}else{
$this->send(0x06, array(
MAGIC,
$this->serverID,
0,
strlen($packet["raw"]),
), false, $packet["ip"], $packet["port"]);
}
break; break;
case 0x07: case 0x07:
$port = $data[2]; $port = $data[2];
$MTU = $data[3]; $MTU = $data[3];
$clientID = $data[4]; $clientID = $data[4];
//console("[DEBUG] ".$packet["ip"].":".$packet["port"]." v".$version." response (".$size.")", true, true, 2); //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( $this->send(0x08, array(
MAGIC, MAGIC,
$this->serverID, $this->serverID,
$data[1], $packet["port"],
$MTU,
0,
), false, $packet["ip"], $packet["port"]); ), false, $packet["ip"], $packet["port"]);
break; break;
case 0x84: case 0x84:

View File

@ -27,55 +27,57 @@ the Free Software Foundation, either version 3 of the License, or
$pstruct = array( $pstruct = array(
0x02 => array( 0x02 => array(
"double", "double", //Ping ID
"magic", "magic",
), ),
0x05 => array( 0x05 => array(
"magic", "magic",
"byte", "byte", //Protocol Version
"special1", "special1", //MTU Size Null Lenght
), ),
0x06 => array( 0x06 => array(
"magic", "magic",
8, 8, //Server GUID
"byte", "byte", //Server Security
"short", "short", //MTU Size
), ),
0x07 => array( 0x07 => array(
"magic", "magic",
5, 5, //Security Cookie (idk why it's sent here)
"short", "short", //Server UDP Port
"short", "short", //MTU Size
8, 8, //Client GUID
), ),
0x08 => array( 0x08 => array(
"magic", "magic",
8, 8, //Server GUID
5, "short", //Client UDP Port
"short", //MTU Size
"byte", //Security
), ),
0x09 => array( 0x1a => array(
8, "byte", //Server Version
"double", "magic",
"byte", 8, //Server GUID
), ),
0x1c => array( 0x1c => array(
"double", "double", //Ping ID
8, 8, //Server ID
"magic", "magic",
"string", "string", //Data
), ),
0x1d => array( 0x1d => array(
"double", "double", //Ping ID
8, 8, //Server ID
"magic", "magic",
"string", "string", //Data
), ),
0x84 => array( 0x84 => array(

View File

@ -26,14 +26,14 @@ the Free Software Foundation, either version 3 of the License, or
*/ */
$packetName = array( $packetName = array(
0x02 => "ID_UNCONNECTED_PING_OPEN_CONNECTIONS", 0x02 => "ID_UNCONNECTED_PING_OPEN_CONNECTIONS", //RakNet
0x05 => "ID_OPEN_CONNECTION_REQUEST_1", 0x05 => "ID_OPEN_CONNECTION_REQUEST_1", //RakNet
0x06 => "ID_OPEN_CONNECTION_REPLY_1", 0x06 => "ID_OPEN_CONNECTION_REPLY_1", //RakNet
0x07 => "ID_OPEN_CONNECTION_REQUEST_2", 0x07 => "ID_OPEN_CONNECTION_REQUEST_2", //RakNet
0x08 => "ID_OPEN_CONNECTION_REPLY_2", 0x08 => "ID_OPEN_CONNECTION_REPLY_2", //RakNet
0x09 => "ID_CONNECTION_REQUEST", 0x1a => "ID_INCOMPATIBLE_PROTOCOL_VERSION", //RakNet
0x1c => "ID_UNCONNECTED_PONG", 0x1c => "ID_UNCONNECTED_PONG", //RakNet
0x1d => "ID_ADVERTISE_SYSTEM", 0x1d => "ID_ADVERTISE_SYSTEM", //RakNet
0x84 => "Unknown", 0x84 => "ID_RESERVED_7", //Minecraft Implementation
0xc0 => "Unknown", 0xc0 => "Unknown", //Minecraft Implementation
); );