@zaisma/game-server 1.41.0 → 1.43.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 +7774 -2378
- 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/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/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. */
|