@voltro/plugin-engine-servers 0.90.0 → 0.91.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/CHANGELOG.md +121 -0
- package/THIRD-PARTY-NOTICES.md +37 -661
- package/dist/index.js +8 -8
- package/dist/inspect.js +26 -26
- package/dist/plugin.js +42 -42
- package/dist/registry.server.js +496 -496
- package/dist/rows.js +8 -1
- package/dist/rpc.js +40 -40
- package/dist/server.js +5 -5
- package/dist/session.server.js +176 -176
- package/dist/tables.entity.js +20 -20
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ENGINE_KINDS as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
export {
|
|
1
|
+
import { engineServersPlugin as e } from "./plugin.js";
|
|
2
|
+
import { ENGINE_KINDS as t, ENGINE_SERVER_BASE_SCOPES as n, ENGINE_SERVER_POOL_LIMITS as r, ENGINE_SERVER_PROTOCOLS as i, ENGINE_SERVER_SCOPES as a, ENGINE_SERVER_TRUST_LEVELS as o, ENGINE_SERVER_WRITE_KINDS as s, ENGINE_SERVER_WRITE_SCOPES as c, defineEngineServerPool as l } from "./pool.js";
|
|
3
|
+
import { serverReportedAntiCheat as u } from "./antiCheat.js";
|
|
4
|
+
import { bootstrapByPool as d, staticBootstrapSource as f } from "./bootstrap.js";
|
|
5
|
+
import { EngineServersPort as p } from "./port.js";
|
|
6
|
+
import { ENGINE_SERVERS_ERROR_CODES as m, EngineServersError as h } from "./errors.js";
|
|
7
|
+
import { ANTICHEAT_STATUSES as g, ENGINE_SERVER_GONE_REASONS as _, ENGINE_SERVER_LIFECYCLE_EVENTS as v, ENGINE_SERVER_LIVE_STATES as y, ENGINE_SERVER_SESSION_STATES as b, ENGINE_SERVER_STATES as x, SESSION_SEAT_PURPOSE as S } from "./contract.js";
|
|
8
|
+
export { g as ANTICHEAT_STATUSES, t as ENGINE_KINDS, m as ENGINE_SERVERS_ERROR_CODES, n as ENGINE_SERVER_BASE_SCOPES, _ as ENGINE_SERVER_GONE_REASONS, v as ENGINE_SERVER_LIFECYCLE_EVENTS, y as ENGINE_SERVER_LIVE_STATES, r as ENGINE_SERVER_POOL_LIMITS, i as ENGINE_SERVER_PROTOCOLS, a as ENGINE_SERVER_SCOPES, b as ENGINE_SERVER_SESSION_STATES, x as ENGINE_SERVER_STATES, o as ENGINE_SERVER_TRUST_LEVELS, s as ENGINE_SERVER_WRITE_KINDS, c as ENGINE_SERVER_WRITE_SCOPES, h as EngineServersError, p as EngineServersPort, S as SESSION_SEAT_PURPOSE, d as bootstrapByPool, l as defineEngineServerPool, e as engineServersPlugin, u as serverReportedAntiCheat, f as staticBootstrapSource };
|
package/dist/inspect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ANTICHEAT_STATUSES as e } from "./contract.js";
|
|
2
|
+
import { ENGINE_SERVER_WRITE_WINDOW_MS as t, writeUsageKey as n } from "./hotStore.js";
|
|
3
|
+
import { ENGINE_SERVER_WRITE_KINDS as r } from "./pool.js";
|
|
4
4
|
import { bool as i, date as a, int as o, json as s, nullableDate as c, nullableText as l, text as u } from "./rows.js";
|
|
5
5
|
import { engineServerAntiCheatTable as d, engineServerBackfillsTable as f, engineServerCheckpointsTable as p, engineServerReportsTable as m, engineServerSessionsTable as h, engineServerTables as g, engineServerTicketsTable as _, engineServersTable as v } from "./tables.entity.js";
|
|
6
6
|
import { Effect as y, Result as b } from "effect";
|
|
@@ -89,17 +89,17 @@ var R = (e, t) => {
|
|
|
89
89
|
},
|
|
90
90
|
backfills: y.length
|
|
91
91
|
};
|
|
92
|
-
}, J = async (
|
|
93
|
-
let a = L.hot(), o = W.get(u(
|
|
94
|
-
if (a === void 0 || o === void 0 || l(
|
|
95
|
-
let s =
|
|
92
|
+
}, J = async (e, i) => {
|
|
93
|
+
let a = L.hot(), o = W.get(u(e, "pool"));
|
|
94
|
+
if (a === void 0 || o === void 0 || l(e, "sessionId") === null) return null;
|
|
95
|
+
let s = r.reduce((e, t) => e + o.writeLimits[t].perMinute, 0), c = await y.runPromise(y.result(a.zrange(n(u(e, "tenantId"), u(e, "id")), { byScore: [i - t, i] }, "asc", { limit: Math.min(s * 2 + 1, 1e5) })));
|
|
96
96
|
if (b.isFailure(c)) return null;
|
|
97
97
|
let d = /* @__PURE__ */ new Map();
|
|
98
98
|
for (let { member: e } of c.success) {
|
|
99
99
|
let t = e.slice(0, e.indexOf(":"));
|
|
100
100
|
d.set(t, (d.get(t) ?? 0) + 1);
|
|
101
101
|
}
|
|
102
|
-
return
|
|
102
|
+
return r.map((e) => ({
|
|
103
103
|
kind: e,
|
|
104
104
|
used: Math.min(d.get(e) ?? 0, 1e6),
|
|
105
105
|
perMinute: o.writeLimits[e].perMinute
|
|
@@ -176,7 +176,7 @@ var R = (e, t) => {
|
|
|
176
176
|
reconnectWindowMs: e.reconnectWindowMs,
|
|
177
177
|
resumeWindowMs: e.resumeWindowMs,
|
|
178
178
|
recovery: e.recovery === null ? null : { ...e.recovery },
|
|
179
|
-
writeLimits:
|
|
179
|
+
writeLimits: r.map((t) => ({
|
|
180
180
|
kind: t,
|
|
181
181
|
perMinute: e.writeLimits[t].perMinute,
|
|
182
182
|
maxAmount: e.writeLimits[t].maxAmount
|
|
@@ -258,13 +258,13 @@ var R = (e, t) => {
|
|
|
258
258
|
path: "/sessions",
|
|
259
259
|
scope: "shared-store",
|
|
260
260
|
description: "One page of a tenant's session runs, newest first, with result summaries and anti-cheat counts",
|
|
261
|
-
handler: (
|
|
262
|
-
let
|
|
261
|
+
handler: (t) => y.gen(function* () {
|
|
262
|
+
let n = yield* y.result(y.try({
|
|
263
263
|
try: () => {
|
|
264
|
-
let
|
|
265
|
-
if (
|
|
264
|
+
let e = z(t, ["after"]), n = e.has("after") ? j.exec(R(e.get("after"), 128)) : null;
|
|
265
|
+
if (e.has("after") && n === null) throw Error("Invalid cursor");
|
|
266
266
|
return {
|
|
267
|
-
tenantId: R(
|
|
267
|
+
tenantId: R(e.get("tenantId"), 256),
|
|
268
268
|
after: n === null ? null : {
|
|
269
269
|
raw: n[0],
|
|
270
270
|
startedAt: Number(n[1]),
|
|
@@ -274,12 +274,12 @@ var R = (e, t) => {
|
|
|
274
274
|
},
|
|
275
275
|
catch: () => "invalid"
|
|
276
276
|
}));
|
|
277
|
-
if (b.isFailure(
|
|
278
|
-
let { tenantId:
|
|
279
|
-
let
|
|
280
|
-
if (_.some((e) => e.tenantId !==
|
|
281
|
-
let v = _.slice(0, k), y = [...new Set(v.map((e) => u(e, "sessionId")))], b = y.length === 0 ? [] : await
|
|
282
|
-
if (j.some((e) => e.tenantId !==
|
|
277
|
+
if (b.isFailure(n)) return B("Session inspection requires one tenantId and an optional after cursor");
|
|
278
|
+
let { tenantId: r, after: f } = n.success, g = yield* y.result(G(async (t) => {
|
|
279
|
+
let n = L.now(), g = f === null ? S("tenantId", r) : x(S("tenantId", r), E(T("startedAt", new Date(f.startedAt)), x(S("startedAt", new Date(f.startedAt)), T("id", f.id)))), _ = await t.query(D(h).where(g).orderBy("startedAt", "desc").orderBy("id", "desc").limit(k + 1).descriptor);
|
|
280
|
+
if (_.some((e) => e.tenantId !== r)) throw Error("Invalid tenant query");
|
|
281
|
+
let v = _.slice(0, k), y = [...new Set(v.map((e) => u(e, "sessionId")))], b = y.length === 0 ? [] : await t.query(D(m).where(x(S("tenantId", r), w("sessionId", y))).limit(y.length * 8 + 1).descriptor), C = new Map(b.map((e) => [u(e, "serverId") + "\0" + u(e, "sessionId"), e])), A = v.map((e) => u(e, "id")), j = A.length === 0 ? [] : await t.query(D(p).select("tenantId", "runId", "revision", "schemaVersion", "bytes", "writtenAt").where(x(S("tenantId", r), w("runId", A))).limit(A.length + 1).descriptor);
|
|
282
|
+
if (j.some((e) => e.tenantId !== r)) throw Error("Invalid tenant query");
|
|
283
283
|
let M = new Map(j.map((e) => [u(e, "runId"), e])), N = v.map((e) => {
|
|
284
284
|
let t = C.get(u(e, "serverId") + "\0" + u(e, "sessionId")), n = t === void 0 ? null : s(t.result) ?? {};
|
|
285
285
|
return {
|
|
@@ -317,16 +317,16 @@ var R = (e, t) => {
|
|
|
317
317
|
violation: 0,
|
|
318
318
|
capped: !1
|
|
319
319
|
};
|
|
320
|
-
for (let
|
|
321
|
-
if (
|
|
322
|
-
let
|
|
323
|
-
P[
|
|
320
|
+
for (let n of e) {
|
|
321
|
+
if (n === "unknown") continue;
|
|
322
|
+
let e = (await t.query(D(d).where(x(S("tenantId", r), S("status", n))).limit(O + 1).descriptor)).length;
|
|
323
|
+
P[n] = Math.min(e, O), e > O && (P.capped = !0);
|
|
324
324
|
}
|
|
325
325
|
let F = N.at(-1);
|
|
326
326
|
return {
|
|
327
|
-
observedAt:
|
|
327
|
+
observedAt: n,
|
|
328
328
|
page: {
|
|
329
|
-
tenantId:
|
|
329
|
+
tenantId: r,
|
|
330
330
|
after: f?.raw ?? null,
|
|
331
331
|
nextAfter: _.length > k && F ? `${F.startedAt}:${F.id}` : null
|
|
332
332
|
},
|
package/dist/plugin.js
CHANGED
|
@@ -2,11 +2,11 @@ import { EngineServersError as e, engineServersError as t } from "./errors.js";
|
|
|
2
2
|
import { ENGINE_SERVER_HOT_TIMEOUT_MS as n, boundedHotStore as r } from "./hotStore.js";
|
|
3
3
|
import { defineEngineServerPool as i } from "./pool.js";
|
|
4
4
|
import { EngineServersPort as a } from "./port.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
5
|
+
import { makeEngineServerRegistry as o } from "./registry.server.js";
|
|
6
|
+
import { BASE_NAME as s, antiCheatReportDescriptor as c, authenticateDescriptor as l, deregisterDescriptor as u, drainDescriptor as d, engineServersRpcClientImports as f, heartbeatDescriptor as p, matchReportDescriptor as m, registerDescriptor as h, resumeDescriptor as g, sessionCheckpointDescriptor as _, sessionEventDescriptor as v, sessionRecoveryDescriptor as y, sessionWriteDescriptor as b, verifySessionDescriptor as x } from "./rpc.js";
|
|
7
|
+
import { engineServersInspectEndpoints as S } from "./inspect.js";
|
|
8
|
+
import { engineServerTables as C } from "./tables.entity.js";
|
|
9
|
+
import { assertEngineSecrets as w } from "./tokens.js";
|
|
10
10
|
import { checkWriteSources as T } from "./writes.js";
|
|
11
11
|
import { defineLicensedGamePlugin as E } from "@voltro/plugin-licensing/gate";
|
|
12
12
|
import { replicaEvidence as D } from "@voltro/protocol/identity";
|
|
@@ -14,18 +14,18 @@ import { Effect as O, Layer as k } from "effect";
|
|
|
14
14
|
// src/plugin.ts
|
|
15
15
|
var A = (e, t) => e.crossNode ? null : t.replicas === null ? t.production ? "Engine servers refuse to boot in production on the in-process HotStore: leases would live in this API process, so every restart or deploy would end every running engine-server session (lease_lost, players dropped). Use a HotStore that outlives the process: Redis (set REDIS_URL) or the SQL store (`hot: { backend: 'database' }` in app.config.ts, or HOT_BACKEND=database)." : null : `Engine server leases need a cross-node HotStore (Redis) when the API runs more than one replica (${t.replicas})`, j = (e) => {
|
|
16
16
|
let t = e.tokenSecrets(), n = e.ticketSecrets();
|
|
17
|
-
|
|
17
|
+
w("engine server token", t), w("engine server ticket", n);
|
|
18
18
|
let r = new Set([t.current.secret, t.previous?.secret].filter((e) => e !== void 0));
|
|
19
19
|
if ([n.current.secret, n.previous?.secret].some((e) => e !== void 0 && r.has(e))) throw Error("Engine server tickets and service tokens need separate signing secrets");
|
|
20
20
|
e.bootstrap.check?.();
|
|
21
|
-
}, M = (
|
|
22
|
-
if (!Array.isArray(
|
|
23
|
-
if (typeof
|
|
24
|
-
if (!
|
|
25
|
-
let M = Object.freeze(
|
|
21
|
+
}, M = (w) => {
|
|
22
|
+
if (!Array.isArray(w?.pools) || w.pools.length < 1) throw TypeError("engineServersPlugin: at least one pool is required");
|
|
23
|
+
if (typeof w.tokenSecrets != "function" || typeof w.ticketSecrets != "function") throw TypeError("engineServersPlugin: tokenSecrets and ticketSecrets must be functions");
|
|
24
|
+
if (!w.bootstrap || typeof w.bootstrap.verify != "function") throw TypeError("engineServersPlugin: a bootstrap source is required");
|
|
25
|
+
let M = Object.freeze(w.pools.map((e) => i(e)));
|
|
26
26
|
if (new Set(M.map((e) => e.name)).size !== M.length) throw TypeError("engineServersPlugin: pool names must be unique");
|
|
27
|
-
T(M,
|
|
28
|
-
let N =
|
|
27
|
+
T(M, w.writes, w.antiCheat);
|
|
28
|
+
let N = w.hotStore, P, F, I, L, R = /* @__PURE__ */ new Set(), z = Math.max(1e3, Math.min(...M.map((e) => e.recovery === null ? Math.min(15e3, Math.floor(e.heartbeatTtlMs / 3)) : Math.min(5e3, Math.floor(e.recovery.waitMs / 6))))), B = (e) => O.suspend(() => F === void 0 ? O.fail(t("unavailable")) : e(F)), V = Object.freeze({
|
|
29
29
|
authorizeSession: (e) => B((t) => t.authorizeSession(e)),
|
|
30
30
|
issueTicket: (e) => B((t) => t.issueTicket(e)),
|
|
31
31
|
reissueTicket: (e) => B((t) => t.reissueTicket(e)),
|
|
@@ -54,61 +54,61 @@ var A = (e, t) => e.crossNode ? null : t.replicas === null ? t.production ? "Eng
|
|
|
54
54
|
}
|
|
55
55
|
}), H = [
|
|
56
56
|
{
|
|
57
|
-
...
|
|
57
|
+
...l,
|
|
58
58
|
execute: (e) => B((t) => t.authenticate(e))
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
|
-
...
|
|
61
|
+
...h,
|
|
62
62
|
execute: (e) => B((t) => t.register(e))
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
|
-
...
|
|
65
|
+
...g,
|
|
66
66
|
execute: (e) => B((t) => t.resume(e))
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
|
-
...
|
|
69
|
+
...p,
|
|
70
70
|
execute: (e) => B((t) => t.heartbeat(e))
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
|
-
...
|
|
73
|
+
...d,
|
|
74
74
|
execute: (e) => B((t) => t.drainSelf(e))
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
|
-
...
|
|
77
|
+
...u,
|
|
78
78
|
execute: (e) => B((t) => t.deregister(e))
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
|
-
...
|
|
81
|
+
...x,
|
|
82
82
|
execute: (e) => B((t) => t.verifySeat(e))
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
|
-
...
|
|
85
|
+
...v,
|
|
86
86
|
execute: (e) => B((t) => t.event(e))
|
|
87
87
|
},
|
|
88
88
|
{
|
|
89
|
-
...
|
|
89
|
+
...b,
|
|
90
90
|
execute: (e) => B((t) => t.write(e))
|
|
91
91
|
},
|
|
92
92
|
{
|
|
93
|
-
...
|
|
93
|
+
..._,
|
|
94
94
|
execute: (e) => B((t) => t.checkpoint(e))
|
|
95
95
|
},
|
|
96
96
|
{
|
|
97
|
-
...
|
|
97
|
+
...y,
|
|
98
98
|
execute: (e) => B((t) => t.recovery(e))
|
|
99
99
|
},
|
|
100
100
|
{
|
|
101
|
-
...
|
|
101
|
+
...m,
|
|
102
102
|
execute: (e) => B((t) => t.report(e))
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
|
-
...
|
|
105
|
+
...c,
|
|
106
106
|
execute: (e) => B((t) => t.antiCheat(e))
|
|
107
107
|
}
|
|
108
108
|
];
|
|
109
109
|
return {
|
|
110
110
|
...E({
|
|
111
|
-
name:
|
|
111
|
+
name: s,
|
|
112
112
|
description: "Service identity, registry with HotStore leases, single-use join tickets, session lifecycle and authoritative writes for engine servers.",
|
|
113
113
|
permissions: [
|
|
114
114
|
"store:write",
|
|
@@ -116,17 +116,17 @@ var A = (e, t) => e.crossNode ? null : t.replicas === null ? t.production ? "Eng
|
|
|
116
116
|
"inspect:write"
|
|
117
117
|
],
|
|
118
118
|
routes: H,
|
|
119
|
-
rpcClientDescriptors: [...
|
|
119
|
+
rpcClientDescriptors: [...f],
|
|
120
120
|
...N === void 0 ? { needs: { hot: "local" } } : {},
|
|
121
121
|
services: k.succeed(a, V),
|
|
122
|
-
inspectEndpoints:
|
|
122
|
+
inspectEndpoints: S({
|
|
123
123
|
pools: M,
|
|
124
|
-
writes:
|
|
125
|
-
antiCheat:
|
|
124
|
+
writes: w.writes,
|
|
125
|
+
antiCheat: w.antiCheat,
|
|
126
126
|
store: () => F === void 0 ? void 0 : P,
|
|
127
127
|
registry: () => F,
|
|
128
128
|
hot: () => F === void 0 ? void 0 : L,
|
|
129
|
-
now:
|
|
129
|
+
now: w.now ?? Date.now
|
|
130
130
|
}),
|
|
131
131
|
errorSchemas: [{
|
|
132
132
|
schema: e,
|
|
@@ -135,14 +135,14 @@ var A = (e, t) => e.crossNode ? null : t.replicas === null ? t.production ? "Eng
|
|
|
135
135
|
name: "EngineServersError"
|
|
136
136
|
}
|
|
137
137
|
}],
|
|
138
|
-
extendSchema: { tables: [...
|
|
138
|
+
extendSchema: { tables: [...C] },
|
|
139
139
|
subjectPrivacy: {
|
|
140
|
-
tables:
|
|
140
|
+
tables: C.map((e) => e.tableName),
|
|
141
141
|
kinds: ["user", "guest"]
|
|
142
142
|
},
|
|
143
143
|
bindDataStore: async (e, t) => {
|
|
144
144
|
if (P !== void 0 && P !== e) throw Error("Engine servers plugin instance cannot cross app stores");
|
|
145
|
-
j(
|
|
145
|
+
j(w);
|
|
146
146
|
let i = N ?? (t?.hotStore === void 0 ? void 0 : await t.hotStore());
|
|
147
147
|
if (i === void 0) throw Error("Engine servers need the app HotStore (needs.hot); none was provided");
|
|
148
148
|
let a = A(i.capabilities, {
|
|
@@ -150,14 +150,14 @@ var A = (e, t) => e.crossNode ? null : t.replicas === null ? t.production ? "Eng
|
|
|
150
150
|
production: process.env.NODE_ENV === "production"
|
|
151
151
|
});
|
|
152
152
|
if (a !== null) throw Error(a);
|
|
153
|
-
if (P = e, L = r(i, n), F =
|
|
153
|
+
if (P = e, L = r(i, n), F = o(e, i, {
|
|
154
154
|
pools: M,
|
|
155
|
-
bootstrap:
|
|
156
|
-
tokenSecrets:
|
|
157
|
-
ticketSecrets:
|
|
158
|
-
...
|
|
159
|
-
...
|
|
160
|
-
...
|
|
155
|
+
bootstrap: w.bootstrap,
|
|
156
|
+
tokenSecrets: w.tokenSecrets,
|
|
157
|
+
ticketSecrets: w.ticketSecrets,
|
|
158
|
+
...w.now === void 0 ? {} : { now: w.now },
|
|
159
|
+
...w.writes === void 0 ? {} : { writes: w.writes },
|
|
160
|
+
...w.antiCheat === void 0 ? {} : { antiCheat: w.antiCheat },
|
|
161
161
|
sessionMoved: async (e, t) => {
|
|
162
162
|
for (let n of R) await n(e, t);
|
|
163
163
|
}
|