Skip to content

Commit 3e98dfc

Browse files
committed
handler: add comments about the extra packet handling logic
1 parent 984a133 commit 3e98dfc

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/muqsit/invmenu/InvMenuEventHandler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,20 @@ public function onDataPacketReceive(DataPacketReceiveEvent $event) : void{
3434
$this->player_manager->getNullable($player)?->network->notify($packet->timestamp);
3535
}
3636
}elseif($packet instanceof ContainerClosePacket){
37+
// these are not magic numbers. 255 (windowId) is supposed to be ContainerIds::NONE (-1) but it appears
38+
// either pocketmine or mojang wrongly encodes/decodes the packet. the same applies to 247 (windowType)
39+
// which actually is WindowTypes::NONE (-9).
3740
if(!$packet->server && $packet->windowId === 255 && $packet->windowType === 247){
3841
$player = $event->getOrigin()->getPlayer();
3942
if($player !== null && $this->player_manager->getNullable($player)?->dispatcher !== null){
4043
$event->cancel();
4144
}
4245
}
4346
}elseif($packet instanceof PacketViolationWarningPacket){
47+
// we (ab)use a packet violation as an ACK the inventory was successfully sent to the player. we expect to
48+
// receive the same number of violation packets as the number of excess ContainerOpenPackets that we sent.
49+
// digesting these excess violation packets is not necessary, but in this way we can intercept violations
50+
// from propagating further if existing plugins print these violations for debugging purposes.
4451
if($packet->getPacketId() === PacketViolationWarningPacket::NETWORK_ID && $packet->getType() === -1 && $packet->getSeverity() === PacketViolationWarningPacket::SEVERITY_WARNING){
4552
$player = $event->getOrigin()->getPlayer();
4653
if($player !== null){

0 commit comments

Comments
 (0)