Networking Architecture
Hyperscape uses a server-authoritative architecture with WebSocket-based real-time communication. The server runs at 600ms ticks while clients render at 60 FPS using prediction and interpolation.Network code lives in
packages/shared/src/systems/client/ClientNetwork.ts (2640+ lines) and packages/server/src/systems/ServerNetwork/.Architecture Overview
Binary Protocol
Communication uses msgpackr binary serialization for efficiency.Packet Format
Entity Update Optimization
Entity updates use abbreviated keys to minimize bandwidth:Combat State Synchronization (Fixed in PR #933)
The combat system uses abbreviated keys for network efficiency, but this caused a critical bug where AI agents couldn’t detect combat state correctly. The Bug (Fixed Feb 25, 2026):CombatStateService syncs abbreviated keys (data.c/data.ct) but EmbeddedHyperscapeService.getGameState() only read full keys (data.inCombat/data.combatTarget). This caused DuelCombatAI to always see inCombat=false and flood executeAttack every tick instead of letting auto-attacks drive combat.
The Fix:
- Network bandwidth optimization for frequent entity updates
inCombat→csaves 7 bytes per packetcombatTarget→ctsaves 10 bytes per packet- Multiplied by 8 Hz sync rate = significant bandwidth savings
packages/server/src/eliza/EmbeddedHyperscapeService.ts(fixed)packages/shared/src/systems/shared/combat/CombatStateService.ts(uses abbreviated keys)- Any system reading combat state from entity data should use the compatibility pattern
handleMagicAttack where cooldown was checked early but claimed after async consumeRunesForSpell. With the combat state bug flooding attacks, two concurrent invocations could both pass the cooldown check before either claimed it, causing duplicate magic projectiles. Fixed by moving cooldown claim before async rune consumption.
See Combat System - Critical Bug Fixes for complete details.
Example Packet
Packet Types
Client → Server
Server → Client
Client-Side Prediction
The client predicts movement locally for responsive controls, then reconciles with server authority.Prediction Flow
Interpolation for Remote Entities
Server Network System
The server handles all authoritative game logic.Connection Flow
Packet Handlers
Event Bridge
TheEventBridge converts game events to network packets automatically.