@roster-lock/match-agent 0.3.1 → 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 (157) 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/@roster-lock_ts-client.js +2 -2
  15. package/client/node_modules/.vite/deps/@roster-lock_types.js +1 -1
  16. package/client/node_modules/.vite/deps/@roster-lock_utils.js +1 -1
  17. package/client/node_modules/.vite/deps/_metadata.json +18 -18
  18. package/client/node_modules/.vite/deps/{chunk-CKYX73LL.js → chunk-3HBL6DQ6.js} +1 -1
  19. package/client/node_modules/.vite/deps/{chunk-CKYX73LL.js.map → chunk-3HBL6DQ6.js.map} +2 -2
  20. package/client/node_modules/.vite/deps/{chunk-EDVVVQBR.js → chunk-QTQN6EZX.js} +2 -2
  21. package/client/node_modules/.vite/deps/chunk-QTQN6EZX.js.map +7 -0
  22. package/client/package.json +4 -1
  23. package/client/src/App.tsx +23 -14
  24. package/client/src/NavBar.tsx +15 -5
  25. package/client/src/api/matchAgent.ts +193 -5
  26. package/client/src/bridge/hostBridge.ts +15 -5
  27. package/client/src/components/FullScreenMenu.tsx +32 -0
  28. package/client/src/components/GameLauncherSettingsForm.tsx +80 -5
  29. package/client/src/components/InputHints.tsx +37 -0
  30. package/client/src/components/OnScreenFileDialog.tsx +83 -0
  31. package/client/src/components/OnScreenKeyboard.tsx +75 -0
  32. package/client/src/components/Selection/PieceCard.tsx +29 -4
  33. package/client/src/components/Selection/PiecePreviewPanel.tsx +48 -0
  34. package/client/src/components/Selection/PieceTypeSection.tsx +124 -46
  35. package/client/src/components/Selection/PlayerSelectionPanel.tsx +1 -5
  36. package/client/src/components/Selection/index.tsx +72 -47
  37. package/client/src/context/GlobalNavContext.tsx +340 -0
  38. package/client/src/context/SelectionSourceContext.tsx +26 -0
  39. package/client/src/hooks/useCursorInput.ts +66 -24
  40. package/client/src/hooks/useDownloadedPieceVersions.ts +39 -0
  41. package/client/src/hooks/useGridColumns.ts +29 -0
  42. package/client/src/hooks/useInView.ts +32 -0
  43. package/client/src/hooks/usePiecePreview.ts +124 -0
  44. package/client/src/pages/Controls/index.tsx +126 -0
  45. package/client/src/pages/Game/index.tsx +11 -15
  46. package/client/src/pages/MatchMaking/index.tsx +6 -3
  47. package/client/src/pages/PreviewRoster/index.tsx +118 -0
  48. package/client/src/styles/global.css +355 -6
  49. package/client/src/utils/inputLabels.ts +25 -0
  50. package/client/test-results/.last-run.json +4 -0
  51. package/client/tsconfig.tsbuildinfo +1 -1
  52. package/dist/config/index.js +2 -0
  53. package/dist/config/index.js.map +1 -1
  54. package/dist/config/inputBindings.js +40 -0
  55. package/dist/config/inputBindings.js.map +1 -0
  56. package/dist/config/manage.js +1 -0
  57. package/dist/config/manage.js.map +1 -1
  58. package/dist/handle-room/version-1/game-launcher/binaries.js +36 -0
  59. package/dist/handle-room/version-1/game-launcher/binaries.js.map +1 -0
  60. package/dist/handle-room/version-1/game-launcher/listing.js +24 -0
  61. package/dist/handle-room/version-1/game-launcher/listing.js.map +1 -0
  62. package/dist/handle-room/version-1/game-launcher/preview.js +38 -0
  63. package/dist/handle-room/version-1/game-launcher/preview.js.map +1 -0
  64. package/dist/handle-room/version-1/game-launcher/process.js +52 -0
  65. package/dist/handle-room/version-1/game-launcher/process.js.map +1 -0
  66. package/dist/handle-room/version-1/game-launcher/router.js +32 -0
  67. package/dist/handle-room/version-1/game-launcher/router.js.map +1 -0
  68. package/dist/handle-room/version-1/game-launcher/settings.js +49 -0
  69. package/dist/handle-room/version-1/game-launcher/settings.js.map +1 -0
  70. package/dist/handle-room/version-1/game-launcher/shared.js +28 -0
  71. package/dist/handle-room/version-1/game-launcher/shared.js.map +1 -0
  72. package/dist/handle-room/version-1/game-launcher/start.js +76 -0
  73. package/dist/handle-room/version-1/game-launcher/start.js.map +1 -0
  74. package/dist/handle-room/version-1/game-launcher/version.js +63 -0
  75. package/dist/handle-room/version-1/game-launcher/version.js.map +1 -0
  76. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js +22 -9
  77. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js.map +1 -1
  78. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js +50 -1
  79. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js.map +1 -1
  80. package/dist/handle-room/version-1/index.js +15 -16
  81. package/dist/handle-room/version-1/index.js.map +1 -1
  82. package/dist/handle-room/version-1/input-bindings.js +22 -0
  83. package/dist/handle-room/version-1/input-bindings.js.map +1 -0
  84. package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js +2 -1
  85. package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js.map +1 -1
  86. package/dist/handle-room/version-1/room-handler-bridge/http-handler.js +1 -1
  87. package/dist/handle-room/version-1/room-handler-bridge/http-handler.js.map +1 -1
  88. package/dist/handle-room/version-1/room-handler-bridge/steps.js +2 -1
  89. package/dist/handle-room/version-1/room-handler-bridge/steps.js.map +1 -1
  90. package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js +2 -2
  91. package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js.map +1 -1
  92. package/dist/index.js +18 -4
  93. package/dist/index.js.map +1 -1
  94. package/dist/util-routers/file-system/env.js +3 -0
  95. package/dist/util-routers/file-system/env.js.map +1 -0
  96. package/dist/util-routers/file-system/index.js +31 -0
  97. package/dist/util-routers/file-system/index.js.map +1 -0
  98. package/dist/util-routers/file-system/list.js +50 -0
  99. package/dist/util-routers/file-system/list.js.map +1 -0
  100. package/dist/util-routers/file-system/resolve-within-root.js +18 -0
  101. package/dist/util-routers/file-system/resolve-within-root.js.map +1 -0
  102. package/dist/util-routers/file-system/roster-lock.js +56 -0
  103. package/dist/util-routers/file-system/roster-lock.js.map +1 -0
  104. package/dist/utils/pick-file.js +82 -0
  105. package/dist/utils/pick-file.js.map +1 -0
  106. package/dist/utils/pick-folder.js +84 -0
  107. package/dist/utils/pick-folder.js.map +1 -0
  108. package/package.json +9 -8
  109. package/src/config/index.ts +8 -3
  110. package/src/config/inputBindings.ts +56 -0
  111. package/src/config/manage.ts +7 -0
  112. package/src/handle-room/version-1/game-launcher/binaries.ts +52 -0
  113. package/src/handle-room/version-1/game-launcher/listing.ts +36 -0
  114. package/src/handle-room/version-1/game-launcher/preview.ts +54 -0
  115. package/src/handle-room/version-1/game-launcher/process.ts +75 -0
  116. package/src/handle-room/version-1/game-launcher/router.ts +42 -0
  117. package/src/handle-room/version-1/game-launcher/settings.ts +58 -0
  118. package/src/handle-room/version-1/game-launcher/shared.ts +34 -0
  119. package/src/handle-room/version-1/game-launcher/start.ts +113 -0
  120. package/src/handle-room/version-1/game-launcher/version.ts +85 -0
  121. package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.ts +39 -14
  122. package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.ts +83 -1
  123. package/src/handle-room/version-1/globals/FolderDB/types.ts +24 -0
  124. package/src/handle-room/version-1/globals/types.ts +24 -2
  125. package/src/handle-room/version-1/index.ts +27 -26
  126. package/src/handle-room/version-1/input-bindings.ts +19 -0
  127. package/src/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.ts +4 -1
  128. package/src/handle-room/version-1/room-handler-bridge/http-handler.ts +4 -1
  129. package/src/handle-room/version-1/room-handler-bridge/steps.ts +8 -0
  130. package/src/handle-room/version-1/room-handler-bridge/ws-handler.ts +2 -2
  131. package/src/index.ts +42 -10
  132. package/src/util-routers/file-system/env.ts +7 -0
  133. package/src/util-routers/file-system/index.ts +23 -0
  134. package/src/util-routers/file-system/list.ts +62 -0
  135. package/src/util-routers/file-system/resolve-within-root.ts +25 -0
  136. package/src/util-routers/file-system/roster-lock.ts +74 -0
  137. package/src/utils/pick-file.ts +81 -0
  138. package/src/utils/pick-folder.ts +92 -0
  139. package/tests/integration/filesystem.test.ts +117 -0
  140. package/tests/integration/game-launcher-binaries.test.ts +263 -0
  141. package/tests/integration/game-launcher-game-complete.test.ts +111 -0
  142. package/tests/integration/game-launcher-preview.test.ts +107 -0
  143. package/tests/integration/game-launcher-settings.test.ts +123 -8
  144. package/tests/integration/game-processes-ws.test.ts +122 -0
  145. package/tests/integration/helpers/fakeFolderDB.ts +16 -0
  146. package/tests/integration/helpers/fakePluginRuntime.ts +10 -1
  147. package/tests/integration/helpers/server.ts +23 -3
  148. package/tests/integration/input-bindings.test.ts +94 -0
  149. package/tests/integration/piece-files.test.ts +1 -1
  150. package/tests/integration/roster-lock.test.ts +86 -0
  151. package/vitest.config.ts +7 -1
  152. package/client/dist/assets/index-CX6eCHuc.js +0 -125
  153. package/client/dist/assets/index-gxAuIfGQ.css +0 -1
  154. package/client/node_modules/.vite/deps/chunk-EDVVVQBR.js.map +0 -7
  155. package/dist/handle-room/version-1/game-launcher.js +0 -197
  156. package/dist/handle-room/version-1/game-launcher.js.map +0 -1
  157. package/src/handle-room/version-1/game-launcher.ts +0 -287
