Skip to content

fix player disconnect#3104

Merged
mercury233 merged 4 commits into
Fluorohydride:masterfrom
mercury233:patch-disconnect
Jul 7, 2026
Merged

fix player disconnect#3104
mercury233 merged 4 commits into
Fluorohydride:masterfrom
mercury233:patch-disconnect

Conversation

@mercury233

@mercury233 mercury233 commented May 31, 2026

Copy link
Copy Markdown
Collaborator

This change prevents the server from writing to a bufferevent that is already being disconnected, and clears stale duel-side player references when a player is removed.

It also marks single duel disconnect endings as DUEL_STAGE_END so remaining clients closing afterward do not trigger a second duel-end notification for observers.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes use-after-free / stale-pointer issues that occurred when a networked player disconnects while a duel mode still holds raw DuelPlayer* pointers into the users map entry that's about to be erased. A new virtual hook lets each duel mode null out its references before the bufferevent is freed, and server-side send helpers now skip writes to the bufferevent currently being torn down.

Changes:

  • Add pure virtual DuelMode::OnPlayerDisconnected() and implement it in SingleDuel and TagDuel to clear host_player, players[], pplayer[], ready[], and (tag) surrender[]/cur_player[], plus erase from observers.
  • Track the currently-disconnecting bufferevent* in NetServer and gate all send helpers behind CanWriteToPlayer() to prevent writing into a buffer that's about to be freed (while still preserving last_sent so ReSendToPlayer works for remaining players).
  • Invoke OnPlayerDisconnected() from DisconnectPlayer() before bufferevent_free(), and reset dp->game/state/type/bev so any subsequent accidental access is benign.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
gframe/network.h Adds pure virtual OnPlayerDisconnected(DuelPlayer*) to DuelMode.
gframe/single_duel.h Declares OnPlayerDisconnected override.
gframe/single_duel.cpp Implements cleanup of host_player, players[], ready[], pplayer[], and observers.
gframe/tag_duel.h Declares OnPlayerDisconnected override.
gframe/tag_duel.cpp Implements cleanup of host_player, players[], ready[], surrender[], pplayer[], cur_player[], and observers.
gframe/netserver.h Adds disconnecting_bev and CanWriteToPlayer(); routes all send helpers through it.
gframe/netserver.cpp Defines disconnecting_bev; sets it around LeaveGame/DisconnectPlayer in the EOF/error path; calls OnPlayerDisconnected and resets DuelPlayer fields before freeing the bufferevent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mercury233 mercury233 marked this pull request as ready for review June 29, 2026 03:28
@mercury233 mercury233 requested a review from Copilot July 1, 2026 01:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@mercury233 mercury233 merged commit 35513e0 into Fluorohydride:master Jul 7, 2026
15 checks passed
@mercury233 mercury233 deleted the patch-disconnect branch July 7, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants