Spaces:
Sleeping
Sleeping
Backend Architecture Update
Core Components
- GameManager (Source of Truth):
- Manages
Map<string, Room>with Automatic Cleanup (garbage collects empty rooms > 5 mins old). - Enforces Server-Side Timer for all phases (Night 15s, Day 30s, Voting 15s).
- Handles Game Logic: Role assignment (Unique distribution), Night Actions (Kill/Save/Investigate), Voting Tally, and Win Conditions.
- Manages
- Sanitizer (Anti-Cheat):
sanitizeRoomState(room, socketId)ensures clients never receive hidden data (e.g., other players' roles) unless allowed (e.g., Mafia teammates).
- Strict Types:
- Updated
types/index.tsto enforceGamePhase,Role, andRoomstructure. - Switched internal storage to
Recordfor better serialization.
- Updated
Key Logic Details
- Night: Mafia Kill vs Doctor Save logic implemented. Detective gets instant private feedback.
- Joker: Specific win condition on Day Vote (Win) vs Night Kill (Loss).
- Disconnects: Handled gracefully. Host migrates if in Lobby. Active players marked offline but kept in game state until timeout/cleanup.
Integration
RoomManager.tswas removed (consolidated intoGameManager).socketHandler.tsupdated to usetry/catchblocks for all events to prevent server crashes.
Verification
npm run buildpassed successfully.