@@ -3,6 +3,7 @@ import { MatchAgentProvider, useMatchAgent } from "./context/MatchAgentContext";
3
3
  import { IdentityProvider } from "./context/IdentityContext";
4
4
  import { JoinSettingsProvider } from "./context/JoinSettingsContext";
5
5
  import { DownloadSessionProvider } from "./context/DownloadSessionContext";
6
+ import { GlobalNavProvider } from "./context/GlobalNavContext";
6
7
  import { ConnectPage } from "./pages/Connect";
7
8
  import { JoinSettingsPage } from "./pages/JoinSettings";
8
9
  import { GameLauncherListPage } from "./pages/GameLauncher";
@@ -10,6 +11,8 @@ import { GameLauncherDetailPage } from "./pages/GameLauncher/Detail";
10
11
  import { MatchMakingPage } from "./pages/MatchMaking";
11
12
  import { DownloadPage } from "./pages/Download";
12
13
  import { GameStatusPage } from "./pages/Game";
14
+ import { ControlsPage } from "./pages/Controls";
15
+ import { PreviewRosterPage } from "./pages/PreviewRoster";
13
16
  import { NavBar } from "./NavBar";
14
17
  import { RequireConnection } from "./components/RequireConnection";
15
18
 
@@ -37,20 +40,26 @@ function ConnectOrApp(){
37
40
 
38
41
  return (
39
42
  <BrowserRouter>
40
- <NavBar />
41
- <Routes>
42
- <Route path="/" element={<Navigate to="/match-making" replace />} />
43
- <Route path="/connect" element={<ConnectPage />} />
44
- <Route path="/join-settings" element={<RequireConnection><JoinSettingsPage /></RequireConnection>} />
45
- <Route path="/game-launcher" element={<RequireConnection><GameLauncherListPage /></RequireConnection>} />
46
- <Route
47
- path="/game-launcher/:pluginName"
48
- element={<RequireConnection><GameLauncherDetailPage /></RequireConnection>}
49
- />
50
- <Route path="/match-making" element={<RequireConnection><MatchMakingPage /></RequireConnection>} />
51
- <Route path="/download" element={<RequireConnection><DownloadPage /></RequireConnection>} />
52
- <Route path="/game" element={<RequireConnection><GameStatusPage /></RequireConnection>} />
53
- </Routes>
43
+ <GlobalNavProvider>
44
+ <NavBar />
45
+ <main id="page-content">
46
+ <Routes>
47
+ <Route path="/" element={<Navigate to="/match-making" replace />} />
48
+ <Route path="/connect" element={<ConnectPage />} />
49
+ <Route path="/join-settings" element={<RequireConnection><JoinSettingsPage /></RequireConnection>} />
50
+ <Route path="/game-launcher" element={<RequireConnection><GameLauncherListPage /></RequireConnection>} />
51
+ <Route
52
+ path="/game-launcher/:pluginName"
53
+ element={<RequireConnection><GameLauncherDetailPage /></RequireConnection>}
54
+ />
55
+ <Route path="/match-making" element={<RequireConnection><MatchMakingPage /></RequireConnection>} />
56
+ <Route path="/download" element={<RequireConnection><DownloadPage /></RequireConnection>} />
57
+ <Route path="/game" element={<RequireConnection><GameStatusPage /></RequireConnection>} />
58
+ <Route path="/controls" element={<RequireConnection><ControlsPage /></RequireConnection>} />
59
+ <Route path="/preview-roster" element={<RequireConnection><PreviewRosterPage /></RequireConnection>} />
60
+ </Routes>
61
+ </main>
62
+ </GlobalNavProvider>
54
63
  </BrowserRouter>
55
64
  )
56
65
  }
