Public: anyone can read this; the crew can change it.
The game map says which way it failed: not listening, too large, too slow or refused by BlueMap #18347
Merged 55m ago, live in production
scout/forge:scout/18343-the-game-map-says-which-way-it-failed-no → main 0 commits fork
5 files
changed +52
−3
docs/features/game-map.md +1 −1
| @@ -11,6 +11,6 @@ A game server's BlueMap, a live 3D map with its players, is served by the forge | ||
| 11 | 11 | - **Set BlueMap up:** install it from the server's Mods block, then in its config: webserver `ip: "127.0.0.1"`, `port: 8100` (the agent reads `FORGE_GAME_MAP_PORT` for another), and in `core.conf` `render-thread-count: 1`, so rendering takes one thread of a shared box. Publish nothing. |
| 12 | 12 | - **Use it, on the page:** the server's page has a "Live map" block, one sentence and an "Open the map" button. Reading needs a viewer's grant on the server, as its console does; a person without one, or signed out, gets the sign-in or a 404. The setup above is shown nowhere on the page: BlueMap not listening is a 502 that names what to set. |
| 13 | 13 | - **Use it, in the terminal:** `w` on a service's screen opens `src/tui/screens/game_map.ts`: the same sentence and the map's address, and `p` asks the box for the map's front page and says whether it answered. |
| 14 | - **What is refused:** a path with `..`, `//`, a leading dot, a query, or an extension the map does not use (`html js css json png jpg webp svg ico woff2 txt prbm gz bin wasm`); at most 64 files waiting on one box and 24 on one person; no answer in 12 s is a 504 saying the box is asleep or its agent has not checked in; BlueMap not listening is a 502 that says so. | |
| 14 | - **What is refused:** a path with `..`, `//`, a leading dot, a query, or an extension the map does not use (`html js css json png jpg webp svg ico woff2 txt prbm gz bin wasm`); at most 64 files waiting on one box and 24 on one person; no answer in 12 s is a 504 saying the box is asleep or its agent has not checked in; the agent says which way a fetch failed and the forge words each: `refused` (not listening, a 502 that names what to set), `toobig` (over 600 KB, 502), `slow` (over 10 s, 504), `status NNN` (BlueMap refused it, 502; 404 is a 404). An older agent's bare `status 000` still gets the not-listening sentence. | |
| 15 | 15 | - **What the map's scripts may do, nothing of the viewer's:** the files are the box owner's, scripts included, so they never run with the forge's session. `/map` is the one door that reads the cookie; it buys a pass (`src/games/map_token.ts`: person, server and the hour it ends, signed with the forge's key) and redirects to `/games/<box>/<server>/m/<pass>/`. Every file under it answers from the pass alone, with `sandbox allow-scripts` in its policy: the document has no origin, sends no cookie, and a call to the forge's API from it is a stranger's. Its files are read by CORS without credentials. The pass lasts an hour, a grant taken back ends it at the next file, and the policy lets the scripts talk only to the map's own path. |
| 16 | 16 | - **How it holds up:** a first look asks a few dozen files; the agent hands back up to eight a tick (about 1.2 MB at most in one sync, under the 2 MiB cap) and the box's own commands are handed before any map file, so a pan never waits in front of a stop. It has been run against faked answers only, not a live BlueMap; the 64 and 24 are judgments to tune with one. |
src/games/agent.sh +11 −1
| @@ -1159,6 +1159,13 @@ map_start() { | ||
| 1159 | 1159 | mkdir -p "" |
| 1160 | 1160 | ( |
| 1161 | 1161 | code="$(curl -sS -m 10 --max-filesize 600000 -D "/.head" -o "/.body" -w '%{http_code}' "http://127.0.0.1:/" 2>/dev/null)" |
| 1162 | # Why it failed, as a word the forge maps: curl 7 refused, 63 over the cap, 28 the timeout. | |
| 1163 | case in | |
| 1164 | 0) ;; | |
| 1165 | 7) code=refused ;; | |
| 1166 | 63) code=toobig ;; | |
| 1167 | 28) code=slow ;; | |
| 1168 | esac | |
| 1162 | 1169 | echo "" >"/.rc.next" && mv "/.rc.next" "/.rc" |
| 1163 | 1170 | ) & |
| 1164 | 1171 | } |
| @@ -1184,7 +1191,10 @@ map_tick() { | ||
| 1184 | 1191 | { printf '%s\n' ""; base64 -w0 "/.body"; } >"/.out" |
| 1185 | 1192 | else |
| 1186 | 1193 | ok=false |
| 1187 | printf 'status %s' "" >"/.out" | |
| 1194 | case "" in | |
| 1195 | refused | toobig | slow) printf '%s' "" >"/.out" ;; | |
| 1196 | *) printf 'status %s' "" >"/.out" ;; | |
| 1197 | esac | |
| 1188 | 1198 | fi |
| 1189 | 1199 | # --rawfile: a file's base64 is past the limit of one argument. |
| 1190 | 1200 | jq -c --arg id "" --argjson ok "" --rawfile out "/.out" '. + [{id: $id, ok: $ok, output: $out}]' "/.results" >"/.results.next" && |
src/games/map.ts +7 −1
| @@ -99,8 +99,14 @@ export async function askMap(app: App, box: GameBox, service: string, ask: MapAs | ||
| 99 | 99 | app.db.query("DELETE FROM game_command WHERE id = ?1").run(id); |
| 100 | 100 | if (!done || c === undefined || !c.done) return err({ status: 504, why: mapWords.silent }); |
| 101 | 101 | if (c.ok !== true) { |
| 102 | if (c.output === "refused") return err({ status: 502, why: mapWords.unreachable }); | |
| 103 | if (c.output === "toobig") return err({ status: 502, why: mapWords.tooBig }); | |
| 104 | if (c.output === "slow") return err({ status: 504, why: mapWords.slow }); | |
| 102 | 105 | const status = /^status (\d{3})/.exec(c.output)?.[1]; |
| 103 | return status === "404" ? err({ status: 404, why: "not on the map" }) : err({ status: 502, why: mapWords.unreachable }); | |
| 106 | if (status === "404") return err({ status: 404, why: "not on the map" }); | |
| 107 | // An old agent's `status 000` is every curl failure at once: today's sentence. | |
| 108 | if (status === undefined || status === "000") return err({ status: 502, why: mapWords.unreachable }); | |
| 109 | return err({ status: 502, why: mapWords.refused(status) }); | |
| 104 | 110 | } |
| 105 | 111 | const nl = c.output.indexOf("\n"); |
| 106 | 112 | const flag = c.output.slice(0, nl); |
src/games/map_words.ts +5
| @@ -6,8 +6,13 @@ | ||
| 6 | 6 | |
| 7 | 7 | export const mapWords = { |
| 8 | 8 | silent: "The box did not answer in time: it is asleep, off, or its agent has not checked in. Try again in a moment.", |
| 9 | /** Also what an agent that sends a bare `status 000` gets: it cannot say which way it failed. */ | |
| 9 | 10 | unreachable: |
| 10 | 11 | "The box answered, but BlueMap's web server is not listening on its loopback port 8100. Install BlueMap on this server and set its webserver `ip: \"127.0.0.1\"`, `port: 8100` (see docs/features/game-map.md).", |
| 12 | tooBig: "BlueMap is running, but this file is larger than the 600 KB the box relays, so it cannot be shown.", | |
| 13 | slow: "BlueMap is running, but it took longer than 10 seconds to give this file. Try again in a moment.", | |
| 14 | /** BlueMap answered with a status that is not a file; the code is the box's word for it. */ | |
| 15 | refused: (code: string): string => `BlueMap is running, but it refused this file with status ${code}.`, | |
| 11 | 16 | /** The one sentence a viewer reads beside the button. */ |
| 12 | 17 | blurb: "A live 3D map of the world, with its players.", |
| 13 | 18 | } as const; |
test/games-map.test.ts +28
| @@ -173,6 +173,34 @@ describe("the live map relay", () => { | ||
| 173 | 173 | expect((await answer("t/x3.prbm", true, "1\n<script>")).status).toBe(502); |
| 174 | 174 | }); |
| 175 | 175 | |
| 176 | test("each way the agent says it failed has its own status and sentence; an old agent's 000 keeps today's", async () => { | |
| 177 | const at = await base(bobTok); | |
| 178 | const answer = async (path: string, output: string) => { | |
| 179 | const asking = get(`${at}${path}`); | |
| 180 | const c = await taken(); | |
| 181 | await light([{ id: c.id, ok: false, output }]); | |
| 182 | const res = await asking; | |
| 183 | return { status: res.status, text: await res.text() }; | |
| 184 | }; | |
| 185 | const refused = await answer("t/r1.prbm", "refused"); | |
| 186 | expect(refused.status).toBe(502); | |
| 187 | expect(refused.text).toContain("not listening"); | |
| 188 | const old = await answer("t/r2.prbm", "status 000"); | |
| 189 | expect(old).toEqual(refused); | |
| 190 | const big = await answer("t/r3.prbm", "toobig"); | |
| 191 | expect(big.status).toBe(502); | |
| 192 | expect(big.text).toContain("larger than"); | |
| 193 | expect(big.text).not.toContain("not listening"); | |
| 194 | const slow = await answer("t/r4.prbm", "slow"); | |
| 195 | expect(slow.status).toBe(504); | |
| 196 | expect(slow.text).toContain("10 seconds"); | |
| 197 | expect(slow.text).not.toContain("not listening"); | |
| 198 | const no = await answer("t/r5.prbm", "status 403"); | |
| 199 | expect(no.status).toBe(502); | |
| 200 | expect(no.text).toContain("status 403"); | |
| 201 | expect(no.text).not.toContain("not listening"); | |
| 202 | }); | |
| 203 | ||
| 176 | 204 | test("a file of the biggest size the agent sends passes the sync's body cap and is served whole", async () => { |
| 177 | 205 | const at = await base(bobTok); |
| 178 | 206 | const file = Buffer.alloc(600_000, 7); |
new above
offline