Repository navigation
Private Lobbies: Add kick player functionality - #1436
Conversation
Expanded the player management feature to allow the lobby host to kick players. Updated the `players` state structure to include both `username` and `clientID`, enabling host-specific actions. Introduced UI elements, such as a remove button and host badge, to enhance usability. Adjusted backend logic to facilitate host-only kicking for private games while maintaining admin override capability. The host is automatically assigned when the first client joins a private game. This change enhances overall control during gameplay setup.
Refactored the player kick functionality to use WebSocket events for better security and efficiency. Instead of HTTP requests, kicking a player is now handled through a "kick-player" event dispatched by the host. The server processes this intent securely, ensuring only hosts can kick players in private games and preventing hosts from kicking themselves.
Added localization for the "Host" badge text in the HostLobbyModal component to ensure language consistency across the application. Modified en.json to include a new entry for the host badge and updated HostLobbyModal.ts to use this localized value. This change prepares the UI for potential future multilingual support.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
Warning Rate limit exceeded@scottanderson has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 6 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (4)
WalkthroughA host-based player kicking feature was added for private lobbies. The host is now tracked, can remove players via the UI, and only the host can issue kick commands. Supporting changes include new event types, schema updates, UI enhancements for host/player distinction, and related CSS styling. Changes
Sequence Diagram(s)sequenceDiagram
participant Host as Host Client
participant UI as HostLobbyModal
participant Main as Client Main
participant Bus as EventBus
participant Transport as Transport
participant Server as GameServer
Host->>UI: Click "Kick" on player
UI->>Main: Dispatch "kick-player" event with target clientID
Main->>Bus: Emit SendKickPlayerIntentEvent(target)
Bus->>Transport: Send SendKickPlayerIntentEvent(target)
Transport->>Server: Send "kick_player" intent (target)
Server->>Server: Verify sender is host, private game, not self
alt Valid kick
Server->>Server: Remove (kick) target client
else Invalid
Server->>Server: Ignore or log attempt
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Poem
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
src/server/Worker.ts (1)
271-316: Ensure consistent response format across all authorization pathsThe endpoint returns different response formats for success cases. Consider standardizing the response structure.
if (isAdmin) { // Admin can kick anyone in any game game.kickClient(clientID); - res.status(200).send("Player kicked successfully (admin)"); + res.status(200).json({ success: true, message: "Player kicked successfully" }); return; }And at line 315:
game.kickClient(clientID); -res.status(200).send("Player kicked successfully"); +res.status(200).json({ success: true, message: "Player kicked successfully" });src/server/GameServer.ts (1)
269-274: Clarify log message for consistencyThe log message could be clearer about what's happening.
-this.log.info(`Host kicking player via secure WebSocket`, { +this.log.info(`Host initiated kick of player`, { authenticatedHostID: authenticatedClientID, targetClientID: clientMsg.intent.targetClientID, gameID: this.id, });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
resources/lang/en.json(1 hunks)src/client/ClientGameRunner.ts(2 hunks)src/client/HostLobbyModal.ts(5 hunks)src/client/Main.ts(7 hunks)src/client/Transport.ts(3 hunks)src/client/styles.css(1 hunks)src/core/Schemas.ts(4 hunks)src/server/GameServer.ts(4 hunks)src/server/Worker.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (7)
resources/lang/en.json (3)
Learnt from: andrewNiziolek
PR: openfrontio/OpenFrontIO#1007
File: resources/lang/de.json:115-115
Timestamp: 2025-06-02T14:27:37.609Z
Learning: For OpenFrontIO project: When localization keys are renamed in language JSON files, the maintainers separate technical changes from translation content updates. They wait for community translators to update the actual translation values rather than attempting to translate in the same PR. This allows technical changes to proceed while ensuring accurate translations from native speakers.
Learnt from: Aotumuri
PR: openfrontio/OpenFrontIO#1357
File: resources/lang/de.json:523-540
Timestamp: 2025-07-12T08:41:35.073Z
Learning: In OpenFrontIO project localization files, always check the en.json source file before flagging potential spelling errors in other language files, as some keys may intentionally use non-standard spellings that need to be consistent across all translations.
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#949
File: resources/lang/en.json:8-10
Timestamp: 2025-05-30T03:53:52.231Z
Learning: For the OpenFrontIO project, do not suggest updating translation files in resources/lang/*.json except for en.json. The project has a dedicated translation team that handles all other locale files.
src/client/styles.css (3)
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
Learnt from: its-sii
PR: openfrontio/OpenFrontIO#1089
File: src/client/styles/components/setting.css:9-22
Timestamp: 2025-06-07T19:47:34.514Z
Learning: In src/client/styles/components/setting.css, the padding difference between .setting-item and .setting-item-group is intentional - .setting-item-group doesn't need padding for the specific grouped setting styling being implemented.
src/client/ClientGameRunner.ts (1)
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
src/core/Schemas.ts (6)
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:34-38
Timestamp: 2025-05-21T04:10:33.435Z
Learning: In the codebase, PlayerStats is defined as `z.infer<typeof PlayerStatsSchema>` where PlayerStatsSchema has `.optional()` applied at the object level, making PlayerStats a union type that already includes undefined (PlayerStats | undefined).
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:44-53
Timestamp: 2025-05-21T04:10:59.706Z
Learning: In Zod, when a schema has `.optional()` applied at the object level, the TypeScript type inferred using `z.infer` already includes `undefined` in the union type. Therefore, when using such a type as a return type annotation, there's no need to explicitly add `| undefined`.
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:34-38
Timestamp: 2025-05-21T04:10:33.435Z
Learning: In the codebase, PlayerStats is defined as a type inferred from a Zod schema that is marked as optional, which means PlayerStats already includes undefined as a possible type (PlayerStats | undefined).
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:44-53
Timestamp: 2025-05-21T04:10:59.706Z
Learning: The PlayerStats type from ArchiveSchemas already includes undefined in its definition, making explicit union types with undefined (PlayerStats | undefined) redundant.
Learnt from: El-Magico777
PR: openfrontio/OpenFrontIO#1166
File: src/core/Schemas.ts:50-56
Timestamp: 2025-06-13T20:57:49.599Z
Learning: In the OpenFrontIO codebase, player identification primarily uses numeric smallIDs throughout the system (e.g., playerBySmallID). When adding new intents or schemas, maintain consistency with this existing pattern rather than introducing mixed ID types, even if string IDs might be more standard elsewhere.
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:189-209
Timestamp: 2025-05-18T23:43:38.150Z
Learning: When working with zod schemas in the OpenFrontIO project, values can be marked as possibly undefined by zod even if logic suggests they should always be defined. It's better to preserve the `| undefined` union types in method signatures to align with zod's type inference, even if runtime checks throw errors for invalid cases.
src/server/GameServer.ts (1)
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
src/client/Main.ts (2)
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
Learnt from: devalnor
PR: openfrontio/OpenFrontIO#1195
File: src/client/graphics/layers/AlertFrame.ts:18-18
Timestamp: 2025-06-20T20:11:00.965Z
Learning: In the OpenFrontIO codebase, UserSettings instances are created directly with `new UserSettings()` in each component that needs them. This pattern is used consistently across at least 12+ files including OptionsMenu, EventsDisplay, DarkModeButton, Main, UserSettingModal, UsernameInput, NameLayer, AlertFrame, UILayer, InputHandler, ClientGameRunner, and GameView. This is the established architectural pattern and should be followed for consistency.
src/client/HostLobbyModal.ts (1)
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
🧬 Code Graph Analysis (4)
src/client/Transport.ts (1)
src/core/EventBus.ts (1)
GameEvent(1-1)
src/client/ClientGameRunner.ts (1)
src/core/EventBus.ts (1)
EventBus(7-44)
src/server/Worker.ts (1)
src/server/GameManager.ts (1)
game(18-20)
src/client/HostLobbyModal.ts (3)
src/client/LangSelector.ts (1)
translateText(233-253)src/client/Utils.ts (1)
translateText(79-98)src/core/Util.ts (1)
generateID(256-262)
🔇 Additional comments (12)
resources/lang/en.json (1)
215-215: LGTM! Clean translation addition.The new host badge translation key is properly placed in the host_modal section and follows the project's naming patterns.
src/client/Transport.ts (3)
169-171: LGTM! Event class follows established patterns.The
SendKickPlayerIntentEventclass correctly implements theGameEventinterface and follows the same pattern as other event classes in this file.
249-251: LGTM! Consistent event bus registration.The event listener registration follows the same pattern as other intent events and is placed in the appropriate constructor section.
623-629: LGTM! Handler implementation is clean and consistent.The
onSendKickPlayerIntentmethod follows the exact same pattern as other intent handlers, using the establishedsendIntentmechanism with proper client ID and target client ID fields.src/client/styles.css (2)
679-683: LGTM! Host badge styling is clear and accessible.The green color and bold font weight effectively distinguish the host from other players.
685-702: LGTM! Remove button styling is intuitive.The circular red button with hover state provides clear visual feedback for the kick action. The size and positioning are appropriate for the UI.
src/client/ClientGameRunner.ts (2)
64-64: LGTM! Good API design improvement.Changing the return type from a simple function to an object with
stopmethod andeventBusproperty is a clean way to expose the needed functionality while maintaining backwards compatibility through thestopmethod.
116-122: LGTM! Clean implementation of the new return structure.The returned object properly exposes both the cleanup functionality and the event bus needed for the kick player feature integration.
src/core/Schemas.ts (4)
45-45: LGTM! Clean union type extension.Adding
KickPlayerIntentto theIntentunion type follows the established pattern and maintains type safety.
77-77: LGTM! Consistent type alias definition.The
KickPlayerIntenttype alias follows the same pattern as other intent type aliases in this file.
364-367: LGTM! Schema definition follows established patterns.The
KickPlayerIntentSchemacorrectly extendsBaseIntentSchemaand uses theIDtype fortargetClientID, maintaining consistency with the codebase's ID handling patterns.
390-390: LGTM! Proper integration into discriminated union.Adding
KickPlayerIntentSchemato the discriminated union maintains the type safety and validation framework.
This change consolidates the .player-tag CSS definition by merging and removing redundant code blocks. The updated styling now uses inline-flex for layout, a dark background color, white text, increased padding, and introduces a gap for alignment, ensuring consistency and reducing duplication in the stylesheet.
This commit removes unnecessary console logging statements from the `kickPlayer` method in HostLobbyModal.ts and the `handleKickPlayer` method in Main.ts. These logs were primarily for debugging and are no longer needed, leading to a cleaner and less cluttered codebase.
|
@CodeRabbitReview review |
|
Tip For best results, initiate chat on the files or code changes. @floriankilian I notice you mentioned I've already provided a comprehensive review of your PR above, including:
The review covers your private lobby kick functionality, the UI changes for host badges and remove buttons, and the backend authorization improvements. Is there any specific aspect of the implementation you'd like me to dive deeper into, or any particular concerns you have about the code? |
|
|
Refactored the 'kick_player' event to consistently use 'target' instead of 'targetClientID', simplifying the interface across client and server modules. Removed redundant return values from `joinLobby` function in `ClientGameRunner.ts`, and streamlined event bus usage.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Description:
Added player management features so lobby hosts can kick players from private games. This includes both UI changes and backend work.
What's new:
How it works:
Known Issues:
Other Issues:
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
[UN]nvm