Closed kyngs closed 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.
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.
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.
Oh, so the event is called before the connection is closed, perfect, thanks for your response.
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?