Skip to content

Close private lobby when host leaves 🚪#3503

Merged
evanpelle merged 1 commit intomainfrom
close-lobby-when-host-leaves
Mar 24, 2026
Merged

Close private lobby when host leaves 🚪#3503
evanpelle merged 1 commit intomainfrom
close-lobby-when-host-leaves

Conversation

@FloPinguin
Copy link
Contributor

Description:

When the host of a private lobby disconnects before the game starts, the lobby is now closed:

  • Server: Detects host disconnection via creatorPersistentID match, kicks all remaining clients with a host_left reason, and marks the game as ended so it's cleaned up by the game manager and can no longer be joined.
  • Client: Participants receive an alert() saying "The host has left the lobby." and their JoinLobbyModal is closed automatically via the leave-lobby event.
  • Phase logic: phase() now returns Finished for ended private lobbies that haven't started, preventing the game from lingering in Lobby state.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

FloPinguin

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 24, 2026

Walkthrough

This pull request adds a new kick reason for when the lobby host disconnects before the game starts. It includes server-side detection of host disconnection, client-side error handling with user alerts, and localization support for the kick message.

Changes

Cohort / File(s) Summary
Localization
resources/lang/en.json
Added new translation key kick_reason.host_left with message "The host has left the lobby."
Server Game Logic
src/server/GameServer.ts
Detects when lobby host disconnects before game starts; kicks all remaining players with KICK_REASON_HOST_LEFT and marks game as ended. Updates phase() control flow to return GamePhase.Finished when game ends without starting.
Client Error Handling
src/client/ClientGameRunner.ts
Handles kick_reason.host_left error by displaying translated alert and dispatching leave-lobby custom event with cause: "host-left".

Sequence Diagram

sequenceDiagram
    participant Host as Host Client
    participant Server as GameServer
    participant OtherPlayers as Other Players
    
    Host->>Server: Disconnects (close event)
    activate Server
    Server->>Server: Detect host disconnect<br/>(creatorPersistentID matches,<br/>!hasStarted, !isPublic)
    Server->>Server: Set _hasEnded = true
    Server->>OtherPlayers: kickClient(...,<br/>KICK_REASON_HOST_LEFT)
    deactivate Server
    
    OtherPlayers->>OtherPlayers: Receive error message<br/>kick_reason.host_left
    OtherPlayers->>OtherPlayers: Show alert
    OtherPlayers->>OtherPlayers: Dispatch<br/>leave-lobby event
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related issues

  • Add handling of kick reasons #1654: This PR directly implements the kick reason handling system by adding KICK_REASON_HOST_LEFT detection on the server and client-side error handling for kick reason messages.

Poem

🚪 When the host takes their leave,
The lobby must grieve—
One kick message sent,
Players off they went,
New phase returns with reprieve! 🎭

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main feature: closing a private lobby when the host disconnects, which is the primary objective across all three modified files.
Description check ✅ Passed The description is well-structured and directly related to the changeset, explaining server-side detection, client-side notifications, and phase logic updates that align with the code modifications.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/server/GameServer.ts`:
- Around line 541-554: Host leaving before game start can set _hasEnded = true
while gameStartInfo is still unset, causing archive logic in end() to access
missing start data; update GameServer.end() to guard the archive/finish flow by
returning early (or skipping archive) if the game never actually started—e.g.,
check this._hasStarted and/or that this.gameStartInfo is defined before running
any code that uses start data, and ensure _hasEnded stays true but archive is
not invoked when those conditions fail.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cfbbae2a-ca58-471b-add5-74fe14fc6de7

📥 Commits

Reviewing files that changed from the base of the PR and between 496f100 and e0d9765.

📒 Files selected for processing (3)
  • resources/lang/en.json
  • src/client/ClientGameRunner.ts
  • src/server/GameServer.ts

@github-project-automation github-project-automation bot moved this from Triage to Development in OpenFront Release Management Mar 24, 2026
Copy link
Collaborator

@evanpelle evanpelle left a comment

Choose a reason for hiding this comment

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

thanks!

@github-project-automation github-project-automation bot moved this from Development to Final Review in OpenFront Release Management Mar 24, 2026
@evanpelle evanpelle merged commit 0dc5224 into main Mar 24, 2026
14 checks passed
@evanpelle evanpelle deleted the close-lobby-when-host-leaves branch March 24, 2026 20:00
@github-project-automation github-project-automation bot moved this from Final Review to Complete in OpenFront Release Management Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

2 participants