Skip to content

feat: production hardening — input validation, anti-cheat, reconnection, zone backup#57

Merged
Taure merged 6 commits intomainfrom
feat/production-hardening
Apr 6, 2026
Merged

feat: production hardening — input validation, anti-cheat, reconnection, zone backup#57
Taure merged 6 commits intomainfrom
feat/production-hardening

Conversation

@Taure
Copy link
Copy Markdown
Contributor

@Taure Taure commented Apr 6, 2026

Summary

Four critical production hardening changes for 60-minute session games:

Phase 1: Input Validation

  • safe_handle_message try/catch wrapper prevents WS handler crashes from malformed payloads
  • Chat content length limit (2000 bytes)

Phase 2: Anti-Cheat Basics

  • Pass tick number into ZoneState for game module cooldown tracking
  • anticheat_violation/3 telemetry event for suspicious input logging

Phase 3: Reconnection Grace Period

  • Wire asobi_reconnect module to world server (module already existed)
  • Monitor player session PIDs, detect disconnect via DOWN messages
  • Grace period keeps entity alive in zones during network blips
  • On reconnect: re-subscribe to zones, re-monitor new session
  • ETS asobi_player_worlds table for PlayerId→WorldPid lookup
  • WS handler checks for pending reconnect on session.connect
  • Backwards compatible: games without reconnect config unchanged

Phase 4: Zone Entity State Backup

  • Backup zone entity state to ETS every 20 ticks (~1 second)
  • On zone restart, recover entities from ETS backup
  • Normal shutdown clears backup, crash preserves it

Test plan

  • 170 eunit tests pass, 0 failures

Taure added 5 commits April 6, 2026 20:14
- Wrap all handle_message dispatches in safe_handle_message try/catch
- Catches badmatch, badkey, function_clause, case_clause errors
- Returns error reply to client instead of crashing the WS process
- Add chat content length limit (2000 bytes)
- Log unexpected crashes via logger:warning

Previously, missing payload fields (e.g. chat.send without content)
would crash the WS handler, killing the session and disconnecting
the player. Now returns {error, invalid_payload} gracefully.
- Pass tick number into ZoneState before calling GameMod:zone_tick
- Add anticheat_violation/3 telemetry event for logging suspicious inputs
- Game modules can now track tick count for cooldown enforcement
- Add reconnect_state to world server init (from config reconnect key)
- Monitor player session PIDs on join, detect disconnect via DOWN
- Grace period via asobi_reconnect module (already existed, now wired)
- On disconnect: start grace timer, keep entity alive in zones
- On reconnect: re-subscribe to zones, re-monitor new session
- On grace expiry: remove player from world and zones
- ETS asobi_player_worlds table for PlayerId→WorldPid lookup
- ETS asobi_world_state table for zone crash recovery (Phase 4)
- WS handler checks for pending reconnect on session.connect
- Backwards compatible: games without reconnect config unchanged
- Backup zone entity state to ETS every 20 ticks (~1 second)
- On zone restart, recover entities from ETS backup
- Normal/graceful shutdown clears backup
- Abnormal termination preserves backup for recovery
- Uses asobi_world_state ETS table (created in asobi_world_sup)
@Taure Taure force-pushed the feat/production-hardening branch from 0008be0 to 1016454 Compare April 6, 2026 18:18
@Taure Taure merged commit e28252a into main Apr 6, 2026
15 checks passed
@Taure Taure deleted the feat/production-hardening branch April 6, 2026 18:40
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.

1 participant