MidLevel / Ruffles

Lightweight and fully managed reliable UDP library.
MIT License
212 stars 28 forks source link

Add functionality for graceful disconnects with Fragmented channels #35

Open cdanek opened 2 years ago

cdanek commented 2 years ago

When a server disconnects a connection that has ReliableSequencedFragmented as the channel type (and potentially others), any pending packets are not sent to the client. This results in "friendly disconnects" (use case - user is on the wrong version of the client, needs a message telling them to upgrade, then disconnect them) not being received by the client, since the _pendingSends aren't flushed to the socket, they're simply reclaimed. See ReliableSequencedFragmented.Release().

I believe I understand the motivation - the Disconnect event should disconnect immediately and not dump data to clients - but there isn't a mechanism to flush() partial packets to users. Unfortunately, I think alternative approaches are not good (ask the client to disconnect in the "final packet" and trust them to do so; mark a connection as pending disconnect and complete the disconnect after MergeDelay amount of time; or my solution - expose a second Send() method with noMerge=true for these scenarios).

I'm not sure if this repo is being actively developed any further with the maintainer moving over into other unity networking solutions, but if the maintainer (or anyone else capable) would like to, this would be a nice feature, both for this use case and others.

Proposal 1: Add Flush() to IChannel and implement in the various channel implementations Proposal 2: Expose method for polling count of _pendingSends in the channels. Proposal 3: Add another Disconnect() method or parameter that attempts to Flush() pending/unmerged packets to the client.

Thanks for the consideration