Fixed Packet of Death

This commit is contained in:
Shoghi Cervantes 2013-11-26 17:23:45 +01:00
parent 5ad72b4f49
commit bd0d708274
4 changed files with 18 additions and 7 deletions

View File

@ -40,6 +40,10 @@ class CustomPacketHandler{
}
return $data;
}
private function feof(){
return !isset($this->raw{$this->offset});
}
public function __construct($pid, $raw = "", $data = array(), $create = false){
$this->raw = $raw;
@ -469,7 +473,7 @@ class CustomPacketHandler{
$this->data["radius"] = Utils::readFloat($this->get(4));
$this->data["count"] = Utils::readInt($this->get(4));
$this->data["records"] = array();
for($r = 0; $r < $this->data["count"]; ++$r){
for($r = 0; $r < $this->data["count"] and !$this->feof(); ++$r){
$this->data["records"][] = new Vector3(Utils::readByte($this->get(1)), Utils::readByte($this->get(1)), Utils::readByte($this->get(1)));
}
}else{
@ -707,7 +711,7 @@ class CustomPacketHandler{
$this->data["windowid"] = ord($this->get(1));
$this->data["count"] = Utils::readShort($this->get(2), false);
$this->data["slots"] = array();
for($s = 0; $s < $this->data["count"]; ++$s){
for($s = 0; $s < $this->data["count"] and !$this->feof(); ++$s){
$this->data["slots"][$s] = Utils::readSlot($this);
}
if($this->data["windowid"] === 1){ //Armor is also sent
@ -791,7 +795,7 @@ class CustomPacketHandler{
$this->data["windowid"] = ord($this->get(1));
$this->data["count"] = Utils::readShort($this->get(2), false);
$this->data["slots"] = array();
for($s = 0; $s < $this->data["count"]; ++$s){
for($s = 0; $s < $this->data["count"] and !$this->feof(); ++$s){
$this->data["slots"][$s] = Utils::readSlot($this);
}
}else{

View File

@ -65,6 +65,9 @@ class MinecraftInterface{
if($len === false){
return $pk;
}
echo "received packet [".strtoupper(bin2hex(Utils::writeInt(crc32($buf))))."]".PHP_EOL;
global $lastPacketSent;
$lastPacketSent = bin2hex($buf);
$this->bandwidth[0] += $len;
$this->parsePacket($buf, $source, $port);
return ($pk !== false ? $pk : $this->popPacket());

View File

@ -173,6 +173,10 @@ class Packet{
$this->offset += $len;
return $data;
}
private function feof(){
return !isset($this->raw{$this->offset});
}
protected function addRaw($str){
$this->raw .= $str;
@ -203,10 +207,10 @@ class Packet{
case 0xa0:
$cnt = Utils::readShort($this->get(2), false);
$this->data[$field] = array();
for($i = 0; $i < $cnt; ++$i){
for($i = 0; $i < $cnt and !$this->feof(); ++$i){
if(Utils::readBool($this->get(1)) === false){
$start = Utils::readTriad(strrev($this->get(3)));
$end = Utils::readTriad(strrev($this->get(3)));
$end = min(Utils::readTriad(strrev($this->get(3))), $start + 4096);
for($c = $start; $c <= $end; ++$c){
$this->data[$field][] = $c;
}

View File

@ -162,7 +162,7 @@ class Utils{
$m = array();
$b = ord($value{$offset});
++$offset;
while($b !== 127){
while($b !== 127 and isset($value{$offset})){
$bottom = $b & 0x1F;
$type = $b >> 5;
switch($type){
@ -220,7 +220,7 @@ class Utils{
public static function readDataArray($str, $len = 10, &$offset = null){
$data = array();
$offset = 0;
for($i = 1; $i <= $len; ++$i){
for($i = 1; $i <= $len and isset($str{$offset}); ++$i){
$l = Utils::readTriad(substr($str, $offset, 3));
$offset += 3;
$data[] = substr($str, $offset, $l);