@voltro/plugin-engine-servers 0.0.0-stage → 0.90.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 +26466 -0
- package/LICENSE +61 -0
- package/README.md +25 -2
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +8333 -0
- package/dist/antiCheat.js +14 -0
- package/dist/bootstrap.js +40 -0
- package/dist/contract.js +374 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.js +30 -0
- package/dist/hotStore.js +43 -0
- package/dist/index.d.ts +1244 -0
- package/dist/index.js +8 -0
- package/dist/inspect.js +402 -0
- package/dist/plugin.js +189 -0
- package/dist/pool.d.ts +223 -0
- package/dist/pool.js +166 -0
- package/dist/port.js +4 -0
- package/dist/registry.server.js +884 -0
- package/dist/rows.js +20 -0
- package/dist/rpc.d.ts +329 -0
- package/dist/rpc.js +115 -0
- package/dist/server.d.ts +1365 -0
- package/dist/server.js +5 -0
- package/dist/session.server.js +687 -0
- package/dist/tables.entity.js +168 -0
- package/dist/tokens.js +97 -0
- package/dist/writes.js +16 -0
- package/package.json +85 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ENGINE_SERVERS_ERROR_CODES as e, EngineServersError as t } from "./errors.js";
|
|
2
|
+
import { ENGINE_KINDS as n, ENGINE_SERVER_BASE_SCOPES as r, ENGINE_SERVER_POOL_LIMITS as i, ENGINE_SERVER_PROTOCOLS as a, ENGINE_SERVER_SCOPES as o, ENGINE_SERVER_TRUST_LEVELS as s, ENGINE_SERVER_WRITE_KINDS as c, ENGINE_SERVER_WRITE_SCOPES as l, defineEngineServerPool as u } from "./pool.js";
|
|
3
|
+
import { EngineServersPort as d } from "./port.js";
|
|
4
|
+
import { ANTICHEAT_STATUSES as f, ENGINE_SERVER_GONE_REASONS as p, ENGINE_SERVER_LIFECYCLE_EVENTS as m, ENGINE_SERVER_LIVE_STATES as h, ENGINE_SERVER_SESSION_STATES as g, ENGINE_SERVER_STATES as _, SESSION_SEAT_PURPOSE as v } from "./contract.js";
|
|
5
|
+
import { engineServersPlugin as y } from "./plugin.js";
|
|
6
|
+
import { serverReportedAntiCheat as b } from "./antiCheat.js";
|
|
7
|
+
import { bootstrapByPool as x, staticBootstrapSource as S } from "./bootstrap.js";
|
|
8
|
+
export { f as ANTICHEAT_STATUSES, n as ENGINE_KINDS, e as ENGINE_SERVERS_ERROR_CODES, r as ENGINE_SERVER_BASE_SCOPES, p as ENGINE_SERVER_GONE_REASONS, m as ENGINE_SERVER_LIFECYCLE_EVENTS, h as ENGINE_SERVER_LIVE_STATES, i as ENGINE_SERVER_POOL_LIMITS, a as ENGINE_SERVER_PROTOCOLS, o as ENGINE_SERVER_SCOPES, g as ENGINE_SERVER_SESSION_STATES, _ as ENGINE_SERVER_STATES, s as ENGINE_SERVER_TRUST_LEVELS, c as ENGINE_SERVER_WRITE_KINDS, l as ENGINE_SERVER_WRITE_SCOPES, t as EngineServersError, d as EngineServersPort, v as SESSION_SEAT_PURPOSE, x as bootstrapByPool, u as defineEngineServerPool, y as engineServersPlugin, b as serverReportedAntiCheat, S as staticBootstrapSource };
|
package/dist/inspect.js
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { ENGINE_SERVER_WRITE_WINDOW_MS as e, writeUsageKey as t } from "./hotStore.js";
|
|
2
|
+
import { ENGINE_SERVER_WRITE_KINDS as n } from "./pool.js";
|
|
3
|
+
import { ANTICHEAT_STATUSES as r } from "./contract.js";
|
|
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
|
+
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
|
+
import { Effect as y, Result as b } from "effect";
|
|
7
|
+
import { and as x, eq as S, gt as C, inSet as w, lt as T, or as E, queryFor as D } from "@voltro/database";
|
|
8
|
+
import { ENGINE_SERVERS_INSPECT_COUNT_CAP as O, ENGINE_SERVERS_INSPECT_PAGE as k, ENGINE_SERVERS_INSPECT_PLAYER_TICKETS as A, ENGINE_SERVERS_RUN_CURSOR as j, decodeEngineServersAction as M, decodeEngineServersPlayer as N, decodeEngineServersServers as P, decodeEngineServersSessions as F, decodeEngineServersStatus as I, parseReplicaSelection as L } from "@voltro/protocol/inspect";
|
|
9
|
+
// src/inspect.ts
|
|
10
|
+
var R = (e, t) => {
|
|
11
|
+
if (typeof e != "string" || !e.trim() || e.length > t || /[\u0000-\u001f\u007f]/.test(e)) throw Error("Invalid identity");
|
|
12
|
+
return e;
|
|
13
|
+
}, z = (e, t, n = []) => {
|
|
14
|
+
let r = new URL(e.url, "http://inspect.local").searchParams;
|
|
15
|
+
L(r), r.delete("replica"), r.delete("replicas");
|
|
16
|
+
let i = /* @__PURE__ */ new Set([
|
|
17
|
+
"tenantId",
|
|
18
|
+
...t,
|
|
19
|
+
...n
|
|
20
|
+
]);
|
|
21
|
+
for (let e of r.keys()) if (!i.has(e)) throw Error("Unknown parameter");
|
|
22
|
+
for (let e of i) if (r.getAll(e).length > 1) throw Error("Ambiguous parameter");
|
|
23
|
+
for (let e of ["tenantId", ...n]) if (!r.has(e)) throw Error("Missing parameter");
|
|
24
|
+
return r;
|
|
25
|
+
}, B = (e) => ({
|
|
26
|
+
kind: "json",
|
|
27
|
+
status: 400,
|
|
28
|
+
data: { error: e }
|
|
29
|
+
}), V = (e) => ({
|
|
30
|
+
kind: "json",
|
|
31
|
+
status: 503,
|
|
32
|
+
data: { error: e }
|
|
33
|
+
}), H = (e) => {
|
|
34
|
+
let t = e.code === "invalid_input" ? 400 : e.code === "not_found" ? 404 : e.code === "conflict" || e.code === "lease_lost" ? 409 : 503;
|
|
35
|
+
return {
|
|
36
|
+
kind: "json",
|
|
37
|
+
status: t,
|
|
38
|
+
data: {
|
|
39
|
+
error: t === 503 ? "The registry did not complete the action. Read the server again and retry." : `Refused: ${e.code}`,
|
|
40
|
+
code: e.code
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}, U = (e) => {
|
|
44
|
+
L(new URL(e.url, "http://inspect.local").searchParams);
|
|
45
|
+
let t = JSON.parse(e.body || "null");
|
|
46
|
+
if (typeof t != "object" || !t || Array.isArray(t)) throw Error("Invalid body");
|
|
47
|
+
let n = Object.keys(t);
|
|
48
|
+
if (n.length !== 2 || !n.includes("tenantId") || !n.includes("serverId")) throw Error("Invalid body");
|
|
49
|
+
let { tenantId: r, serverId: i } = t;
|
|
50
|
+
return {
|
|
51
|
+
tenantId: R(r, 256),
|
|
52
|
+
serverId: R(i, 64)
|
|
53
|
+
};
|
|
54
|
+
}, W = (L) => {
|
|
55
|
+
let W = new Map(L.pools.map((e) => [e.name, e])), G = (e) => y.tryPromise({
|
|
56
|
+
try: async () => {
|
|
57
|
+
let t = L.store();
|
|
58
|
+
if (t === void 0) throw Error("Engine servers are not bound");
|
|
59
|
+
return e(t);
|
|
60
|
+
},
|
|
61
|
+
catch: (e) => e
|
|
62
|
+
}), K = {
|
|
63
|
+
inventory: L.writes?.inventory !== void 0,
|
|
64
|
+
economy: L.writes?.economy !== void 0,
|
|
65
|
+
progression: L.writes?.progression !== void 0,
|
|
66
|
+
leaderboards: L.writes?.leaderboards !== void 0,
|
|
67
|
+
telemetry: !0
|
|
68
|
+
}, q = async (e, t, n) => {
|
|
69
|
+
let r = l(t, "sessionId"), i = W.get(u(t, "pool"));
|
|
70
|
+
if (r === null || i === void 0) return {
|
|
71
|
+
seats: {
|
|
72
|
+
issued: 0,
|
|
73
|
+
redeemed: 0,
|
|
74
|
+
connected: 0
|
|
75
|
+
},
|
|
76
|
+
backfills: 0
|
|
77
|
+
};
|
|
78
|
+
let s = u(t, "tenantId"), d = u(t, "id"), p = o(t, "capacity"), m = await e.query(D(_).where(x(S("tenantId", s), S("serverId", d), S("sessionId", r), w("state", ["issued", "redeemed"]))).limit(p * 2 + 1).descriptor), h = 0, g = 0, v = 0;
|
|
79
|
+
for (let e of m) {
|
|
80
|
+
let t = c(e.leftAt);
|
|
81
|
+
e.state === "issued" && a(e.redeemBy) >= n ? h++ : e.state === "redeemed" && (t === null || t + i.reconnectWindowMs >= n) && (g++, t === null && e.joinedAt !== null && e.joinedAt !== void 0 && v++);
|
|
82
|
+
}
|
|
83
|
+
let y = await e.query(D(f).where(x(S("tenantId", s), S("serverId", d), S("sessionId", r))).limit(O + 1).descriptor);
|
|
84
|
+
return {
|
|
85
|
+
seats: {
|
|
86
|
+
issued: h,
|
|
87
|
+
redeemed: g,
|
|
88
|
+
connected: v
|
|
89
|
+
},
|
|
90
|
+
backfills: y.length
|
|
91
|
+
};
|
|
92
|
+
}, J = async (r, i) => {
|
|
93
|
+
let a = L.hot(), o = W.get(u(r, "pool"));
|
|
94
|
+
if (a === void 0 || o === void 0 || l(r, "sessionId") === null) return null;
|
|
95
|
+
let s = n.reduce((e, t) => e + o.writeLimits[t].perMinute, 0), c = await y.runPromise(y.result(a.zrange(t(u(r, "tenantId"), u(r, "id")), { byScore: [i - e, i] }, "asc", { limit: Math.min(s * 2 + 1, 1e5) })));
|
|
96
|
+
if (b.isFailure(c)) return null;
|
|
97
|
+
let d = /* @__PURE__ */ new Map();
|
|
98
|
+
for (let { member: e } of c.success) {
|
|
99
|
+
let t = e.slice(0, e.indexOf(":"));
|
|
100
|
+
d.set(t, (d.get(t) ?? 0) + 1);
|
|
101
|
+
}
|
|
102
|
+
return n.map((e) => ({
|
|
103
|
+
kind: e,
|
|
104
|
+
used: Math.min(d.get(e) ?? 0, 1e6),
|
|
105
|
+
perMinute: o.writeLimits[e].perMinute
|
|
106
|
+
}));
|
|
107
|
+
}, Y = (e, t, n) => ({
|
|
108
|
+
method: "POST",
|
|
109
|
+
path: `/${e}`,
|
|
110
|
+
scope: "shared-store",
|
|
111
|
+
description: t,
|
|
112
|
+
handler: (t) => y.gen(function* () {
|
|
113
|
+
let r = yield* y.result(y.try({
|
|
114
|
+
try: () => U(t),
|
|
115
|
+
catch: () => "invalid"
|
|
116
|
+
}));
|
|
117
|
+
if (b.isFailure(r)) return B("Engine server actions require a JSON body with exactly one tenantId and one serverId");
|
|
118
|
+
let i = L.registry();
|
|
119
|
+
if (i === void 0) return V("Engine servers are not bound. Read the status endpoint and try again.");
|
|
120
|
+
let a = r.success, o = yield* y.result(y.gen(function* () {
|
|
121
|
+
let e = yield* i.get(a);
|
|
122
|
+
return e === null ? null : (yield* n(i, a), {
|
|
123
|
+
before: e,
|
|
124
|
+
after: yield* i.get(a)
|
|
125
|
+
});
|
|
126
|
+
}));
|
|
127
|
+
if (b.isFailure(o)) return H(o.failure);
|
|
128
|
+
if (o.success === null || o.success.after === null) return {
|
|
129
|
+
kind: "json",
|
|
130
|
+
status: 404,
|
|
131
|
+
data: {
|
|
132
|
+
error: "Refused: not_found",
|
|
133
|
+
code: "not_found"
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
let { before: s, after: c } = o.success;
|
|
137
|
+
return {
|
|
138
|
+
kind: "json",
|
|
139
|
+
data: M({
|
|
140
|
+
observedAt: L.now(),
|
|
141
|
+
action: e,
|
|
142
|
+
tenantId: a.tenantId,
|
|
143
|
+
serverId: a.serverId,
|
|
144
|
+
changed: s.state !== c.state || s.stateChangedAt !== c.stateChangedAt,
|
|
145
|
+
state: c.state,
|
|
146
|
+
goneReason: c.goneReason
|
|
147
|
+
})
|
|
148
|
+
};
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
return [
|
|
152
|
+
{
|
|
153
|
+
method: "GET",
|
|
154
|
+
path: "/status",
|
|
155
|
+
scope: "process",
|
|
156
|
+
description: "Pools, write limits, write sources and anti-cheat provider this process captured at install",
|
|
157
|
+
handler: () => y.sync(() => ({
|
|
158
|
+
kind: "json",
|
|
159
|
+
data: I({
|
|
160
|
+
observedAt: L.now(),
|
|
161
|
+
bound: L.store() !== void 0,
|
|
162
|
+
antiCheatProvider: L.antiCheat?.name ?? null,
|
|
163
|
+
writeSources: K,
|
|
164
|
+
pools: L.pools.map((e) => ({
|
|
165
|
+
name: e.name,
|
|
166
|
+
engine: e.engine,
|
|
167
|
+
trust: e.trust,
|
|
168
|
+
builds: [...e.builds],
|
|
169
|
+
regions: [...e.regions],
|
|
170
|
+
players: e.capacity.players,
|
|
171
|
+
scopes: [...e.scopes],
|
|
172
|
+
protocols: [...e.protocols],
|
|
173
|
+
heartbeatTtlMs: e.heartbeatTtlMs,
|
|
174
|
+
tokenTtlMs: e.tokenTtlMs,
|
|
175
|
+
ticketTtlMs: e.ticketTtlMs,
|
|
176
|
+
reconnectWindowMs: e.reconnectWindowMs,
|
|
177
|
+
resumeWindowMs: e.resumeWindowMs,
|
|
178
|
+
recovery: e.recovery === null ? null : { ...e.recovery },
|
|
179
|
+
writeLimits: n.map((t) => ({
|
|
180
|
+
kind: t,
|
|
181
|
+
perMinute: e.writeLimits[t].perMinute,
|
|
182
|
+
maxAmount: e.writeLimits[t].maxAmount
|
|
183
|
+
}))
|
|
184
|
+
})),
|
|
185
|
+
tables: g.map((e) => e.tableName)
|
|
186
|
+
})
|
|
187
|
+
}))
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
method: "GET",
|
|
191
|
+
path: "/servers",
|
|
192
|
+
scope: "shared-store",
|
|
193
|
+
description: "One page of a tenant's servers by id with state, heartbeat, held session, seats and backfill keys",
|
|
194
|
+
handler: (e) => y.gen(function* () {
|
|
195
|
+
let t = yield* y.result(y.try({
|
|
196
|
+
try: () => {
|
|
197
|
+
let t = z(e, ["after"]);
|
|
198
|
+
return {
|
|
199
|
+
tenantId: R(t.get("tenantId"), 256),
|
|
200
|
+
after: t.has("after") ? R(t.get("after"), 64) : null
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
catch: () => "invalid"
|
|
204
|
+
}));
|
|
205
|
+
if (b.isFailure(t)) return B("Engine server inspection requires one tenantId and an optional after cursor");
|
|
206
|
+
let { tenantId: n, after: r } = t.success, i = yield* y.result(G(async (e) => {
|
|
207
|
+
let t = L.now(), i = await e.query(D(v).where(r === null ? S("tenantId", n) : x(S("tenantId", n), C("id", r))).orderBy("id", "asc").limit(k + 1).descriptor);
|
|
208
|
+
if (i.some((e) => e.tenantId !== n)) throw Error("Invalid tenant query");
|
|
209
|
+
let s = i.slice(0, k), c = [];
|
|
210
|
+
for (let n of s) {
|
|
211
|
+
let r = u(n, "state"), i = W.get(u(n, "pool")), s = r === "gone" ? "gone" : i !== void 0 && a(n.lastHeartbeatAt) >= t - i.heartbeatTtlMs ? "fresh" : "stale", d = r === "suspended" && i !== void 0;
|
|
212
|
+
c.push({
|
|
213
|
+
id: u(n, "id"),
|
|
214
|
+
pool: u(n, "pool"),
|
|
215
|
+
region: u(n, "region"),
|
|
216
|
+
buildId: u(n, "buildId"),
|
|
217
|
+
protocol: u(n, "protocol"),
|
|
218
|
+
capacity: o(n, "capacity"),
|
|
219
|
+
state: r,
|
|
220
|
+
goneReason: l(n, "goneReason"),
|
|
221
|
+
sessionId: l(n, "sessionId"),
|
|
222
|
+
heartbeat: s,
|
|
223
|
+
registeredAt: a(n.registeredAt),
|
|
224
|
+
lastHeartbeatAt: a(n.lastHeartbeatAt),
|
|
225
|
+
stateChangedAt: a(n.stateChangedAt),
|
|
226
|
+
resumeState: d ? l(n, "resumeState") ?? "ready" : null,
|
|
227
|
+
resumableUntil: d ? a(n.lastHeartbeatAt) + i.heartbeatTtlMs + i.resumeWindowMs : null,
|
|
228
|
+
recoveredFrom: l(n, "sessionOrigin"),
|
|
229
|
+
...r === "allocated" || r === "draining" || r === "suspended" ? await q(e, n, t) : {
|
|
230
|
+
seats: {
|
|
231
|
+
issued: 0,
|
|
232
|
+
redeemed: 0,
|
|
233
|
+
connected: 0
|
|
234
|
+
},
|
|
235
|
+
backfills: 0
|
|
236
|
+
},
|
|
237
|
+
writes: r === "allocated" || r === "draining" ? await J(n, t) : null
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
observedAt: t,
|
|
242
|
+
page: {
|
|
243
|
+
tenantId: n,
|
|
244
|
+
after: r,
|
|
245
|
+
nextAfter: i.length > k ? c.at(-1).id : null
|
|
246
|
+
},
|
|
247
|
+
servers: c
|
|
248
|
+
};
|
|
249
|
+
}));
|
|
250
|
+
return b.isFailure(i) ? V("Engine server inspection is unavailable. Read the status endpoint and try again.") : {
|
|
251
|
+
kind: "json",
|
|
252
|
+
data: P(i.success)
|
|
253
|
+
};
|
|
254
|
+
})
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
method: "GET",
|
|
258
|
+
path: "/sessions",
|
|
259
|
+
scope: "shared-store",
|
|
260
|
+
description: "One page of a tenant's session runs, newest first, with result summaries and anti-cheat counts",
|
|
261
|
+
handler: (e) => y.gen(function* () {
|
|
262
|
+
let t = yield* y.result(y.try({
|
|
263
|
+
try: () => {
|
|
264
|
+
let t = z(e, ["after"]), n = t.has("after") ? j.exec(R(t.get("after"), 128)) : null;
|
|
265
|
+
if (t.has("after") && n === null) throw Error("Invalid cursor");
|
|
266
|
+
return {
|
|
267
|
+
tenantId: R(t.get("tenantId"), 256),
|
|
268
|
+
after: n === null ? null : {
|
|
269
|
+
raw: n[0],
|
|
270
|
+
startedAt: Number(n[1]),
|
|
271
|
+
id: n[2]
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
catch: () => "invalid"
|
|
276
|
+
}));
|
|
277
|
+
if (b.isFailure(t)) return B("Session inspection requires one tenantId and an optional after cursor");
|
|
278
|
+
let { tenantId: n, after: f } = t.success, g = yield* y.result(G(async (e) => {
|
|
279
|
+
let t = L.now(), g = f === null ? S("tenantId", n) : x(S("tenantId", n), E(T("startedAt", new Date(f.startedAt)), x(S("startedAt", new Date(f.startedAt)), T("id", f.id)))), _ = await e.query(D(h).where(g).orderBy("startedAt", "desc").orderBy("id", "desc").limit(k + 1).descriptor);
|
|
280
|
+
if (_.some((e) => e.tenantId !== n)) 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 e.query(D(m).where(x(S("tenantId", n), 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 e.query(D(p).select("tenantId", "runId", "revision", "schemaVersion", "bytes", "writtenAt").where(x(S("tenantId", n), w("runId", A))).limit(A.length + 1).descriptor);
|
|
282
|
+
if (j.some((e) => e.tenantId !== n)) throw Error("Invalid tenant query");
|
|
283
|
+
let M = new Map(j.map((e) => [u(e, "runId"), e])), N = v.map((e) => {
|
|
284
|
+
let t = C.get(u(e, "serverId") + "\0" + u(e, "sessionId")), n = t === void 0 ? null : s(t.result) ?? {};
|
|
285
|
+
return {
|
|
286
|
+
id: u(e, "id"),
|
|
287
|
+
serverId: u(e, "serverId"),
|
|
288
|
+
pool: u(e, "pool"),
|
|
289
|
+
sessionId: u(e, "sessionId"),
|
|
290
|
+
trust: u(e, "trust"),
|
|
291
|
+
state: u(e, "state"),
|
|
292
|
+
sequence: o(e, "sequence"),
|
|
293
|
+
startedAt: a(e.startedAt),
|
|
294
|
+
endedAt: c(e.endedAt),
|
|
295
|
+
endReason: l(e, "endReason"),
|
|
296
|
+
waitingSince: c(e.waitingSince),
|
|
297
|
+
resumedAt: c(e.resumedAt),
|
|
298
|
+
resumes: e.resumes === null || e.resumes === void 0 ? 0 : o(e, "resumes"),
|
|
299
|
+
recoveries: e.recoveries === null || e.recoveries === void 0 ? 0 : o(e, "recoveries"),
|
|
300
|
+
recoveredAt: c(e.recoveredAt),
|
|
301
|
+
checkpoint: M.has(u(e, "id")) ? ((e) => ({
|
|
302
|
+
revision: o(e, "revision"),
|
|
303
|
+
schemaVersion: o(e, "schemaVersion"),
|
|
304
|
+
bytes: o(e, "bytes"),
|
|
305
|
+
writtenAt: a(e.writtenAt)
|
|
306
|
+
}))(M.get(u(e, "id"))) : null,
|
|
307
|
+
report: t === void 0 ? null : {
|
|
308
|
+
outcome: u(t, "outcome"),
|
|
309
|
+
trusted: i(t.trusted),
|
|
310
|
+
standings: Array.isArray(n?.standings) ? n.standings.length : 0,
|
|
311
|
+
reportedAt: a(t.reportedAt)
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}), P = {
|
|
315
|
+
verified: 0,
|
|
316
|
+
unverified: 0,
|
|
317
|
+
violation: 0,
|
|
318
|
+
capped: !1
|
|
319
|
+
};
|
|
320
|
+
for (let t of r) {
|
|
321
|
+
if (t === "unknown") continue;
|
|
322
|
+
let r = (await e.query(D(d).where(x(S("tenantId", n), S("status", t))).limit(O + 1).descriptor)).length;
|
|
323
|
+
P[t] = Math.min(r, O), r > O && (P.capped = !0);
|
|
324
|
+
}
|
|
325
|
+
let F = N.at(-1);
|
|
326
|
+
return {
|
|
327
|
+
observedAt: t,
|
|
328
|
+
page: {
|
|
329
|
+
tenantId: n,
|
|
330
|
+
after: f?.raw ?? null,
|
|
331
|
+
nextAfter: _.length > k && F ? `${F.startedAt}:${F.id}` : null
|
|
332
|
+
},
|
|
333
|
+
runs: N,
|
|
334
|
+
antiCheat: P
|
|
335
|
+
};
|
|
336
|
+
}));
|
|
337
|
+
return b.isFailure(g) ? V("Session inspection is unavailable. Read the status endpoint and try again.") : {
|
|
338
|
+
kind: "json",
|
|
339
|
+
data: F(g.success)
|
|
340
|
+
};
|
|
341
|
+
})
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
method: "GET",
|
|
345
|
+
path: "/player",
|
|
346
|
+
scope: "shared-store",
|
|
347
|
+
description: "One player by id: anti-cheat status and newest join tickets without the ticket, digest or claims",
|
|
348
|
+
handler: (e) => y.gen(function* () {
|
|
349
|
+
let t = yield* y.result(y.try({
|
|
350
|
+
try: () => {
|
|
351
|
+
let t = z(e, [], ["subjectId"]);
|
|
352
|
+
return {
|
|
353
|
+
tenantId: R(t.get("tenantId"), 256),
|
|
354
|
+
subjectId: R(t.get("subjectId"), 256)
|
|
355
|
+
};
|
|
356
|
+
},
|
|
357
|
+
catch: () => "invalid"
|
|
358
|
+
}));
|
|
359
|
+
if (b.isFailure(t)) return B("Player inspection requires one tenantId and one subjectId");
|
|
360
|
+
let { tenantId: n, subjectId: r } = t.success, i = yield* y.result(G(async (e) => {
|
|
361
|
+
let t = (await e.query(D(d).where(x(S("tenantId", n), S("subjectId", r))).limit(1).descriptor))[0], i = await e.query(D(_).where(x(S("tenantId", n), S("subjectId", r))).orderBy("issuedAt", "desc").orderBy("id", "desc").limit(A).descriptor), s = [...new Set(i.map((e) => u(e, "serverId")))], f = s.length === 0 ? [] : await e.query(D(v).where(x(S("tenantId", n), w("id", s))).limit(s.length).descriptor), p = new Map(f.map((e) => [u(e, "id"), u(e, "state")]));
|
|
362
|
+
return {
|
|
363
|
+
observedAt: L.now(),
|
|
364
|
+
tenantId: n,
|
|
365
|
+
subjectId: r,
|
|
366
|
+
antiCheat: t === void 0 ? {
|
|
367
|
+
status: "unknown",
|
|
368
|
+
provider: null,
|
|
369
|
+
updatedAt: null
|
|
370
|
+
} : {
|
|
371
|
+
status: u(t, "status"),
|
|
372
|
+
provider: l(t, "provider"),
|
|
373
|
+
updatedAt: c(t.updatedAt)
|
|
374
|
+
},
|
|
375
|
+
tickets: i.map((e) => ({
|
|
376
|
+
id: u(e, "id"),
|
|
377
|
+
serverId: u(e, "serverId"),
|
|
378
|
+
sessionId: u(e, "sessionId"),
|
|
379
|
+
subjectKind: u(e, "subjectKind"),
|
|
380
|
+
state: u(e, "state"),
|
|
381
|
+
issuedAt: a(e.issuedAt),
|
|
382
|
+
redeemBy: a(e.redeemBy),
|
|
383
|
+
redeemedAt: c(e.redeemedAt),
|
|
384
|
+
joinedAt: c(e.joinedAt),
|
|
385
|
+
leftAt: c(e.leftAt),
|
|
386
|
+
redemptions: o(e, "redemptions"),
|
|
387
|
+
serverState: p.get(u(e, "serverId")) ?? null
|
|
388
|
+
}))
|
|
389
|
+
};
|
|
390
|
+
}));
|
|
391
|
+
return b.isFailure(i) ? V("Player inspection is unavailable. Read the status endpoint and try again.") : {
|
|
392
|
+
kind: "json",
|
|
393
|
+
data: N(i.success)
|
|
394
|
+
};
|
|
395
|
+
})
|
|
396
|
+
},
|
|
397
|
+
Y("drain", "Drain one server: it takes no new session, the running one finishes (a suspended server drains once it resumes)", (e, t) => e.drain(t)),
|
|
398
|
+
Y("revoke", "Revoke one server now: its lease, credentials and tickets end, its running session is abandoned", (e, t) => e.revokeServer(t)),
|
|
399
|
+
Y("exit", "Report that one server's process exited (orchestrator): its lease ends now and crash recovery starts without waiting for afterMs", (e, t) => e.reportExit(t))
|
|
400
|
+
];
|
|
401
|
+
};
|
|
402
|
+
export { W as engineServersInspectEndpoints };
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { EngineServersError as e, engineServersError as t } from "./errors.js";
|
|
2
|
+
import { ENGINE_SERVER_HOT_TIMEOUT_MS as n, boundedHotStore as r } from "./hotStore.js";
|
|
3
|
+
import { defineEngineServerPool as i } from "./pool.js";
|
|
4
|
+
import { EngineServersPort as a } from "./port.js";
|
|
5
|
+
import { engineServerTables as o } from "./tables.entity.js";
|
|
6
|
+
import { assertEngineSecrets as s } from "./tokens.js";
|
|
7
|
+
import { makeEngineServerRegistry as c } from "./registry.server.js";
|
|
8
|
+
import { BASE_NAME as l, antiCheatReportDescriptor as u, authenticateDescriptor as d, deregisterDescriptor as f, drainDescriptor as p, engineServersRpcClientImports as m, heartbeatDescriptor as h, matchReportDescriptor as g, registerDescriptor as _, resumeDescriptor as v, sessionCheckpointDescriptor as y, sessionEventDescriptor as b, sessionRecoveryDescriptor as x, sessionWriteDescriptor as S, verifySessionDescriptor as C } from "./rpc.js";
|
|
9
|
+
import { engineServersInspectEndpoints as w } from "./inspect.js";
|
|
10
|
+
import { checkWriteSources as T } from "./writes.js";
|
|
11
|
+
import { defineLicensedGamePlugin as E } from "@voltro/plugin-licensing/gate";
|
|
12
|
+
import { replicaEvidence as D } from "@voltro/protocol/identity";
|
|
13
|
+
import { Effect as O, Layer as k } from "effect";
|
|
14
|
+
// src/plugin.ts
|
|
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
|
+
let t = e.tokenSecrets(), n = e.ticketSecrets();
|
|
17
|
+
s("engine server token", t), s("engine server ticket", n);
|
|
18
|
+
let r = new Set([t.current.secret, t.previous?.secret].filter((e) => e !== void 0));
|
|
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
|
+
e.bootstrap.check?.();
|
|
21
|
+
}, M = (s) => {
|
|
22
|
+
if (!Array.isArray(s?.pools) || s.pools.length < 1) throw TypeError("engineServersPlugin: at least one pool is required");
|
|
23
|
+
if (typeof s.tokenSecrets != "function" || typeof s.ticketSecrets != "function") throw TypeError("engineServersPlugin: tokenSecrets and ticketSecrets must be functions");
|
|
24
|
+
if (!s.bootstrap || typeof s.bootstrap.verify != "function") throw TypeError("engineServersPlugin: a bootstrap source is required");
|
|
25
|
+
let M = Object.freeze(s.pools.map((e) => i(e)));
|
|
26
|
+
if (new Set(M.map((e) => e.name)).size !== M.length) throw TypeError("engineServersPlugin: pool names must be unique");
|
|
27
|
+
T(M, s.writes, s.antiCheat);
|
|
28
|
+
let N = s.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
|
+
authorizeSession: (e) => B((t) => t.authorizeSession(e)),
|
|
30
|
+
issueTicket: (e) => B((t) => t.issueTicket(e)),
|
|
31
|
+
reissueTicket: (e) => B((t) => t.reissueTicket(e)),
|
|
32
|
+
seatBackfill: (e) => B((t) => t.seatBackfill(e)),
|
|
33
|
+
reclaimBackfill: (e) => B((t) => t.reclaimBackfill(e)),
|
|
34
|
+
withdrawBackfill: (e) => B((t) => t.withdrawBackfill(e)),
|
|
35
|
+
vacateWaitingSeats: (e) => B((t) => t.vacateWaitingSeats(e)),
|
|
36
|
+
revokeTicket: (e) => B((t) => t.revokeTicket(e)),
|
|
37
|
+
reserve: (e) => B((t) => t.reserve(e)),
|
|
38
|
+
release: (e) => B((t) => t.release(e)),
|
|
39
|
+
drain: (e) => B((t) => t.drain(e)),
|
|
40
|
+
revokeServer: (e) => B((t) => t.revokeServer(e)),
|
|
41
|
+
revokePool: (e) => B((t) => t.revokePool(e)),
|
|
42
|
+
get: (e) => B((t) => t.get(e)),
|
|
43
|
+
list: (e) => B((t) => t.list(e)),
|
|
44
|
+
sweep: (e) => B((t) => t.sweep(e)),
|
|
45
|
+
getReport: (e) => B((t) => t.getReport(e)),
|
|
46
|
+
antiCheatStatus: (e) => B((t) => t.antiCheatStatus(e)),
|
|
47
|
+
activity: (e) => B((t) => t.activity(e)),
|
|
48
|
+
reportExit: (e) => B((t) => t.reportExit(e)),
|
|
49
|
+
onSessionMoved: (e) => {
|
|
50
|
+
if (typeof e != "function") throw TypeError("engineServers.onSessionMoved: listener must be a function");
|
|
51
|
+
return R.add(e), () => {
|
|
52
|
+
R.delete(e);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}), H = [
|
|
56
|
+
{
|
|
57
|
+
...d,
|
|
58
|
+
execute: (e) => B((t) => t.authenticate(e))
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
..._,
|
|
62
|
+
execute: (e) => B((t) => t.register(e))
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
...v,
|
|
66
|
+
execute: (e) => B((t) => t.resume(e))
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
...h,
|
|
70
|
+
execute: (e) => B((t) => t.heartbeat(e))
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
...p,
|
|
74
|
+
execute: (e) => B((t) => t.drainSelf(e))
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
...f,
|
|
78
|
+
execute: (e) => B((t) => t.deregister(e))
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
...C,
|
|
82
|
+
execute: (e) => B((t) => t.verifySeat(e))
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
...b,
|
|
86
|
+
execute: (e) => B((t) => t.event(e))
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
...S,
|
|
90
|
+
execute: (e) => B((t) => t.write(e))
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
...y,
|
|
94
|
+
execute: (e) => B((t) => t.checkpoint(e))
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
...x,
|
|
98
|
+
execute: (e) => B((t) => t.recovery(e))
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
...g,
|
|
102
|
+
execute: (e) => B((t) => t.report(e))
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
...u,
|
|
106
|
+
execute: (e) => B((t) => t.antiCheat(e))
|
|
107
|
+
}
|
|
108
|
+
];
|
|
109
|
+
return {
|
|
110
|
+
...E({
|
|
111
|
+
name: l,
|
|
112
|
+
description: "Service identity, registry with HotStore leases, single-use join tickets, session lifecycle and authoritative writes for engine servers.",
|
|
113
|
+
permissions: [
|
|
114
|
+
"store:write",
|
|
115
|
+
"inspect:read",
|
|
116
|
+
"inspect:write"
|
|
117
|
+
],
|
|
118
|
+
routes: H,
|
|
119
|
+
rpcClientDescriptors: [...m],
|
|
120
|
+
...N === void 0 ? { needs: { hot: "local" } } : {},
|
|
121
|
+
services: k.succeed(a, V),
|
|
122
|
+
inspectEndpoints: w({
|
|
123
|
+
pools: M,
|
|
124
|
+
writes: s.writes,
|
|
125
|
+
antiCheat: s.antiCheat,
|
|
126
|
+
store: () => F === void 0 ? void 0 : P,
|
|
127
|
+
registry: () => F,
|
|
128
|
+
hot: () => F === void 0 ? void 0 : L,
|
|
129
|
+
now: s.now ?? Date.now
|
|
130
|
+
}),
|
|
131
|
+
errorSchemas: [{
|
|
132
|
+
schema: e,
|
|
133
|
+
import: {
|
|
134
|
+
module: "@voltro/plugin-engine-servers/errors",
|
|
135
|
+
name: "EngineServersError"
|
|
136
|
+
}
|
|
137
|
+
}],
|
|
138
|
+
extendSchema: { tables: [...o] },
|
|
139
|
+
subjectPrivacy: {
|
|
140
|
+
tables: o.map((e) => e.tableName),
|
|
141
|
+
kinds: ["user", "guest"]
|
|
142
|
+
},
|
|
143
|
+
bindDataStore: async (e, t) => {
|
|
144
|
+
if (P !== void 0 && P !== e) throw Error("Engine servers plugin instance cannot cross app stores");
|
|
145
|
+
j(s);
|
|
146
|
+
let i = N ?? (t?.hotStore === void 0 ? void 0 : await t.hotStore());
|
|
147
|
+
if (i === void 0) throw Error("Engine servers need the app HotStore (needs.hot); none was provided");
|
|
148
|
+
let a = A(i.capabilities, {
|
|
149
|
+
replicas: D(),
|
|
150
|
+
production: process.env.NODE_ENV === "production"
|
|
151
|
+
});
|
|
152
|
+
if (a !== null) throw Error(a);
|
|
153
|
+
if (P = e, L = r(i, n), F = c(e, i, {
|
|
154
|
+
pools: M,
|
|
155
|
+
bootstrap: s.bootstrap,
|
|
156
|
+
tokenSecrets: s.tokenSecrets,
|
|
157
|
+
ticketSecrets: s.ticketSecrets,
|
|
158
|
+
...s.now === void 0 ? {} : { now: s.now },
|
|
159
|
+
...s.writes === void 0 ? {} : { writes: s.writes },
|
|
160
|
+
...s.antiCheat === void 0 ? {} : { antiCheat: s.antiCheat },
|
|
161
|
+
sessionMoved: async (e, t) => {
|
|
162
|
+
for (let n of R) await n(e, t);
|
|
163
|
+
}
|
|
164
|
+
}), typeof t?.scheduleCoordinated == "function") {
|
|
165
|
+
let e = F;
|
|
166
|
+
I = t.scheduleCoordinated("engine-servers.sweep", z, () => O.runPromise(e.sweep().pipe(O.asVoid)));
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
onDeactivate: () => O.promise(async () => {
|
|
170
|
+
await I?.stop(), I = void 0, F = void 0;
|
|
171
|
+
}),
|
|
172
|
+
onExport: (e, { tenantId: t }) => t === null ? O.succeed({
|
|
173
|
+
engineServerTickets: [],
|
|
174
|
+
engineServerSessionEvents: [],
|
|
175
|
+
engineServerReports: [],
|
|
176
|
+
engineServerAntiCheat: null
|
|
177
|
+
}) : B((n) => n.exportSubject({
|
|
178
|
+
subjectId: e,
|
|
179
|
+
tenantId: t
|
|
180
|
+
})),
|
|
181
|
+
onErase: (e, { tenantId: t }) => t === null ? O.void : B((n) => n.eraseSubject({
|
|
182
|
+
subjectId: e,
|
|
183
|
+
tenantId: t
|
|
184
|
+
}))
|
|
185
|
+
}),
|
|
186
|
+
engineServers: V
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
export { M as engineServersPlugin, A as hotStoreRefusal };
|