Skip to content

Fix endgame role mask bug on 5th policy liberal victory#199

Open
AnyaJain wants to merge 1 commit into
ShrimpCryptid:developmentfrom
AnyaJain:fix-liberal-victory-roles
Open

Fix endgame role mask bug on 5th policy liberal victory#199
AnyaJain wants to merge 1 commit into
ShrimpCryptid:developmentfrom
AnyaJain:fix-liberal-victory-roles

Conversation

@AnyaJain
Copy link
Copy Markdown

Problem

Fixes #164
Fixes #157 I think

On a 5-policy Liberal victory, the game-over screen hides the true roles of all other players (rendering them blank or defaulting them to Fascist identities). This happens due to a race condition where the game instance state is completely nullified mid-flight inside Lobby.java before all players' outbound WebSocket frames finish serialization, combined with a state-machine issue where policy placement logic overwrites the victory status with a standard gameplay phase before the final broadcast evaluation.

Solution

  1. State Preservation: Modified SecretHitlerGame.onEnactPolicy() to run checkIfGameOver() and return early if a victory condition is met, preventing the victory state from being immediately overwritten by subsequent gameplay cycles.
  2. Delayed Session Cleanup: Refactored Lobby.updateAllUsers() to move the game session deletion block (game = null) to the absolute bottom of the method. This ensures every connected user's WebSocket connection finishes broadcasting unmasked identities before the state memory is torn down.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Change summary:

  • Fix endgame role mask bug on 5th policy liberal victory
  • Refactor Lobby updates to broadcast unmasked roles prior to session nullification

Steps to Verify:

  1. Launch the application locally using docker-compose up --build.
  2. Open multiple browser tabs/windows to fill a match lobby with human players and/or CPU bots. (IT TOOK ME THREE)
  3. Advance the match until the Liberal team successfully enacts their 5th and final policy on the board. (TOOK FOREVER js open three tabs the bots are too good for a predictable outcome)
  4. Expected behavior: The final screen accurately renders the true unmasked identities (Liberal, Fascist, or Hitler) for all active players and bots seamlessly across all connected clients.
  5. Suggestions for testing: Temporarily set LIBERAL_POLICIES_TO_WIN = 1 in your game rules configuration to test the victory end-screen state instantly.

Keyfiles:

  1. backend/src/main/java/game/SecretHitlerGame.java
  2. backend/src/main/java/server/util/Lobby.java

@ShrimpCryptid ShrimpCryptid self-requested a review May 28, 2026 16:31
@ShrimpCryptid
Copy link
Copy Markdown
Owner

Thanks for your patience and for the contribution! Going to take a look at this when I have time but the changes overall look clean and simple :)

Just a fair warning, it may take a while before these changes are live-- I'm having some fun and exciting new bugs on the development branch that I haven't had the motivation to chase down yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Roles incorrect on end screen End of game reveal doesn't show correct roles

2 participants