mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Fixed the disaster of packet receive error handling
This commit is contained in:
@ -23,7 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
use pocketmine\network\BadPacketException;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\BinaryDataException;
|
||||
|
||||
class PacketPool{
|
||||
/** @var \SplFixedArray<DataPacket> */
|
||||
@ -175,10 +177,15 @@ class PacketPool{
|
||||
* @param string $buffer
|
||||
*
|
||||
* @return DataPacket
|
||||
* @throws BadPacketException
|
||||
*/
|
||||
public static function getPacket(string $buffer) : DataPacket{
|
||||
$offset = 0;
|
||||
$pk = static::getPacketById(Binary::readUnsignedVarInt($buffer, $offset));
|
||||
try{
|
||||
$pk = static::getPacketById(Binary::readUnsignedVarInt($buffer, $offset));
|
||||
}catch(BinaryDataException $e){
|
||||
throw new BadPacketException("Packet is too short");
|
||||
}
|
||||
$pk->setBuffer($buffer, $offset);
|
||||
|
||||
return $pk;
|
||||
|
Reference in New Issue
Block a user