DataPacket no longer keeps its own serializer

since a while ago, we're anyway just discarding the internal buffer anyway when the packet is repeatedly encoded, so this doesn't serve any advantage anymore.
We do need a system to be able to reuse encoded packet buffers, but right now we're not reusing them anyway.
This commit is contained in:
Dylan K. Taylor
2021-04-09 15:37:58 +01:00
parent 19f536d68a
commit 0312b62c8a
7 changed files with 29 additions and 50 deletions

View File

@@ -73,6 +73,7 @@ use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
use pocketmine\network\mcpe\protocol\RemoveActorPacket;
use pocketmine\network\mcpe\protocol\serializer\PacketBatch;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\ServerboundPacket;
use pocketmine\network\mcpe\protocol\ServerToClientHandshakePacket;
use pocketmine\network\mcpe\protocol\SetActorDataPacket;
@@ -355,11 +356,11 @@ class NetworkSession{
}
try{
foreach($stream->getPackets($this->packetPool, 500) as $packet){
foreach($stream->getPackets($this->packetPool, 500) as [$packet, $buffer]){
try{
$this->handleDataPacket($packet);
$this->handleDataPacket($packet, $buffer);
}catch(PacketHandlingException $e){
$this->logger->debug($packet->getName() . ": " . base64_encode($packet->getSerializer()->getBuffer()));
$this->logger->debug($packet->getName() . ": " . base64_encode($buffer));
throw PacketHandlingException::wrap($e, "Error processing " . $packet->getName());
}
}
@@ -372,10 +373,10 @@ class NetworkSession{
/**
* @throws PacketHandlingException
*/
public function handleDataPacket(Packet $packet) : void{
public function handleDataPacket(Packet $packet, string $buffer) : void{
if(!($packet instanceof ServerboundPacket)){
if($packet instanceof GarbageServerboundPacket){
$this->logger->debug("Garbage serverbound " . $packet->getName() . ": " . base64_encode($packet->getSerializer()->getBuffer()));
$this->logger->debug("Garbage serverbound " . $packet->getName() . ": " . base64_encode($buffer));
return;
}
throw new PacketHandlingException("Unexpected non-serverbound packet");
@@ -385,12 +386,12 @@ class NetworkSession{
$timings->startTiming();
try{
$stream = new PacketSerializer($buffer);
try{
$packet->decode();
$packet->decode($stream);
}catch(PacketDecodeException $e){
throw PacketHandlingException::wrap($e);
}
$stream = $packet->getSerializer();
if(!$stream->feof()){
$remains = substr($stream->getBuffer(), $stream->getOffset());
$this->logger->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": " . bin2hex($remains));