@@ -1,13 +1,23 @@
1
1
  import { Link } from "react-router-dom";
2
2
 
3
+ // Shared with FullScreenMenu so a gamepad's Start-button menu (see
4
+ // GlobalNavContext) lists exactly the same destinations as this bar.
5
+ export const NAV_LINKS = [
6
+ { to: "/match-making", label: "Match Making" },
7
+ { to: "/game", label: "Games" },
8
+ { to: "/join-settings", label: "Join Settings" },
9
+ { to: "/game-launcher", label: "Game Launchers" },
10
+ { to: "/preview-roster", label: "Preview Roster" },
11
+ { to: "/controls", label: "Controls" },
12
+ { to: "/connect", label: "Connect" },
13
+ ];
14
+
3
15
  export function NavBar() {
4
16
  return (
5
17
  <nav className="nav-bar">
6
- <Link to="/match-making">Match Making</Link>
7
- <Link to="/game">Games</Link>
8
- <Link to="/join-settings">Join Settings</Link>
9
- <Link to="/game-launcher">Game Launchers</Link>
10
- <Link to="/connect">Connect</Link>
18
+ {NAV_LINKS.map((link) => (
19
+ <Link key={link.to} to={link.to}>{link.label}</Link>
20
+ ))}
11
21
  </nav>
12
22
  );
13
23
  }
@@ -1,11 +1,12 @@
1
1
  // Thin wrappers around match-agent's own /v1/game-launcher/* control routes
2
- // (see core/match-agent/src/handle-room/version-1/game-launcher.ts). These are
2
+ // (see core/match-agent/src/handle-room/version-1/game-launcher/). These are
3
3
  // specific to this app (configuring/launching a local game launcher) rather
4
4
  // than something a game itself needs, so they live here instead of
5
5
  // @roster-lock/ts-client - see that package's README/index.ts for the
6
6
  // asset-loading surface games actually consume.
7
7
 
