Repository navigation
feat(gameserver): give rooms a lobby with a deterministic host - #2701
Merged
Merged
Conversation
A room had only capacity, privacy, state, members and inboxes, so every party or custom-match game kept its own lobby table that drifted on leave and close #1320. CreateWith opens a room with a name, a scrypt-hashed password and settings; JoinPassword verifies it in constant time. Members ready up individually, the host alone changes settings (which clears readiness) and starts through StartBy once everyone else is ready. The host is the named peer or the earliest-joined member, so a transfer is deterministic, and HostServer keeps the host at 0. RoomInfo and Find expose names, hosts, readiness, passwords and mode filters, and LobbyEvents drains the changes to broadcast.
This was referenced Nov 30, 2026
Play now had to list rooms, pick one and create another, so two peers looking at the same moment each opened a room, and modes could not be told apart #1321. QuickJoin fills the fullest public room of a configured mode with a free seat or opens one with the mode's capacity, under a lock so a burst fills rooms instead of opening one each. Modes carry a capacity and a late-join policy, an unknown mode is ErrUnknownMode and a server out of rooms is ErrNoCapacity. Tests cover filling, opening, modes apart, the room cap, late join and concurrent joins.
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.
A room held only an ID, capacity, privacy, lifecycle state, members and inboxes. A party or custom-match lobby needs a host who picks settings and starts once the others are ready, a display name, a password, and a way to list open rooms by mode; without it every game kept a side table keyed by room ID that drifted out of sync on leave and close. The prior art in the issue got three parts wrong in ways worth not repeating: it took the new host from Go's map iteration order, compared passwords as plain text and ignored the owner's own ready flag.
What changed
Rooms.CreateWith(host, RoomOptions{Capacity, Private, Name, Password, Settings})opens a lobby;Createkeeps its signature and behavior. Passwords are salted scrypt hashes (N=32768, r=8, p=1, 16-byte salt, 32-byte key) compared withsubtle.ConstantTimeCompare, never stored in plain text.JoinandJoinCoderefuse a password-protected room withErrPasswordRequired;JoinPassword/JoinPasswordWithMetaadmit on a matching password and reportErrWrongPasswordotherwise. A room without a password ignores the argument.SetReady,ReadyandAllReady(at least two members, every member except the host ready, so the host starts rather than marking itself ready);StartBy(peer)refuses a non-host withErrNotHostand a lobby that is not all ready withErrNotReady;Startkeeps working without readiness.Room.order, which already keeps join order; leaving clears an explicit host so the next member takes over deterministically.Rooms.HostPolicyselectsHostOldest(default) orHostServer, where the host is 0 andStartBy(0)starts the room.Settingsreturns a copy,Settingreads one, andSetSettingis host-only, clears every ready flag and emits a change; writing the same value changes nothing.RoomInfogainsName,Host,Ready,HasPasswordandSettings;Find(RoomFilter{Mode, NotFull, Waiting, IncludePrivate})filters, with private rooms hidden unless asked for;Rooms.LobbyEventsdrains the ready and host changes a game broadcasts.Tests
Host start only, ready rules and all-ready, settings change clearing readiness (and an unchanged value not clearing it), password join (right, wrong, none, through a join code), deterministic host transfer across two leaves, names and every
Findfilter including private rooms, drained lobby events (a repeated ready emits nothing, a host leave emits the transfer), theHostServerpolicy, andCreate/Startkeeping their old behavior.go tool nsgo test ./pkg/online/gameserver: 124 passed.go tool nsgo check,go test ./internal/repocheck,bun run verify-notesandgo run ./tools/changelog checkpass.Docs, changelog, notes
docs/en/gameserver.mdanddocs/zh/gameserver.mdgain the Lobby section;changelog.d/1320-lobby.mdand.agents/notes/implemented/feature/2026-11-30-lobby-state-1320.mdrecord the host policy contract, why readiness excludes the host, and why the password hash and the separate event lock.No visual change: no screenshot.
Fixes #1320