GeyserMC / PacketLib

A library for packet-based networking between clients and servers.
MIT License
80 stars 40 forks source link

Session#disconnect reason not visible on remote. #28

Closed kyngs closed 3 years ago

kyngs commented 3 years ago

So I have a setup of Server and Client if on Client I do session.disconnect("0");, on Server SessionListener#disconnected is called, however if I do DisconnectedEvent#getReason(), I get "Connection Closed", but, on client in SessionListener#disconnected I get reason "0" which is fine. Is this intended? If yes, is there a way to bypass it?

ghost commented 3 years ago

You will have to send your own disconnect packet to accompany it. There is no built in way to transmit the disconnect reason to the other end.

kyngs commented 3 years ago

Understand, however, it would certainly be nice to have because I cannot guarantee that the message packet will be sent when Session#disconnect is called.

ghost commented 3 years ago

What you can do is listen for DisconnectingEvent, which is raised when disconnect() is called and the channel is about to be closed, and send out a packet with the attached reason first.

That's what MCProtocolLib does on the server side to send the reason to the client.

kyngs commented 3 years ago

Oh, so the event is called before the connection is closed, perfect, thanks for your response.