Muqsit / SimplePacketHandler

A PocketMine-MP library/virion that provides a simple API to handle data packets per network session.
https://poggit.pmmp.io/ci/Muqsit/SimplePacketHandler
GNU General Public License v3.0
38 stars 11 forks source link

Common handler for more than one packet. #14

Open Endermanbugzjfc opened 1 month ago

Endermanbugzjfc commented 1 month ago

Description

PHP 8.0 union type not supported.

A common handler for more than one packet comes in handy for packets with similar properties, such as changing the metadata for SetActorDataPacket and AddActorPacket.

Steps to reproduce

  1. Install muqsit/simple-packet-handler:dev-pm5
  2. Register an outgoing packet interceptor with a closure in which its first argument has more than one packet type in union. (Sample code below.)
  3. Run the code.

Expected result: the handler is called when the server sends both packets. Actual result: server crashed on startup. (Crashdump below.)

Sample code

            $handler = SimplePacketHandler::createInterceptor($this->plugin);
            $handler->interceptOutgoing($callback = function (
                SetActorDataPacket|AddActorPacket $packet,
                NetworkSession $origin,
            ) : bool {
                // ...
                $packet->metadata[EntityMetadataProperties::NAMETAG] = new StringMetadataProperty(
                    // ...

Crashdump

https://crash.pmmp.io/view/11713385?access_token=c5f7e6eee1d988b5

Please notice that the original stack trace was generated by Await-Generator. Parts of the content are unneeded.

Unhandled async exception: Closure must satisfy signature (pocketmine\network\mcpe\protocol\ClientboundPacket, pocketmine\network\mcpe\NetworkSession) : bool

Environment

PHP: 8.2.17 PocketMine-MP: 5.19.0 SimplePacketHandler: 8121eca3f21cb9912c3ac8406a11f70cf105c905

Endermanbugzjfc commented 1 month ago

什麼東西飛過去了