Full Data packet handling

This commit is contained in:
Shoghi Cervantes Pueyo 2012-11-23 19:19:58 +01:00
parent 6b12832b02
commit c104e21ef0
6 changed files with 119 additions and 35 deletions

View File

@ -49,47 +49,23 @@ class CustomPacketHandler{
$this->offset = 0;
$this->c = (bool) $create;
switch($pid){
case 0x60:
case 0x40:
if($this->c === false){
$this->data["packets"] = array();
$i = 0;
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));
$raw = $this->get($len - 1);
$pk = new CustomPacketHandler($id, $raw);
$pk->data["length"] = $len;
$pk->data["id"] = $id;
$pk->data["counter"] = $c;
$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;
}
}
break;
case 0x82:
if($this->c === false){
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
$this->data["unknown1"] = $this->get(8);
$this->data["unknown1"] = Utils::readInt($this->get(4));
$this->data["unknown2"] = Utils::readInt($this->get(4));
}else{
$this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"];
$this->raw .= "\x00\x00\x00\x07\x00\x00\x00\x07";
}
break;
case 0x85:
if($this->c === false){
$this->data["message"] = $this->get(ord($this->get(1)));
}else{
$this->raw .= chr(strlen($this->data["message"])).$this->data["message"];
}
break;
case 0x86:
if($this->c === false){
$this->data["time"] = Utils::readInt($this->get(4));

View File

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

View File

@ -129,6 +129,17 @@ class PocketMinecraftClient{
$this->send(0xc0, array(1, true, $data[0]));
}
switch($data["id"]){
case 0x00:
$this->send(0x84, array(
$this->counter[0],
0x40,
array(
"id" => 0x00,
"payload" => $data["payload"],
),
));
++$this->counter[0];
break;
case 0x10:
$this->send(0x84, array(
$this->counter[0],

View File

@ -0,0 +1,93 @@
<?php
/*
-
/ \
/ \
/ POCKET \
/ MINECRAFT PHP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
class SerializedPacketHandler{
var $offset, $raw, $c, $data, $name = "";
private function get($len = true, $check = true){
if($len === true){
$data = substr($this->raw, $this->offset);
if($check === true){
$this->offset = strlen($this->raw);
}
return $data;
}
$data = substr($this->raw, $this->offset, $len);
if($check === true){
$this->offset += $len;
}
return $data;
}
public function __construct($pid, $raw = "", $data = array(), $create = false){
$this->raw = $raw;
$this->data = $data;
$this->offset = 0;
$this->c = (bool) $create;
switch($pid){
case 0x60:
case 0x40:
case 0x00:
if($this->c === false){
$this->data["packets"] = array();
$i = 0;
while($this->offset < strlen($this->raw)){
if($i > 0){
$pid = ord($this->get(1));
}
$len = Utils::readShort($this->get(2), false) >> 3;
if($pid !== 0x00){
$c = Utils::readTriad($this->get(3));
}
if($pid === 0x60 and $i === 0){
$this->data["unknown1"] = $this->get(4);
}
$id = ord($this->get(1));
$raw = $this->get($len - 1);
$pk = new CustomPacketHandler($id, $raw);
$pk->data["length"] = $len;
$pk->data["id"] = $id;
if($pid !== 0x00 and $i === 0){
$pk->data["counter"] = $c;
}
$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;
}
}
break;
}
}
}

View File

@ -72,6 +72,7 @@ if($errors > 0){
require_once("classes/Utils.class.php");
require_once("classes/Socket.class.php");
require_once("classes/Packet.class.php");
require_once("classes/SerializedPacketHandler.class.php");
require_once("classes/CustomPacketHandler.class.php");
require_once("classes/MinecraftInterface.class.php");

View File

@ -36,4 +36,8 @@ $dataName = array(
0x84 => "Ready",
0x85 => "Message",
0x66 => "SetTime",
0x93 => "MoveEntity_PosRot",
0xa4 => "SetEntityMotion",
);