1.5 KiB
1.5 KiB
2024-12-18 16:55:00 - Implement Server Persistence and Room Cleanup
Description
Implemented server-side state persistence to ensure game rooms, drafts, and game states survive server restarts and network issues. Added logic to keep rooms alive for at least 8 hours after the last activity, satisfying the requirements for robustness and re-joinability.
Key Changes
-
Persistence Manager:
- Created
PersistenceManager.tsto save and loadrooms,drafts, andgamesto/from JSON files in./server-data. - Integrated into
server/index.tswith auto-save interval (every 5s) and save-on-shutdown.
- Created
-
Room Manager:
- Added
lastActivetimestamp toRoominterface. - Updated
lastActiveon all significant interactions (join, leave, message, etc.). - Implemented
disconnectlogic: if players disconnect, the room is NOT deleted immediately. - Implemented
leaveRoomlogic: Explicit leaving (waiting phase) still removes players but preserves the room until cleanup if empty. - Added
cleanupRooms()method running every 5 minutes to delete rooms inactive for > 8 hours.
- Added
Impact
- Reliability: Server crashes or restarts will no longer wipe out active games or drafts.
- User Experience: Users can reconnect to their room even hours later (up to 8 hours), or after a server reboot, using their room code.
- Maintenance:
server-datadirectory now contains the active state, useful for debugging.
Status
- Code implementation complete.
- Verify
server-datafolder is created and populated on run.