mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Data packet handling!!!
This commit is contained in:
@ -26,7 +26,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
*/
|
||||
|
||||
class CustomPacketHandler{
|
||||
var $data, $name = "";
|
||||
var $offset, $raw, $c, $data, $name = "";
|
||||
|
||||
private function get($len = true, $check = true){
|
||||
if($len === true){
|
||||
@ -49,48 +49,95 @@ class CustomPacketHandler{
|
||||
$this->offset = 0;
|
||||
$this->c = (bool) $create;
|
||||
switch($pid){
|
||||
case 0x400090:
|
||||
case "clientHandshake":
|
||||
$this->name = "clientHandshake";
|
||||
case 0x60:
|
||||
case 0x40:
|
||||
if($this->c === false){
|
||||
$this->data["counter"] = Utils::readTriad($this->get(3));
|
||||
$this->data["id"] = ord($this->get(1));
|
||||
if($pid === 0x60){
|
||||
$this->data["unknown1"] = $this->get(4);
|
||||
}
|
||||
$this->data["packets"] = array();
|
||||
while($this->offset < strlen($this->raw)){
|
||||
$id = ord($this->get(1));
|
||||
$raw = $this->get(true);
|
||||
$pk = new CustomPacketHandler($id, $raw);
|
||||
$pk->data["id"] = $id;
|
||||
$pk->data["packetName"] = $pk->name;
|
||||
$this->data["packets"][] = array($pid, $pk->data, $raw);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0x82:
|
||||
if($this->c === false){
|
||||
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
$this->data["unknown1"] = $this->get(5);
|
||||
}else{
|
||||
$this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"];
|
||||
$this->raw .= "\x00\x00\x00\x08\x00";
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 0x09:
|
||||
if($this->c === false){
|
||||
$this->data["clientID"] = $this->get(8);
|
||||
$this->data["unknown1"] = $this->get(1);
|
||||
$this->data["unknown2"] = $this->get(4);
|
||||
$this->data["session"] = $this->get(4);
|
||||
}else{
|
||||
$this->raw .= Utils::writeTriad(0); //counter
|
||||
$this->raw .= chr(9);
|
||||
$this->raw .= $this->data["clientID"];
|
||||
$this->raw .= "\x00";
|
||||
$this->raw .= "\x00\x00\x00\x00";
|
||||
$this->raw .= $this->data["session"];
|
||||
}
|
||||
break;
|
||||
case 0x600300:
|
||||
case "serverHandshake":
|
||||
$this->name = "serverHandshake";
|
||||
case 0x10:
|
||||
if($this->c === false){
|
||||
$this->data["counter"] = Utils::readTriad($this->get(3));
|
||||
$this->data["id"] = ord($this->get(1));
|
||||
$this->data["unknown1"] = $this->get(4);
|
||||
$this->data["cookie"] = $this->get(4); // 043f57ff
|
||||
$this->data["unknown2"] = ord($this->get(1));
|
||||
$this->data["port"] = Utils::readShort($this->get(2));
|
||||
$this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 10);
|
||||
$this->data["unknown3"] = $this->get(1);
|
||||
$this->data["unknown4"] = $this->get(4);
|
||||
$this->data["unknown1"] = $this->get(1);
|
||||
$this->data["port"] = Utils::readShort($this->get(2), false);
|
||||
$this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 10, $offset);
|
||||
$this->get($offset);
|
||||
$this->data["unknown2"] = $this->get(7);
|
||||
$this->data["session"] = $this->get(4);
|
||||
$this->data["unknown5"] = $this->get(8);
|
||||
$this->data["unknown3"] = $this->get(7);
|
||||
}else{
|
||||
$this->raw .= Utils::writeTriad(0); //counter
|
||||
$this->raw .= chr(0);
|
||||
$this->raw .= "\x00\x00\x00\x10";
|
||||
$this->raw .= "\x04\x3f\x57\xff";
|
||||
$this->raw .= "\x00";
|
||||
$this->raw .= "\x7f";
|
||||
$this->raw .= Utils::writeShort($this->data["port"]);
|
||||
$this->raw .= Utils::writeDataArray(array(
|
||||
"\x80\xff\xff\xfe",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
));
|
||||
$this->raw .= "\x00\x00\x00\x00\x00\x00\x00";
|
||||
$this->raw .= $this->data["session"];
|
||||
$this->raw .= "\x00\x00\x00\x00\x00\x00\x00";
|
||||
}
|
||||
break;
|
||||
case 0x13:
|
||||
if($this->c === false){
|
||||
$this->data["cookie"] = $this->get(4); // 043f57ff
|
||||
$this->data["unknown1"] = $this->get(1);
|
||||
$this->data["port"] = Utils::readShort($this->get(2), false);
|
||||
$this->data["dataArray0"] = $this->get(ord($this->get(1)));
|
||||
$this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 9, $offset);
|
||||
$this->get($offset);
|
||||
$this->data["unknown2"] = $this->get(13);
|
||||
}else{
|
||||
$this->raw .= "\x04\x3f\x57\xff";
|
||||
$this->raw .= "\x3d";
|
||||
$this->raw .= Utils::writeShort($this->data["port"]);
|
||||
$w = array_shift($this->data["dataArray"]);
|
||||
$this->raw .= chr(strlen($w)).$w;
|
||||
$this->raw .= Utils::writeDataArray($this->data["dataArray"]);
|
||||
$this->raw .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user