Reduce BatchPacket hacks

we can't get rid of these hacks entirely because BAcKWARdS ComPaTIbilitY, but this at least ensures that things over PID 127 won't burn the house down when 1.12 gets here. This also reduces conflicts with 4.0 line.
This commit is contained in:
Dylan K. Taylor 2019-04-25 14:48:36 +01:00
parent 74b9922a28
commit 4a35516441
2 changed files with 5 additions and 9 deletions

View File

@ -27,7 +27,6 @@ use pocketmine\event\player\PlayerCreationEvent;
use pocketmine\network\AdvancedSourceInterface;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\network\Network;
use pocketmine\Player;
@ -166,7 +165,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
$address = $player->getAddress();
try{
if($packet->buffer !== ""){
$pk = PacketPool::getPacket($packet->buffer);
$pk = new BatchPacket($packet->buffer);
$player->handleDataPacket($pk);
}
}catch(\Throwable $e){

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
use function ord;
use pocketmine\utils\Binary;
class PacketPool{
/** @var \SplFixedArray<DataPacket> */
@ -32,7 +32,6 @@ class PacketPool{
public static function init(){
static::$pool = new \SplFixedArray(256);
//Normal packets
static::registerPacket(new LoginPacket());
static::registerPacket(new PlayStatusPacket());
static::registerPacket(new ServerToClientHandshakePacket());
@ -158,8 +157,6 @@ class PacketPool{
static::registerPacket(new VideoStreamConnectPacket());
static::registerPacket(new MapCreateLockedCopyPacket());
static::registerPacket(new OnScreenTextureAnimationPacket());
static::registerPacket(new BatchPacket());
}
/**
@ -184,10 +181,10 @@ class PacketPool{
* @return DataPacket
*/
public static function getPacket(string $buffer) : DataPacket{
$pk = static::getPacketById(ord($buffer{0}));
$pk->setBuffer($buffer);
$offset = 0;
$pk = static::getPacketById(Binary::readUnsignedVarInt($buffer, $offset));
$pk->setBuffer($buffer, $offset);
return $pk;
}
}