Skip to main content

Scripting model

Sanverse has three distinct scripting surfaces for Definitive Edition:

SurfaceRuns whereUse it forTrust level
Server-side TypeScriptSanverse serverplayers, NPCs, actors, vehicles, rules, persistence and authoritative world statetrusted resource
Client-side TypeScriptplayer's Sanverse clientlocal input, camera, HUD, effects and local presentationuntrusted client
CEF/browser UIembedded client UImenus, forms, inventory and web-style interfacesuntrusted UI

The server is authoritative. Client and CEF code never receive join tickets, server credentials, other players' private data or native game-memory access. A client request is validated and applied by a server resource; replicated state is then sent back to eligible clients.

Resource layout

resources/<name>/resource.json # server-side manifest
resources/<name>/dist/index.js # compiled server entry point
client-resources/<name>/resource.json
client-resources/<name>/dist/index.js

Server resources are loaded by server.json. Client resources are delivered only after a validated join and are versioned and integrity-checked by the launcher/client runtime. CEF bundles are loaded by a client resource and communicate with it through an explicit UI bridge.

Communication directions

DirectionMechanismExample
server → clientnamed client eventshow a notification or update a HUD
client → servernamed server request/eventask to interact with a vehicle; server validates player and distance
client ↔ CEFlocal typed UI bridgesubmit a menu form or render server-provided state
server ↔ native hostinternal request/responseread or mutate authoritative NPC/vehicle state

Use explicit event/request names and versioned payloads. Never trust client-supplied position, health, inventory or entity ownership; the server re-checks all gameplay mutations. Server NPCs, actors and ambient NPC toggles are server-side APIs and do not consume player slots.

API documentation conventions

Each API page will document: side, signature, parameters and limits, return value, events emitted, authority/security rules, and a runnable TypeScript example. Client APIs are documented separately from server APIs so a developer can immediately see which calls are authoritative and which are local presentation helpers.