@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.
Files changed (181) hide show
  1. package/client/dist/assets/index-D2395vmC.css +1 -0
  2. package/client/dist/assets/index-DcKsa72V.js +125 -0
  3. package/client/dist/index.html +2 -2
  4. package/client/e2e/lib/env.ts +50 -0
  5. package/client/e2e/lib/fileDialog.ts +31 -0
  6. package/client/e2e/lib/mockGamepad.ts +71 -0
  7. package/client/e2e/lib/onscreenKeyboard.ts +32 -0
  8. package/client/e2e/playwright.config.ts +48 -0
  9. package/client/e2e/tests/gamepad-only.spec.ts +274 -0
  10. package/client/e2e/tests/keyboard-only.spec.ts +67 -0
  11. package/client/e2e/tsconfig.json +15 -0
  12. package/client/node_modules/.bin/playwright +17 -0
  13. package/client/node_modules/.bin/roster-lock-plugin-manager +17 -0
  14. package/client/node_modules/.vite/deps/@rjsf_core.js +95 -95
  15. package/client/node_modules/.vite/deps/@rjsf_validator-ajv8.js +4 -3
  16. package/client/node_modules/.vite/deps/@roster-lock_ts-client.js +25 -25
  17. package/client/node_modules/.vite/deps/@roster-lock_types.js +2 -1
  18. package/client/node_modules/.vite/deps/@roster-lock_utils.js +2 -1
  19. package/client/node_modules/.vite/deps/_metadata.json +27 -27
  20. package/client/node_modules/.vite/deps/{chunk-NE7PXY4V.js → chunk-3HBL6DQ6.js} +99 -98
  21. package/client/node_modules/.vite/deps/{chunk-NE7PXY4V.js.map → chunk-3HBL6DQ6.js.map} +3 -3
  22. package/client/node_modules/.vite/deps/{chunk-4D2L7OBZ.js → chunk-3IRPLLFB.js} +498 -501
  23. package/client/node_modules/.vite/deps/{chunk-4D2L7OBZ.js.map → chunk-3IRPLLFB.js.map} +1 -1
  24. package/client/node_modules/.vite/deps/{chunk-I55GDNGV.js → chunk-7DRNB6P7.js} +5 -5
  25. package/client/node_modules/.vite/deps/{chunk-77TXW5ZT.js → chunk-FFVS6IUX.js} +6 -6
  26. package/client/node_modules/.vite/deps/{chunk-5KLROPUR.js → chunk-G44QLPFQ.js} +6 -6
  27. package/client/node_modules/.vite/deps/{chunk-IIDO6PKU.js → chunk-QTQN6EZX.js} +98 -98
  28. package/client/node_modules/.vite/deps/chunk-QTQN6EZX.js.map +7 -0
  29. package/client/node_modules/.vite/deps/chunk-WMTNK64S.js +1 -0
  30. package/client/node_modules/.vite/deps/react-dom.js +3 -2
  31. package/client/node_modules/.vite/deps/react-dom_client.js +12 -12
  32. package/client/node_modules/.vite/deps/react-dom_client.js.map +1 -1
  33. package/client/node_modules/.vite/deps/react-router-dom.js +42 -9
  34. package/client/node_modules/.vite/deps/react.js +2 -1
  35. package/client/node_modules/.vite/deps/react_jsx-dev-runtime.js +5 -5
  36. package/client/node_modules/.vite/deps/react_jsx-runtime.js +3 -2
  37. package/client/package.json +4 -1
  38. package/client/src/App.tsx +23 -14
  39. package/client/src/NavBar.tsx +15 -5
  40. package/client/src/api/matchAgent.ts +208 -5
  41. package/client/src/bridge/hostBridge.ts +39 -10
  42. package/client/src/components/FullScreenMenu.tsx +32 -0
  43. package/client/src/components/GameLauncherSettingsForm.tsx +80 -5
  44. package/client/src/components/InputHints.tsx +37 -0
  45. package/client/src/components/InstallGameLauncherLightbox.tsx +27 -14
  46. package/client/src/components/OnScreenFileDialog.tsx +83 -0
  47. package/client/src/components/OnScreenKeyboard.tsx +75 -0
  48. package/client/src/components/Selection/PieceCard.tsx +29 -4
  49. package/client/src/components/Selection/PiecePreviewPanel.tsx +48 -0
  50. package/client/src/components/Selection/PieceTypeSection.tsx +124 -46
  51. package/client/src/components/Selection/PlayerSelectionPanel.tsx +1 -5
  52. package/client/src/components/Selection/index.tsx +72 -47
  53. package/client/src/context/GlobalNavContext.tsx +340 -0
  54. package/client/src/context/SelectionSourceContext.tsx +26 -0
  55. package/client/src/hooks/useCursorInput.ts +66 -24
  56. package/client/src/hooks/useDownloadedPieceVersions.ts +39 -0
  57. package/client/src/hooks/useGridColumns.ts +29 -0
  58. package/client/src/hooks/useInView.ts +32 -0
  59. package/client/src/hooks/usePiecePreview.ts +124 -0
  60. package/client/src/pages/Controls/index.tsx +126 -0
  61. package/client/src/pages/Game/index.tsx +11 -15
  62. package/client/src/pages/MatchMaking/index.tsx +14 -7
  63. package/client/src/pages/PreviewRoster/index.tsx +118 -0
  64. package/client/src/styles/global.css +355 -6
  65. package/client/src/utils/inputLabels.ts +25 -0
  66. package/client/test-results/.last-run.json +4 -0
  67. package/client/tsconfig.tsbuildinfo +1 -1
  68. package/dist/config/index.js +2 -0
  69. package/dist/config/index.js.map +1 -1
  70. package/dist/config/inputBindings.js +40 -0
  71. package/dist/config/inputBindings.js.map +1 -0
  72. package/dist/config/manage.js +1 -0
  73. package/dist/config/manage.js.map +1 -1
  74. package/dist/handle-room/version-1/game-launcher/binaries.js +36 -0
  75. package/dist/handle-room/version-1/game-launcher/binaries.js.map +1 -0
  76. package/dist/handle-room/version-1/game-launcher/listing.js +24 -0
  77. package/dist/handle-room/version-1/game-launcher/listing.js.map +1 -0
  78. package/dist/handle-room/version-1/game-launcher/preview.js +38 -0
  79. package/dist/handle-room/version-1/game-launcher/preview.js.map +1 -0
  80. package/dist/handle-room/version-1/game-launcher/process.js +52 -0
  81. package/dist/handle-room/version-1/game-launcher/process.js.map +1 -0
  82. package/dist/handle-room/version-1/game-launcher/router.js +32 -0
  83. package/dist/handle-room/version-1/game-launcher/router.js.map +1 -0
  84. package/dist/handle-room/version-1/game-launcher/settings.js +49 -0
  85. package/dist/handle-room/version-1/game-launcher/settings.js.map +1 -0
  86. package/dist/handle-room/version-1/game-launcher/shared.js +28 -0
  87. package/dist/handle-room/version-1/game-launcher/shared.js.map +1 -0
  88. package/dist/handle-room/version-1/game-launcher/start.js +76 -0
  89. package/dist/handle-room/version-1/game-launcher/start.js.map +1 -0
  90. package/dist/handle-room/version-1/game-launcher/version.js +63 -0
  91. package/dist/handle-room/version-1/game-launcher/version.js.map +1 -0
  92. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js +22 -9
  93. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js.map +1 -1
  94. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js +50 -1
  95. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js.map +1 -1
  96. package/dist/handle-room/version-1/index.js +15 -15
  97. package/dist/handle-room/version-1/index.js.map +1 -1
  98. package/dist/handle-room/version-1/input-bindings.js +22 -0
  99. package/dist/handle-room/version-1/input-bindings.js.map +1 -0
  100. package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js +2 -1
  101. package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js.map +1 -1
  102. package/dist/handle-room/version-1/room-handler-bridge/http-handler.js +1 -1
  103. package/dist/handle-room/version-1/room-handler-bridge/http-handler.js.map +1 -1
  104. package/dist/handle-room/version-1/room-handler-bridge/steps.js +2 -1
  105. package/dist/handle-room/version-1/room-handler-bridge/steps.js.map +1 -1
  106. package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js +2 -2
  107. package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js.map +1 -1
  108. package/dist/index.js +18 -4
  109. package/dist/index.js.map +1 -1
  110. package/dist/util-routers/file-system/env.js +3 -0
  111. package/dist/util-routers/file-system/env.js.map +1 -0
  112. package/dist/util-routers/file-system/index.js +31 -0
  113. package/dist/util-routers/file-system/index.js.map +1 -0
  114. package/dist/util-routers/file-system/list.js +50 -0
  115. package/dist/util-routers/file-system/list.js.map +1 -0
  116. package/dist/util-routers/file-system/resolve-within-root.js +18 -0
  117. package/dist/util-routers/file-system/resolve-within-root.js.map +1 -0
  118. package/dist/util-routers/file-system/roster-lock.js +56 -0
  119. package/dist/util-routers/file-system/roster-lock.js.map +1 -0
  120. package/dist/utils/pick-file.js +82 -0
  121. package/dist/utils/pick-file.js.map +1 -0
  122. package/dist/utils/pick-folder.js +84 -0
  123. package/dist/utils/pick-folder.js.map +1 -0
  124. package/package.json +10 -7
  125. package/src/config/index.ts +8 -3
  126. package/src/config/inputBindings.ts +56 -0
  127. package/src/config/manage.ts +7 -0
  128. package/src/handle-room/version-1/game-launcher/binaries.ts +52 -0
  129. package/src/handle-room/version-1/game-launcher/listing.ts +36 -0
  130. package/src/handle-room/version-1/game-launcher/preview.ts +54 -0
  131. package/src/handle-room/version-1/game-launcher/process.ts +75 -0
  132. package/src/handle-room/version-1/game-launcher/router.ts +42 -0
  133. package/src/handle-room/version-1/game-launcher/settings.ts +58 -0
  134. package/src/handle-room/version-1/game-launcher/shared.ts +34 -0
  135. package/src/handle-room/version-1/game-launcher/start.ts +113 -0
  136. package/src/handle-room/version-1/game-launcher/version.ts +85 -0
  137. package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.ts +39 -14
  138. package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.ts +83 -1
  139. package/src/handle-room/version-1/globals/FolderDB/types.ts +24 -0
  140. package/src/handle-room/version-1/globals/types.ts +24 -2
  141. package/src/handle-room/version-1/index.ts +27 -25
  142. package/src/handle-room/version-1/input-bindings.ts +19 -0
  143. package/src/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.ts +4 -1
  144. package/src/handle-room/version-1/room-handler-bridge/http-handler.ts +4 -1
  145. package/src/handle-room/version-1/room-handler-bridge/steps.ts +8 -0
  146. package/src/handle-room/version-1/room-handler-bridge/ws-handler.ts +2 -2
  147. package/src/index.ts +42 -10
  148. package/src/util-routers/file-system/env.ts +7 -0
  149. package/src/util-routers/file-system/index.ts +23 -0
  150. package/src/util-routers/file-system/list.ts +62 -0
  151. package/src/util-routers/file-system/resolve-within-root.ts +25 -0
  152. package/src/util-routers/file-system/roster-lock.ts +74 -0
  153. package/src/utils/pick-file.ts +81 -0
  154. package/src/utils/pick-folder.ts +92 -0
  155. package/tests/integration/filesystem.test.ts +117 -0
  156. package/tests/integration/game-launcher-binaries.test.ts +263 -0
  157. package/tests/integration/game-launcher-game-complete.test.ts +111 -0
  158. package/tests/integration/game-launcher-preview.test.ts +107 -0
  159. package/tests/integration/game-launcher-settings.test.ts +123 -8
  160. package/tests/integration/game-processes-ws.test.ts +122 -0
  161. package/tests/integration/helpers/fakeFolderDB.ts +16 -0
  162. package/tests/integration/helpers/fakePluginRuntime.ts +10 -1
  163. package/tests/integration/helpers/relayHarness.ts +24 -0
  164. package/tests/integration/helpers/server.ts +23 -3
  165. package/tests/integration/input-bindings.test.ts +94 -0
  166. package/tests/integration/piece-ensure-ws.test.ts +1 -1
  167. package/tests/integration/piece-files.test.ts +1 -1
  168. package/tests/integration/relay-protocol.test.ts +100 -0
  169. package/tests/integration/roster-lock.test.ts +86 -0
  170. package/tests/integration/sync-dl.test.ts +1 -1
  171. package/vitest.config.ts +7 -1
  172. package/client/dist/assets/index-DeYshswm.js +0 -125
  173. package/client/dist/assets/index-gxAuIfGQ.css +0 -1
  174. package/client/node_modules/.vite/deps/chunk-IIDO6PKU.js.map +0 -7
  175. package/client/node_modules/.vite/deps_temp_ab51ebe9/package.json +0 -3
  176. package/dist/handle-room/version-1/game-launcher.js +0 -181
  177. package/dist/handle-room/version-1/game-launcher.js.map +0 -1
  178. package/src/handle-room/version-1/game-launcher.ts +0 -263
  179. /package/client/node_modules/.vite/deps/{chunk-I55GDNGV.js.map → chunk-7DRNB6P7.js.map} +0 -0
  180. /package/client/node_modules/.vite/deps/{chunk-77TXW5ZT.js.map → chunk-FFVS6IUX.js.map} +0 -0
  181. /package/client/node_modules/.vite/deps/{chunk-5KLROPUR.js.map → chunk-G44QLPFQ.js.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roster-lock/match-agent",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "To be used in game to ensure all peices are ready",
5
5
  "keywords": [
6
6
  "roster-lock",
@@ -39,11 +39,14 @@
39
39
  "vitest": "^4.1.5",
40
40
  "@roster-lock/dl-archive-tar": "1.0.0",
41
41
  "@roster-lock/dl-compression-gzip": "1.0.0",
42
- "@roster-lock/dl-protocol-http": "1.0.0",
42
+ "@roster-lock/dl-protocol-http": "1.1.0",
43
43
  "@roster-lock/piece-selection-sort-most-used-locally": "1.0.0",
44
44
  "@roster-lock/piece-selection-sort-highest-winrate-locally": "1.0.0",
45
- "@roster-lock/game-launcher-ikemen-go": "1.0.0",
46
- "@roster-lock/match-agent-client": "0.1.0"
45
+ "@roster-lock/game-launcher-ikemen-go": "1.3.0",
46
+ "@roster-lock/game-launcher-headless": "1.0.0",
47
+ "@roster-lock/match-agent-client": "0.1.0",
48
+ "@roster-lock/relay-conformance": "0.0.0",
49
+ "@roster-lock/relay-server-hosted": "1.0.1"
47
50
  },
48
51
  "dependencies": {
49
52
  "ajv": "^8.17.1",
@@ -58,10 +61,10 @@
58
61
  "webtorrent": "^2.6.3",
59
62
  "ws": "^8.19.0",
60
63
  "zod": "^4.3.5",
61
- "@roster-lock/plugin-runtime": "^0.2.0",
62
- "@roster-lock/types": "1.1.0",
63
64
  "@roster-lock/shared": "0.2.0",
64
- "@roster-lock/utils": "1.0.0"
65
+ "@roster-lock/utils": "1.1.0",
66
+ "@roster-lock/plugin-runtime": "^0.4.0",
67
+ "@roster-lock/types": "1.3.0"
65
68
  },
66
69
  "scripts": {
67
70
  "test": "vitest run",
@@ -2,16 +2,21 @@
2
2
  export * from "./constants";
3
3
  export * from "./manage";
4
4
  export * from "./findFile";
5
+ export * from "./inputBindings";
5
6
 
6
7
  import { dirname, resolve as pathResolve } from "node:path";
7
8
  import { MatchAgentConfig } from "./manage";
8
9
 
9
- // Resolves a config's pieceFolder/pluginFolder (relative to the config file's
10
- // own directory, defaulting to "pieces"/"plugins") to absolute paths.
11
- export function resolveConfigFolders(configFilePath: string, config: Pick<MatchAgentConfig, "pieceFolder" | "pluginFolder">){
10
+ // Resolves a config's pieceFolder/pluginFolder/rosterLockFolder (relative
11
+ // to the config file's own directory, defaulting to "pieces"/"plugins"/
12
+ // "roster-locks") to absolute paths.
13
+ export function resolveConfigFolders(
14
+ configFilePath: string, config: Pick<MatchAgentConfig, "pieceFolder" | "pluginFolder" | "rosterLockFolder">
15
+ ){
12
16
  const configDir = dirname(configFilePath);
13
17
  return {
14
18
  pieceFolder: pathResolve(configDir, config.pieceFolder ?? "pieces"),
15
19
  pluginFolder: pathResolve(configDir, config.pluginFolder ?? "plugins"),
20
+ rosterLockFolder: pathResolve(configDir, config.rosterLockFolder ?? "roster-locks"),
16
21
  };
17
22
  }
@@ -0,0 +1,56 @@
1
+ import { join as pathJoin, dirname } from "node:path";
2
+ import { readFile, writeFile, mkdir } from "node:fs/promises";
3
+ import { z, ZodType } from "zod";
4
+
5
+ export type NavAction = "select" | "back" | "menu";
6
+ export type KeyboardBindings = Record<NavAction, string>;
7
+ export type GamepadBindings = Record<NavAction, number>;
8
+ export type InputBindings = { keyboard: KeyboardBindings, gamepad: GamepadBindings };
9
+
10
+ export const DEFAULT_INPUT_BINDINGS: InputBindings = {
11
+ keyboard: { select: "Enter", back: "Backspace", menu: " " },
12
+ gamepad: { select: 0, back: 1, menu: 9 },
13
+ };
14
+
15
+ function actionMap<T extends ZodType>(value: T) {
16
+ return z.object({ select: value, back: value, menu: value }).strict();
17
+ }
18
+
19
+ export const inputBindingsSchema: ZodType<InputBindings> = z.object({
20
+ keyboard: actionMap(z.string().min(1)),
21
+ gamepad: actionMap(z.number().int().min(0)),
22
+ }).strict();
23
+
24
+ // Stored as its own file rather than a field on MatchAgentConfig
25
+ // (match-agent.json, see ../config/manage.ts): rebindable keys/buttons are
26
+ // a match-agent-client UI concern, not part of the auth-code/folder
27
+ // settings that file's schema is scoped to. It's still a *sibling* of that
28
+ // file though - same directory - so it resolves through the exact same
29
+ // portable-root discovery (see findConfigFile): next to the match-agent
30
+ // executable when that's a mounted USB, the per-user home directory
31
+ // otherwise. This is what lets rebound controls follow a player's USB
32
+ // from one arcade/cafe machine to the next instead of living in whatever
33
+ // browser profile happened to be open on the host (see
34
+ // docs/economics/machine-environments/pieces-usb.md/cafe.md).
35
+ export function inputBindingsFilePath(configFilePath: string): string {
36
+ return pathJoin(dirname(configFilePath), "input-bindings.json");
37
+ }
38
+
39
+ export async function getInputBindings(configFilePath: string): Promise<InputBindings> {
40
+ try {
41
+ const contents = await readFile(inputBindingsFilePath(configFilePath), "utf8");
42
+ const parsed = inputBindingsSchema.safeParse(JSON.parse(contents));
43
+ if (parsed.success) return parsed.data;
44
+ } catch {
45
+ // No file yet (first run / fresh USB) or it's unreadable - either way,
46
+ // defaults are the right answer rather than surfacing an error for
47
+ // something that just means "never rebound".
48
+ }
49
+ return DEFAULT_INPUT_BINDINGS;
50
+ }
51
+
52
+ export async function setInputBindings(configFilePath: string, bindings: InputBindings): Promise<void> {
53
+ const filePath = inputBindingsFilePath(configFilePath);
54
+ await mkdir(dirname(filePath), { recursive: true });
55
+ await writeFile(filePath, JSON.stringify(bindings, null, 2) + "\n");
56
+ }
@@ -17,6 +17,12 @@ export type MatchAgentConfig = {
17
17
  authCode: string,
18
18
  pieceFolder?: string,
19
19
  pluginFolder?: string,
20
+ // Machine-scoped, like pieceFolder/pluginFolder - the arcade/host decides
21
+ // what's in here (same as it decides which plugins/binaries are
22
+ // installed), unlike a player's own saved selections, which need to
23
+ // follow the player across devices and so can't live in a folder scoped
24
+ // to one match-agent install - see util-routers/file-system.
25
+ rosterLockFolder?: string,
20
26
  };
21
27
 
22
28
  import { z, ZodType } from "zod";
@@ -25,6 +31,7 @@ const matchAgentConfig: ZodType<MatchAgentConfig> = z.object({
25
31
  authCode: z.string(),
26
32
  pieceFolder: z.string().optional(),
27
33
  pluginFolder: z.string().optional(),
34
+ rosterLockFolder: z.string().optional(),
28
35
  });
29
36
 
30
37
  export async function getConfig(filePath: string){
@@ -0,0 +1,52 @@
1
+ import { HTTPRequestHandler, HTTPError } from "../../../utils/http-router";
2
+ import { V1Env } from "../globals/types";
3
+ import { requirePluginName, resolveTarget } from "./shared";
4
+
5
+ // Every binary GameLauncher.getBinary has ever downloaded for this plugin,
6
+ // with when it was downloaded/last actually used merged in from match-agent's
7
+ // own bookkeeping (see FolderDB's game_launcher_binaries table -
8
+ // GameLauncherPlugin itself has no way to report either) - lets a settings
9
+ // UI show what's accumulating under dataDir and offer removeGameLauncherBinary
10
+ // below instead of old versions silently piling up forever.
11
+ export const listGameLauncherBinaries: HTTPRequestHandler = async function(
12
+ this: V1Env, { res }, routeInfo
13
+ ){
14
+ const pluginName = requirePluginName(routeInfo);
15
+ const target = resolveTarget(routeInfo);
16
+
17
+ const binaries = await this.pluginRuntime.gameLauncher.listBinaries(pluginName, target);
18
+ const usage = await this.fileDB.getBinaryUsageFor(pluginName, binaries.map((b) => b.binaryLocation));
19
+
20
+ const result = binaries.map((binary) => ({
21
+ ...binary,
22
+ downloadedAt: usage.get(binary.binaryLocation)?.downloadedAt ?? null,
23
+ lastUsedAt: usage.get(binary.binaryLocation)?.lastUsedAt ?? null,
24
+ }));
25
+
26
+ res.writeHead(200, { "Content-Type": "application/json" });
27
+ res.end(JSON.stringify(result));
28
+ }
29
+
30
+ // binaryLocation as a query param, not a JSON body - same shape as
31
+ // util-routers/file-system's routes, for the same reason (a DELETE
32
+ // identifying one resource by path). GameLauncher.removeBinary rejects
33
+ // anything outside this plugin's own dataDir with a plain Error, surfaced
34
+ // here as a 400 rather than a 500 - a client-facing "that's not a binary
35
+ // this plugin downloaded", not a server fault.
36
+ export const removeGameLauncherBinary: HTTPRequestHandler = async function(
37
+ this: V1Env, { res }, routeInfo
38
+ ){
39
+ const pluginName = requirePluginName(routeInfo);
40
+ const binaryLocation = routeInfo.url.searchParams.get("binaryLocation");
41
+ if(!binaryLocation) throw new HTTPError(400, "Missing binaryLocation query parameter");
42
+
43
+ try {
44
+ await this.pluginRuntime.gameLauncher.removeBinary(pluginName, binaryLocation);
45
+ } catch(e){
46
+ throw new HTTPError(400, (e as Error).message);
47
+ }
48
+ await this.fileDB.removeBinaryUsage(pluginName, binaryLocation);
49
+
50
+ res.writeHead(200, { "Content-Type": "application/json" });
51
+ res.end(JSON.stringify({ ok: true }));
52
+ }
@@ -0,0 +1,36 @@
1
+ import { HTTPRequestHandler, HTTPError } from "../../../utils/http-router";
2
+ import { V1Env } from "../globals/types";
3
+ import { requirePluginName } from "./shared";
4
+
5
+ // One listing endpoint, mirroring /piece/sort-list/available - every installed
6
+ // game-launcher plugin's full AvailableGameLauncher record in one response, rather
7
+ // than splitting connection-mode support and gameConfigSchema into separate
8
+ // per-plugin routes. Both are small, static JSON already computed by
9
+ // listAvailable() from the plugin's own module fields, so there's no
10
+ // fetch-cost reason to make a client ask for them separately, and nothing
11
+ // else in this router splits a plugin's metadata that way either.
12
+ export const listAvailableGameLaunchers: HTTPRequestHandler = async function(
13
+ this: V1Env, { res }
14
+ ){
15
+ const available = await this.pluginRuntime.gameLauncher.listAvailable();
16
+ res.writeHead(200, { "Content-Type": "application/json" });
17
+ res.end(JSON.stringify(available));
18
+ }
19
+
20
+ // Installs the plugin *package* itself (registry/manifest-based, via
21
+ // PluginManager - distinct from getBinary in version.ts, which fetches the
22
+ // engine binary that installed plugin actually runs).
23
+ export const installGameLauncherPlugin: HTTPRequestHandler = async function(
24
+ this: V1Env, { res }, routeInfo
25
+ ){
26
+ const pluginName = requirePluginName(routeInfo);
27
+
28
+ try {
29
+ await this.pluginRuntime.installPlugin(pluginName);
30
+ } catch(e){
31
+ throw new HTTPError(400, (e as Error).message);
32
+ }
33
+
34
+ res.writeHead(200, { "Content-Type": "application/json" });
35
+ res.end(JSON.stringify({ ok: true }));
36
+ }
@@ -0,0 +1,54 @@
1
+ import { ServerResponse } from "node:http";
2
+ import z from "zod";
3
+ import { jsonBody, HTTPRequestHandler, HTTPError } from "../../../utils/http-router";
4
+ import { PiecePreview } from "@roster-lock/types";
5
+ import { V1Env } from "../globals/types";
6
+ import { engineCaster, pieceFileInfoCaster } from "../schema/lock";
7
+ import { requirePluginName } from "./shared";
8
+
9
+ const getPreviewBodySchema = z.object({
10
+ engine: engineCaster, pieceType: z.string(), piece: pieceFileInfoCaster,
11
+ }).strict();
12
+
13
+ // Live per-piece preview for the selection screen's hover/focus panel - see
14
+ // GameLauncherPlugin["getPreview"]/["useDefaultPreview"]. Unlike every other
15
+ // route in this router, this one also needs this.fileDB, to turn the piece
16
+ // identity a browser can actually send (engine/pieceType/piece.{version,
17
+ // pathVariables}) into the real on-disk folder only match-agent can resolve.
18
+ //
19
+ // `source` tells the caller which of the two it got back ("piece" from
20
+ // getPreview, "default" from useDefaultPreview, null when neither produced
21
+ // anything). The plugin type collapses both into one PiecePreview, but a
22
+ // selection UI wants them ranked differently: a generic engine silhouette is
23
+ // worth *less* than the roster author's own humanInfo.image thumbnail, while
24
+ // a real portrait read out of the piece's own assets is worth more.
25
+ export const getGameLauncherPreview: HTTPRequestHandler = async function (
26
+ this: V1Env, { req, res }, routeInfo
27
+ ){
28
+ const pluginName = requirePluginName(routeInfo);
29
+ const body = await jsonBody(req);
30
+ const parsed = getPreviewBodySchema.safeParse(body);
31
+ if(!parsed.success) throw new HTTPError(400, "Bad Form", parsed.error);
32
+ const { engine, pieceType, piece } = parsed.data;
33
+
34
+ // A piece is selectable before it's downloaded (see PieceTypeSection's own
35
+ // "downloaded"/undefined tri-state) - no folder yet means there's nothing
36
+ // for getPreview to read, so ask the plugin for its generic placeholder
37
+ // instead (useDefaultPreview) rather than surfacing this as an error.
38
+ let folder: string;
39
+ try {
40
+ folder = await this.fileDB.getPieceFolder(engine, pieceType, piece);
41
+ } catch {
42
+ const preview = await this.pluginRuntime.gameLauncher.useDefaultPreview(pluginName, pieceType);
43
+ respond(res, preview ?? null, preview ? "default" : null);
44
+ return;
45
+ }
46
+
47
+ const preview = await this.pluginRuntime.gameLauncher.getPreview(pluginName, pieceType, piece.pathVariables, folder);
48
+ respond(res, preview ?? null, preview ? "piece" : null);
49
+ }
50
+
51
+ function respond(res: ServerResponse, preview: PiecePreview | null, source: "piece" | "default" | null): void {
52
+ res.writeHead(200, { "Content-Type": "application/json" });
53
+ res.end(JSON.stringify({ preview, source }));
54
+ }
@@ -0,0 +1,75 @@
1
+ import { MessageBridge } from "@roster-lock/utils";
2
+ import { HTTPRequestHandler, HTTPError } from "../../../utils/http-router";
3
+ import { WebSocketHandlerCallback } from "../../../utils/websocket-router";
4
+ import { V1Env } from "../globals/types";
5
+
6
+ export const getGameProcessStatus: HTTPRequestHandler = async function(
7
+ this: V1Env, { res }, routeInfo
8
+ ){
9
+ const handleId = routeInfo.params.handleId;
10
+ const entry = handleId ? this.processHandles.get(handleId) : undefined;
11
+ if(!entry) throw new HTTPError(404, "Unknown process handle");
12
+
13
+ res.writeHead(200, { "Content-Type": "application/json" });
14
+ res.end(JSON.stringify({ exited: entry.handle.exited }));
15
+ }
16
+
17
+ // Shared by both the HTTP listing below and gameProcessesWs's push updates,
18
+ // so the two stay in the same shape.
19
+ function summarizeProcesses(env: V1Env){
20
+ return Array.from(env.processHandles.entries()).map(([handleId, entry]) => ({
21
+ handleId, pluginName: entry.pluginName, exited: entry.handle.exited,
22
+ }));
23
+ }
24
+
25
+ // Every process this match-agent has started, across every game-launcher
26
+ // plugin - backs pages/Game in match-agent-client, which shows one row per
27
+ // entry regardless of which plugin launched it.
28
+ export const listGameProcesses: HTTPRequestHandler = async function(
29
+ this: V1Env, { res }
30
+ ){
31
+ res.writeHead(200, { "Content-Type": "application/json" });
32
+ res.end(JSON.stringify(summarizeProcesses(this)));
33
+ }
34
+
35
+ // WS counterpart to listGameProcesses - pushes a "processes" snapshot as
36
+ // soon as a client connects, then again on every processEvents "changed" (a
37
+ // process started, exited, or crashed). No "ready" handshake like the other
38
+ // WS routes here use: those exist so a client knows it's safe to send a
39
+ // request (onRequest handlers registered), but this route never receives a
40
+ // request at all - it's pure server push, so the first "processes" event
41
+ // already doubles as that signal.
42
+ export const gameProcessesWs: WebSocketHandlerCallback = async function(
43
+ this: V1Env, { ws }, params, next
44
+ ){
45
+ try {
46
+ const bridge = new MessageBridge((message)=>ws.send(JSON.stringify(message)));
47
+ ws.on("message", (message)=>{
48
+ bridge.handleMessage(JSON.parse(message.toString()));
49
+ });
50
+
51
+ const sendSnapshot = ()=>{ bridge.sendEvent("processes", summarizeProcesses(this)); };
52
+ this.processEvents.on("changed", sendSnapshot);
53
+ ws.on("close", ()=>{ this.processEvents.off("changed", sendSnapshot); });
54
+
55
+ sendSnapshot();
56
+ }catch(e){
57
+ ws.terminate();
58
+ next(e);
59
+ }
60
+ }
61
+
62
+ // Best-effort, same as GameProcessHandle.stop() itself - see that type's own
63
+ // docs on why a plugin may not always be able to actually stop the game.
64
+ export const stopGameProcess: HTTPRequestHandler = async function(
65
+ this: V1Env, { res }, routeInfo
66
+ ){
67
+ const handleId = routeInfo.params.handleId;
68
+ const entry = handleId ? this.processHandles.get(handleId) : undefined;
69
+ if(!entry) throw new HTTPError(404, "Unknown process handle");
70
+
71
+ await entry.handle.stop();
72
+
73
+ res.writeHead(200, { "Content-Type": "application/json" });
74
+ res.end(JSON.stringify({ ok: true }));
75
+ }
@@ -0,0 +1,42 @@
1
+ import { HTTPRouter } from "../../../utils/http-router";
2
+ import { V1Env } from "../globals/types";
3
+ import { listAvailableGameLaunchers, installGameLauncherPlugin } from "./listing";
4
+ import { getGameLauncherSettings, setGameLauncherSettings, pickGameLauncherBinaryLocation } from "./settings";
5
+ import {
6
+ getGameLauncherVersion, validateGameLauncherBinaryLocation, validateGameLauncherGameConfig, updateGameLauncherBinary,
7
+ } from "./version";
8
+ import { getGameLauncherPreview } from "./preview";
9
+ import { startGameLauncher } from "./start";
10
+ import { getGameProcessStatus, listGameProcesses, stopGameProcess } from "./process";
11
+ import { listGameLauncherBinaries, removeGameLauncherBinary } from "./binaries";
12
+
13
+ // Mounted at /game-launcher (see index.ts's httpRouter.use) - every path
14
+ // below is relative to that prefix. gameProcessesWs, the one WS route in
15
+ // this family, isn't part of this router: WebSocketRouter has no
16
+ // prefix/child-router support, so it's mounted directly on wsRouter in
17
+ // index.ts instead.
18
+ export function createGameLauncherRouter(env: V1Env): HTTPRouter {
19
+ const router = new HTTPRouter();
20
+ router.get("/available", listAvailableGameLaunchers.bind(env));
21
+ // Plugin-agnostic - lists every process this
22
+ // match-agent has started across every plugin (see pages/Game in
23
+ // match-agent-client), not just one plugin's.
24
+ router.get("/processes", listGameProcesses.bind(env));
25
+
26
+ router.post("/:pluginName/install", installGameLauncherPlugin.bind(env));
27
+ router.get("/:pluginName/settings", getGameLauncherSettings.bind(env));
28
+ router.put("/:pluginName/settings", setGameLauncherSettings.bind(env));
29
+ router.post("/:pluginName/pick-binary-location", pickGameLauncherBinaryLocation.bind(env));
30
+ router.get("/:pluginName/version", getGameLauncherVersion.bind(env));
31
+ router.get("/:pluginName/validate", validateGameLauncherBinaryLocation.bind(env));
32
+ router.post("/:pluginName/validate-game-config", validateGameLauncherGameConfig.bind(env));
33
+ router.post("/:pluginName/update", updateGameLauncherBinary.bind(env));
34
+ router.get("/:pluginName/binaries", listGameLauncherBinaries.bind(env));
35
+ router.delete("/:pluginName/binaries", removeGameLauncherBinary.bind(env));
36
+ router.post("/:pluginName/start", startGameLauncher.bind(env));
37
+ router.post("/:pluginName/preview", getGameLauncherPreview.bind(env));
38
+ router.get("/:pluginName/process/:handleId", getGameProcessStatus.bind(env));
39
+ router.post("/:pluginName/process/:handleId/stop", stopGameProcess.bind(env));
40
+
41
+ return router;
42
+ }
@@ -0,0 +1,58 @@
1
+ import z, { ZodType } from "zod";
2
+ import { GameLauncherLocalSettings } from "@roster-lock/plugin-runtime";
3
+ import { jsonBody, HTTPRequestHandler, HTTPError } from "../../../utils/http-router";
4
+ import { pickFolder, NoFolderPickerAvailable } from "../../../utils/pick-folder";
5
+ import { V1Env } from "../globals/types";
6
+ import { requirePluginName } from "./shared";
7
+
8
+ export const getGameLauncherSettings: HTTPRequestHandler = async function(
9
+ this: V1Env, { res }, routeInfo
10
+ ){
11
+ const pluginName = requirePluginName(routeInfo);
12
+ const settings = await this.pluginRuntime.gameLauncher.getLocalSettings(pluginName);
13
+ res.writeHead(200, { "Content-Type": "application/json" });
14
+ res.end(JSON.stringify(settings));
15
+ }
16
+
17
+ const localSettingsBodySchema: ZodType<GameLauncherLocalSettings> = z.object({
18
+ binaryLocation: z.string().optional(),
19
+ localConfig: z.unknown().optional(),
20
+ }).strict();
21
+
22
+ export const setGameLauncherSettings: HTTPRequestHandler = async function(
23
+ this: V1Env, { req, res }, routeInfo
24
+ ){
25
+ const pluginName = requirePluginName(routeInfo);
26
+ const body = await jsonBody(req);
27
+ const parseResult = localSettingsBodySchema.safeParse(body);
28
+ if(!parseResult.success) throw new HTTPError(400, "Bad Form", parseResult.error);
29
+
30
+ await this.pluginRuntime.gameLauncher.setLocalSettings(pluginName, parseResult.data);
31
+ res.writeHead(200, { "Content-Type": "application/json" });
32
+ res.end(JSON.stringify({ ok: true }));
33
+ }
34
+
35
+ // Opens a native OS folder-picker on match-agent's own host and returns the
36
+ // chosen absolute path, so a UI can offer "Browse..." for binaryLocation
37
+ // instead of only free-text entry - see docs/v2/binary-location.md (it's a
38
+ // folder, not a single file) and pick-folder.ts (why this has to happen
39
+ // server-side rather than via a browser <input>). Pre-seeds the dialog with
40
+ // the plugin's current binaryLocation, if any, since that's the most useful
41
+ // starting point for re-pointing an existing config.
42
+ export const pickGameLauncherBinaryLocation: HTTPRequestHandler = async function(
43
+ this: V1Env, { res }, routeInfo
44
+ ){
45
+ const pluginName = requirePluginName(routeInfo);
46
+ const settings = await this.pluginRuntime.gameLauncher.getLocalSettings(pluginName);
47
+
48
+ let path: string | null;
49
+ try {
50
+ path = await pickFolder(settings.binaryLocation);
51
+ } catch(e){
52
+ if(e instanceof NoFolderPickerAvailable) throw new HTTPError(400, e.message);
53
+ throw e;
54
+ }
55
+
56
+ res.writeHead(200, { "Content-Type": "application/json" });
57
+ res.end(JSON.stringify(path === null ? { cancelled: true } : { path }));
58
+ }
@@ -0,0 +1,34 @@
1
+ import { PlatformTarget } from "@roster-lock/types";
2
+ import { HTTPError } from "../../../utils/http-router";
3
+ import { V1Env } from "../globals/types";
4
+
5
+ export function requirePluginName(routeInfo: { params: Record<string, string | undefined> }): string {
6
+ const pluginName = routeInfo.params.pluginName;
7
+ if(!pluginName) throw new HTTPError(400, "Missing pluginName");
8
+ return pluginName;
9
+ }
10
+
11
+ export async function requireBinaryLocation(env: V1Env, pluginName: string): Promise<string> {
12
+ const settings = await env.pluginRuntime.gameLauncher.getLocalSettings(pluginName);
13
+ if(!settings.binaryLocation){
14
+ throw new HTTPError(400, `Game launcher "${pluginName}" has no binaryLocation configured`);
15
+ }
16
+ return settings.binaryLocation;
17
+ }
18
+
19
+ // See docs/v2/binary-location.md - every GameLauncherPlugin function that
20
+ // resolves a concrete binary out of a (possibly multi-platform) binaryLocation
21
+ // bundle takes a required target, with no implicit "current host" default at
22
+ // that layer. match-agent is what decides the target value: it defaults to
23
+ // its own process.platform/process.arch (the ordinary case - a client asking
24
+ // match-agent to run/inspect the game it's about to run on this same host),
25
+ // but a caller can override either via query params for the deliberate
26
+ // exception (e.g. forcing a win32-x64 build under Wine on a Linux host).
27
+ export function resolveTarget(routeInfo: { url: URL }): PlatformTarget {
28
+ const platform = routeInfo.url.searchParams.get("platform");
29
+ const arch = routeInfo.url.searchParams.get("arch");
30
+ return {
31
+ platform: (platform || process.platform) as PlatformTarget["platform"],
32
+ arch: (arch || process.arch) as PlatformTarget["arch"],
33
+ };
34
+ }
@@ -0,0 +1,113 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import z, { ZodType } from "zod";
3
+ import { ConnectionSetup, StartGameArgs } from "@roster-lock/types";
4
+ import { jsonBody, HTTPRequestHandler, HTTPError } from "../../../utils/http-router";
5
+ import { V1Env } from "../globals/types";
6
+ import { castLockConfig } from "../piece-sort";
7
+ import { requirePluginName, requireBinaryLocation, resolveTarget } from "./shared";
8
+
9
+ const coordinatorAddressSchema = z.object({ host: z.string(), port: z.number() }).strict();
10
+
11
+ // This is what a caller sends match-agent, not what the plugin ends up
12
+ // with - direct-tcp still carries a coordinator address here.
13
+ // GameLauncher.startGame (plugin-runtime) resolves it into a ConnectionConfig
14
+ // before ever invoking a plugin, so a plugin never has to know a coordinator
15
+ // exists at all.
16
+ const connectionSetupSchema: ZodType<ConnectionSetup> = z.union([
17
+ z.object({
18
+ type: z.literal("direct-tcp"), party: z.literal("host"), port: z.number(), coordinator: coordinatorAddressSchema,
19
+ }).strict(),
20
+ z.object({
21
+ type: z.literal("direct-tcp"), party: z.literal("client"), port: z.number(), coordinator: coordinatorAddressSchema,
22
+ }).strict(),
23
+ z.object({ type: z.literal("room"), version: z.string(), url: z.string() }).strict(),
24
+ z.object({ type: z.literal("internal") }).strict(),
25
+ ]);
26
+
27
+ // Everything StartGameArgs needs except currentMachine.privateKeyFile (a
28
+ // match-agent-managed temp file, not something a caller ever supplies) and
29
+ // matchAgent (match-agent knows its own port/authCode - trusting a caller's
30
+ // claim about either would let it point a plugin at a different match-agent
31
+ // entirely). currentMachine's raw privateKey *is* client-supplied here: only
32
+ // the browser holds it, and GameLauncher.startGame is what turns it into the
33
+ // restrictive-permission temp file plugins actually receive.
34
+ type StartGameBody = {
35
+ connectionConfig: ConnectionSetup,
36
+ currentMachine: { machineId: string, publicKey: string, privateKey: string },
37
+ allMachines: unknown,
38
+ selectionResult: unknown,
39
+ rosterConfig: unknown,
40
+ gameConfig: unknown,
41
+ relayRoomId: string,
42
+ }
43
+
44
+ const startGameBodySchema: ZodType<StartGameBody> = z.object({
45
+ connectionConfig: connectionSetupSchema,
46
+ currentMachine: z.object({
47
+ machineId: z.string(), publicKey: z.string(), privateKey: z.string(),
48
+ }).strict(),
49
+ allMachines: z.unknown(),
50
+ selectionResult: z.unknown(),
51
+ rosterConfig: z.unknown(),
52
+ gameConfig: z.unknown(),
53
+ relayRoomId: z.string(),
54
+ }).strict();
55
+
56
+ export const startGameLauncher: HTTPRequestHandler = async function(
57
+ this: V1Env, { req, res }, routeInfo
58
+ ){
59
+ const pluginName = requirePluginName(routeInfo);
60
+ const binaryLocation = await requireBinaryLocation(this, pluginName);
61
+ const target = resolveTarget(routeInfo);
62
+
63
+ const body = await jsonBody(req);
64
+ const parseResult = startGameBodySchema.safeParse(body);
65
+ if(!parseResult.success) throw new HTTPError(400, "Bad Form", parseResult.error);
66
+ const { connectionConfig, currentMachine, allMachines, selectionResult, gameConfig, relayRoomId } = parseResult.data;
67
+ const rosterConfig = castLockConfig(parseResult.data.rosterConfig);
68
+
69
+ const handle = await this.pluginRuntime.gameLauncher.startGame(pluginName, binaryLocation, target, connectionConfig, {
70
+ currentMachine,
71
+ allMachines: allMachines as StartGameArgs<unknown>["allMachines"],
72
+ selectionResult: selectionResult as StartGameArgs<unknown>["selectionResult"],
73
+ rosterConfig,
74
+ gameConfig,
75
+ relayRoomId,
76
+ matchAgent: { port: this.matchAgent.getPort(), authCode: this.matchAgent.authCode },
77
+ gameEnded: (result)=>{
78
+ const ctx = this.gameCompletionContext.get(relayRoomId);
79
+ if(!ctx){
80
+ console.error(`No game-completion context for relayRoomId "${relayRoomId}"`);
81
+ return;
82
+ }
83
+ this.gameCompletionContext.delete(relayRoomId);
84
+ this.pluginRuntime.pieceSort.handleGameComplete({ ...ctx, winners: result.winners }).catch((e)=>{
85
+ console.error("piece-selection-sort handleGameComplete failed", e);
86
+ });
87
+ },
88
+ });
89
+ // Resolved to the same absolute path listBinaries reports (binaryLocation
90
+ // above is whatever raw form is stored - see resolveBinaryLocation's own
91
+ // docs) - otherwise a downloaded-and-used binary's usage row would never
92
+ // match what GET /binaries looks up, and lastUsedAt would never populate
93
+ // for the one case this bookkeeping actually exists for. Best-effort - a
94
+ // bookkeeping failure here shouldn't take down a game that already
95
+ // started successfully.
96
+ this.fileDB.recordBinaryUsed(
97
+ pluginName, this.pluginRuntime.gameLauncher.resolveBinaryLocation(binaryLocation)
98
+ ).catch((e)=>{
99
+ console.error("Failed to record binary usage", e);
100
+ });
101
+
102
+ const handleId = randomUUID();
103
+ this.processHandles.set(handleId, { pluginName, handle });
104
+ // onExit/onCrash rather than polling handle.exited - these are the only
105
+ // moments a process's status can actually change after this point, and
106
+ // gameProcessesWs's subscribers need to hear about it as it happens.
107
+ handle.onExit(()=>this.processEvents.emit("changed"));
108
+ handle.onCrash(()=>this.processEvents.emit("changed"));
109
+ this.processEvents.emit("changed");
110
+
111
+ res.writeHead(200, { "Content-Type": "application/json" });
112
+ res.end(JSON.stringify({ handleId }));
113
+ }