Add per-client slot disconnect reason to the server#154
Merged
Conversation
The connect_disconnect_callback only reports (client_index, connected),
so server code could not tell why a client disconnected: did it leave
cleanly (disconnect packet), time out, or get disconnected by server
code calling netcode_server_disconnect_client?
New function int netcode_server_client_disconnect_reason( server,
client_index ) returns NETCODE_SERVER_CLIENT_DISCONNECT_REASON_NONE /
TIMED_OUT / CLIENT_DISCONNECT / SERVER_DISCONNECT for the client that
last occupied the slot. Tracked per-client slot: reset to NONE at
server start and when a new client connects to the slot, and recorded
before the connect_disconnect_callback fires, so the reason can be
queried from inside that callback. Existing functions are unchanged.
Tests: new test_server_client_disconnect_reason covers none ->
timed out -> cleared on reconnect, and the existing client-side and
server-side disconnect tests now also assert the recorded reason,
directly verifying their stated intent ("disconnects cleanly, rather
than timing out").
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
4 tasks
pull Bot
pushed a commit
to Mu-L/yojimbo
that referenced
this pull request
Jul 10, 2026
Pulls in mas-bandwidth/netcode#154 (netcode@4edccb4): new function netcode_server_client_disconnect_reason( server, client_index ) distinguishing TIMED_OUT / CLIENT_DISCONNECT / SERVER_DISCONNECT, tracked per-client slot and recorded before the connect_disconnect_callback fires. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
connect_disconnect_callbackonly reports(client_index, connected), so server code cannot tell why a client disconnected — did it leave cleanly (disconnect packet), time out, or get disconnected by server code? This is the key "is it us or them" signal for game backends built on netcode (motivated by mas-bandwidth/yojimbo#290, which exposes disconnect reasons at the yojimbo layer but could not distinguish timeout from clean disconnect without this).int netcode_server_client_disconnect_reason( server, client_index )returning:NETCODE_SERVER_CLIENT_DISCONNECT_REASON_NONE— no disconnect in this slot yet (or a new client has since connected to it)NETCODE_SERVER_CLIENT_DISCONNECT_REASON_TIMED_OUT— client went silent past its timeoutNETCODE_SERVER_CLIENT_DISCONNECT_REASON_CLIENT_DISCONNECT— received a disconnect packet from the client (clean)NETCODE_SERVER_CLIENT_DISCONNECT_REASON_SERVER_DISCONNECT— server code callednetcode_server_disconnect_client/disconnect_all_clients/disconnect_loopback_clientNONEatnetcode_server_startand when a new client connects to the slot. Recorded beforeconnect_disconnect_callbackfires, so it can be queried from inside the callback.Test plan
test_server_client_disconnect_reason: reason isNONEat server start and while connected → client goes silent → server times it out →TIMED_OUT→ reconnect clears the slot back toNONEtest_client_side_disconnectnow assertsCLIENT_DISCONNECTandtest_server_side_disconnectassertsSERVER_DISCONNECT— directly verifying their stated intent ("disconnects cleanly, rather than timing out")🤖 Generated with Claude Code