Skip to content

feat(gameserver): give rooms a lobby with a deterministic host - #2701

Merged
houko merged 2 commits into
mainfrom
feat/lobby-state-1320
Dec 1, 2026
Merged

houko merged 2 commits into
mainfrom
feat/lobby-state-1320

Conversation

@houko

@houko houko commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

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; Create keeps its signature and behavior. Passwords are salted scrypt hashes (N=32768, r=8, p=1, 16-byte salt, 32-byte key) compared with subtle.ConstantTimeCompare, never stored in plain text.
  • Join: Join and JoinCode refuse a password-protected room with ErrPasswordRequired; JoinPassword/JoinPasswordWithMeta admit on a matching password and report ErrWrongPassword otherwise. A room without a password ignores the argument.
  • Ready and start: SetReady, Ready and AllReady (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 with ErrNotHost and a lobby that is not all ready with ErrNotReady; Start keeps working without readiness.
  • Host: the named host while it is one, otherwise the earliest-joined member from Room.order, which already keeps join order; leaving clears an explicit host so the next member takes over deterministically. Rooms.HostPolicy selects HostOldest (default) or HostServer, where the host is 0 and StartBy(0) starts the room.
  • Settings: Settings returns a copy, Setting reads one, and SetSetting is host-only, clears every ready flag and emits a change; writing the same value changes nothing.
  • Listing and events: RoomInfo gains Name, Host, Ready, HasPassword and Settings; Find(RoomFilter{Mode, NotFull, Waiting, IncludePrivate}) filters, with private rooms hidden unless asked for; Rooms.LobbyEvents drains 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 Find filter including private rooms, drained lobby events (a repeated ready emits nothing, a host leave emits the transfer), the HostServer policy, and Create/Start keeping their old behavior. go tool nsgo test ./pkg/online/gameserver: 124 passed. go tool nsgo check, go test ./internal/repocheck, bun run verify-notes and go run ./tools/changelog check pass.

Docs, changelog, notes

docs/en/gameserver.md and docs/zh/gameserver.md gain the Lobby section; changelog.d/1320-lobby.md and .agents/notes/implemented/feature/2026-11-30-lobby-state-1320.md record 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

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.
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.
@houko
houko merged commit 4485daf into main Dec 1, 2026
14 checks passed
@github-actions github-actions Bot added size/XL and removed size/L labels Dec 1, 2026
@houko
houko deleted the feat/lobby-state-1320 branch December 1, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agents documentation Improvements or additions to documentation enhancement New feature or request pkg/online size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rooms: lobby state (host, ready, settings, name, password, host transfer)

1 participant