@zaisma/cli 0.48.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skill/references/game-server.md +3 -2
- package/zaisma.mjs +2 -2
package/package.json
CHANGED
|
@@ -139,11 +139,12 @@ zaisma-server/
|
|
|
139
139
|
|
|
140
140
|
- **Plain JavaScript ES modules:** `zaisma-server/index.js` default-exports the game server above, and can import the folder's other files by relative path: `.js` code, `.json` data (`import levels from "./levels.json"`) and `.wasm` WebAssembly, like a physics engine (`import mod from "./physics.wasm"` gives a `WebAssembly.Module`; `new WebAssembly.Instance(mod, imports)` starts it). Packages from npm (`import "lodash"`) and TypeScript need a build step: bundle into one `zaisma-server.js` at the top of the upload instead (`npx esbuild server.ts --format=esm --bundle --outfile=zaisma-server.js`), or into `zaisma-server/index.js` when it has data files. Up to 500 files and 32 MB in all, data files included (`GAME_SERVER_LIMITS`).
|
|
141
141
|
- **Data files:** every other file in `zaisma-server/` (`.bin`, `.gz`, `.txt`, anything but `.js`, `.json` and `.wasm`) ships beside the code as a data file, like prebuilt navigation meshes, level geometry or a dictionary. `room.readDataFile("maps/docks.bin")` (or `server.readDataFile` in `onRequest`, `onSchedule` and `onWebhook`) answers it as an `ArrayBuffer`, by its path from `zaisma-server/`: no base64, no download, and nothing on the meter, since it comes with the code. It's the same `ArrayBuffer` every time, shared by every room of the version running in the same place, so read it and never change it; keep what you build from it in a variable outside the handlers (`const meshes = new Map()`) and every room there shares it too. A path with no data file throws a `GameServerError` `bad_room_call`. On your own server, data files are read from the game server's folder (`--data-folder`, or `startServer({ dataFolder })`; `zaisma-server` by default).
|
|
142
|
-
- **Time to start:** each call into the game server, a tick with the messages since the last one, a join, a request, has 50 ms of CPU (`GAME_SERVER_LIMITS.maximumCallCpuDurationMs`). A start has 5 seconds (`maximumStartCpuDurationMs`): loading the game server, `setup`, `onRestored`, and a real-time room's first tick after
|
|
142
|
+
- **Time to start:** each call into the game server, a tick with the messages since the last one, a join, a request, has 50 ms of CPU (`GAME_SERVER_LIMITS.maximumCallCpuDurationMs`). A start has 5 seconds (`maximumStartCpuDurationMs`): loading the game server, `setup`, `onRestored`, and a real-time room's first tick after any of them, or after the room puts its state back in a fresh copy of the game server (one that started again and lost its memory, or one opened again after a stop), whether or not the game has `onRestored`, so build what the match needs once (a map's navigation, its collision) in that first tick, not spread over many. The game server's top-level code, outside its handlers, has Cloudflare's 1 second as it loads (`maximumLoadCpuDurationMs`), so heavy work goes in that first tick. One copy of the game server, shared by the version's rooms in one place, has 128 MB of memory (`maximumMemorySizeBytes`), its data files included. Every second of CPU is on the game's hosting meter, starts included.
|
|
143
143
|
- **Sealed off:** nothing of Zaisma's but its own game's database and secrets, and other servers only on the hosts you list (below), so it talks to its players through `room` and its answers to their requests. State is plain JSON.
|
|
144
144
|
- **Private:** players never get its files; the game domain refuses `zaisma-server/` and `zaisma-server.js`.
|
|
145
|
-
- **Real-time rooms batch input:** in a room with `ticksPerSec`, the state stays inside the sandbox, and players' messages and bytes reach `onMessage` and `onBytes` just before the next `onTick`, in the order they came, with what they send going out then (at most a tick later). A handler that throws leaves the rest of the batch to run, and what it changed in the state before throwing stays, as on your own server, where they run as they come.
|
|
145
|
+
- **Real-time rooms batch input:** in a room with `ticksPerSec`, the state stays inside the sandbox, and players' messages and bytes reach `onMessage` and `onBytes` just before the next `onTick`, in the order they came, with what they send going out then (at most a tick later). A handler that throws leaves the rest of the batch to run, and what it changed in the state before throwing stays, as on your own server, where they run as they come. Either way a room's handlers run one at a time: one that awaits (the database, say) finishes before the room's next message, bytes or tick reaches the game server.
|
|
146
146
|
- **Kept in check:** an error in a handler loses that one message or tick and the match carries on. A call that runs past its CPU (above; a loop that never ends) is stopped, freezing the match meanwhile, and a match stopped twice ends. Your dashboard and the MCP's `get_stats` show these errors with the file and line they came from.
|
|
147
|
+
- **Memory outside the handlers:** a room's state is plain JSON, and it's all Zaisma keeps of a room. What the game server keeps in its own variables, outside the handlers (`const worlds = new Map()`), lives in the copy of the version that runs the room: the version's rooms running in the same place share it, as they share data files, and rooms elsewhere have copies of their own. It's lost whenever that copy starts again, which can happen at any time (a while unused, Zaisma's own updates, a call stopped for running too long), and then the room carries on from its last state, with no `onRestored` (that runs only when the room itself restarts): a turn-based room's state as of its last call, a real-time room's as of its last copy, taken every 5 seconds. So a world that isn't JSON (typed arrays, a collision tree, a physics engine's bodies) goes there, keyed by `room.roomCode`; each handler that finds its room's entry missing rebuilds it from the state, and the room deletes its entry once its match is over, since every room in that copy shares its 128 MB. On your own server and in play-locally, one process runs every room, so they all share it; it's lost when the process starts again (play-locally starts it again on each change to the game server), and every room then comes back through `onRestored`.
|
|
147
148
|
- **Updates:** rooms keep the version they started with until they end; new rooms get the live version.
|
|
148
149
|
|
|
149
150
|
The same file runs on your own machine too (below), so you can test it there or move off Zaisma any time.
|
package/zaisma.mjs
CHANGED
|
@@ -21,7 +21,7 @@ const KEY = process.env.ZAISMA_KEY || "";
|
|
|
21
21
|
const CLI_VERSION = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).version;
|
|
22
22
|
/** Files bigger than this go in parts; the server says how big each part is. */
|
|
23
23
|
const DIRECT_BYTES = 95 * 1024 * 1024;
|
|
24
|
-
// .zaisma-local
|
|
24
|
+
// .zaisma-local held what play-locally keeps (its keys, saves and database) before it moved out of the game's folder: never sent.
|
|
25
25
|
const JUNK = new Set([".DS_Store", "Thumbs.db", "desktop.ini", "__MACOSX", ".git", "node_modules", ".zaisma-local"]);
|
|
26
26
|
/** How long upload waits for the scan (200 checks, 3 seconds apart) before it says it's still scanning. ZAISMA_SCAN_CHECK_INTERVAL_MS is for tests. */
|
|
27
27
|
const SCAN_CHECK_INTERVAL_MS = Number(process.env.ZAISMA_SCAN_CHECK_INTERVAL_MS) || 3000;
|
|
@@ -2370,7 +2370,7 @@ async function installSkill(flags) {
|
|
|
2370
2370
|
/**
|
|
2371
2371
|
* play-locally: the game server package's command, run through npx so this command stays free of dependencies
|
|
2372
2372
|
* (ZAISMA_GAME_SERVER_BIN, a path to its bin/node.js, is for tests and the repository). Its output and exit code
|
|
2373
|
-
* come through as they are; with --json it prints { bench_url, game_site_url, rooms_url, network_url } once listening.
|
|
2373
|
+
* come through as they are; with --json it prints { bench_url, game_site_url, rooms_url, network_url, game_slug, is_game_slug_from_folder, bench_folder } once listening.
|
|
2374
2374
|
*/
|
|
2375
2375
|
async function playLocally(values, flags) {
|
|
2376
2376
|
const { spawn } = await import("node:child_process");
|