Overview
The@hyperscape/server package runs the authoritative game server:
- Fastify 5 HTTP API with rate limiting
- WebSocket real-time game state
- PostgreSQL (production) / SQLite (local) database
- LiveKit voice chat integration
Package Location
Entry Point
src/index.ts initializes:
- Database connection (PostgreSQL or SQLite)
- Asset CDN (Docker nginx, optional)
- Fastify HTTP server with plugins
- WebSocket handlers
- Game world and systems
API Routes
Database
The server supports both PostgreSQL (production via Neon) and SQLite (local development). Schema is defined with Drizzle ORM.Key Tables
Database Commands
Environment Variables
Build Scripts
Model Bounds Extraction
The server includes build-time scripts for automatic collision footprint detection:- Scans
world/assets/models/**/*.glbfiles - Parses glTF position accessor min/max values
- Calculates bounding boxes and dimensions
- Computes tile footprints at scale 1.0
- Writes manifest for runtime use
- Runs automatically before
buildanddevcommands - Cached based on GLB file changes
- Only rebuilds when models are added/modified
Footprints are calculated from model dimensions ×
modelScale from stations.json. A furnace with raw dimensions 1.51×1.45 and scale 1.5 becomes 2.27×2.18 meters → 2×2 tiles.Running
Development
Production
http://localhost:5555 by default.
Dependencies
Docker Services
The server can use Docker for CDN and PostgreSQL:Deployment
Cloudflare Workers
Railway
Therailway.server.json in the project root configures Railway deployment.
ElizaCloud AI Integration (March 2026)
All duel arena AI agents now use@elizaos/plugin-elizacloud for unified model access (commit 4d1eb53).
13 Frontier Models:
American Models:
openai/gpt-5- GPT-5anthropic/claude-sonnet-4.6- Claude Sonnet 4.6anthropic/claude-opus-4.6- Claude Opus 4.6google/gemini-3.1-pro-preview- Gemini 3.1 Proxai/grok-4- Grok 4meta/llama-4-maverick- Llama 4 Maverickmistral/magistral-medium- Magistral Medium
deepseek/deepseek-v3.2- DeepSeek V3.2alibaba/qwen3-max- Qwen 3 Maxminimax/minimax-m2.5- Minimax M2.5zai/glm-5- GLM-5moonshotai/kimi-k2.5- Kimi K2.5bytedance/seed-1.8- Seed 1.8
- Simplified configuration (one API key instead of multiple provider keys)
- Access to 13 frontier models from 13 different providers
- Consistent model routing and error handling
- Reduced dependency complexity
src/eliza/agentHelpers.ts- Addedelizacloudprovidersrc/eliza/ModelAgentSpawner.ts- Updated model agent spawningpackages/plugin-hyperscape/src/index.ts- Added ElizaCloud plugin types
Duel Arena Oracle (March 2026)
The server publishes duel outcomes to EVM and Solana oracle contracts for verifiable results (commit aecab58). New Oracle Fields:damageA- Total damage dealt by participant AdamageB- Total damage dealt by participant BwinReason- Detailed win reason (knockout, timeout, forfeit, draw)seed- Cryptographic seed for replay verificationreplayHashHex- Hash of replay data for integrity verificationresultHashHex- Combined hash of all duel outcome data
arena_rounds table with comprehensive outcome data for betting market settlement and replay verification.
Files:
src/oracle/DuelArenaOraclePublisher.ts- Oracle publishing logicsrc/oracle/config.ts- Oracle configuration and target managementsrc/oracle/types.ts- Oracle type definitions
Duel System
The server includes a comprehensive duel arena system with AI combat, streaming, and betting integration.Combat Roles (PR #933, commit 82ff784)
Duel agents are assigned weighted random combat roles:- Melee (50%): Bronze weapons (longsword, scimitar, 2h sword)
- Ranged (25%): Shortbow + bronze arrows (500 qty)
- Mage (25%): Staff of air + wind strike autocast + runes
DuelOrchestrator.pickCombatRole(): Weighted random selectionDuelOrchestrator.ensureAgentCombatSetup(): Role-specific gear equippingDuelOrchestrator.cleanupAgentCombatSetup(): Full gear removal after duelDuelCombatAI: Adapts style switching based on combat role
- Pre-duel: Role selected → gear equipped → food filled → health restored
- Post-duel: Gear removed → food removed → health restored → teleport back
Critical Bug Fixes (PR #933)
Combat State Key Mismatch:- Issue: CombatStateService syncs abbreviated keys (
data.c/data.ct) butgetGameState()only read full keys - Impact: DuelCombatAI always saw
inCombat=falseand floodedexecuteAttackevery tick - Fix: EmbeddedHyperscapeService now reads both abbreviated and full keys
- File:
packages/server/src/eliza/EmbeddedHyperscapeService.ts
- Issue: Cooldown checked early but claimed after async
consumeRunesForSpellcall - Impact: Duplicate magic projectiles, double rune consumption
- Fix: Moved cooldown claim and
enterCombatbefore async rune consumption - File:
packages/shared/src/systems/shared/combat/CombatSystem.ts
Terrain Flat Zones (commit 7a60135)
DuelArenaVisualsSystem registers flat zones programmatically for all 8 floor areas (6 arenas + lobby + hospital):- Prevents players/agents from sinking ~0.4m into arena floors
- Terrain height queries return correct floor-level values
- Terrain mesh carved under floors to prevent grass/vegetation clipping
- File:
packages/shared/src/systems/client/DuelArenaVisualsSystem.ts