implemented game server sync
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
|
||||
# 2024-12-18 16:35:00 - Refactor Game Battlefield Sidebar
|
||||
|
||||
## Description
|
||||
Refactored the `GameView` sidebar to be graphically and functionally consistent with `DeckBuilderView` and `DraftView`.
|
||||
|
||||
## Key Changes
|
||||
- **Component**: `GameView.tsx`
|
||||
- **Functionality**:
|
||||
- Implemented collapsible sidebar state with persistence (`game_sidebarCollapsed`).
|
||||
- Implemented resizable sidebar width with persistence (`game_sidebarWidth`).
|
||||
- Added transition animations for collapsing/expanding.
|
||||
- **Visuals**:
|
||||
- Adopted the "Card Preview" style with a 3D flip effect.
|
||||
- Used `back.jpg` (path `/images/back.jpg`) for the empty/back state.
|
||||
- Moved the resize handle *inside* the sidebar container with consistent styling (floating pill).
|
||||
- Preserved Oracle Text display below the card image (as it is critical for gameplay), styled within the new container.
|
||||
|
||||
## Consistent Elements
|
||||
- **Icons**: Used `Eye` and `ChevronLeft` from Lucide.
|
||||
- **Styling**: `slate-900` backgrounds, glassmorphism borders (`slate-800/50`), shadow effects.
|
||||
- **Behavior**: Sidebar width allows dragging between 200px and 600px.
|
||||
|
||||
## Status
|
||||
- [ ] Verify `back.jpg` exists in the deployed `public/images` folder (currently assumed based on other files).
|
||||
- [x] Code refactoring complete.
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
# 2024-12-18 16:45:00 - Implement Game Persistence on Reload
|
||||
|
||||
## Description
|
||||
Updated `LobbyManager.tsx` to ensure that when a user reloads the page and automatically rejoins a room, the active game state (`initialGameState`) is correctly retrieved from the server and passed to the game view components.
|
||||
|
||||
## Key Changes
|
||||
- **Component**: `LobbyManager.tsx`
|
||||
- **Functionality**:
|
||||
- Added `initialGameState` state.
|
||||
- Updated `join_room` and `rejoin_room` response handling to capture `gameState` if present.
|
||||
- Passed `initialGameState` to the `GameRoom` component.
|
||||
|
||||
## Impact
|
||||
- **User Experience**: If a user is in the middle of a game (battlefield phase) and refreshes the browser, they will now immediately see the battlefield state instead of a loading or broken screen, ensuring continuity.
|
||||
- **Data Flow**: `GameRoom` uses this prop to initialize its local `gameState` before the first socket update event arrives.
|
||||
|
||||
## Status
|
||||
- [x] Implementation logic complete.
|
||||
- [ ] User testing required (refresh page during active game).
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
# 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
|
||||
1. **Persistence Manager**:
|
||||
- Created `PersistenceManager.ts` to save and load `rooms`, `drafts`, and `games` to/from JSON files in `./server-data`.
|
||||
- Integrated into `server/index.ts` with auto-save interval (every 5s) and save-on-shutdown.
|
||||
|
||||
2. **Room Manager**:
|
||||
- Added `lastActive` timestamp to `Room` interface.
|
||||
- Updated `lastActive` on all significant interactions (join, leave, message, etc.).
|
||||
- Implemented `disconnect` logic: if players disconnect, the room is NOT deleted immediately.
|
||||
- Implemented `leaveRoom` logic: 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.
|
||||
|
||||
## 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-data` directory now contains the active state, useful for debugging.
|
||||
|
||||
## Status
|
||||
- [x] Code implementation complete.
|
||||
- [ ] Verify `server-data` folder is created and populated on run.
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
# 2024-12-18 17:05:00 - Distributed Storage with Redis
|
||||
|
||||
## Description
|
||||
Implemented distributed storage using Redis (`ioredis`) to support horizontal scaling and persistence outside of local file systems, while retaining local storage for development.
|
||||
|
||||
## Key Changes
|
||||
1. **Dependencies**: Added `ioredis` and `@types/ioredis`.
|
||||
2. **Redis Manager**: created `RedisClientManager.ts` to manage connections:
|
||||
- `db0`: Session Persistence (Rooms, Drafts, Games).
|
||||
- `db1`: File Storage (Card Images, Metadata).
|
||||
- Enabled via environment variable `USE_REDIS=true`.
|
||||
3. **Persistence Manager**: Updated `PersistenceManager.ts` to read/write state to Redis DB 0 if enabled.
|
||||
4. **File Storage Manager**: Created `FileStorageManager.ts` to abstract file operations (`saveFile`, `readFile`, `exists`).
|
||||
- Uses Redis DB 1 if enabled.
|
||||
- Uses Local FS otherwise.
|
||||
5. **Card Service**: Refactored `CardService.ts` to use `FileStorageManager` instead of `fs` direct calls.
|
||||
6. **Server File Serving**: Updated `server/index.ts` to conditionally serve files:
|
||||
- If Redis enabled: Dynamic route intercepting `/cards/*` to fetch from Redis DB 1.
|
||||
- If Local: Standard `express.static` middleware.
|
||||
|
||||
## Configuration
|
||||
- `USE_REDIS`: Set to `true` to enable Redis.
|
||||
- `REDIS_HOST`: Default `localhost`.
|
||||
- `REDIS_PORT`: Default `6379`.
|
||||
|
||||
## Status
|
||||
- [x] Code implementation complete.
|
||||
- [ ] Redis functionality verification (requires Redis instance).
|
||||
Reference in New Issue
Block a user