mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
NetworkSession: inject PacketPool instead of hardcoding it
this will make it slightly easier for multi version implementations, but handlers are still quite a big problem.
This commit is contained in:
parent
09e994a026
commit
b6214744d5
@ -64,6 +64,7 @@ use pocketmine\network\mcpe\protocol\MovePlayerPacket;
|
||||
use pocketmine\network\mcpe\protocol\NetworkChunkPublisherUpdatePacket;
|
||||
use pocketmine\network\mcpe\protocol\Packet;
|
||||
use pocketmine\network\mcpe\protocol\PacketDecodeException;
|
||||
use pocketmine\network\mcpe\protocol\PacketPool;
|
||||
use pocketmine\network\mcpe\protocol\PlayerListPacket;
|
||||
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
|
||||
use pocketmine\network\mcpe\protocol\serializer\PacketBatch;
|
||||
@ -150,13 +151,16 @@ class NetworkSession{
|
||||
/** @var Compressor */
|
||||
private $compressor;
|
||||
|
||||
/** @var PacketPool */
|
||||
private $packetPool;
|
||||
|
||||
/** @var InventoryManager|null */
|
||||
private $invManager = null;
|
||||
|
||||
/** @var PacketSender */
|
||||
private $sender;
|
||||
|
||||
public function __construct(Server $server, NetworkSessionManager $manager, PacketSender $sender, Compressor $compressor, string $ip, int $port){
|
||||
public function __construct(Server $server, NetworkSessionManager $manager, PacketPool $packetPool, PacketSender $sender, Compressor $compressor, string $ip, int $port){
|
||||
$this->server = $server;
|
||||
$this->manager = $manager;
|
||||
$this->sender = $sender;
|
||||
@ -167,6 +171,7 @@ class NetworkSession{
|
||||
|
||||
$this->compressedQueue = new \SplQueue();
|
||||
$this->compressor = $compressor;
|
||||
$this->packetPool = $packetPool;
|
||||
|
||||
$this->connectTime = time();
|
||||
|
||||
@ -301,7 +306,7 @@ class NetworkSession{
|
||||
throw new BadPacketException("Too many packets in a single batch");
|
||||
}
|
||||
try{
|
||||
$pk = $stream->getPacket();
|
||||
$pk = $stream->getPacket($this->packetPool);
|
||||
}catch(BinaryDataException $e){
|
||||
$this->logger->debug("Packet batch: " . base64_encode($stream->getBuffer()));
|
||||
throw BadPacketException::wrap($e, "Packet batch decode error");
|
||||
|
@ -37,8 +37,8 @@ class PacketBatch extends NetworkBinaryStream{
|
||||
/**
|
||||
* @throws BinaryDataException
|
||||
*/
|
||||
public function getPacket() : Packet{
|
||||
return PacketPool::getInstance()->getPacket($this->getString());
|
||||
public function getPacket(PacketPool $packetPool) : Packet{
|
||||
return $packetPool->getPacket($this->getString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,6 +27,7 @@ use pocketmine\network\AdvancedNetworkInterface;
|
||||
use pocketmine\network\BadPacketException;
|
||||
use pocketmine\network\mcpe\compression\ZlibCompressor;
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
use pocketmine\network\mcpe\protocol\PacketPool;
|
||||
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
||||
use pocketmine\network\Network;
|
||||
use pocketmine\Server;
|
||||
@ -156,6 +157,7 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
|
||||
$session = new NetworkSession(
|
||||
$this->server,
|
||||
$this->network->getSessionManager(),
|
||||
PacketPool::getInstance(),
|
||||
new RakLibPacketSender($sessionId, $this),
|
||||
ZlibCompressor::getInstance(), //TODO: this shouldn't be hardcoded, but we might need the RakNet protocol version to select it
|
||||
$address,
|
||||
|
Loading…
x
Reference in New Issue
Block a user