A ruleset is identified as “name@major version”, for example
doudizhu@1. A game declares its ruleset in realtime.ruleset in manifest.json.
Determinism
A ruleset must be a pure function: the same state, action, and random numbers produce the same result.- Use only the random numbers the room provides. The seed is committed publicly before the match and revealed afterward, so the match can be replayed in full.
- Do not read the clock or access the network or files.
- The state must serialize to JSON and read back. The platform uses it for snapshots and cross-instance takeover.
First-party rulesets
The platform’s own games are written in Go and compiled into the game service, for example Dou Dizhudoudizhu@1 and Gomoku gomoku@1.
Third-party rulesets (WASM)
A third-party ruleset is a WASM module that exports the following functions, all with JSON input and output:state is JSON defined by the ruleset, and the platform stores it as is. An event with an empty to is visible to everyone (including spectators); otherwise it is sent only to the listed seats. The error returned by nl_apply is sent back to the client as the failure reason in action.ack.
ABI (version 1)
- Export
memory,nl_abi_version() -> i32(returns1),nl_alloc(size i32) -> i32, andnl_free(ptr i32, size i32). - Every rule function has the signature
(ptr i32, len i32) -> i64. The input JSON is at[ptr, ptr+len); the high 32 bits of the return value are the output pointer and the low 32 bits are the output length. The platform callsnl_freeafter reading it. - Imports from module
"nl":rng_u32() -> i32: the room’s deterministic random number. Call it only innl_setupandnl_apply.log(ptr i32, len i32): debug logging, rate-limited in production.
- WASI is not imported: there is no clock, file system, network, or environment variables.
- Limits: up to 16 MiB of linear memory and up to 50 milliseconds per call. A call that exceeds them fails.
ruleset.json
id consists of lowercase letters, digits, dots, and hyphens, and third-party rulesets carry a developer prefix (such as dev.). Bump the major version when you change the state format or the rules; rooms in progress keep using the old version. Player count is 1–16.
Planned publishing flow
- Upload
module.wasm(up to 4 MiB) andruleset.json. The response is{id, sha256, status: "pending_review"}. - Staff review it: they check the source or a reproducible build, verify that the same input produces the same output twice, and run a large number of random matches within the limits.
- Once approved, the game service loads the module, and
realtime.rulesetinmanifest.jsonand table configurations can use the name.
