@roster-lock/match-agent 0.2.0 → 0.4.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/client/dist/assets/index-D2395vmC.css +1 -0
- package/client/dist/assets/index-DcKsa72V.js +125 -0
- package/client/dist/index.html +2 -2
- package/client/e2e/lib/env.ts +50 -0
- package/client/e2e/lib/fileDialog.ts +31 -0
- package/client/e2e/lib/mockGamepad.ts +71 -0
- package/client/e2e/lib/onscreenKeyboard.ts +32 -0
- package/client/e2e/playwright.config.ts +48 -0
- package/client/e2e/tests/gamepad-only.spec.ts +274 -0
- package/client/e2e/tests/keyboard-only.spec.ts +67 -0
- package/client/e2e/tsconfig.json +15 -0
- package/client/node_modules/.bin/playwright +17 -0
- package/client/node_modules/.bin/roster-lock-plugin-manager +17 -0
- package/client/node_modules/.vite/deps/@rjsf_core.js +95 -95
- package/client/node_modules/.vite/deps/@rjsf_validator-ajv8.js +4 -3
- package/client/node_modules/.vite/deps/@roster-lock_ts-client.js +25 -25
- package/client/node_modules/.vite/deps/@roster-lock_types.js +2 -1
- package/client/node_modules/.vite/deps/@roster-lock_utils.js +2 -1
- package/client/node_modules/.vite/deps/_metadata.json +27 -27
- package/client/node_modules/.vite/deps/{chunk-NE7PXY4V.js → chunk-3HBL6DQ6.js} +99 -98
- package/client/node_modules/.vite/deps/{chunk-NE7PXY4V.js.map → chunk-3HBL6DQ6.js.map} +3 -3
- package/client/node_modules/.vite/deps/{chunk-4D2L7OBZ.js → chunk-3IRPLLFB.js} +498 -501
- package/client/node_modules/.vite/deps/{chunk-4D2L7OBZ.js.map → chunk-3IRPLLFB.js.map} +1 -1
- package/client/node_modules/.vite/deps/{chunk-I55GDNGV.js → chunk-7DRNB6P7.js} +5 -5
- package/client/node_modules/.vite/deps/{chunk-77TXW5ZT.js → chunk-FFVS6IUX.js} +6 -6
- package/client/node_modules/.vite/deps/{chunk-5KLROPUR.js → chunk-G44QLPFQ.js} +6 -6
- package/client/node_modules/.vite/deps/{chunk-IIDO6PKU.js → chunk-QTQN6EZX.js} +98 -98
- package/client/node_modules/.vite/deps/chunk-QTQN6EZX.js.map +7 -0
- package/client/node_modules/.vite/deps/chunk-WMTNK64S.js +1 -0
- package/client/node_modules/.vite/deps/react-dom.js +3 -2
- package/client/node_modules/.vite/deps/react-dom_client.js +12 -12
- package/client/node_modules/.vite/deps/react-dom_client.js.map +1 -1
- package/client/node_modules/.vite/deps/react-router-dom.js +42 -9
- package/client/node_modules/.vite/deps/react.js +2 -1
- package/client/node_modules/.vite/deps/react_jsx-dev-runtime.js +5 -5
- package/client/node_modules/.vite/deps/react_jsx-runtime.js +3 -2
- package/client/package.json +4 -1
- package/client/src/App.tsx +23 -14
- package/client/src/NavBar.tsx +15 -5
- package/client/src/api/matchAgent.ts +208 -5
- package/client/src/bridge/hostBridge.ts +39 -10
- package/client/src/components/FullScreenMenu.tsx +32 -0
- package/client/src/components/GameLauncherSettingsForm.tsx +80 -5
- package/client/src/components/InputHints.tsx +37 -0
- package/client/src/components/InstallGameLauncherLightbox.tsx +27 -14
- package/client/src/components/OnScreenFileDialog.tsx +83 -0
- package/client/src/components/OnScreenKeyboard.tsx +75 -0
- package/client/src/components/Selection/PieceCard.tsx +29 -4
- package/client/src/components/Selection/PiecePreviewPanel.tsx +48 -0
- package/client/src/components/Selection/PieceTypeSection.tsx +124 -46
- package/client/src/components/Selection/PlayerSelectionPanel.tsx +1 -5
- package/client/src/components/Selection/index.tsx +72 -47
- package/client/src/context/GlobalNavContext.tsx +340 -0
- package/client/src/context/SelectionSourceContext.tsx +26 -0
- package/client/src/hooks/useCursorInput.ts +66 -24
- package/client/src/hooks/useDownloadedPieceVersions.ts +39 -0
- package/client/src/hooks/useGridColumns.ts +29 -0
- package/client/src/hooks/useInView.ts +32 -0
- package/client/src/hooks/usePiecePreview.ts +124 -0
- package/client/src/pages/Controls/index.tsx +126 -0
- package/client/src/pages/Game/index.tsx +11 -15
- package/client/src/pages/MatchMaking/index.tsx +14 -7
- package/client/src/pages/PreviewRoster/index.tsx +118 -0
- package/client/src/styles/global.css +355 -6
- package/client/src/utils/inputLabels.ts +25 -0
- package/client/test-results/.last-run.json +4 -0
- package/client/tsconfig.tsbuildinfo +1 -1
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/inputBindings.js +40 -0
- package/dist/config/inputBindings.js.map +1 -0
- package/dist/config/manage.js +1 -0
- package/dist/config/manage.js.map +1 -1
- package/dist/handle-room/version-1/game-launcher/binaries.js +36 -0
- package/dist/handle-room/version-1/game-launcher/binaries.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/listing.js +24 -0
- package/dist/handle-room/version-1/game-launcher/listing.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/preview.js +38 -0
- package/dist/handle-room/version-1/game-launcher/preview.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/process.js +52 -0
- package/dist/handle-room/version-1/game-launcher/process.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/router.js +32 -0
- package/dist/handle-room/version-1/game-launcher/router.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/settings.js +49 -0
- package/dist/handle-room/version-1/game-launcher/settings.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/shared.js +28 -0
- package/dist/handle-room/version-1/game-launcher/shared.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/start.js +76 -0
- package/dist/handle-room/version-1/game-launcher/start.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/version.js +63 -0
- package/dist/handle-room/version-1/game-launcher/version.js.map +1 -0
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js +22 -9
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js.map +1 -1
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js +50 -1
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js.map +1 -1
- package/dist/handle-room/version-1/index.js +15 -15
- package/dist/handle-room/version-1/index.js.map +1 -1
- package/dist/handle-room/version-1/input-bindings.js +22 -0
- package/dist/handle-room/version-1/input-bindings.js.map +1 -0
- package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js +2 -1
- package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js.map +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/http-handler.js +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/http-handler.js.map +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/steps.js +2 -1
- package/dist/handle-room/version-1/room-handler-bridge/steps.js.map +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js +2 -2
- package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js.map +1 -1
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/dist/util-routers/file-system/env.js +3 -0
- package/dist/util-routers/file-system/env.js.map +1 -0
- package/dist/util-routers/file-system/index.js +31 -0
- package/dist/util-routers/file-system/index.js.map +1 -0
- package/dist/util-routers/file-system/list.js +50 -0
- package/dist/util-routers/file-system/list.js.map +1 -0
- package/dist/util-routers/file-system/resolve-within-root.js +18 -0
- package/dist/util-routers/file-system/resolve-within-root.js.map +1 -0
- package/dist/util-routers/file-system/roster-lock.js +56 -0
- package/dist/util-routers/file-system/roster-lock.js.map +1 -0
- package/dist/utils/pick-file.js +82 -0
- package/dist/utils/pick-file.js.map +1 -0
- package/dist/utils/pick-folder.js +84 -0
- package/dist/utils/pick-folder.js.map +1 -0
- package/package.json +10 -7
- package/src/config/index.ts +8 -3
- package/src/config/inputBindings.ts +56 -0
- package/src/config/manage.ts +7 -0
- package/src/handle-room/version-1/game-launcher/binaries.ts +52 -0
- package/src/handle-room/version-1/game-launcher/listing.ts +36 -0
- package/src/handle-room/version-1/game-launcher/preview.ts +54 -0
- package/src/handle-room/version-1/game-launcher/process.ts +75 -0
- package/src/handle-room/version-1/game-launcher/router.ts +42 -0
- package/src/handle-room/version-1/game-launcher/settings.ts +58 -0
- package/src/handle-room/version-1/game-launcher/shared.ts +34 -0
- package/src/handle-room/version-1/game-launcher/start.ts +113 -0
- package/src/handle-room/version-1/game-launcher/version.ts +85 -0
- package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.ts +39 -14
- package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.ts +83 -1
- package/src/handle-room/version-1/globals/FolderDB/types.ts +24 -0
- package/src/handle-room/version-1/globals/types.ts +24 -2
- package/src/handle-room/version-1/index.ts +27 -25
- package/src/handle-room/version-1/input-bindings.ts +19 -0
- package/src/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.ts +4 -1
- package/src/handle-room/version-1/room-handler-bridge/http-handler.ts +4 -1
- package/src/handle-room/version-1/room-handler-bridge/steps.ts +8 -0
- package/src/handle-room/version-1/room-handler-bridge/ws-handler.ts +2 -2
- package/src/index.ts +42 -10
- package/src/util-routers/file-system/env.ts +7 -0
- package/src/util-routers/file-system/index.ts +23 -0
- package/src/util-routers/file-system/list.ts +62 -0
- package/src/util-routers/file-system/resolve-within-root.ts +25 -0
- package/src/util-routers/file-system/roster-lock.ts +74 -0
- package/src/utils/pick-file.ts +81 -0
- package/src/utils/pick-folder.ts +92 -0
- package/tests/integration/filesystem.test.ts +117 -0
- package/tests/integration/game-launcher-binaries.test.ts +263 -0
- package/tests/integration/game-launcher-game-complete.test.ts +111 -0
- package/tests/integration/game-launcher-preview.test.ts +107 -0
- package/tests/integration/game-launcher-settings.test.ts +123 -8
- package/tests/integration/game-processes-ws.test.ts +122 -0
- package/tests/integration/helpers/fakeFolderDB.ts +16 -0
- package/tests/integration/helpers/fakePluginRuntime.ts +10 -1
- package/tests/integration/helpers/relayHarness.ts +24 -0
- package/tests/integration/helpers/server.ts +23 -3
- package/tests/integration/input-bindings.test.ts +94 -0
- package/tests/integration/piece-ensure-ws.test.ts +1 -1
- package/tests/integration/piece-files.test.ts +1 -1
- package/tests/integration/relay-protocol.test.ts +100 -0
- package/tests/integration/roster-lock.test.ts +86 -0
- package/tests/integration/sync-dl.test.ts +1 -1
- package/vitest.config.ts +7 -1
- package/client/dist/assets/index-DeYshswm.js +0 -125
- package/client/dist/assets/index-gxAuIfGQ.css +0 -1
- package/client/node_modules/.vite/deps/chunk-IIDO6PKU.js.map +0 -7
- package/client/node_modules/.vite/deps_temp_ab51ebe9/package.json +0 -3
- package/dist/handle-room/version-1/game-launcher.js +0 -181
- package/dist/handle-room/version-1/game-launcher.js.map +0 -1
- package/src/handle-room/version-1/game-launcher.ts +0 -263
- /package/client/node_modules/.vite/deps/{chunk-I55GDNGV.js.map → chunk-7DRNB6P7.js.map} +0 -0
- /package/client/node_modules/.vite/deps/{chunk-77TXW5ZT.js.map → chunk-FFVS6IUX.js.map} +0 -0
- /package/client/node_modules/.vite/deps/{chunk-5KLROPUR.js.map → chunk-G44QLPFQ.js.map} +0 -0
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { ConnectionSetup, StartGameArgs, PlatformTarget } from "@roster-lock/types";
|
|
3
|
-
import { GameLauncherLocalSettings } from "@roster-lock/plugin-runtime";
|
|
4
|
-
import { jsonBody, HTTPRequestHandler, HTTPError } from "../../utils/http-router";
|
|
5
|
-
import { V1Env } from "./globals/types";
|
|
6
|
-
import { castLockConfig } from "./piece-sort";
|
|
7
|
-
import z, { ZodType } from "zod";
|
|
8
|
-
|
|
9
|
-
// One listing endpoint, mirroring /piece/sort-list/available - every installed
|
|
10
|
-
// game-launcher plugin's full AvailableGameLauncher record in one response, rather
|
|
11
|
-
// than splitting connection-mode support and gameConfigSchema into separate
|
|
12
|
-
// per-plugin routes. Both are small, static JSON already computed by
|
|
13
|
-
// listAvailable() from the plugin's own module fields, so there's no
|
|
14
|
-
// fetch-cost reason to make a client ask for them separately, and nothing
|
|
15
|
-
// else in this router splits a plugin's metadata that way either.
|
|
16
|
-
export const listAvailableGameLaunchers: HTTPRequestHandler = async function(
|
|
17
|
-
this: V1Env, { res }
|
|
18
|
-
){
|
|
19
|
-
const available = await this.pluginRuntime.gameLauncher.listAvailable();
|
|
20
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
21
|
-
res.end(JSON.stringify(available));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function requirePluginName(routeInfo: { params: Record<string, string | undefined> }): string {
|
|
25
|
-
const pluginName = routeInfo.params.pluginName;
|
|
26
|
-
if(!pluginName) throw new HTTPError(400, "Missing pluginName");
|
|
27
|
-
return pluginName;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function requireBinaryLocation(env: V1Env, pluginName: string): Promise<string> {
|
|
31
|
-
const settings = await env.pluginRuntime.gameLauncher.getLocalSettings(pluginName);
|
|
32
|
-
if(!settings.binaryLocation){
|
|
33
|
-
throw new HTTPError(400, `Game launcher "${pluginName}" has no binaryLocation configured`);
|
|
34
|
-
}
|
|
35
|
-
return settings.binaryLocation;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// See docs/v2/binary-location.md - every GameLauncherPlugin function that
|
|
39
|
-
// resolves a concrete binary out of a (possibly multi-platform) binaryLocation
|
|
40
|
-
// bundle takes a required target, with no implicit "current host" default at
|
|
41
|
-
// that layer. match-agent is what decides the target value: it defaults to
|
|
42
|
-
// its own process.platform/process.arch (the ordinary case - a client asking
|
|
43
|
-
// match-agent to run/inspect the game it's about to run on this same host),
|
|
44
|
-
// but a caller can override either via query params for the deliberate
|
|
45
|
-
// exception (e.g. forcing a win32-x64 build under Wine on a Linux host).
|
|
46
|
-
function resolveTarget(routeInfo: { url: URL }): PlatformTarget {
|
|
47
|
-
const platform = routeInfo.url.searchParams.get("platform");
|
|
48
|
-
const arch = routeInfo.url.searchParams.get("arch");
|
|
49
|
-
return {
|
|
50
|
-
platform: (platform || process.platform) as PlatformTarget["platform"],
|
|
51
|
-
arch: (arch || process.arch) as PlatformTarget["arch"],
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const getGameLauncherSettings: HTTPRequestHandler = async function(
|
|
56
|
-
this: V1Env, { res }, routeInfo
|
|
57
|
-
){
|
|
58
|
-
const pluginName = requirePluginName(routeInfo);
|
|
59
|
-
const settings = await this.pluginRuntime.gameLauncher.getLocalSettings(pluginName);
|
|
60
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
61
|
-
res.end(JSON.stringify(settings));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const localSettingsBodySchema: ZodType<GameLauncherLocalSettings> = z.object({
|
|
65
|
-
binaryLocation: z.string().optional(),
|
|
66
|
-
localConfig: z.unknown().optional(),
|
|
67
|
-
}).strict();
|
|
68
|
-
|
|
69
|
-
export const setGameLauncherSettings: HTTPRequestHandler = async function(
|
|
70
|
-
this: V1Env, { req, res }, routeInfo
|
|
71
|
-
){
|
|
72
|
-
const pluginName = requirePluginName(routeInfo);
|
|
73
|
-
const body = await jsonBody(req);
|
|
74
|
-
const parseResult = localSettingsBodySchema.safeParse(body);
|
|
75
|
-
if(!parseResult.success) throw new HTTPError(400, "Bad Form", parseResult.error);
|
|
76
|
-
|
|
77
|
-
await this.pluginRuntime.gameLauncher.setLocalSettings(pluginName, parseResult.data);
|
|
78
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
79
|
-
res.end(JSON.stringify({ ok: true }));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Installs the plugin *package* itself (registry/manifest-based, via
|
|
83
|
-
// PluginManager - distinct from updateBinary below, which fetches a newer
|
|
84
|
-
// engine binary for a plugin that's already installed).
|
|
85
|
-
export const installGameLauncherPlugin: HTTPRequestHandler = async function(
|
|
86
|
-
this: V1Env, { res }, routeInfo
|
|
87
|
-
){
|
|
88
|
-
const pluginName = requirePluginName(routeInfo);
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
await this.pluginRuntime.installPlugin(pluginName);
|
|
92
|
-
} catch(e){
|
|
93
|
-
throw new HTTPError(400, (e as Error).message);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
97
|
-
res.end(JSON.stringify({ ok: true }));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export const getGameLauncherVersion: HTTPRequestHandler = async function(
|
|
101
|
-
this: V1Env, { res }, routeInfo
|
|
102
|
-
){
|
|
103
|
-
const pluginName = requirePluginName(routeInfo);
|
|
104
|
-
const binaryLocation = await requireBinaryLocation(this, pluginName);
|
|
105
|
-
const target = resolveTarget(routeInfo);
|
|
106
|
-
|
|
107
|
-
const [local, supported] = await Promise.all([
|
|
108
|
-
this.pluginRuntime.gameLauncher.getLocalVersion(pluginName, binaryLocation, target),
|
|
109
|
-
this.pluginRuntime.gameLauncher.getSupportedVersion(pluginName, binaryLocation),
|
|
110
|
-
]);
|
|
111
|
-
|
|
112
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
113
|
-
res.end(JSON.stringify({ local, supported }));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export const validateGameLauncherBinaryLocation: HTTPRequestHandler = async function(
|
|
117
|
-
this: V1Env, { res }, routeInfo
|
|
118
|
-
){
|
|
119
|
-
const pluginName = requirePluginName(routeInfo);
|
|
120
|
-
const binaryLocation = await requireBinaryLocation(this, pluginName);
|
|
121
|
-
const target = resolveTarget(routeInfo);
|
|
122
|
-
|
|
123
|
-
const result = await this.pluginRuntime.gameLauncher.validateBinaryLocation(pluginName, binaryLocation, target);
|
|
124
|
-
|
|
125
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
126
|
-
res.end(JSON.stringify(result));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export const updateGameLauncherBinary: HTTPRequestHandler = async function(
|
|
130
|
-
this: V1Env, { res }, routeInfo
|
|
131
|
-
){
|
|
132
|
-
const pluginName = requirePluginName(routeInfo);
|
|
133
|
-
const binaryLocation = await requireBinaryLocation(this, pluginName);
|
|
134
|
-
const target = resolveTarget(routeInfo);
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
await this.pluginRuntime.gameLauncher.updateBinary(pluginName, binaryLocation, target);
|
|
138
|
-
} catch(e){
|
|
139
|
-
// updateBinary throws a plain Error when a plugin doesn't declare one at
|
|
140
|
-
// all (see GameLauncher.updateBinary) - that's a client-facing 400 ("this
|
|
141
|
-
// runner can't be updated in-app"), not a server fault.
|
|
142
|
-
throw new HTTPError(400, (e as Error).message);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
146
|
-
res.end(JSON.stringify({ ok: true }));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const coordinatorAddressSchema = z.object({ host: z.string(), port: z.number() }).strict();
|
|
150
|
-
|
|
151
|
-
// This is what a caller sends match-agent, not what the plugin ends up
|
|
152
|
-
// with - direct-tcp still carries a coordinator address here.
|
|
153
|
-
// GameLauncher.startGame (plugin-runtime) resolves it into a ConnectionConfig
|
|
154
|
-
// before ever invoking a plugin, so a plugin never has to know a coordinator
|
|
155
|
-
// exists at all.
|
|
156
|
-
const connectionSetupSchema: ZodType<ConnectionSetup> = z.union([
|
|
157
|
-
z.object({
|
|
158
|
-
type: z.literal("direct-tcp"), party: z.literal("host"), port: z.number(), coordinator: coordinatorAddressSchema,
|
|
159
|
-
}).strict(),
|
|
160
|
-
z.object({
|
|
161
|
-
type: z.literal("direct-tcp"), party: z.literal("client"), port: z.number(), coordinator: coordinatorAddressSchema,
|
|
162
|
-
}).strict(),
|
|
163
|
-
z.object({ type: z.literal("room"), version: z.string(), url: z.string() }).strict(),
|
|
164
|
-
z.object({ type: z.literal("internal") }).strict(),
|
|
165
|
-
]);
|
|
166
|
-
|
|
167
|
-
// Everything StartGameArgs needs except currentMachine.privateKeyFile (a
|
|
168
|
-
// match-agent-managed temp file, not something a caller ever supplies) and
|
|
169
|
-
// matchAgent (match-agent knows its own port/authCode - trusting a caller's
|
|
170
|
-
// claim about either would let it point a plugin at a different match-agent
|
|
171
|
-
// entirely). currentMachine's raw privateKey *is* client-supplied here: only
|
|
172
|
-
// the browser holds it, and GameLauncher.startGame is what turns it into the
|
|
173
|
-
// restrictive-permission temp file plugins actually receive.
|
|
174
|
-
type StartGameBody = {
|
|
175
|
-
connectionConfig: ConnectionSetup,
|
|
176
|
-
currentMachine: { machineId: string, publicKey: string, privateKey: string },
|
|
177
|
-
allMachines: unknown,
|
|
178
|
-
selectionResult: unknown,
|
|
179
|
-
rosterConfig: unknown,
|
|
180
|
-
gameConfig: unknown,
|
|
181
|
-
relayRoomId: string,
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const startGameBodySchema: ZodType<StartGameBody> = z.object({
|
|
185
|
-
connectionConfig: connectionSetupSchema,
|
|
186
|
-
currentMachine: z.object({
|
|
187
|
-
machineId: z.string(), publicKey: z.string(), privateKey: z.string(),
|
|
188
|
-
}).strict(),
|
|
189
|
-
allMachines: z.unknown(),
|
|
190
|
-
selectionResult: z.unknown(),
|
|
191
|
-
rosterConfig: z.unknown(),
|
|
192
|
-
gameConfig: z.unknown(),
|
|
193
|
-
relayRoomId: z.string(),
|
|
194
|
-
}).strict();
|
|
195
|
-
|
|
196
|
-
export const startGameLauncher: HTTPRequestHandler = async function(
|
|
197
|
-
this: V1Env, { req, res }, routeInfo
|
|
198
|
-
){
|
|
199
|
-
const pluginName = requirePluginName(routeInfo);
|
|
200
|
-
const binaryLocation = await requireBinaryLocation(this, pluginName);
|
|
201
|
-
const target = resolveTarget(routeInfo);
|
|
202
|
-
|
|
203
|
-
const body = await jsonBody(req);
|
|
204
|
-
const parseResult = startGameBodySchema.safeParse(body);
|
|
205
|
-
if(!parseResult.success) throw new HTTPError(400, "Bad Form", parseResult.error);
|
|
206
|
-
const { connectionConfig, currentMachine, allMachines, selectionResult, gameConfig, relayRoomId } = parseResult.data;
|
|
207
|
-
const rosterConfig = castLockConfig(parseResult.data.rosterConfig);
|
|
208
|
-
|
|
209
|
-
const handle = await this.pluginRuntime.gameLauncher.startGame(pluginName, binaryLocation, target, connectionConfig, {
|
|
210
|
-
currentMachine,
|
|
211
|
-
allMachines: allMachines as StartGameArgs<unknown>["allMachines"],
|
|
212
|
-
selectionResult: selectionResult as StartGameArgs<unknown>["selectionResult"],
|
|
213
|
-
rosterConfig,
|
|
214
|
-
gameConfig,
|
|
215
|
-
relayRoomId,
|
|
216
|
-
matchAgent: { port: this.matchAgent.getPort(), authCode: this.matchAgent.authCode },
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
const handleId = randomUUID();
|
|
220
|
-
this.processHandles.set(handleId, { pluginName, handle });
|
|
221
|
-
|
|
222
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
223
|
-
res.end(JSON.stringify({ handleId }));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export const getGameProcessStatus: HTTPRequestHandler = async function(
|
|
227
|
-
this: V1Env, { res }, routeInfo
|
|
228
|
-
){
|
|
229
|
-
const handleId = routeInfo.params.handleId;
|
|
230
|
-
const entry = handleId ? this.processHandles.get(handleId) : undefined;
|
|
231
|
-
if(!entry) throw new HTTPError(404, "Unknown process handle");
|
|
232
|
-
|
|
233
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
234
|
-
res.end(JSON.stringify({ exited: entry.handle.exited }));
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Every process this match-agent has started, across every game-launcher
|
|
238
|
-
// plugin - backs pages/Game in match-agent-client, which shows one row per
|
|
239
|
-
// entry regardless of which plugin launched it.
|
|
240
|
-
export const listGameProcesses: HTTPRequestHandler = async function(
|
|
241
|
-
this: V1Env, { res }
|
|
242
|
-
){
|
|
243
|
-
const processes = Array.from(this.processHandles.entries()).map(([handleId, entry]) => ({
|
|
244
|
-
handleId, pluginName: entry.pluginName, exited: entry.handle.exited,
|
|
245
|
-
}));
|
|
246
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
247
|
-
res.end(JSON.stringify(processes));
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Best-effort, same as GameProcessHandle.stop() itself - see that type's own
|
|
251
|
-
// docs on why a plugin may not always be able to actually stop the game.
|
|
252
|
-
export const stopGameProcess: HTTPRequestHandler = async function(
|
|
253
|
-
this: V1Env, { res }, routeInfo
|
|
254
|
-
){
|
|
255
|
-
const handleId = routeInfo.params.handleId;
|
|
256
|
-
const entry = handleId ? this.processHandles.get(handleId) : undefined;
|
|
257
|
-
if(!entry) throw new HTTPError(404, "Unknown process handle");
|
|
258
|
-
|
|
259
|
-
await entry.handle.stop();
|
|
260
|
-
|
|
261
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
262
|
-
res.end(JSON.stringify({ ok: true }));
|
|
263
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|