- Modified startup script to instantiate GameProcessServer separately
before wrapping in WsServer/HttpServer, allowing direct access to
set event loop after IoServer creation
- Implemented setLoop() method to set event loop after construction
- Added error handling for fwrite() to gracefully handle broken pipes
when process closes
- Suppressed fread() warnings with @ operator to avoid noise
- Simplified startOutputReader() since event loop polling is now
handled directly in onOpen()
- Added null checks for event loop before using in timers
- Server now properly starts with continuous 100ms output polling
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
Issues fixed:
- GameProcessServer.readProcessOutput() was using fgets() which could cause
line breaks to be mishandled when reading multiple lines at once
- Changed to use fread() with 8KB buffer for non-blocking I/O
- fread() is better for interactive programs
- Properly handles newlines within chunks
- Doesn't break lines unnecessarily
Frontend improvements:
- Changed sendInput() to use terminal.writeln() instead of write() + write('\n')
- Ensures consistent line ending handling
- Cleaner terminal output
Changes:
1. GameProcessServer.php (readProcessOutput):
- Replaced fgets() loop with fread() loops
- 8192-byte buffer size for optimal performance
- Better handles non-blocking I/O streams
2. web/process.html (sendInput):
- Use terminal.writeln() for user input display
- More consistent with xterm.js behavior
Results:
- Line breaks now display correctly
- Output formatting preserved
- Better handling of rapid output
- No double line breaks
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Issues fixed:
- Remove redundant parameter in handleGameInput (line 195)
- Add getStateInfo() method to GameSession to return current game state
- Return state metadata in both handleGameRender() and handleGameInput()
- Add playerInfo (hp, mana, exp) to responses for UI sync
- Add state name mapping for debugging
Changes:
1. GameSession.php:
- Rename getPlayerInfo() to include full stats (mana, exp)
- Add getStateInfo() returning state, stateName, playerInfo
- Add getStateName() helper to convert state constant to string
2. server.php:
- Fix handleGameInput() parameter error
- handleGameRender() now returns state metadata
- handleGameInput() now returns state metadata
3. index.html (web):
- Add console.log for debugging state sync
- Add stateName logging to track state transitions
- Prepare for renderGame() refresh (commented)
These changes allow:
- Frontend to verify correct game state after each action
- Debugging state sync issues via browser console
- Foundation for state validation in UI
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Redesign web battle system from buffered to streaming architecture:
Backend Changes:
- New SSEOutput class for real-time event streaming to clients
- GameSession::streamBattle() for SSE-based battle execution
- Enhanced Screen::delay() to support SSE timing and buffering modes
- New /api/game/battle-stream endpoint handling SSE connections
Frontend Changes:
- Enhanced sendInput() to detect battle command (input "1")
- New streamBattle() function using EventSource for SSE connections
- Real-time log display matching terminal experience
- Event handlers for start, message, complete, error events
Benefits:
✓ Real-time streaming instead of waiting for complete battle
✓ Web frontend experience identical to terminal
✓ Lightweight implementation without WebSocket
✓ Automatic browser reconnection support
✓ ANSI colors fully preserved
✓ Backward compatible for non-battle screens
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>