@zaisma/game-server 1.42.0 → 1.44.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/bench/glass.js +29974 -29426
- package/bin/local-play-bench.js +1 -1
- package/bin/local-play.js +1 -1
- package/package.json +1 -1
- package/sdk/relay.js +105 -0
- package/sdk/zaisma.d.ts +8 -3
- package/sdk/zaisma.js +55 -2
- package/src/webhooks.d.ts +3 -1
package/bin/local-play-bench.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// (bench/glass.ts) and one frame, the player's page, which is zaisma.com's game page with its own scripts. These never reach into it.
|
|
3
3
|
|
|
4
4
|
/** What the dev page's frame lets the player's page pass on to the game: the game page's own list (apps/site/src/pages.ts; test/node/local-play-parity.test.ts holds the two together). */
|
|
5
|
-
export const FRAME_ALLOW = "fullscreen; gamepad; autoplay; web-share; clipboard-write; cross-origin-isolated";
|
|
5
|
+
export const FRAME_ALLOW = "fullscreen; gamepad; autoplay; web-share; clipboard-write; cross-origin-isolated; compute-pressure";
|
|
6
6
|
|
|
7
7
|
/** The dev page's script: it keeps the player's place, reloads the game when a file changes, runs the dev bar's menus and the Players panel. */
|
|
8
8
|
export const devScriptSource = () => `(${devScript.toString()})();\n`;
|
package/bin/local-play.js
CHANGED
|
@@ -38,7 +38,7 @@ export const LOCAL_VERSION_ID = "version_local";
|
|
|
38
38
|
export const LOCAL_FOLDER = ".zaisma-local";
|
|
39
39
|
/** Every _zaisma/ file the games Worker serves, split by whether it works here or only loads and does nothing (test/node/local-play-parity.test.ts holds this to apps/games/src/index.ts). */
|
|
40
40
|
export const SERVED_ZAISMA_PATHS = ["_zaisma/v1.js", "_zaisma/v1.d.ts", "_zaisma/relay.js", "_zaisma/picture.js", "_zaisma/saves.js", "_zaisma/restore"];
|
|
41
|
-
export const ONLY_ON_ZAISMA_PATHS = ["_zaisma/performance.js", "_zaisma/warm", "_zaisma/warm.json", "_zaisma/warm-redirects.json", "_zaisma/warm.js"];
|
|
41
|
+
export const ONLY_ON_ZAISMA_PATHS = ["_zaisma/performance.js", "_zaisma/pressure.js", "_zaisma/warm", "_zaisma/warm.json", "_zaisma/warm-redirects.json", "_zaisma/warm.js"];
|
|
42
42
|
const OPTION_NAMES = ["gameFolder", "port", "isOnNetwork", "gameSlug", "benchFolder", "zaismaKey", "developerApiUrl", "log"];
|
|
43
43
|
const SAVE_LIMIT_BYTES = 5 * 1024 * 1024;
|
|
44
44
|
const PASS_DURATION_SEC = 24 * 3600;
|
package/package.json
CHANGED
package/sdk/relay.js
CHANGED
|
@@ -71,8 +71,20 @@
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
/** A frame of the game's own (a srcdoc frame runs its own copy of this script) asks the game page's copy, which Zaisma's page answers. */
|
|
75
|
+
var RELAY_KEY = typeof Symbol === "function" ? Symbol.for("zaisma.relayServers") : "__zaismaRelayServers";
|
|
76
|
+
function parentRelayServers() {
|
|
77
|
+
try {
|
|
78
|
+
return window.parent !== window && typeof window.parent[RELAY_KEY] === "function" ? window.parent[RELAY_KEY] : null;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return null; // another site's frame
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
/** Zaisma's relay servers, as iceServers: [] when there are none to be had (connections then don't connect, rather than go direct). */
|
|
75
85
|
function relayServers() {
|
|
86
|
+
var fromParent = parentRelayServers();
|
|
87
|
+
if (fromParent) return fromParent();
|
|
76
88
|
if (isFresh(kept)) return Promise.resolve(kept.iceServers);
|
|
77
89
|
var stored = storedCredentials();
|
|
78
90
|
if (stored) {
|
|
@@ -251,6 +263,7 @@
|
|
|
251
263
|
Object.defineProperty(Element.prototype, property, { configurable: true, enumerable: descriptor.enumerable, get: get });
|
|
252
264
|
});
|
|
253
265
|
});
|
|
266
|
+
watchInsertedFrames(target);
|
|
254
267
|
var nativeOpen = target.open;
|
|
255
268
|
if (typeof nativeOpen === "function" && !getters.has(nativeOpen)) {
|
|
256
269
|
var open = function () {
|
|
@@ -263,6 +276,98 @@
|
|
|
263
276
|
}
|
|
264
277
|
}
|
|
265
278
|
|
|
279
|
+
/**
|
|
280
|
+
* A frame is a window of its own the moment it's in the page, and a game can reach it by index (window[0]) without
|
|
281
|
+
* going through contentWindow: every frame in the page is wrapped right after anything is put into the page, and a
|
|
282
|
+
* frame made from text (srcdoc) runs this script first, from the address it came from. Only the page's own frames
|
|
283
|
+
* are looked at, so a page with none pays one length check per change.
|
|
284
|
+
*/
|
|
285
|
+
var relayUrl = window.document && window.document.currentScript && window.document.currentScript.src ? window.document.currentScript.src : "";
|
|
286
|
+
|
|
287
|
+
function installFrames(target) {
|
|
288
|
+
try {
|
|
289
|
+
var targetDocument = target.document;
|
|
290
|
+
["iframe", "frame", "object"].forEach(function (tag) {
|
|
291
|
+
var frames = targetDocument.getElementsByTagName(tag);
|
|
292
|
+
for (var index = 0; index < frames.length; index++) install(frames[index].contentWindow);
|
|
293
|
+
});
|
|
294
|
+
} catch (error) {
|
|
295
|
+
/* a frame of another site: nothing of it is reachable from here */
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function watchInsertedFrames(target) {
|
|
300
|
+
var Node = target.Node;
|
|
301
|
+
var Element = target.Element;
|
|
302
|
+
if (typeof Node !== "function" || typeof Element !== "function") return;
|
|
303
|
+
var after = function (proto, name) {
|
|
304
|
+
var native = proto[name];
|
|
305
|
+
if (typeof native !== "function" || getters.has(native)) return;
|
|
306
|
+
var wrapped = function () {
|
|
307
|
+
var answer = native.apply(this, arguments);
|
|
308
|
+
installFrames(target);
|
|
309
|
+
return answer;
|
|
310
|
+
};
|
|
311
|
+
getters.add(wrapped);
|
|
312
|
+
Object.defineProperty(proto, name, { configurable: true, writable: true, enumerable: false, value: wrapped });
|
|
313
|
+
};
|
|
314
|
+
["appendChild", "insertBefore", "replaceChild"].forEach(function (name) { after(Node.prototype, name); });
|
|
315
|
+
["append", "prepend", "before", "after", "replaceWith", "replaceChildren", "insertAdjacentElement", "insertAdjacentHTML"].forEach(function (name) { after(Element.prototype, name); });
|
|
316
|
+
// A frame's own page replaces its first one when it loads (a srcdoc in the page's markup, say): wrapped before the game's load handler runs.
|
|
317
|
+
if (target.document && typeof target.document.addEventListener === "function") target.document.addEventListener("load", function () { installFrames(target); }, true);
|
|
318
|
+
["innerHTML", "outerHTML"].forEach(function (property) {
|
|
319
|
+
var descriptor = Object.getOwnPropertyDescriptor(Element.prototype, property);
|
|
320
|
+
if (!descriptor || !descriptor.set || getters.has(descriptor.set)) return;
|
|
321
|
+
var nativeSet = descriptor.set;
|
|
322
|
+
var set = function (text) {
|
|
323
|
+
nativeSet.call(this, text);
|
|
324
|
+
installFrames(target);
|
|
325
|
+
};
|
|
326
|
+
getters.add(set);
|
|
327
|
+
Object.defineProperty(Element.prototype, property, { configurable: true, enumerable: descriptor.enumerable, get: descriptor.get, set: set });
|
|
328
|
+
});
|
|
329
|
+
// A frame made from text runs this script before its own.
|
|
330
|
+
var Frame = target.HTMLIFrameElement;
|
|
331
|
+
if (!relayUrl || typeof Frame !== "function") return;
|
|
332
|
+
var withRelay = function (text) { return '<script src="' + relayUrl.replace(/"/g, """) + '"></script>' + String(text); };
|
|
333
|
+
var srcdoc = Object.getOwnPropertyDescriptor(Frame.prototype, "srcdoc");
|
|
334
|
+
if (srcdoc && srcdoc.set && !getters.has(srcdoc.set)) {
|
|
335
|
+
var nativeSrcdoc = srcdoc.set;
|
|
336
|
+
var setSrcdoc = function (text) { nativeSrcdoc.call(this, withRelay(text)); };
|
|
337
|
+
getters.add(setSrcdoc);
|
|
338
|
+
Object.defineProperty(Frame.prototype, "srcdoc", { configurable: true, enumerable: srcdoc.enumerable, get: srcdoc.get, set: setSrcdoc });
|
|
339
|
+
}
|
|
340
|
+
// Whatever else puts a frame or a srcdoc in the page (the page's own markup, document.write, setHTMLUnsafe, an attribute
|
|
341
|
+
// set some other way) is seen here, before the frame's page loads: its srcdoc gets this script first, and its window is wrapped.
|
|
342
|
+
var Observer = target.MutationObserver;
|
|
343
|
+
if (typeof Observer === "function" && target.document && target.document.documentElement && typeof nativeSrcdoc === "function") {
|
|
344
|
+
var prefix = withRelay("");
|
|
345
|
+
new Observer(function () {
|
|
346
|
+
var frames = target.document.getElementsByTagName("iframe");
|
|
347
|
+
for (var index = 0; index < frames.length; index++) {
|
|
348
|
+
var frame = frames[index];
|
|
349
|
+
var text = frame.getAttribute("srcdoc");
|
|
350
|
+
if (text !== null && text.indexOf(prefix) !== 0) nativeSrcdoc.call(frame, withRelay(text));
|
|
351
|
+
}
|
|
352
|
+
installFrames(target);
|
|
353
|
+
}).observe(target.document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ["srcdoc"] });
|
|
354
|
+
}
|
|
355
|
+
var nativeSetAttribute = Element.prototype.setAttribute;
|
|
356
|
+
if (typeof nativeSetAttribute === "function" && !getters.has(nativeSetAttribute)) {
|
|
357
|
+
var setAttribute = function (name, text) {
|
|
358
|
+
var isSrcdoc = this instanceof Frame && String(name).toLowerCase() === "srcdoc";
|
|
359
|
+
return nativeSetAttribute.call(this, name, isSrcdoc ? withRelay(text) : text);
|
|
360
|
+
};
|
|
361
|
+
getters.add(setAttribute);
|
|
362
|
+
Object.defineProperty(Element.prototype, "setAttribute", { configurable: true, writable: true, enumerable: false, value: setAttribute });
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
try {
|
|
367
|
+
Object.defineProperty(window, RELAY_KEY, { configurable: false, enumerable: false, writable: false, value: relayServers });
|
|
368
|
+
} catch (error) {
|
|
369
|
+
/* already there: this script ran twice */
|
|
370
|
+
}
|
|
266
371
|
install(window);
|
|
267
372
|
// A game that plays online gets its relay servers while it loads, so its first connection doesn't wait.
|
|
268
373
|
if (config.fetchEarly && NAMES.some(function (name) { return typeof window[name] === "function"; })) relayServers();
|
package/sdk/zaisma.d.ts
CHANGED
|
@@ -1268,8 +1268,11 @@ declare namespace Zaisma {
|
|
|
1268
1268
|
block(playerId: string): Promise<boolean>;
|
|
1269
1269
|
/**
|
|
1270
1270
|
* Report a player to Zaisma, with what happened in the player's own words if they gave any (details).
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1271
|
+
* On Zaisma it opens Zaisma's report sheet beside the game, filled in with the player, reason and words,
|
|
1272
|
+
* where the player picks the messages to send and sends it: only reports a player sends there count
|
|
1273
|
+
* toward muting someone. Resolves once they send it; rejects with error.code "report_not_sent" when they
|
|
1274
|
+
* close it without sending. Off Zaisma (a game's own site) the last chat lines (up to 20) they sent this
|
|
1275
|
+
* player, or this player sent them, go with it; nothing else about the reporting player is sent.
|
|
1273
1276
|
*/
|
|
1274
1277
|
report(playerId: string, reason: ReportReason, details?: string): Promise<ReportAnswer>;
|
|
1275
1278
|
/**
|
|
@@ -1782,6 +1785,7 @@ declare namespace Zaisma {
|
|
|
1782
1785
|
* - slow_down: too many calls; try again in a minute.
|
|
1783
1786
|
* - zaisma_rooms_not_used: the game doesn't use Zaisma rooms.
|
|
1784
1787
|
* - bad_report: a report whose reason isn't a {@link ReportReason}, or whose player ID isn't one.
|
|
1788
|
+
* - report_not_sent: the player closed Zaisma's report sheet, which {@link Room.report} opened, without sending it.
|
|
1785
1789
|
* - bad_origin: the call didn't come from the game's own page.
|
|
1786
1790
|
* - not_on_zaisma: the game is played off Zaisma, so it has no player passes, sign-in or room lists; joinRoom and server.request need {@link setUpOffZaisma} and a serverUrl.
|
|
1787
1791
|
* - bad_game_slug: {@link setUpOffZaisma}'s gameSlug isn't a game slug: 1 to 40 lowercase letters, digits or hyphens.
|
|
@@ -1811,6 +1815,7 @@ declare namespace Zaisma {
|
|
|
1811
1815
|
type ErrorCode =
|
|
1812
1816
|
| RoomErrorCode
|
|
1813
1817
|
| RequestErrorCode
|
|
1818
|
+
| "report_not_sent"
|
|
1814
1819
|
| "chat_stopped"
|
|
1815
1820
|
| "chat_not_allowed"
|
|
1816
1821
|
| "chat_empty"
|
|
@@ -1916,7 +1921,7 @@ declare namespace Zaisma {
|
|
|
1916
1921
|
type ChatCheckReason = "contact_details" | "personal_details" | "slur" | "sexual" | "unchecked" | "too_long";
|
|
1917
1922
|
|
|
1918
1923
|
/** What happened, in a player report. Zaisma looks at real_life_threat (a threat that reaches past the game: their real details, finding them, a plan), personal_details (sharing someone's), following_after_block and sexual (behavior); harassment, cheating and other go to the game's developer. */
|
|
1919
|
-
type ReportReason = "real_life_threat" | "personal_details" | "following_after_block" | "sexual" | "harassment" | "cheating" | "other";
|
|
1924
|
+
type ReportReason = "real_life_threat" | "personal_details" | "following_after_block" | "sexual" | "harassment" | "cheating" | "wrong_age" | "under_13" | "other";
|
|
1920
1925
|
|
|
1921
1926
|
/** Zaisma's answer to a report. */
|
|
1922
1927
|
interface ReportAnswer {
|
package/sdk/zaisma.js
CHANGED
|
@@ -1751,10 +1751,20 @@
|
|
|
1751
1751
|
return blockAsk;
|
|
1752
1752
|
}
|
|
1753
1753
|
/**
|
|
1754
|
-
* Report a player to Zaisma. reason: real_life_threat, personal_details, following_after_block or
|
|
1755
|
-
*
|
|
1754
|
+
* Report a player to Zaisma. reason: real_life_threat, personal_details, following_after_block, sexual, wrong_age or under_13 (Zaisma looks), or harassment, cheating or other (passed to the game's developer).
|
|
1755
|
+
* On a Zaisma page it opens Zaisma's report sheet beside the game, filled in, and the player sends it there: only a report the
|
|
1756
|
+
* player sends from Zaisma counts toward muting someone. Anywhere else the last chat lines they sent you, or you sent them,
|
|
1757
|
+
* go with it (up to 20); nothing else about you is sent.
|
|
1756
1758
|
*/
|
|
1757
1759
|
Room.prototype.report = function (playerId, reason, details) {
|
|
1760
|
+
var reported = this.players.filter(function (each) { return each.id === playerId; })[0];
|
|
1761
|
+
var room = this;
|
|
1762
|
+
var sendDirectly = function () { return room._sendReport(playerId, reason, details); };
|
|
1763
|
+
if (onZaismaPage() && this.roomCode) return askPageToReport(this.roomCode, { id: playerId, name: reported ? reported.name : "" }, reason, details || "", sendDirectly);
|
|
1764
|
+
return sendDirectly();
|
|
1765
|
+
};
|
|
1766
|
+
/** A report straight to Zaisma's rooms, with the last chat lines: off Zaisma, or when the page has no report sheet. */
|
|
1767
|
+
Room.prototype._sendReport = function (playerId, reason, details) {
|
|
1758
1768
|
var reported = this.players.filter(function (each) { return each.id === playerId; })[0];
|
|
1759
1769
|
var me = this.me ? this.me.id : null;
|
|
1760
1770
|
var chatMessages = this._chatLines.filter(function (line) {
|
|
@@ -2845,6 +2855,49 @@
|
|
|
2845
2855
|
});
|
|
2846
2856
|
});
|
|
2847
2857
|
|
|
2858
|
+
/**
|
|
2859
|
+
* Zaisma's report sheet, opened beside the game for room.report: resolves { isReported: true } once the player sends it, and rejects
|
|
2860
|
+
* (report_not_sent) when they close it. A page that doesn't say it opened the sheet within REPORT_SHEET_WAIT_MS gets the report the
|
|
2861
|
+
* way it goes off Zaisma instead (fallback), so room.report never hangs.
|
|
2862
|
+
*/
|
|
2863
|
+
var REPORT_SHEET_WAIT_MS = 3000;
|
|
2864
|
+
var reportAsks = {};
|
|
2865
|
+
function askPageToReport(roomCode, player, reason, details, fallback) {
|
|
2866
|
+
if (reportAsks[player.id]) return reportAsks[player.id];
|
|
2867
|
+
reportAsks[player.id] = new Promise(function (resolve, reject) {
|
|
2868
|
+
var isOpened = false;
|
|
2869
|
+
var timer = setTimeout(function () { if (!isOpened) settle(function () { fallback().then(resolve, reject); }); }, REPORT_SHEET_WAIT_MS);
|
|
2870
|
+
function settle(then) {
|
|
2871
|
+
removeEventListener("message", onMessage);
|
|
2872
|
+
clearTimeout(timer);
|
|
2873
|
+
delete reportAsks[player.id];
|
|
2874
|
+
then();
|
|
2875
|
+
}
|
|
2876
|
+
function onMessage(event) {
|
|
2877
|
+
if (event.origin !== config.site || event.source !== window.parent || !event.data || event.data.playerId !== player.id) return;
|
|
2878
|
+
if (event.data.type === "zaisma:report-opened") { isOpened = true; return; }
|
|
2879
|
+
if (event.data.type !== "zaisma:report-done") return;
|
|
2880
|
+
settle(function () {
|
|
2881
|
+
if (event.data.isReported === true) resolve({ isReported: true });
|
|
2882
|
+
else reject(codedError("report_not_sent", "The player closed Zaisma's report sheet without sending it."));
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2885
|
+
addEventListener("message", onMessage);
|
|
2886
|
+
window.parent.postMessage({ type: "zaisma:report-player", code: roomCode, player: player, reason: typeof reason === "string" ? reason : "", details: String(details).slice(0, 2000) }, config.site);
|
|
2887
|
+
});
|
|
2888
|
+
return reportAsks[player.id];
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
// Zaisma's report sheet asks for a player's last chat lines on this screen, for the player to tick the ones to send.
|
|
2892
|
+
window.addEventListener("message", function (event) {
|
|
2893
|
+
if (!config.site || event.origin !== config.site || event.source !== window.parent || !event.data || event.data.type !== "zaisma:chat-lines-request") return;
|
|
2894
|
+
var playerId = event.data.playerId, lines = [];
|
|
2895
|
+
joined.forEach(function (room) {
|
|
2896
|
+
room._chatLines.forEach(function (line) { if (line.fromPlayerId === playerId) lines.push({ fromPlayerId: line.fromPlayerId, text: line.text, sentAt: line.sentAt }); });
|
|
2897
|
+
});
|
|
2898
|
+
window.parent.postMessage({ type: "zaisma:chat-lines", id: event.data.id, playerId: playerId, lines: lines.slice(-REPORTED_CHAT_LINE_COUNT) }, config.site);
|
|
2899
|
+
});
|
|
2900
|
+
|
|
2848
2901
|
// The Zaisma page says when a player report was sent from its plate: mute them, as the panel's own form does.
|
|
2849
2902
|
window.addEventListener("message", function (event) {
|
|
2850
2903
|
if (!config.site || event.origin !== config.site || event.source !== window.parent || !event.data || event.data.type !== "zaisma:reported") return;
|
package/src/webhooks.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ import type { Server } from "./requests.ts";
|
|
|
13
13
|
* Every kind of event Zaisma sends today. A WebhookEvent's kind is one of these or a kind added later,
|
|
14
14
|
* so a game server switches on the ones it knows and skips the rest.
|
|
15
15
|
*/
|
|
16
|
-
export type WebhookEventKind = "bug_reported" | "player_reported" | "scan_status_changed"
|
|
16
|
+
export type WebhookEventKind = "bug_reported" | "player_reported" | "scan_status_changed"
|
|
17
|
+
/** No longer sent: Zaisma's fixed checks replaced the AI review. Kept so v1's type only ever gains. */
|
|
18
|
+
| "ai_review_finished" | "live_version_changed" | "review_status_changed" | "country_blocks_changed" | "game_server_error_found" | "alert_raised" | "account_deleted" | "security_alert" | "purchase_completed" | "purchase_refunded" | "test";
|
|
17
19
|
/** Who deleted their Zaisma account, on an account_deleted event. */
|
|
18
20
|
export interface AccountDeletion {
|
|
19
21
|
/** The player who deleted their Zaisma account. */
|