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:
Dylan K. Taylor
2019-01-17 12:21:56 +00:00
parent 9c0ebb6350
commit b82e00ffdf
15 changed files with 167 additions and 79 deletions

View File

@ -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));