mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Extract a Packet interface from DataPacket
this is in preparation for clientbound/serverbound packet separation. I did this already on another branch, but the changeset was dependent on a massive refactor to split apart packets and binarystream which i'm still not fully happy with.
This commit is contained in:
@ -28,7 +28,7 @@ use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\BinaryDataException;
|
||||
|
||||
class PacketPool{
|
||||
/** @var \SplFixedArray<DataPacket> */
|
||||
/** @var \SplFixedArray<Packet> */
|
||||
protected static $pool = null;
|
||||
|
||||
public static function init() : void{
|
||||
@ -158,28 +158,28 @@ class PacketPool{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataPacket $packet
|
||||
* @param Packet $packet
|
||||
*/
|
||||
public static function registerPacket(DataPacket $packet) : void{
|
||||
public static function registerPacket(Packet $packet) : void{
|
||||
static::$pool[$packet->pid()] = clone $packet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pid
|
||||
*
|
||||
* @return DataPacket
|
||||
* @return Packet
|
||||
*/
|
||||
public static function getPacketById(int $pid) : DataPacket{
|
||||
public static function getPacketById(int $pid) : Packet{
|
||||
return isset(static::$pool[$pid]) ? clone static::$pool[$pid] : new UnknownPacket();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $buffer
|
||||
*
|
||||
* @return DataPacket
|
||||
* @return Packet
|
||||
* @throws BadPacketException
|
||||
*/
|
||||
public static function getPacket(string $buffer) : DataPacket{
|
||||
public static function getPacket(string $buffer) : Packet{
|
||||
$offset = 0;
|
||||
try{
|
||||
$pk = static::getPacketById(Binary::readUnsignedVarInt($buffer, $offset));
|
||||
|
Reference in New Issue
Block a user