@zaisma/cli 0.20.0 → 0.22.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/check.d.mts +1 -0
- package/check.mjs +11 -4
- package/package.json +1 -1
- package/zaisma.mjs +19 -1
package/check.d.mts
CHANGED
|
@@ -71,4 +71,5 @@ export const CHECK_PROBLEM_CODES: Record<CheckProblemCode, { problemKind: Proble
|
|
|
71
71
|
export function extensionOf(path: string): string;
|
|
72
72
|
export function isEngineOutput(path: string, lowercasePaths: Set<string>): boolean;
|
|
73
73
|
export function findOutsideReferences(text: string, fileKind: "html" | "css" | "module", options?: { baseUrl?: string | null }): OutsideReference[];
|
|
74
|
+
export function buildHasThreads(files: Pick<CheckedFile, "path" | "contentText">[]): boolean;
|
|
74
75
|
export function checkGameFiles(files: CheckedFile[], options?: { slug?: string | null; ownServerUrls?: readonly string[] | null }): GameCheck;
|
package/check.mjs
CHANGED
|
@@ -41,7 +41,7 @@ export const CHECK_PROBLEM_CODES = {
|
|
|
41
41
|
outside_file: { problemKind: "broken", isFixedByUploadCommand: true, meaning: "The page, a stylesheet or a module loads a file from another site; the upload command downloads it into the game." },
|
|
42
42
|
outside_address: { problemKind: "broken", isFixedByUploadCommand: false, meaning: "The code connects to or loads from another site while it runs." },
|
|
43
43
|
address_not_allowed: { problemKind: "broken", isFixedByUploadCommand: false, meaning: "The code connects to an address no game can use: plain ws:// or http://, localhost, or an IP address." },
|
|
44
|
-
needs_threads: { problemKind: "broken", isFixedByUploadCommand: false, meaning: "The build needs threads (SharedArrayBuffer), which games on Zaisma
|
|
44
|
+
needs_threads: { problemKind: "broken", isFixedByUploadCommand: false, meaning: "The build needs threads (SharedArrayBuffer), which games on Zaisma have only in Chrome and Edge." },
|
|
45
45
|
browser_dialog: { problemKind: "broken", isFixedByUploadCommand: false, meaning: "alert, confirm or prompt, which never show in the game's frame." },
|
|
46
46
|
form_submission: { problemKind: "broken", isFixedByUploadCommand: false, meaning: "A form, which never submits in the game's frame." },
|
|
47
47
|
file_download: { problemKind: "broken", isFixedByUploadCommand: false, meaning: "A file download, which the game's frame doesn't allow." },
|
|
@@ -301,6 +301,12 @@ function dialogOf(code) {
|
|
|
301
301
|
return null;
|
|
302
302
|
}
|
|
303
303
|
const THREADS_PATTERNS = [/\bGODOT_THREADS_ENABLED\s*=\s*true\b/, /\bENVIRONMENT_IS_PTHREAD\b/, /coi-serviceworker/i, /\b__wbindgen_thread_destroy\b/, /\binitThreadPool\b/];
|
|
304
|
+
const COI_SERVICE_WORKER_PATTERN = /coi-serviceworker/i;
|
|
305
|
+
|
|
306
|
+
/** Whether a game's files ({ path, contentText }, as checkGameFiles takes them) are a build that needs threads (SharedArrayBuffer). */
|
|
307
|
+
export function buildHasThreads(files) {
|
|
308
|
+
return files.some(({ path, contentText }) => (typeof contentText === "string" ? THREADS_PATTERNS.some((pattern) => pattern.test(contentText)) : COI_SERVICE_WORKER_PATTERN.test(path)));
|
|
309
|
+
}
|
|
304
310
|
|
|
305
311
|
/**
|
|
306
312
|
* Checks a game's files: [{ path, sizeBytes, contentText, headBytes }], contentText a string for the checked text
|
|
@@ -366,7 +372,8 @@ export function checkGameFiles(files, { slug = null, ownServerUrls = null } = {}
|
|
|
366
372
|
if (files.length > UPLOAD_LIMITS.maximumFileCount) add("too_many_files", { message: `The game has ${files.length} files; the limit is 20,000.`, fix: "Leave out files the game doesn't load, or pack small ones together (like sprites into an atlas)." });
|
|
367
373
|
if (sizeBytes > UPLOAD_LIMITS.maximumGameSizeBytes) add("game_too_big", { message: `The game is ${(sizeBytes / 1024 ** 3).toFixed(1)} GB; the limit is 2 GB.`, fix: "Leave out files the game doesn't load, or ask Zaisma (message_zaisma, kind gap) for more." });
|
|
368
374
|
|
|
369
|
-
const threadsFix = "
|
|
375
|
+
const threadsFix = "Threads run in Chrome and Edge on computers and Android. Firefox, Safari and every browser on iPhone and iPad can't start this build, and the game page tells their players it needs Chrome or Edge. To reach every browser, export without threads: in Godot 4.3 or newer, turn Thread Support off in the Web export preset; in Unity, leave Native C/C++ Multithreading off (the default); in Rust, build without the `atomics` target feature and without wasm-bindgen-rayon.";
|
|
376
|
+
const coiServiceWorkerMessage = (path) => `${path} is there to turn on threads (SharedArrayBuffer). Zaisma doesn't need it: the game is already isolated in Chrome and Edge, and it can't turn threads on in other browsers.`;
|
|
370
377
|
let hasThreadsProblem = false;
|
|
371
378
|
const addThreads = (message, quote, path) => {
|
|
372
379
|
if (!hasThreadsProblem) add("needs_threads", { message, quote, path, fix: threadsFix });
|
|
@@ -375,7 +382,7 @@ export function checkGameFiles(files, { slug = null, ownServerUrls = null } = {}
|
|
|
375
382
|
for (const file of files) {
|
|
376
383
|
const { path, contentText: text } = file;
|
|
377
384
|
if (typeof text !== "string") {
|
|
378
|
-
if (
|
|
385
|
+
if (buildHasThreads([file])) addThreads(coiServiceWorkerMessage(path), null, path);
|
|
379
386
|
continue;
|
|
380
387
|
}
|
|
381
388
|
const extension = extensionOf(path);
|
|
@@ -406,7 +413,7 @@ export function checkGameFiles(files, { slug = null, ownServerUrls = null } = {}
|
|
|
406
413
|
}
|
|
407
414
|
|
|
408
415
|
const threadsMatch = THREADS_PATTERNS.map((pattern) => pattern.exec(text)).find(Boolean);
|
|
409
|
-
if (threadsMatch) addThreads(`${path} is from a build that needs threads (SharedArrayBuffer), which
|
|
416
|
+
if (threadsMatch) addThreads(COI_SERVICE_WORKER_PATTERN.test(path) ? coiServiceWorkerMessage(path) : `${path} is from a build that needs threads (SharedArrayBuffer), which only Chrome and Edge give games on Zaisma.`, lineAround(text, threadsMatch.index), path);
|
|
410
417
|
|
|
411
418
|
if (isEngineOutput(path, lowercasePaths)) continue;
|
|
412
419
|
// What the code does, not what its comments say: a library's docs mention alert() and window.open.
|
package/package.json
CHANGED
package/zaisma.mjs
CHANGED
|
@@ -136,6 +136,8 @@ const COMMANDS = {
|
|
|
136
136
|
secrets: { about: "A game's secrets, which its game server reads as server.secrets and room.secrets: their names and when each was set, never the values", arguments: [{ name: "slug" }], flags: {} },
|
|
137
137
|
"secrets set": { about: "Set a secret for a game's server, replacing one of the same name: the value piped in, or typed without showing; it's never shown again", arguments: [{ name: "slug" }, { name: "secret_name" }], flags: {} },
|
|
138
138
|
"secrets delete": { about: "Delete one of a game's secrets", arguments: [{ name: "slug" }, { name: "secret_name" }], flags: {} },
|
|
139
|
+
"kept-rooms": { about: "A game's kept rooms (room.setKept), worlds that sleep with nobody in them: each one's code, name, size and when it was last played, and the game's storage", arguments: [{ name: "slug" }], flags: {} },
|
|
140
|
+
"kept-rooms delete": { about: "Delete a kept room's world for good; players in it are sent out", arguments: [{ name: "slug" }, { name: "room_code" }], flags: {} },
|
|
139
141
|
logs: {
|
|
140
142
|
about: "What a game's server printed on Zaisma in the last 30 days, oldest first: the newest lines, older ones with --cursor, or new ones as they come with --follow",
|
|
141
143
|
arguments: [{ name: "slug" }],
|
|
@@ -237,7 +239,7 @@ const COMMANDS = {
|
|
|
237
239
|
help: { about: "This help; with --json, every command, flag, exit code and error code", arguments: [], flags: {} },
|
|
238
240
|
};
|
|
239
241
|
/** Commands with a second word, like zaisma forum post. */
|
|
240
|
-
const SUBCOMMANDS = { links: ["set", "remove"], forum: ["post", "message", "reply"], database: ["query", "batch", "export", "import", "restore", "undo-restore"], saves: ["get", "change", "replace", "reset", "copies", "copy", "restore"], secrets: ["set", "delete"] };
|
|
242
|
+
const SUBCOMMANDS = { links: ["set", "remove"], forum: ["post", "message", "reply"], database: ["query", "batch", "export", "import", "restore", "undo-restore"], saves: ["get", "change", "replace", "reset", "copies", "copy", "restore"], secrets: ["set", "delete"], "kept-rooms": ["delete"] };
|
|
241
243
|
/** Flags every command takes. */
|
|
242
244
|
const GLOBAL_FLAGS = {
|
|
243
245
|
json: { hasValue: false, about: "Print the API's answer as JSON, as-is (on failure its { error }), and nothing else" },
|
|
@@ -1455,6 +1457,21 @@ async function secrets(command, values) {
|
|
|
1455
1457
|
if (answer.next_steps.some((step) => step.tool === "update_game")) console.log(`It calls no other servers yet: list the hosts it uses this with, like zaisma allowed-hosts ${values.slug} discord.com`);
|
|
1456
1458
|
}
|
|
1457
1459
|
|
|
1460
|
+
/** A game's kept rooms (…/games/<slug>/kept-rooms…), as the MCP's list_kept_rooms and delete_kept_room. */
|
|
1461
|
+
async function keptRooms(command, values) {
|
|
1462
|
+
if (command === "kept-rooms") {
|
|
1463
|
+
const answer = await api("GET", `/games/${values.slug}/kept-rooms`);
|
|
1464
|
+
if (isJson) return printJson(answer);
|
|
1465
|
+
if (!answer.kept_rooms.length) console.log(`No kept rooms. A game server keeps one with room.setKept(true).`);
|
|
1466
|
+
for (const keptRoom of answer.kept_rooms) console.log(`${keptRoom.room_code} ${(keptRoom.name ?? "").padEnd(24)} ${sizeText(keptRoom.saved_size_bytes).padStart(9)} played ${keptRoom.last_played_at ? when(keptRoom.last_played_at) : "never"}`);
|
|
1467
|
+
console.log(`Storage: ${sizeText(answer.storage_size_bytes)} of ${sizeText(answer.free_storage_size_bytes)} free (database and kept rooms).`);
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
const answer = await api("DELETE", `/games/${values.slug}/kept-rooms/${encodeURIComponent(values.room_code)}`);
|
|
1471
|
+
if (isJson) return printJson(answer);
|
|
1472
|
+
console.log(`Deleted kept room ${values.room_code.toUpperCase()} from ${values.slug}, and its world with it.`);
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1458
1475
|
/** A game server's logs (GET …/games/<slug>/logs), as the MCP's get_logs; --follow asks for new lines every 2 seconds. */
|
|
1459
1476
|
async function logs(values, flags) {
|
|
1460
1477
|
if (flags.follow && flags.cursor) refuse("conflicting_flags", { message: "--follow prints new lines, and --cursor older ones.", field: "cursor", fix: `Use one: zaisma logs ${values.slug} --follow, or zaisma logs ${values.slug} --cursor <next_cursor>.` });
|
|
@@ -1673,6 +1690,7 @@ async function run({ command, values, flags, globalFlags, rest }) {
|
|
|
1673
1690
|
else if (command === "own-servers") await ownServers(values, flags);
|
|
1674
1691
|
else if (command === "links" || command.startsWith("links ")) await links(command, values, flags);
|
|
1675
1692
|
else if (command === "secrets" || command.startsWith("secrets ")) await secrets(command, values);
|
|
1693
|
+
else if (command === "kept-rooms" || command.startsWith("kept-rooms ")) await keptRooms(command, values);
|
|
1676
1694
|
else if (command === "logs") await logs(values, flags);
|
|
1677
1695
|
else if (command === "database" || command.startsWith("database ")) await database(command, values, flags);
|
|
1678
1696
|
else if (command === "saves" || command.startsWith("saves ")) await saves(command, values, flags);
|