Server->batchPackets() now only accepts DataPacket objects, fixed players receiving double PlayerListPackets with their own data

This commit is contained in:
Dylan K. Taylor
2017-05-17 17:15:42 +01:00
parent 15b47fcb2f
commit fe8cb8cd86
2 changed files with 29 additions and 30 deletions

View File

@ -54,20 +54,17 @@ class BatchPacket extends DataPacket{
}
/**
* @param DataPacket|string $packet
* @param DataPacket $packet
*/
public function addPacket($packet){
if($packet instanceof DataPacket){
if(!$packet->canBeBatched()){
throw new \InvalidArgumentException(get_class($packet) . " cannot be put inside a BatchPacket");
}
if(!$packet->isEncoded){
$packet->encode();
}
$packet = $packet->buffer;
public function addPacket(DataPacket $packet){
if(!$packet->canBeBatched()){
throw new \InvalidArgumentException(get_class($packet) . " cannot be put inside a BatchPacket");
}
if(!$packet->isEncoded){
$packet->encode();
}
$this->payload .= Binary::writeUnsignedVarInt(strlen($packet)) . $packet;
$this->payload .= Binary::writeUnsignedVarInt(strlen($packet->buffer)) . $packet->buffer;
}
public function compress(int $level = 7){