Transfer host when lobby creator disconnects 🔧#3374
Conversation
When the host of a private lobby disconnects, transfer host role to the next active player. The new host's JoinLobbyModal automatically converts to a HostLobbyModal with full controls (edit settings, kick, start). Nation count and other config values are preserved from the original host.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
WalkthroughThese changes implement automatic host transfer functionality. When the original host disconnects from a private lobby during the lobby phase, the server selects a new host, notifies the client, and the client reopens the host modal with the existing configuration intact. Changes
Sequence DiagramsequenceDiagram
participant Host as Original Host
participant Server
participant NewClient as New Client (JoinLobbyModal)
participant Main
participant HostModal
Host->>Server: Disconnect WebSocket
Server->>Server: maybeTransferHost()<br/>Select NewClient as host
Server->>Server: Update creatorPersistentID
Server->>NewClient: Broadcast updated lobby info<br/>(NewClient is now creator)
NewClient->>NewClient: handleLobbyInfo()<br/>Detect: currentClient == creator
NewClient->>NewClient: Set hostTransferDispatched=true
NewClient->>Main: Dispatch host-transfer event<br/>(lobbyId, gameConfig, clients)
Main->>Main: handleHostTransfer()<br/>Validate data
Main->>NewClient: Close JoinLobbyModal
Main->>Main: Navigate to host page
Main->>HostModal: Call openExisting()<br/>(lobbyId, gameConfig, clients)
HostModal->>HostModal: loadNationCountThenRestore()<br/>Hydrate form state
HostModal->>Main: Ready with restored configuration
Main->>NewClient: Display confirmation:<br/>"You are now the host"
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
In discord we said we would rather close the lobby instead of host transfer, there’s two tickets open saying the same |
evanpelle
left a comment
There was a problem hiding this comment.
regarding the ux, do we want to transfer the host or just tell players that the host has left and the game is cancelled?
| this.lobbyId = lobbyId; | ||
|
|
||
| // Hydrate form state from the existing game config | ||
| this.selectedMap = gameConfig.gameMap; |
There was a problem hiding this comment.
do you think it would be possible to just store the gameConfig as a field instead of storing each element seperately?
Each time we add a new config option, we need to remember to add it here
I'm not totally sure. Wonder said that a discord discussion apparently concluded that we should close the lobby But letting the lobby open reduces frustration, everybody doesn't need to join again |
Description:
When the host of a private lobby leaves, the remaining players were shown a new host but that player had no actual host controls. DougDoug and many other people had this problem. This fixes the issue by:
creatorPersistentIDto the next active player when the host disconnects (private lobbies, pre-game only)JoinLobbyModalto aHostLobbyModalwith full controls (edit settings, kick players, start game)Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
FloPinguin