8
- import { PlatformTarget } from "@roster-lock/types";
8
+ import { PlatformTarget, PiecePreview, RosterLockV1Config, RosterLockPiece } from "@roster-lock/types";
9
+ import { MessageBridge } from "@roster-lock/utils";
9
10
 
10
11
  export type GameLauncherLocalSettings = {
11
12
  binaryLocation?: string,
@@ -40,7 +41,7 @@ async function matchAgentFetch(
40
41
  }
41
42
 
42
43
  // Appended as query params on any game-launcher route that resolves a
43
- // concrete binary - see resolveTarget in game-launcher.ts. Omitting `target`
44
+ // concrete binary - see resolveTarget in game-launcher/shared.ts. Omitting `target`
44
45
  // entirely (the ordinary case) leaves match-agent to default to its own
45
46
  // current host; passing one is only for the deliberate exception (see
46
47
  // docs/v2/binary-location.md).
@@ -84,6 +85,22 @@ export async function setGameLauncherSettings(
84
85
  });
85
86
  }
86
87
 
88
+ // Opens a native OS folder-picker on match-agent's own host (see
89
+ // core/match-agent/src/utils/pick-folder.ts for why a browser <input> can't
90
+ // do this itself) and returns the chosen absolute path. `cancelled: true`
91
+ // means the user closed the dialog without picking anything; the picker
92
+ // itself may not exist on a headless/remote match-agent, in which case this
93
+ // throws and the caller should fall back to manual text entry.
94
+ export async function pickGameLauncherBinaryLocation(
95
+ matchAgentUrl: string, authCode: string, pluginName: string
96
+ ): Promise<{ path: string } | { cancelled: true }> {
97
+ const res = await matchAgentFetch(
98
+ matchAgentUrl, authCode, `/v1/game-launcher/${encodeURIComponent(pluginName)}/pick-binary-location`,
99
+ { method: "POST" }
100
+ );
101
+ return res.json();
102
+ }
103
+
87
104
  export async function getGameLauncherVersion(
88
105
  matchAgentUrl: string, authCode: string, pluginName: string, target?: PlatformTarget
89
106
  ): Promise<{ local: { title: string, id: string }, supported: { title: string, id: string } }> {
@@ -117,13 +134,77 @@ export async function validateGameLauncherGameConfig(
117
134
  return problems;
118
135
  }
119
136
 
137
+ // `source` says which of the plugin's two preview functions answered:
138
+ // "piece" is a real preview read out of that piece's downloaded assets,
139
+ // "default" the plugin's generic engine placeholder for a piece that isn't
140
+ // downloaded yet, null when neither produced anything. A selection UI ranks
141
+ // those differently against the roster author's own humanInfo.image - see
142
+ // match-agent's game-launcher/preview.ts.
143
+ export type PiecePreviewResult = {
144
+ preview: PiecePreview | null,
145
+ source: "piece" | "default" | null,
146
+ };
147
+
148
+ export async function getGameLauncherPreview(
149
+ matchAgentUrl: string, authCode: string, pluginName: string,
150
+ engine: RosterLockV1Config["engine"], pieceType: string, piece: Pick<RosterLockPiece, "version" | "pathVariables">
151
+ ): Promise<PiecePreviewResult> {
152
+ const res = await matchAgentFetch(
153
+ matchAgentUrl, authCode, `/v1/game-launcher/${encodeURIComponent(pluginName)}/preview`,
154
+ {
155
+ method: "POST",
156
+ headers: { "Content-Type": "application/json" },
157
+ body: JSON.stringify({ engine, pieceType, piece }),
158
+ }
159
+ );
160
+ const { preview, source } = await res.json();
161
+ return { preview: preview ?? null, source: source ?? null };
162
+ }
163
+
164
+ // No binaryLocation needs to already be configured to call this - getBinary
165
+ // (see GameLauncherPlugin.getBinary) acquires one from scratch, rather than
166
+ // updating an already-set path, so this returns the one it just persisted.
120
167
  export async function updateGameLauncherBinary(
121
168
  matchAgentUrl: string, authCode: string, pluginName: string, target?: PlatformTarget
122
- ): Promise<void> {
123
- await matchAgentFetch(
169
+ ): Promise<{ binaryLocation: string }> {
170
+ const res = await matchAgentFetch(
124
171
  matchAgentUrl, authCode, withTarget(`/v1/game-launcher/${encodeURIComponent(pluginName)}/update`, target),
125
172
  { method: "POST" }
126
173
  );
174
+ return res.json();
175
+ }
176
+
177
+ export type DownloadedGameLauncherBinary = {
178
+ binaryLocation: string,
179
+ version: { title: string, id: string } | null,
180
+ active: boolean,
181
+ downloadedAt: number | null,
182
+ lastUsedAt: number | null,
183
+ };
184
+
185
+ // Everything getBinary has ever put under this plugin's own dataDir (see
186
+ // GameLauncher.listBinaries), so a settings UI can show what's accumulating
187
+ // on disk and offer removeGameLauncherBinary below instead of letting old
188
+ // engine versions pile up unnoticed. `version: null` means the folder is
189
+ // there but doesn't look like a real install any more (e.g. partially
190
+ // deleted by hand) - still listed, just not a candidate anyone would pick.
191
+ export async function listGameLauncherBinaries(
192
+ matchAgentUrl: string, authCode: string, pluginName: string, target?: PlatformTarget
193
+ ): Promise<Array<DownloadedGameLauncherBinary>> {
194
+ const res = await matchAgentFetch(
195
+ matchAgentUrl, authCode, withTarget(`/v1/game-launcher/${encodeURIComponent(pluginName)}/binaries`, target)
196
+ );
197
+ return res.json();
198
+ }
199
+
200
+ export async function removeGameLauncherBinary(
201
+ matchAgentUrl: string, authCode: string, pluginName: string, binaryLocation: string
202
+ ): Promise<void> {
203
+ const params = new URLSearchParams({ binaryLocation });
204
+ await matchAgentFetch(
205
+ matchAgentUrl, authCode, `/v1/game-launcher/${encodeURIComponent(pluginName)}/binaries?${params.toString()}`,
206
+ { method: "DELETE" }
207
+ );
127
208
  }
128
209
 
129
210
  export async function startGameLauncher(
@@ -163,6 +244,27 @@ export async function listGameProcesses(
163
244
  return res.json();
164
245
  }
165
246
 
247
+ // WS counterpart to listGameProcesses (see game-launcher/process.ts's gameProcessesWs)
248
+ // - pushes the current snapshot immediately and again on every later
249
+ // start/exit, so a caller like pages/Game doesn't have to poll. Returns an
250
+ // unsubscribe function that closes the socket.
251
+ export function subscribeToGameProcesses(
252
+ matchAgentUrl: string, authCode: string,
253
+ onUpdate: (processes: Array<GameProcessSummary>) => void, onError: (error: Error) => void
254
+ ): () => void {
255
+ const wsUrl = new URL("/v1/game-launcher/processes", matchAgentUrl);
256
+ wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
257
+ wsUrl.searchParams.set("authorization", authCode);
258
+
259
+ const ws = new WebSocket(wsUrl.href);
260
+ const bridge = new MessageBridge((message) => ws.send(JSON.stringify(message)));
261
+ ws.addEventListener("message", (event) => bridge.handleMessage(JSON.parse(event.data)));
262
+ ws.addEventListener("error", () => onError(new Error("Lost connection to match agent")));
263
+ bridge.onEvent("processes", (processes) => onUpdate(processes));
264
+
265
+ return () => ws.close();
266
+ }
267
+
166
268
  export async function stopGameLauncher(
167
269
  matchAgentUrl: string, authCode: string, pluginName: string, handleId: string
168
270
  ): Promise<void> {
@@ -172,3 +274,89 @@ export async function stopGameLauncher(
172
274
  { method: "POST" }
173
275
  );
174
276
  }
277
+
278
+ export type NavAction = "select" | "back" | "menu";
279
+ export type KeyboardBindings = Record<NavAction, string>;
280
+ export type GamepadBindings = Record<NavAction, number>;
281
+ export type InputBindings = { keyboard: KeyboardBindings, gamepad: GamepadBindings };
282
+
283
+ // Stored by match-agent next to its own portable config file (see
284
+ // core/match-agent/src/config/inputBindings.ts), not in this browser's
285
+ // localStorage - an arcade/internet-cafe host's browser profile doesn't
286
+ // travel with the player, but match-agent run off their own USB does (see
287
+ // docs/economics/machine-environments/pieces-usb.md/cafe.md).
288
+ export async function getInputBindings(matchAgentUrl: string, authCode: string): Promise<InputBindings> {
289
+ const res = await matchAgentFetch(matchAgentUrl, authCode, "/v1/input-bindings");
290
+ return res.json();
291
+ }
292
+
293
+ export async function setInputBindings(
294
+ matchAgentUrl: string, authCode: string, bindings: InputBindings
295
+ ): Promise<void> {
296
+ await matchAgentFetch(matchAgentUrl, authCode, "/v1/input-bindings", {
297
+ method: "PUT",
298
+ headers: { "Content-Type": "application/json" },
299
+ body: JSON.stringify(bindings),
300
+ });
301
+ }
302
+
303
+ // Opens a native OS file-picker on match-agent's own host (see
304
+ // core/match-agent/src/utils/pick-file.ts for why a browser <input> can't
305
+ // hand back an absolute path) pre-seeded with whatever path is already
306
+ // typed, if any. `cancelled: true` means the user closed the dialog
307
+ // without picking anything; the picker itself may not exist on a
308
+ // headless/remote match-agent, in which case this throws and the caller
309
+ // should fall back to typing the path manually (which, via the on-screen
310
+ // keyboard, is also the only option a gamepad-only player has anyway).
311
+ // Mounted outside /v1 (see src/index.ts's startServer) - these don't touch
312
+ // the room protocol, and are bounded to match-agent's configured
313
+ // rosterLockFolder (core/match-agent/src/util-routers/file-system/
314
+ // resolve-within-root.ts), not anywhere else its host filesystem happens
315
+ // to reach: a plain "list any path, read any file" HTTP API would hand
316
+ // anyone holding the auth code a way to enumerate/read the whole machine
317
+ // programmatically, which the native OS dialog this feature replaces
318
+ // never could (it only ever returns one path, chosen through a trusted
319
+ // OS UI - never a general filesystem-browsing capability).
320
+ export async function pickRosterLockFile(
321
+ matchAgentUrl: string, authCode: string, startPath?: string
322
+ ): Promise<{ path: string } | { cancelled: true }> {
323
+ const res = await matchAgentFetch(matchAgentUrl, authCode, "/util/file-system/roster-lock/pick", {
324
+ method: "POST",
325
+ headers: { "Content-Type": "application/json" },
326
+ body: JSON.stringify({ startPath }),
327
+ });
328
+ return res.json();
329
+ }
330
+
331
+ // Reads+parses a roster-lock config straight off match-agent's own host
332
+ // disk - lets pages/PreviewRoster open a SelectionBoard against a roster
333
+ // lock directly, with no matchmaker/room (and so none of the Docker
334
+ // services/real login flow those need) involved at all.
335
+ export async function readRosterLock(
336
+ matchAgentUrl: string, authCode: string, path: string
337
+ ): Promise<RosterLockV1Config> {
338
+ const res = await matchAgentFetch(
339
+ matchAgentUrl, authCode, `/util/file-system/roster-lock?path=${encodeURIComponent(path)}`
340
+ );
341
+ return res.json();
342
+ }
343
+
344
+ export type DirectoryEntry = { name: string, path: string, isDirectory: boolean };
345
+ export type DirectoryListing = { path: string, parent: string | null, entries: Array<DirectoryEntry> };
346
+
347
+ // Backs OnScreenFileDialog - a file picker rendered in the page itself
348
+ // rather than a native OS dialog, so it's reachable through the same
349
+ // Move/Select/Back scheme (GlobalNavContext) a gamepad already uses
350
+ // everywhere else. `path` omitted defaults to match-agent's configured
351
+ // rosterLockFolder; `extension` (e.g. ".roster-lock.json") filters which
352
+ // files show up without hiding any folders, so navigation is never blocked.
353
+ export async function listDirectory(
354
+ matchAgentUrl: string, authCode: string, path?: string, extension?: string
355
+ ): Promise<DirectoryListing> {
356
+ const params = new URLSearchParams();
357
+ if (path) params.set("path", path);
358
+ if (extension) params.set("extension", extension);
359
+ const query = params.toString();
360
+ const res = await matchAgentFetch(matchAgentUrl, authCode, `/util/file-system/list${query ? `?${query}` : ""}`);
361
+ return res.json();
362
+ }
@@ -17,7 +17,10 @@ import { DownloadSession } from "../context/DownloadSessionContext";
17
17
 
18
18
  export type PendingLightbox = (
19
19
  | { type: "install", pluginName: string, resolve: () => void, reject: (e: Error) => void }
20
- | { type: "selection", rosterConfig: RequestSelectionRequest["rosterLockConfig"], numPlayers: number, resolve: (v: RequestSelectionResponse) => void, reject: (e: Error) => void }
20
+ | {
21
+ type: "selection", rosterConfig: RequestSelectionRequest["rosterLockConfig"], numPlayers: number,
22
+ pluginName: string, resolve: (v: RequestSelectionResponse) => void, reject: (e: Error) => void,
23
+ }
21
24
  );
22
25
 
23
26
  // Host-side half of the matchmaker bridge protocol (see
@@ -27,7 +30,7 @@ export type PendingLightbox = (
27
30
  // sync-dl.ws.ts uses over WebSocket, just over postMessage here).
28
31
  export function useHostBridge(args: {
29
32
  iframeRef: RefObject<HTMLIFrameElement | null>,
30
- iframeLoaded: boolean,
33
+ iframeLoaded: number,
31
34
  matchAgent: { url: string, authCode: string },
32
35
  identityKeys: UserKeyPair,
33
36
  machineId: string,
@@ -36,6 +39,8 @@ export function useHostBridge(args: {
36
39
  }) {
37
40
  const { iframeRef, iframeLoaded, matchAgent, identityKeys, machineId, playerSlots, onInitiateRelay } = args;
38
41
 
42
+ const activeConnection = useRef<number>(-1);
43
+
39
44
  const [pendingLightbox, setPendingLightbox] = useState<PendingLightbox | null>(null);
40
45
  const [connected, setConnected] = useState(false);
41
46
  const [connectionError, setConnectionError] = useState(false);
@@ -49,7 +54,8 @@ export function useHostBridge(args: {
49
54
  latest.current = args;
50
55
 
51
56
  useEffect(() => {
52
- if (!iframeLoaded) return;
57
+ if (iframeLoaded === -1) return;
58
+ activeConnection.current = iframeLoaded
53
59
  setConnected(false);
54
60
  setConnectionError(false);
55
61
 
@@ -83,12 +89,13 @@ export function useHostBridge(args: {
83
89
 
84
90
  bridge.onRequest(
85
91
  MATCHMAKER_BRIDGE_PATHS.requestSelection,
86
- ({ rosterLockConfig, numPlayers }: RequestSelectionRequest) => {
92
+ ({ rosterLockConfig, numPlayers, pluginName }: RequestSelectionRequest) => {
87
93
  return new Promise<RequestSelectionResponse>((resolve, reject) => {
88
94
  setPendingLightbox({
89
95
  type: "selection",
90
96
  rosterConfig: rosterLockConfig,
91
97
  numPlayers,
98
+ pluginName,
92
99
  resolve: (selection) => {
93
100
  pendingSelectionRef.current = selection;
94
101
  resolve(selection);
@@ -132,7 +139,10 @@ export function useHostBridge(args: {
132
139
 
133
140
  waitForBridgeEvent(bridge, MATCHMAKER_BRIDGE_PATHS.ready, 15_000)
134
141
  .then(() => setConnected(true))
135
- .catch(() => setConnectionError(true));
142
+ .catch(()=>{
143
+ if(activeConnection.current !== iframeLoaded) return;
144
+ setConnectionError(true)
145
+ });
136
146
 
137
147
  return () => {
138
148
  window.removeEventListener("message", onMessage);
@@ -0,0 +1,32 @@
1
+ import { RefObject } from "react";
2
+ import { NavLink } from "react-router-dom";
3
+ import { NAV_LINKS } from "../NavBar";
4
+ import { useGlobalNav } from "../context/GlobalNavContext";
5
+ import { backHint } from "../utils/inputLabels";
6
+
7
+ // Opened by Space / a gamepad's Start button - see GlobalNavContext. Lets
8
+ // either device reach NavBar's links in one press rather than
9
+ // roving-focusing all the way up to them from wherever the page scrolled.
10
+ export function FullScreenMenu({ containerRef, open, onClose }: {
11
+ containerRef: RefObject<HTMLDivElement | null>,
12
+ open: boolean,
13
+ onClose: () => void,
14
+ }) {
15
+ const { inputDevice, keyboardBindings, gamepadBindings } = useGlobalNav();
16
+ if (!open) return null;
17
+
18
+ return (
19
+ <div className="fullscreen-menu-backdrop" onClick={onClose}>
20
+ <div className="fullscreen-menu" ref={containerRef} onClick={(e) => e.stopPropagation()}>
21
+ {NAV_LINKS.map((link) => (
22
+ <NavLink key={link.to} to={link.to} className="fullscreen-menu-link" onClick={onClose}>
23
+ {link.label}
24
+ </NavLink>
25
+ ))}
26
+ <button type="button" className="fullscreen-menu-close" onClick={onClose}>
27
+ Close ({backHint(inputDevice, keyboardBindings, gamepadBindings)})
28
+ </button>
29
+ </div>
30
+ </div>
31
+ );
32
+ }
@@ -5,7 +5,8 @@ import type { RJSFSchema } from "@rjsf/utils";
5
5
  import { useMatchAgent } from "../context/MatchAgentContext";
6
6
  import {
7
7
  getGameLauncherSettings, setGameLauncherSettings, getGameLauncherVersion, updateGameLauncherBinary,
8
- validateGameLauncherBinaryLocation, listAvailableGameLaunchers,
8
+ validateGameLauncherBinaryLocation, listAvailableGameLaunchers, pickGameLauncherBinaryLocation,
9
+ listGameLauncherBinaries, removeGameLauncherBinary, DownloadedGameLauncherBinary,
9
10
  } from "../api/matchAgent";
10
11
 
11
12
  // A schema with no declared properties renders nothing useful in rjsf - most
@@ -41,6 +42,16 @@ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string })
41
42
  const [localConfig, setLocalConfig] = useState<unknown>(undefined);
42
43
  const [busy, setBusy] = useState(false);
43
44
  const [error, setError] = useState<string | null>(null);
45
+ // Everything getBinary has put under this plugin's own dataDir so far -
46
+ // reloaded after every download/remove so the "hoarding old versions"
47
+ // list a player sees always matches what's actually on disk.
48
+ const [binaries, setBinaries] = useState<Array<DownloadedGameLauncherBinary>>([]);
49
+
50
+ const loadBinaries = () => {
51
+ listGameLauncherBinaries(settings.url, settings.authCode, pluginName)
52
+ .then(setBinaries)
53
+ .catch((e) => setError(e.message));
54
+ };
44
55
 
45
56
  const validate = async (location: string) => {
46
57
  if(!location){
@@ -70,13 +81,22 @@ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string })
70
81
  };
71
82
 
72
83
  useEffect(load, [pluginName, settings]);
84
+ useEffect(loadBinaries, [pluginName, settings]);
85
+
86
+ // validateGameLauncherBinaryLocation checks whatever is currently *saved*
87
+ // on the match-agent side, not a value the client merely holds in state -
88
+ // so any caller that wants a freshly-picked/edited location validated has
89
+ // to persist it first, otherwise it'd just re-validate the old one.
90
+ const persistAndValidate = async (location: string) => {
91
+ await setGameLauncherSettings(settings.url, settings.authCode, pluginName, { binaryLocation: location, localConfig });
92
+ await validate(location);
93
+ };
73
94
 
74
95
  const save = async () => {
75
96
  setBusy(true);
76
97
  setError(null);
77
98
  try {
78
- await setGameLauncherSettings(settings.url, settings.authCode, pluginName, { binaryLocation, localConfig });
79
- await validate(binaryLocation);
99
+ await persistAndValidate(binaryLocation);
80
100
  } catch (e) {
81
101
  setError((e as Error).message);
82
102
  } finally {
@@ -96,12 +116,49 @@ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string })
96
116
  }
97
117
  };
98
118
 
119
+ const browse = async () => {
120
+ setBusy(true);
121
+ setError(null);
122
+ try {
123
+ const result = await pickGameLauncherBinaryLocation(settings.url, settings.authCode, pluginName);
124
+ if ("path" in result) {
125
+ setBinaryLocation(result.path);
126
+ await persistAndValidate(result.path);
127
+ }
128
+ } catch (e) {
129
+ setError((e as Error).message);
130
+ } finally {
131
+ setBusy(false);
132
+ }
133
+ };
134
+
135
+ // Deliberately doesn't require binaryLocation to already be set (unlike
136
+ // checkVersion) - getBinary acquires one from scratch, so this is also
137
+ // how a plugin that supports it gets its *first* binaryLocation, not
138
+ // just later updates. The returned path is both displayed and validated
139
+ // immediately, same as a freshly Browse'd/typed one would be.
99
140
  const download = async () => {
100
141
  setBusy(true);
101
142
  setError(null);
102
143
  try {
103
- await updateGameLauncherBinary(settings.url, settings.authCode, pluginName);
144
+ const { binaryLocation: newLocation } = await updateGameLauncherBinary(settings.url, settings.authCode, pluginName);
145
+ setBinaryLocation(newLocation);
146
+ await validate(newLocation);
104
147
  await checkVersion();
148
+ loadBinaries();
149
+ } catch (e) {
150
+ setError((e as Error).message);
151
+ } finally {
152
+ setBusy(false);
153
+ }
154
+ };
155
+
156
+ const removeBinary = async (location: string) => {
157
+ setBusy(true);
158
+ setError(null);
159
+ try {
160
+ await removeGameLauncherBinary(settings.url, settings.authCode, pluginName, location);
161
+ loadBinaries();
105
162
  } catch (e) {
106
163
  setError((e as Error).message);
107
164
  } finally {
@@ -115,6 +172,7 @@ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string })
115
172
  Binary location
116
173
  <input value={binaryLocation} onChange={(e) => setBinaryLocation(e.target.value)} />
117
174
  </label>
175
+ <button type="button" disabled={busy} onClick={browse}>Browse...</button>
118
176
  {hasProperties(localConfigSchema) && (
119
177
  // Own submit button suppressed - localConfig just feeds into this
120
178
  // component's own state via onChange, and goes out through the
@@ -129,11 +187,28 @@ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string })
129
187
  )}
130
188
  <button type="button" disabled={busy} onClick={save}>Save</button>
131
189
  <button type="button" disabled={busy || !binaryLocation} onClick={checkVersion}>Check version</button>
132
- <button type="button" disabled={busy || !binaryLocation} onClick={download}>Download / update</button>
190
+ <button type="button" disabled={busy} onClick={download}>Download / update</button>
133
191
  {validation && !validation.valid && <p className="error">{validation.message}</p>}
134
192
  {version && (
135
193
  <p>Local: {version.local.title} - Supported: {version.supported.title}</p>
136
194
  )}
195
+ {binaries.length > 0 && (
196
+ <ul className="game-launcher-binaries-list">
197
+ {binaries.map((binary) => (
198
+ <li key={binary.binaryLocation}>
199
+ <span>
200
+ {binary.version?.title ?? "(unrecognized install)"}
201
+ {binary.active && " - active"}
202
+ {binary.downloadedAt && ` - downloaded ${new Date(binary.downloadedAt).toLocaleString()}`}
203
+ {binary.lastUsedAt && ` - last used ${new Date(binary.lastUsedAt).toLocaleString()}`}
204
+ </span>
205
+ <button type="button" disabled={busy} onClick={() => removeBinary(binary.binaryLocation)}>
206
+ Remove
207
+ </button>
208
+ </li>
209
+ ))}
210
+ </ul>
211
+ )}
137
212
  {error && <p className="error">{error}</p>}
138
213
  </div>
139
214
  );
@@ -0,0 +1,37 @@
1
+ import { useGlobalNav } from "../context/GlobalNavContext";
2
+ import { gamepadButtonLabel, keyLabel } from "../utils/inputLabels";
3
+
4
+ // A persistent reminder of the four-action scheme GlobalNavContext drives
5
+ // the whole shell with, swapping key labels for button labels (and
6
+ // reflecting whatever the player has rebound on the Controls page)
7
+ // depending on whichever device was used most recently - so a player who
8
+ // just picked up a controller isn't stuck remembering a keyboard-labelled
9
+ // hint, and vice versa.
10
+ export function InputHints() {
11
+ const { inputDevice, keyboardBindings, gamepadBindings } = useGlobalNav();
12
+
13
+ const items = inputDevice === "gamepad"
14
+ ? [
15
+ { action: "Select", key: gamepadButtonLabel(gamepadBindings.select) },
16
+ { action: "Back", key: gamepadButtonLabel(gamepadBindings.back) },
17
+ { action: "Menu", key: gamepadButtonLabel(gamepadBindings.menu) },
18
+ { action: "Move", key: "D-pad" },
19
+ ]
20
+ : [
21
+ { action: "Select", key: keyLabel(keyboardBindings.select) },
22
+ { action: "Back", key: keyLabel(keyboardBindings.back) },
23
+ { action: "Menu", key: keyLabel(keyboardBindings.menu) },
24
+ { action: "Move", key: "Arrow keys" },
25
+ ];
26
+
27
+ return (
28
+ <div className="input-hints">
29
+ {items.map((hint) => (
30
+ <span key={hint.action} className="input-hint">
31
+ <span className="input-hint-key">{hint.key}</span>
32
+ {hint.action}
33
+ </span>
34
+ ))}
35
+ </div>
36
+ );
37
+ }