Multiple tree packet handling

This commit is contained in:
Shoghi Cervantes Pueyo 2012-11-22 20:14:36 +01:00
parent aae04b8dfd
commit 4daf7840d8
4 changed files with 41 additions and 16 deletions

View File

@ -52,30 +52,50 @@ class CustomPacketHandler{
case 0x60: case 0x60:
case 0x40: case 0x40:
if($this->c === false){ if($this->c === false){
$this->data["counter"] = Utils::readTriad($this->get(3));
if($pid === 0x60){
$this->data["unknown1"] = $this->get(4);
}
$this->data["packets"] = array(); $this->data["packets"] = array();
$i = 0;
while($this->offset < strlen($this->raw)){ 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)); $id = ord($this->get(1));
$raw = $this->get(true); $raw = $this->get($len - 1);
$pk = new CustomPacketHandler($id, $raw); $pk = new CustomPacketHandler($id, $raw);
$pk->data["lenght"] = $len;
$pk->data["id"] = $id; $pk->data["id"] = $id;
$pk->data["counter"] = $c;
$pk->data["packetName"] = $pk->name; $pk->data["packetName"] = $pk->name;
$this->data["packets"][] = array($pid, $pk->data, $raw); $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; break;
case 0x82: case 0x82:
if($this->c === false){ if($this->c === false){
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false)); $this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
$this->data["unknown1"] = $this->get(5); $this->data["unknown1"] = $this->get(8);
}else{ }else{
$this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"]; $this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"];
$this->raw .= "\x00\x00\x00\x08\x00"; $this->raw .= "\x00\x00\x00\x07\x00\x00\x00\x07";
} }
break; break;
case 0x86:
if($this->c === false){
$this->data["time"] = Utils::readInt($this->get(4));
}else{
$this->raw .= Utils::writeInt($this->data["time"]);
}
break; break;
case 0x09: case 0x09:
if($this->c === false){ if($this->c === false){
@ -132,12 +152,13 @@ class CustomPacketHandler{
$this->data["unknown2"] = $this->get(13); $this->data["unknown2"] = $this->get(13);
}else{ }else{
$this->raw .= "\x04\x3f\x57\xff"; $this->raw .= "\x04\x3f\x57\xff";
$this->raw .= "\x3d"; $this->raw .= "\x3e";
$this->raw .= Utils::writeShort($this->data["port"]); $this->raw .= Utils::writeShort($this->data["port"]);
$w = array_shift($this->data["dataArray"]); $w = array_shift($this->data["dataArray"]);
$this->raw .= chr(strlen($w)).$w; $this->raw .= chr(strlen($w)).$w;
$this->raw .= Utils::writeDataArray($this->data["dataArray"]); $this->raw .= Utils::writeDataArray($this->data["dataArray"]);
$this->raw .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; $this->raw .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$this->raw .= "\x00\xae\x21\x4e";
} }
break; break;
} }

View File

@ -102,17 +102,17 @@ class MinecraftInterface{
$packet->protocol = $this->protocol; $packet->protocol = $this->protocol;
$packet->parse(); $packet->parse();
$this->data[] = array($pid, $packet->data, $data[0], $data[1], $data[2]); $this->data[] = array($pid, $packet->data, $data[0], $data[1], $data[2]);
if(isset($packet->data["packets"]) and is_array($packet->data["packets"])){
foreach($packet->data["packets"] as $p){
$this->data[] = array($pid, $p[1], $p[2], $data[1], $data[2]);
}
}
return $this->popPacket(); return $this->popPacket();
} }
public function popPacket(){ public function popPacket(){
if(count($this->data) > 0){ if(count($this->data) > 0){
$p = array_shift($this->data); $p = array_shift($this->data);
if(isset($p[1]["packets"]) and is_array($p[1]["packets"])){
foreach($p[1]["packets"] as $d){
$this->data[] = array($p[0], $d[1], $d[2], $p[3], $p[4]);
}
}
$c = (isset($p[1]["id"]) ? true:false); $c = (isset($p[1]["id"]) ? true:false);
$p[2] = $c ? chr($p[1]["id"]).$p[2]:$p[2]; $p[2] = $c ? chr($p[1]["id"]).$p[2]:$p[2];
$this->writeDump(($c ? $p[1]["id"]:$p[0]), $p[2], $p[1], "server", $p[3], $p[4]); $this->writeDump(($c ? $p[1]["id"]:$p[0]), $p[2], $p[1], "server", $p[3], $p[4]);

View File

@ -165,7 +165,7 @@ class Packet{
} }
break; break;
case "customData": case "customData":
$d = new CustomPacketHandler($this->data[1], $this->get(Utils::readShort($this->get(2), false) >> 3)); $d = new CustomPacketHandler($this->data[1], $this->get(true));
$d->data["packetName"] = $d->name; $d->data["packetName"] = $d->name;
if(isset($d->data["packets"])){ if(isset($d->data["packets"])){
$this->data["packets"] = $d->data["packets"]; $this->data["packets"] = $d->data["packets"];

View File

@ -137,6 +137,7 @@ class PocketMinecraftClient{
"id" => 0x13, "id" => 0x13,
"port" => 19132, "port" => 19132,
"dataArray" => $data["dataArray"], "dataArray" => $data["dataArray"],
"session" => $data["session"],
), ),
)); ));
++$this->counter[0]; ++$this->counter[0];
@ -150,6 +151,9 @@ class PocketMinecraftClient{
)); ));
++$this->counter[0]; ++$this->counter[0];
break; break;
case 0x86:
console("[DEBUG] Time: ".$data["time"], true, true, 3);
break;
} }
break; break;
} }