Merge 'stable' into 'minor-next'

Automatic merge performed by: https://github.com/pmmp/RestrictedActions/actions/runs/16923820104
This commit is contained in:
pmmp-admin-bot[bot] 2025-08-13 00:03:15 +00:00
commit cce55e8939
2 changed files with 34 additions and 1 deletions

View File

@ -415,6 +415,11 @@ class NetworkSession{
$this->logger->debug($packet->getName() . ": " . base64_encode($buffer)); $this->logger->debug($packet->getName() . ": " . base64_encode($buffer));
throw PacketHandlingException::wrap($e, "Error processing " . $packet->getName()); throw PacketHandlingException::wrap($e, "Error processing " . $packet->getName());
} }
if(!$this->isConnected()){
//handling this packet may have caused a disconnection
$this->logger->debug("Aborting batch processing due to server-side disconnection");
break;
}
} }
}catch(PacketDecodeException|BinaryDataException $e){ }catch(PacketDecodeException|BinaryDataException $e){
$this->logger->logException($e); $this->logger->logException($e);

View File

@ -36,6 +36,7 @@ use pocketmine\network\mcpe\protocol\types\Experiments;
use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackInfoEntry; use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackInfoEntry;
use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackStackEntry; use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackStackEntry;
use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackType; use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackType;
use pocketmine\network\PacketHandlingException;
use pocketmine\resourcepacks\ResourcePack; use pocketmine\resourcepacks\ResourcePack;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use function array_keys; use function array_keys;
@ -43,6 +44,7 @@ use function array_map;
use function ceil; use function ceil;
use function count; use function count;
use function implode; use function implode;
use function sprintf;
use function strpos; use function strpos;
use function strtolower; use function strtolower;
use function substr; use function substr;
@ -66,6 +68,9 @@ class ResourcePacksPacketHandler extends PacketHandler{
*/ */
private array $resourcePacksById = []; private array $resourcePacksById = [];
private bool $requestedMetadata = false;
private bool $requestedStack = false;
/** @var bool[][] uuid => [chunk index => hasSent] */ /** @var bool[][] uuid => [chunk index => hasSent] */
private array $downloadedChunks = []; private array $downloadedChunks = [];
@ -140,6 +145,21 @@ class ResourcePacksPacketHandler extends PacketHandler{
$this->session->disconnect("Refused resource packs", "You must accept resource packs to join this server.", true); $this->session->disconnect("Refused resource packs", "You must accept resource packs to join this server.", true);
break; break;
case ResourcePackClientResponsePacket::STATUS_SEND_PACKS: case ResourcePackClientResponsePacket::STATUS_SEND_PACKS:
if($this->requestedMetadata){
throw new PacketHandlingException("Cannot request resource pack metadata multiple times");
}
$this->requestedMetadata = true;
if($this->requestedStack){
//client already told us that they have all the packs, they shouldn't be asking for more
throw new PacketHandlingException("Cannot request resource pack metadata after resource pack stack");
}
if(count($packet->packIds) > count($this->resourcePacksById)){
throw new PacketHandlingException(sprintf("Requested metadata for more resource packs (%d) than available on the server (%d)", count($packet->packIds), count($this->resourcePacksById)));
}
$seen = [];
foreach($packet->packIds as $uuid){ foreach($packet->packIds as $uuid){
//dirty hack for mojang's dirty hack for versions //dirty hack for mojang's dirty hack for versions
$splitPos = strpos($uuid, "_"); $splitPos = strpos($uuid, "_");
@ -153,6 +173,9 @@ class ResourcePacksPacketHandler extends PacketHandler{
$this->disconnectWithError("Unknown pack $uuid requested, available packs: " . implode(", ", array_keys($this->resourcePacksById))); $this->disconnectWithError("Unknown pack $uuid requested, available packs: " . implode(", ", array_keys($this->resourcePacksById)));
return false; return false;
} }
if(isset($seen[$pack->getPackId()])){
throw new PacketHandlingException("Repeated metadata request for pack $uuid");
}
$this->session->sendDataPacket(ResourcePackDataInfoPacket::create( $this->session->sendDataPacket(ResourcePackDataInfoPacket::create(
$pack->getPackId(), $pack->getPackId(),
@ -163,11 +186,16 @@ class ResourcePacksPacketHandler extends PacketHandler{
false, false,
ResourcePackType::RESOURCES //TODO: this might be an addon (not behaviour pack), needed to properly support client-side custom items ResourcePackType::RESOURCES //TODO: this might be an addon (not behaviour pack), needed to properly support client-side custom items
)); ));
$seen[$pack->getPackId()] = true;
} }
$this->session->getLogger()->debug("Player requested download of " . count($packet->packIds) . " resource packs"); $this->session->getLogger()->debug("Player requested download of " . count($packet->packIds) . " resource packs");
break; break;
case ResourcePackClientResponsePacket::STATUS_HAVE_ALL_PACKS: case ResourcePackClientResponsePacket::STATUS_HAVE_ALL_PACKS:
if($this->requestedStack){
throw new PacketHandlingException("Cannot request resource pack stack multiple times");
}
$this->requestedStack = true;
$stack = array_map(static function(ResourcePack $pack) : ResourcePackStackEntry{ $stack = array_map(static function(ResourcePack $pack) : ResourcePackStackEntry{
return new ResourcePackStackEntry($pack->getPackId(), $pack->getPackVersion(), ""); //TODO: subpacks return new ResourcePackStackEntry($pack->getPackId(), $pack->getPackVersion(), ""); //TODO: subpacks
}, $this->resourcePackStack); }, $this->resourcePackStack);