MirrorNetworking / Mirror

#1 Open Source Unity Networking Library
https://mirror-networking.com
MIT License
5.27k stars 777 forks source link

Sending Disconnect Messages #533

Closed MichalPetryka closed 3 years ago

MichalPetryka commented 5 years ago

Is your feature request related to a problem? Please describe. Having possibility to send some text on disconnect would be useful for things like "You have been banned".

Describe the solution you'd like Optional string parameter in Disconnect method.

Describe alternatives you've considered Sending message manually with TargetRPCs before disconnect.

Additional context Some transports might have possibility to send the reason in disconnect packet, utilizing that would be useful.

miwarnec commented 5 years ago

I need this in uMMORPG as well. right now I have a workaround where I send an error message without disconnecting, and the client disconnects itself.

I could be wrong, but I think not all transports will deliver the last message properly if we call disconnect immediately after calling send.

miwarnec commented 5 years ago

closing this for now, unless anyone has an idea how to do send(DisconnectMessage); close(); in TCP with the disconnect message actually being sent.

MichalPetryka commented 5 years ago

Send a message with this, and make the client respond with disconnect? @vis2k

uweeby commented 5 years ago

could you do something on the server where after the msg to disconnect is sent you give them until the normal timeout period then drop the connection anyway?

miwarnec commented 5 years ago

reopening: according to c6 it might work with LingerState

paulpach commented 5 years ago

In websockets you also send a close message with a reason.

MichalPetryka commented 5 years ago

Okay, so: 2 transports support disconnect reasons (WebSockets and LiteNetLib) 1 transport has DisconnectLater (Ignorance)

MrGadget1024 commented 3 years ago

TargetRpc ahead of the server's call to Disconnect (perhaps with a 1 frame delay) is the only way to sanely do this, since we can't be assured of what various transports might support in terms of a d/c reason. Closing.