Improve duel client connection handling and bot room startup#3133
Open
mercury233 wants to merge 12 commits into
Open
Improve duel client connection handling and bot room startup#3133mercury233 wants to merge 12 commits into
mercury233 wants to merge 12 commits into
Conversation
Previously, this failure path only called `StopServer`. When the server shut down, the client would encounter an error or timeout, allowing it to restore the UI. Although the recently added `StopClient` is semantically clearer, it may does not trigger the client's failure path, so the UI is not restored.
fix ignoring BEV_EVENT_EOF between connected and joined
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors and hardens the duel client/server connection lifecycle, improves LAN host discovery reliability, and changes bot-room startup to be private-by-default with randomized ports and delayed bot spawning.
Changes:
- Centralize host name resolution in
DuelClient(usinginet_ptonfor numeric IPv4 andevutil_getaddrinfofor DNS). - Improve connection lifecycle correctness (explicit connect states/close reasons, connect-timeout tracking/cancellation, safer disconnect handling).
- Make bot rooms private by default (bind localhost, random port, no LAN broadcast unless configured), and defer bot process spawn until after the host joins.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| strings.conf | Adds a new system string for bot-start failure messaging. |
| gframe/netserver.h | Extends StartServer API to support bind IP, actual port output, and optional broadcast. |
| gframe/netserver.cpp | Implements bind-IP and ephemeral-port support and gates broadcast by configuration. |
| gframe/menu_handler.cpp | Moves hostname resolution into DuelClient and updates bot-room startup to use private-by-default randomized local binding. |
| gframe/game.h | Adds bot_room_public config and pending bot spawn state. |
| gframe/game.cpp | Loads/saves new bot_room_public option and adjusts client stop reason on exit. |
| gframe/duelclient.h | Adds explicit connect-state/close-reason constants and exposes ResolveHostName. |
| gframe/duelclient.cpp | Implements hostname resolution, connect-timeout tracking/cancellation, improved disconnect paths, safer LAN refresh cleanup, and delayed bot spawning. |
Comments suppressed due to low confidence (1)
gframe/duelclient.cpp:4187
SOCKADDR_IN localandSOCKADDR_IN sockToare not zero-initialized before being passed tobind/sendto. Uninitialized padding/fields can trigger warnings (and, on some platforms, can be observable via kernel copies).
SOCKADDR_IN local;
local.sin_family = AF_INET;
local.sin_port = htons(7922);
SOCKADDR_IN sockTo;
sockTo.sin_addr.s_addr = htonl(INADDR_BROADCAST);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This reverts commit 9ad8908. The threading issue has not been resolved. Releasing it here would instead cause a conflict.
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
This PR improves duel client connection lifecycle handling, LAN room discovery, and bot room startup behavior.
Changes
Move host name resolution out of
menu_handlerand intoDuelClient.menu_handlercan be made cheaper to compile in the future.Use
inet_ptonfor parsing numeric IPv4 addresses.inet_ptonis available on Windows since Vista, which is older than the supported Windows baseline.evutil_getaddrinfo.Add named constants for duel client connection state.
CONNECT_STATE_*names.Replace the client
is_closingflag withclose_reason.CLIENT_CLOSE_REASON_EXITskips a little more UI/update handling than a normal stop.Fix disconnect handling while the client is connected but has not joined a room yet.
CONNECTEDstate could leave the client stuck forever.www.baidu.com:443.Track and cancel the client connect timeout event.
event_newfrom leaking.Disable the client bufferevent inStopClient.Avoids extra processing after the client has already started closing.Fix LAN room refresh cleanup paths.
Stop using
gethostbynamefor LAN room refresh.evutil_getaddrinfo.Make bot rooms private by default.
bot_room_publicconfig option restores the previous public fixed-port behavior.Delay spawning the bot process until after the host has joined the room.
NetServer::StopServer()directly.Allow
StopClientto stop the client from any active connection state, not only after successfully joining a room.Extend
NetServer::StartServer.Improve LAN discovery across multiple interfaces.
Future Work
btnCreateHost->setEnabled(true).