Public: anyone can read this; the crew can change it.
The people adapter and the identity prover move behind the Minecraft kind, with nothing a person sees changed #18538
Its check is red, 27m ago
check failed: 1 of 23446 tests — "the general layer reaches the Minecraft kind only through src/kinds/index.ts"
scout/forge:scout/18531-the-people-adapter-and-the-identity-prov → main 10 commits fork
33 files
changed +270
−135
- docs/features/games.md
- src/games/ask.ts
- src/games/chat.ts
- src/games/client_pack.ts
- src/games/desk_snapshot.ts
- src/games/door_leave.ts
- src/games/findings.ts
- src/games/forge_read.ts
- src/games/gist.ts
- src/games/heal.ts
- src/games/plugin_config.ts
- src/games/reach.ts
- src/games/when_quiet.ts
- src/http/games_routes.ts
- src/http/mcp/tools/games.ts
- src/kinds/index.ts
- src/kinds/kind.ts
- src/kinds/minecraft/index.ts
- src/kinds/minecraft/people.ts
- src/kinds/minecraft/plain.ts
- src/kinds/minecraft/player_events.ts
- src/kinds/minecraft/speak.ts
- src/tui/screens/games.ts
- src/web/pages/games.ts
- src/web/pages/games_topology.ts
- test/game-findings.test.ts
- test/game-people.test.ts
- test/game-player-events.test.ts
- test/game-player-set.test.ts
- test/game-topology.test.ts
- test/kinds-people-identity.test.ts
- test/kinds.test.ts
- test/tui-games.test.ts
docs/features/games.md +1 −1
| @@ -50,7 +50,7 @@ A service page has a People block (#17284), with no plugin on the game servers: | ||
| 50 | 50 | |
| 51 | 51 | `/games/<box>` draws **the network**: the proxy on top and each game server under it, awake, waking (running while its health check starts), asleep (stopped by its sleep) or stopped, with its TPS and the heads of who is on it, every player by server as the proxy says (Velocircon, an RCON console on Velocity that only the compose network reaches; the agent speaks to it itself, from the host inside the proxy's own network, and its password is in no command line and no game server's container), with **Move**: an operator opens a player's head and picks a server that is up. A move goes only to a server of the same box that the person also operates, on the page, in the terminal and in the `games` tool alike. A server's card opens its page (`src/web/pages/games_topology.ts`). In the terminal, the Games screen (`src/tui/screens/games.ts`) lists the same servers with their state, players and TPS. |
| 52 | 52 | |
| 53 | **Refused joins and wakes (#17610).** The proxy's own log lines, and only those, also say a join a server refused, a wake and how long it took, and a server that did not wake (`src/games/player_events.ts`). They are events of the server they are about, on its page, the terminal's people tab and the tool's `people` list; no address is kept. AutoStopper drops the reason a server gives for a refusal, so most refusals at a sleeping server have none. The same refusal twice in a day is a finding, with its fix under it: for a mod server it names the mods Modrinth says a player needs too, as likely when the server's reason is not known. After a refusal the forge looks the mods up in the background and keeps them on the service's row (`player_set_json`), again when the compose file changes; the page, the terminal and the tool read only that, and say "Mods: being looked up." until it is there. A finding changes nothing itself. | |
| 53 | **Refused joins and wakes (#17610).** The proxy's own log lines, and only those, also say a join a server refused, a wake and how long it took, and a server that did not wake (`src/kinds/minecraft/player_events.ts`). They are events of the server they are about, on its page, the terminal's people tab and the tool's `people` list; no address is kept. AutoStopper drops the reason a server gives for a refusal, so most refusals at a sleeping server have none. The same refusal twice in a day is a finding, with its fix under it: for a mod server it names the mods Modrinth says a player needs too, as likely when the server's reason is not known. After a refusal the forge looks the mods up in the background and keeps them on the service's row (`player_set_json`), again when the compose file changes; the page, the terminal and the tool read only that, and say "Mods: being looked up." until it is there. A finding changes nothing itself. | |
| 54 | 54 | |
| 55 | 55 | A refused player is told why in game, once (`tellRefused`): the server, the reason when the proxy logged one (Velocity's own "An internal server connection error occurred." is none), and the mods to install with where to get them. The list is the lockfile's and `MODRINTH_PROJECTS`' projects: those Modrinth marks as required on a client, and what each of them requires (Fabric API and Balm are marked optional on their own pages, yet Waystones does not start without them), never a mod only the server runs; a version is said only when the lockfile pins it. The limit: Velocity closes the player's old server before the new one answers, and AutoStopper does not send them back, so the words wait until a server lists the player again (within 30 minutes). They do not stop the drop itself. |
| 56 | 56 |
src/games/ask.ts +5 −5
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | import type { App } from "../app.ts"; |
| 11 | 11 | import type { User } from "../core/users.ts"; |
| 12 | 12 | import { composeServices, serviceEnv } from "./compose.ts"; |
| 13 | import { peopleOf } from "./people.ts"; | |
| 14 | import { needLines, whyLines } from "./player_events.ts"; | |
| 15 | 13 | import { forcedHosts } from "./presets.ts"; |
| 16 | 14 | import { proxyOf, proxyPort } from "./sleep.ts"; |
| 17 | 15 | import { mayDo, roleOn, servicesOf, type GameBox } from "./store.ts"; |
| 16 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 17 | ||
| 18 | 18 | |
| 19 | 19 | export type Question = |
| 20 | 20 | | { readonly kind: "who" } |
| @@ -53,16 +53,16 @@ const some = (names: readonly string[]): string => | ||
| 53 | 53 | export async function answerTo(app: App, user: User, box: GameBox, compose: string, player: string, q: Question, now: Date): Promise<string[]> { |
| 54 | 54 | const seen = serversSeen(app, user, box, compose); |
| 55 | 55 | const services = servicesOf(app.db, box.id); |
| 56 | const on = (name: string): string[] => peopleOf(app.db, box.id, name).online.map((p) => p.name).sort(); | |
| 56 | const on = (name: string): string[] => peopleAdapter().peopleOf(app.db, box.id, name).online.map((p) => p.name).sort(); | |
| 57 | 57 | if (q.kind === "who") { |
| 58 | 58 | const lines = services.filter((s) => seen.includes(s.name) && s.state === "running" && on(s.name).length > 0).map((s) => `On ${s.name}: ${some(on(s.name))}.`); |
| 59 | 59 | return lines.length === 0 ? ["Nobody is on now."] : lines; |
| 60 | 60 | } |
| 61 | if (q.kind === "why") return whyLines(app.db, box.id, player, seen, now); | |
| 61 | if (q.kind === "why") return peopleAdapter().whyLines(app.db, box.id, player, seen, now); | |
| 62 | 62 | if (q.kind === "address") return addressLines(compose, seen); |
| 63 | 63 | // Asked again here: the role can go while the question waits. |
| 64 | 64 | if (!seen.includes(q.service)) return ["You have no role on that server."]; |
| 65 | if (q.kind === "need") return needLines(app, box, q.service, serviceEnv(compose, q.service)["VERSION"] ?? "", now); | |
| 65 | if (q.kind === "need") return peopleAdapter().needLines(app, box, q.service, serviceEnv(compose, q.service)["VERSION"] ?? "", now); | |
| 66 | 66 | const s = services.find((x) => x.name === q.service); |
| 67 | 67 | if (s?.asleep === true) { |
| 68 | 68 | const woke = app.db |
src/games/chat.ts +3 −3
| @@ -39,14 +39,14 @@ import { composeServices, readCompose, serviceEnv } from "./compose.ts"; | ||
| 39 | 39 | import { asksIn, keepAsk, say, takeConfirmed, type Confirmed, type Where } from "./door.ts"; |
| 40 | 40 | import { holdBuild, type Holding } from "./door_hold.ts"; |
| 41 | 41 | import { doorOf, lockDoor, windowUsed } from "./write_window.ts"; |
| 42 | import { defaultKind } from "../kinds/index.ts"; | |
| 42 | import { defaultKind, peopleAdapter } from "../kinds/index.ts"; | |
| 43 | 43 | import { readLines, readOf } from "./forge_read.ts"; |
| 44 | 44 | import { commitServer, planServer, wishOn } from "./presets.ts"; |
| 45 | import { peopleOf } from "./people.ts"; | |
| 46 | 45 | import { checksAccounts, OFFLINE_WORDS } from "./reach.ts"; |
| 47 | 46 | import { proxyOf } from "./sleep.ts"; |
| 48 | 47 | import { LINES_OUT, listBoxes, mayDo, roleOn, SERVICE_NAME, type GameBox, type Role } from "./store.ts"; |
| 49 | 48 | |
| 49 | ||
| 50 | 50 | export const CODE_MS = 10 * 60_000; |
| 51 | 51 | /** Said where `newLinkCode` gives none. */ |
| 52 | 52 | export const NO_LINK_HERE = "This forge has no game box to link a name on."; |
| @@ -147,7 +147,7 @@ export function newLinkCode(app: App, user: User, now = Date.now()): string | un | ||
| 147 | 147 | * who is online), or "" when the name is not listed there with one. |
| 148 | 148 | */ |
| 149 | 149 | export const onlineUuid = (app: App, boxId: string, service: string, player: string): string => |
| 150 | peopleOf(app.db, boxId, service).online.find((p) => p.name === player)?.uuid ?? ""; | |
| 150 | peopleAdapter().peopleOf(app.db, boxId, service).online.find((p) => p.name === player)?.uuid ?? ""; | |
| 151 | 151 | |
| 152 | 152 | /** |
| 153 | 153 | * The player names linked to `userId`, on every box, each with the UUID it is bound to: its |
src/games/client_pack.ts +3 −2
| @@ -19,9 +19,10 @@ import type { App } from "../app.ts"; | ||
| 19 | 19 | import { id as newId, secret } from "../kernel/id.ts"; |
| 20 | 20 | import { sha256 } from "../kernel/hash.ts"; |
| 21 | 21 | import { versionById, type Result } from "./modrinth.ts"; |
| 22 | import { playerMods } from "./player_events.ts"; | |
| 23 | 22 | import { modsOf, type Mods } from "./mods.ts"; |
| 24 | 23 | import { LOG_KEEP, logsOf, type GameBox } from "./store.ts"; |
| 24 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 25 | ||
| 25 | 26 | |
| 26 | 27 | export const LINK_DAYS = 30; |
| 27 | 28 | |
| @@ -162,7 +163,7 @@ async function buildPack(app: App, box: GameBox, service: string, m: Mods): Prom | ||
| 162 | 163 | : { ok: false, error: `The lockfile's address for ${m.pack.title} is not on Modrinth's own download server, so the forge hands no one a link to it. Install the pack again from the Mods list.` }; |
| 163 | 164 | const loader = loaderOf(m, startLines(app.db, box.id, service)); |
| 164 | 165 | if (!loader.ok) return loader; |
| 165 | const need = await playerMods(app, m); | |
| 166 | const need = await peopleAdapter().playerMods(app, m); | |
| 166 | 167 | if (!need.ok) return need; |
| 167 | 168 | const mine = need.value.locked.filter((l) => l.path.startsWith("mods/")); |
| 168 | 169 | if (need.value.unpinned.length > 0) return { ok: false, error: `Modrinth could not pin ${need.value.unpinned.map((p) => p.title).join(", ")} to a version, so they cannot go in a pack; pin them under Mods first.` }; |
src/games/desk_snapshot.ts +3 −2
| @@ -23,10 +23,11 @@ import { answerTo, questionOf, serversSeen } from "./ask.ts"; | ||
| 23 | 23 | import { composeServices, readCompose } from "./compose.ts"; |
| 24 | 24 | import { helpLines } from "./chat.ts"; |
| 25 | 25 | import { readLines } from "./forge_read.ts"; |
| 26 | import { peopleOf } from "./people.ts"; | |
| 27 | 26 | import { whoMayReach } from "./reach.ts"; |
| 28 | 27 | import { proxyOf } from "./sleep.ts"; |
| 29 | 28 | import { mayDo, roleOn, type GameBox } from "./store.ts"; |
| 29 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 30 | ||
| 30 | 31 | |
| 31 | 32 | /** How long an answer in the file is good for once it is in place, and how often the file is made again. */ |
| 32 | 33 | export const SNAPSHOT_TTL_MS = 120_000; |
| @@ -136,7 +137,7 @@ async function make(app: App, box: GameBox, origin: string, now: number): Promis | ||
| 136 | 137 | ); |
| 137 | 138 | const on: { uuid: string; userId: string; service: string; player: string }[] = []; |
| 138 | 139 | for (const service of composeServices(compose).filter((s) => s !== proxy)) |
| 139 | for (const p of peopleOf(app.db, box.id, service).online) { | |
| 140 | for (const p of peopleAdapter().peopleOf(app.db, box.id, service).online) { | |
| 140 | 141 | const link = links.get(bare(p.uuid)); |
| 141 | 142 | if (link !== undefined && !on.some((o) => o.uuid === link.uuid)) on.push({ uuid: link.uuid, userId: link.user_id, service, player: link.player }); |
| 142 | 143 | } |
src/games/door_leave.ts +4 −3
| @@ -9,9 +9,10 @@ | ||
| 9 | 9 | |
| 10 | 10 | import type { Database } from "bun:sqlite"; |
| 11 | 11 | import { createLog } from "../kernel/log.ts"; |
| 12 | import { networkOf, peopleOf } from "./people.ts"; | |
| 13 | 12 | import { SERVICE_NAME } from "./store.ts"; |
| 14 | 13 | import { doorOf, lockDoor, locksOnLeave } from "./write_window.ts"; |
| 14 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 15 | ||
| 15 | 16 | |
| 16 | 17 | const log = createLog("games"); |
| 17 | 18 | |
| @@ -22,8 +23,8 @@ export const LEFT_WORDS = "locked: the player who opened the window left the net | ||
| 22 | 23 | function onNetwork(db: Database, boxId: string): Set<string> { |
| 23 | 24 | const names = new Set<string>(); |
| 24 | 25 | const services = db.query<{ name: string }, [string]>("SELECT name FROM game_service WHERE box_id = ?1").all(boxId); |
| 25 | for (const s of services) if (SERVICE_NAME.test(s.name)) for (const p of peopleOf(db, boxId, s.name).online) names.add(p.name.toLowerCase()); | |
| 26 | for (const list of Object.values(networkOf(db, boxId))) for (const n of list) names.add(n.toLowerCase()); | |
| 26 | for (const s of services) if (SERVICE_NAME.test(s.name)) for (const p of peopleAdapter().peopleOf(db, boxId, s.name).online) names.add(p.name.toLowerCase()); | |
| 27 | for (const list of Object.values(peopleAdapter().networkOf(db, boxId))) for (const n of list) names.add(n.toLowerCase()); | |
| 27 | 28 | return names; |
| 28 | 29 | } |
| 29 | 30 |
src/games/findings.ts +3 −2
| @@ -11,7 +11,8 @@ | ||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | import type { Database } from "bun:sqlite"; |
| 14 | import { peopleOf } from "./people.ts"; | |
| 14 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 15 | ||
| 15 | 16 | |
| 16 | 17 | export interface Finding { |
| 17 | 18 | /** |
| @@ -97,7 +98,7 @@ export function findingsOf(db: Database, boxId: string, service: string): Findin | ||
| 97 | 98 | // Who is an operator is known only once the agent has read the lists; before that nobody is |
| 98 | 99 | // told they were not one. |
| 99 | 100 | const listed = db.query<{ n: number }, [string, string]>("SELECT instr(people_json, '\"whitelist\"') > 0 AS n FROM game_service WHERE box_id = ?1 AND name = ?2").get(boxId, service)?.n === 1; |
| 100 | const ops = new Set(peopleOf(db, boxId, service).lists.ops.map((o) => o.name)); | |
| 101 | const ops = new Set(peopleAdapter().peopleOf(db, boxId, service).lists.ops.map((o) => o.name)); | |
| 101 | 102 | const groups = new Map<string, { cause: Pick<Cause, "key" | "says" | "fix">; rows: Row[] }>(); |
| 102 | 103 | // One group a cause; an unnamed cause is one group a reason, so two different strangers' words |
| 103 | 104 | // are not "the same trouble". |
src/games/forge_read.ts +4 −8
| @@ -9,9 +9,11 @@ import type { User } from "../core/users.ts"; | ||
| 9 | 9 | import type { Ctx } from "../http/context.ts"; |
| 10 | 10 | import { loadMcp } from "../http/mcp/load.ts"; |
| 11 | 11 | import { visible } from "../http/mcp/shared.ts"; |
| 12 | import { peopleOf } from "./people.ts"; | |
| 13 | 12 | import { serversSeen } from "./ask.ts"; |
| 14 | 13 | import { servicesOf, type GameBox } from "./store.ts"; |
| 14 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 15 | import { line } from "../kinds/minecraft/plain.ts"; | |
| 16 | ||
| 15 | 17 | |
| 16 | 18 | export type Read = "status" | "servers"; |
| 17 | 19 | |
| @@ -21,12 +23,6 @@ export function readOf(words: string): Read | undefined { | ||
| 21 | 23 | return w === "status" || w === "servers" ? w : undefined; |
| 22 | 24 | } |
| 23 | 25 | |
| 24 | /** One line of somebody's text: no control characters, no colour codes, cut. */ | |
| 25 | export const line = (text: string, most = 120): string => { | |
| 26 | const flat = text.replace(/§.?/gu, "").replace(/[\p{Cc}\s]+/gu, " ").trim(); | |
| 27 | return flat.length <= most ? flat : `${flat.slice(0, most - 3)}...`; | |
| 28 | }; | |
| 29 | ||
| 30 | 26 | /** A read-only tool's answer as `user` gets it at /mcp; undefined when it refuses them. */ |
| 31 | 27 | async function readTool(app: App, user: User, origin: string, name: "now" | "releases", args: Record<string, unknown>): Promise<unknown> { |
| 32 | 28 | const { TOOLS } = await loadMcp(); |
| @@ -56,7 +52,7 @@ function serverLines(app: App, user: User, box: GameBox, compose: string): strin | ||
| 56 | 52 | return rows.map((s) => { |
| 57 | 53 | if (s.asleep) return `${s.name}: asleep, wakes when someone joins`; |
| 58 | 54 | if (s.state !== "running") return `${s.name}: ${line(s.state, 20)}`; |
| 59 | const on = peopleOf(app.db, box.id, s.name).online.length; | |
| 55 | const on = peopleAdapter().peopleOf(app.db, box.id, s.name).online.length; | |
| 60 | 56 | // 0 MiB while running is a reading the agent could not take. |
| 61 | 57 | const memory = s.memMiB > 0 ? `, ${(s.memMiB / 1024).toFixed(1)} GB` : ""; |
| 62 | 58 | return `${s.name}: ${s.health === "starting" ? "starting" : "running"}, ${on === 1 ? "1 player" : `${String(on)} players`}${memory}`; |
src/games/gist.ts +3 −2
| @@ -8,9 +8,10 @@ | ||
| 8 | 8 | import type { Database } from "bun:sqlite"; |
| 9 | 9 | import { isIP } from "node:net"; |
| 10 | 10 | import { isPublicAddress } from "../apps/egress.ts"; |
| 11 | import { peopleOf } from "./people.ts"; | |
| 12 | 11 | import type { Power } from "./power.ts"; |
| 13 | 12 | import { commandOf, type GameService } from "./store.ts"; |
| 13 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 14 | ||
| 14 | 15 | |
| 15 | 16 | const DOING: Record<Power, string> = { start: "Starting", stop: "Stopping", restart: "Restarting", recreate: "Rebuilding", pull: "Updating" }; |
| 16 | 17 | const DID: Record<Power, string> = { start: "Started", stop: "Stopped", restart: "Restarted", recreate: "Rebuilt", pull: "Updated" }; |
| @@ -104,7 +105,7 @@ export const NO_ADDRESS = "There is no address to give yet: this box has no mach | ||
| 104 | 105 | |
| 105 | 106 | /** Who is on, server by server. Servers nobody is on are left out. */ |
| 106 | 107 | export function whoIsOn(db: Database, boxId: string, services: readonly string[]): { service: string; names: string[] }[] { |
| 107 | return services.map((service) => ({ service, names: peopleOf(db, boxId, service).online.map((p) => p.name) })).filter((x) => x.names.length > 0); | |
| 108 | return services.map((service) => ({ service, names: peopleAdapter().peopleOf(db, boxId, service).online.map((p) => p.name) })).filter((x) => x.names.length > 0); | |
| 108 | 109 | } |
| 109 | 110 | |
| 110 | 111 | /** |
src/games/heal.ts +3 −2
| @@ -9,9 +9,10 @@ | ||
| 9 | 9 | |
| 10 | 10 | import type { Database } from "bun:sqlite"; |
| 11 | 11 | import { playerEvents } from "./metrics.ts"; |
| 12 | import { networkOf } from "./people.ts"; | |
| 13 | 12 | import { proxyOf } from "./sleep.ts"; |
| 14 | 13 | import { queueCommand, servicesOf, SERVICE_NAME, type GameBox } from "./store.ts"; |
| 14 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 15 | ||
| 15 | 16 | |
| 16 | 17 | /** Tries a service gets in `WINDOW_MS`. */ |
| 17 | 18 | export const TRIES = 2; |
| @@ -104,7 +105,7 @@ export function heal(db: Database, box: Pick<GameBox, "id">, composeText: string | ||
| 104 | 105 | const asleep = services.filter((s) => s.asleep).map((s) => s.name); |
| 105 | 106 | const proxy = composeText === undefined ? undefined : proxyOf(composeText); |
| 106 | 107 | if (asleep.length === 1 && proxy !== undefined) { |
| 107 | const who = waiting(playerEvents(db, box.id, proxy, 20), networkOf(db, box.id), now); | |
| 108 | const who = waiting(playerEvents(db, box.id, proxy, 20), peopleAdapter().networkOf(db, box.id), now); | |
| 108 | 109 | if (who.length > 0) startOnce(db, box, asleep[0]!, "wake", `${who.length === 1 ? "a player joined" : `${who.length} players joined`} and ${asleep[0]} stayed asleep`, now); |
| 109 | 110 | } |
| 110 | 111 | const lost = db |
src/games/plugin_config.ts +3 −2
| @@ -37,8 +37,9 @@ import type { User } from "../core/users.ts"; | ||
| 37 | 37 | import { lineDiff, type DiffLine } from "../web/render/json-doc.ts"; |
| 38 | 38 | import { commitCompose, composeHistory, readCompose, readRepoFile, setServiceEnv, setServiceLabels, setServiceListItem, setTopEntry } from "./compose.ts"; |
| 39 | 39 | import type { Result } from "./modrinth.ts"; |
| 40 | import { peopleOf } from "./people.ts"; | |
| 41 | 40 | import type { GameBox } from "./store.ts"; |
| 41 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 42 | ||
| 42 | 43 | |
| 43 | 44 | /** Where a file lives: the compose file and a pointer into it. */ |
| 44 | 45 | export interface ConfigRef { |
| @@ -319,7 +320,7 @@ const count = (n: number, one: string, many: string): string => `${String(n)} ${ | ||
| 319 | 320 | |
| 320 | 321 | /** The sentence before a commit: the server restarts to read the file, and who is on it. */ |
| 321 | 322 | export function restartWords(app: App, box: GameBox, service: string): string { |
| 322 | const { online } = peopleOf(app.db, box.id, service); | |
| 323 | const { online } = peopleAdapter().peopleOf(app.db, box.id, service); | |
| 323 | 324 | const who = |
| 324 | 325 | online.length === 0 |
| 325 | 326 | ? "nobody is online" |
src/games/reach.ts +3 −2
| @@ -14,9 +14,10 @@ import type { Database } from "bun:sqlite"; | ||
| 14 | 14 | import type { User } from "../core/users.ts"; |
| 15 | 15 | import { getUserById, isActive } from "../core/users.ts"; |
| 16 | 16 | import { composeServices, serviceEnv } from "./compose.ts"; |
| 17 | import { peopleOf } from "./people.ts"; | |
| 18 | 17 | import { proxyOf } from "./sleep.ts"; |
| 19 | 18 | import { mayDo, queueCommand, roleOn, type GameBox } from "./store.ts"; |
| 19 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 20 | ||
| 20 | 21 | |
| 21 | 22 | /** The words a player hears when the network lets any name in. */ |
| 22 | 23 | export const OFFLINE_WORDS = "This network does not check accounts with Mojang (online-mode is off), so no name here can act for a forge account."; |
| @@ -102,7 +103,7 @@ export function whitelistPlan(db: Database, box: Pick<GameBox, "id">, compose: s | ||
| 102 | 103 | ); |
| 103 | 104 | const plan: { service: string; op: "whitelist-add" | "whitelist-remove"; player: string }[] = []; |
| 104 | 105 | for (const [service, may] of Object.entries(reach)) { |
| 105 | const listed = peopleOf(db, box.id, service).lists.whitelist.map((p) => p.name); | |
| 106 | const listed = peopleAdapter().peopleOf(db, box.id, service).lists.whitelist.map((p) => p.name); | |
| 106 | 107 | const has = new Set(listed.map((n) => n.toLowerCase())); |
| 107 | 108 | const allowed = new Set(may.map((n) => n.toLowerCase())); |
| 108 | 109 | for (const name of may) if (!has.has(name.toLowerCase())) plan.push({ service, op: "whitelist-add", player: name }); |
src/games/when_quiet.ts +3 −2
| @@ -7,10 +7,11 @@ | ||
| 7 | 7 | import type { App } from "../app.ts"; |
| 8 | 8 | import { getUserById } from "../core/users.ts"; |
| 9 | 9 | import { readCompose } from "./compose.ts"; |
| 10 | import { peopleOf } from "./people.ts"; | |
| 11 | 10 | import { commitJar, pinOf } from "./proxy_jars.ts"; |
| 12 | 11 | import { proxyOf } from "./sleep.ts"; |
| 13 | 12 | import { mayDo, roleOn, servicesOf, type GameBox } from "./store.ts"; |
| 13 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 14 | ||
| 14 | 15 | |
| 15 | 16 | export const QUIET_MINUTES = 30; |
| 16 | 17 | const QUIET_MS = QUIET_MINUTES * 60_000; |
| @@ -55,7 +56,7 @@ export function isQuiet(app: App, box: Pick<GameBox, "id">, now = Date.now()): b | ||
| 55 | 56 | const lists = app.db.query<{ online_json: string; online_at: string | null }, [string]>("SELECT online_json, online_at FROM game_service WHERE box_id = ?1 AND online_at IS NOT NULL").all(box.id); |
| 56 | 57 | const fresh = (at: string | null): boolean => at !== null && now - Date.parse(at) <= FRESH_MS; |
| 57 | 58 | if (lists.length === 0 || lists.some((l) => !fresh(l.online_at))) return false; |
| 58 | if (servicesOf(app.db, box.id).some((s) => peopleOf(app.db, box.id, s.name).online.length > 0)) return false; | |
| 59 | if (servicesOf(app.db, box.id).some((s) => peopleAdapter().peopleOf(app.db, box.id, s.name).online.length > 0)) return false; | |
| 59 | 60 | // The event's time is the forge's own receive time, not the box's clock; one that does not read is not quiet. |
| 60 | 61 | const last = app.db.query<{ at: string | null }, [string]>("SELECT MAX(at) AS at FROM game_player_event WHERE box_id = ?1").get(box.id)?.at; |
| 61 | 62 | if (last === null || last === undefined) return true; |
src/http/games_routes.ts +5 −5
| @@ -13,14 +13,12 @@ import { heal } from "../games/heal.ts"; | ||
| 13 | 13 | import { synced } from "../games/notify.ts"; |
| 14 | 14 | import { auditShellResults } from "../games/shell.ts"; |
| 15 | 15 | import { recordMetrics } from "../games/metrics.ts"; |
| 16 | import { recordPeople } from "../games/people.ts"; | |
| 17 | 16 | import { followGrants } from "../games/reach.ts"; |
| 18 | 17 | import { gameAsk, gameChat, runChat } from "../games/chat.ts"; |
| 19 | 18 | import { snapshotFor } from "../games/desk_snapshot.ts"; |
| 20 | 19 | import { toldGot, toldTo } from "../games/door.ts"; |
| 21 | 20 | import { packChecks } from "../games/pack_check.ts"; |
| 22 | 21 | import { lendAnswer } from "../games/lend.ts"; |
| 23 | import { recordProxyEvents, tellRefused } from "../games/player_events.ts"; | |
| 24 | 22 | import { proxyOf, sleeping } from "../games/sleep.ts"; |
| 25 | 23 | import { jarsOf } from "../games/proxy_jars.ts"; |
| 26 | 24 | import { boxByToken, envFiles, markAsleep, recordSync, signJarUrls, swapGameBoxToken, type GameBox, type SyncBody } from "../games/store.ts"; |
| @@ -40,6 +38,8 @@ import type { Ctx, Handler } from "./context.ts"; | ||
| 40 | 38 | import { InvalidJson } from "./json_body.ts"; |
| 41 | 39 | import { apiError, boundedMachineBody, json } from "./respond.ts"; |
| 42 | 40 | import type { Router } from "./router.ts"; |
| 41 | import { peopleAdapter } from "../kinds/index.ts"; | |
| 42 | ||
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * How long a sync waits for the answers to the requests it just took: a read or a question is done in |
| @@ -103,7 +103,7 @@ export async function gameAgentSync(ctx: Ctx): Promise<Response> { | ||
| 103 | 103 | } catch (e) { |
| 104 | 104 | ctx.app.log.warn("game agent watch failed", { error: String(e) }); |
| 105 | 105 | } |
| 106 | recordPeople(ctx.app.db, box, body.people); | |
| 106 | peopleAdapter().record(ctx.app.db, box, body.people); | |
| 107 | 107 | // A pack server's files against its lockfile: the answers judged, a check asked where one is due. |
| 108 | 108 | if (body.boot === undefined) await packChecks(ctx.app, box, body); |
| 109 | 109 | const compose = await readCompose(ctx.app, box); |
| @@ -112,9 +112,9 @@ export async function gameAgentSync(ctx: Ctx): Promise<Response> { | ||
| 112 | 112 | // A server its sleep stopped is asleep, not down: the compose file says which sleep. |
| 113 | 113 | markAsleep(ctx.app.db, box.id, compose === undefined ? [] : sleeping(compose.text)); |
| 114 | 114 | // Refused joins and wakes, from the proxy's own log. |
| 115 | recordProxyEvents(ctx.app.db, box, body.logs, compose === undefined ? undefined : proxyOf(compose.text)); | |
| 115 | peopleAdapter().recordProxyEvents(ctx.app.db, box, body.logs, compose === undefined ? undefined : proxyOf(compose.text)); | |
| 116 | 116 | // A refused player is told why once a server lists them again; Modrinth is never waited for. |
| 117 | void tellRefused(ctx.app, box, body.metrics).catch((e: unknown) => ctx.app.log.warn(`game box ${box.name}: telling a refused player failed`, { error: String(e) })); | |
| 117 | void peopleAdapter().tellRefused(ctx.app, box, body.metrics).catch((e: unknown) => ctx.app.log.warn(`game box ${box.name}: telling a refused player failed`, { error: String(e) })); | |
| 118 | 118 | // What is safe is mended alone and said (`games/heal.ts`): a stuck wake, a lost start, with a |
| 119 | 119 | // limit. |
| 120 | 120 | if (body.boot === undefined) heal(ctx.app.db, box, compose?.text); |
src/http/mcp/tools/games.ts +7 −7
| @@ -18,8 +18,6 @@ import { good, bad, type Tool, str } from "../shared.ts"; | ||
| 18 | 18 | import { ALIASES, commitServer, LEVELS, planRemoveServer, planServer, wishOn, type Level } from "../../../games/presets.ts"; |
| 19 | 19 | import { commitPolicy } from "../../../games/sleep.ts"; |
| 20 | 20 | import { findingsOf as kickFindingsOf } from "../../../games/findings.ts"; |
| 21 | import { eventsOf, networkOf, PEOPLE_OPS, peopleOf, peopleWords, queuePeople } from "../../../games/people.ts"; | |
| 22 | import { findingsOf } from "../../../games/player_events.ts"; | |
| 23 | 21 | import { linkShown } from "../../../games/snapshots.ts"; |
| 24 | 22 | import { verdictsOf } from "../../../games/set_verdict.ts"; |
| 25 | 23 | import { takeBack } from "../../../games/take_back.ts"; |
| @@ -28,6 +26,8 @@ import { queueWorld } from "../../../games/worlds.ts"; | ||
| 28 | 26 | import { principalOf } from "../../../core/principal.ts"; |
| 29 | 27 | import { mayOnGame, seesGameBox } from "../../../games/game_may.ts"; |
| 30 | 28 | import { neutralArgs } from "../../../games/neutral_args.ts"; |
| 29 | import { peopleAdapter } from "../../../kinds/index.ts"; | |
| 30 | ||
| 31 | 31 | |
| 32 | 32 | export const tool: Tool = { |
| 33 | 33 | name: "games", |
| @@ -38,7 +38,7 @@ export const tool: Tool = { | ||
| 38 | 38 | type: "object", |
| 39 | 39 | properties: { |
| 40 | 40 | action: { type: "string", enum: ["list", "machines", "metrics", "console", "take_back", "power", "env", "mods", "mods_search", "mods_pack_search", "mods_install", "mods_update", "mods_remove", "mods_pack", "pack", "pack_link", "pack_end", "people", "config", "config_set", "plugin_config", "plugin_config_set", "plugin_config_revert", "sleep", "create_server", "remove_server", "world"] }, |
| 41 | op: { type: "string", enum: ["list", ...PEOPLE_OPS, "import", "restore", "snapshot"] }, | |
| 41 | op: { type: "string", enum: ["list", ...peopleAdapter().ops, "import", "restore", "snapshot"] }, | |
| 42 | 42 | player: { type: "string", maxLength: 17 }, |
| 43 | 43 | to: { type: "string", maxLength: 64 }, |
| 44 | 44 | window: { type: "string", enum: Object.keys(WINDOWS) }, |
| @@ -263,11 +263,11 @@ export const tool: Tool = { | ||
| 263 | 263 | if (action === "people") { |
| 264 | 264 | const op = str(args["op"]); |
| 265 | 265 | if (op === "list") { |
| 266 | const { online, lists } = peopleOf(db, box.id, service); | |
| 267 | return good({ service, online, ...lists, network: networkOf(db, box.id), latest: eventsOf(db, box.id, service, 50), findings: kickFindingsOf(db, box.id, service), refusals: findingsOf(db, box.id, service) }); | |
| 266 | const { online, lists } = peopleAdapter().peopleOf(db, box.id, service); | |
| 267 | return good({ service, online, ...lists, network: peopleAdapter().networkOf(db, box.id), latest: peopleAdapter().eventsOf(db, box.id, service, 50), findings: kickFindingsOf(db, box.id, service), refusals: peopleAdapter().findingsOf(db, box.id, service) }); | |
| 268 | 268 | } |
| 269 | const queued = await queuePeople(ctx.app, box, service, op, str(args["player"]), user, str(args["to"])); | |
| 270 | return queued.ok ? good({ says: `Queued: ${peopleWords(JSON.stringify({ op, player: str(args["player"]), server: str(args["to"]) }))}; the box does it on its next check-in.`, id: queued.id }) : bad("refused", queued.error); | |
| 269 | const queued = await peopleAdapter().queue(ctx.app, box, service, op, str(args["player"]), user, str(args["to"])); | |
| 270 | return queued.ok ? good({ says: `Queued: ${peopleAdapter().words(JSON.stringify({ op, player: str(args["player"]), server: str(args["to"]) }))}; the box does it on its next check-in.`, id: queued.id }) : bad("refused", queued.error); | |
| 271 | 271 | } |
| 272 | 272 | if (action === "config_set") { |
| 273 | 273 | const plan = await previewSettings(ctx.app, box, service, { [str(args["key"])]: str(args["value"]) }); |
src/kinds/index.ts +7 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /** The kinds the forge knows, found by name. The only door the general layer uses to reach one. */ |
| 2 | 2 | |
| 3 | import type { Kind } from "./kind.ts"; | |
| 3 | import type { Kind, PeopleAdapter } from "./kind.ts"; | |
| 4 | 4 | import { minecraft } from "./minecraft/index.ts"; |
| 5 | 5 | |
| 6 | 6 | const KINDS: readonly Kind[] = [minecraft]; |
| @@ -16,3 +16,9 @@ export function kindNamed(name: string): Kind | undefined { | ||
| 16 | 16 | export function defaultKind(): Kind { |
| 17 | 17 | return kindNamed("minecraft") ?? minecraft; |
| 18 | 18 | } |
| 19 | ||
| 20 | /** | |
| 21 | * The people adapter of the default kind. Looked up at each call, not once at load: the games | |
| 22 | * modules that call it are loaded by the kind itself, so reading it while they load finds nothing. | |
| 23 | */ | |
| 24 | export const peopleAdapter = (): PeopleAdapter => defaultKind().people; |
src/kinds/kind.ts +77 −5
| @@ -4,13 +4,18 @@ | ||
| 4 | 4 | * a kind's directory, so what is specific to one game (Minecraft's compose design, its console, |
| 5 | 5 | * RCON) stays in `src/kinds/<name>/`. |
| 6 | 6 | * |
| 7 | * The compose design and the console adapter live behind it. The identity prover is the first | |
| 8 | * of the three declared parts to move; the people adapter and metrics probe are still stubbed by | |
| 9 | * each kind: the code behind them is in `src/games` until the next move. | |
| 7 | * The compose design, the console, the people adapter and the identity prover live behind it. The | |
| 8 | * metrics probe is declared here and still stubbed by each kind: the code behind it is in | |
| 9 | * `src/games` until the next move. | |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | import type { Database } from "bun:sqlite"; |
| 13 | 13 | import type { App } from "../app.ts"; |
| 14 | import type { User } from "../core/users.ts"; | |
| 15 | import type { Locked, Project, Result as ModsResult } from "../games/modrinth.ts"; | |
| 16 | import type { Mods } from "../games/mods.ts"; | |
| 17 | import type { PlayerEventKind } from "../games/metrics.ts"; | |
| 18 | import type { GameBox } from "../games/store.ts"; | |
| 14 | 19 | import type { AccountLink } from "../core/account_link.ts"; |
| 15 | 20 | import type { DnsWant, MachineWant } from "../cloud/plan.ts"; |
| 16 | 21 | import type { Result } from "../kernel/result.ts"; |
| @@ -82,8 +87,75 @@ export interface Stub { | ||
| 82 | 87 | readonly livesIn: string; |
| 83 | 88 | } |
| 84 | 89 | |
| 85 | /** Part 3: who is on a server, and who may be (whitelist, ops). */ | |
| 86 | export type PeopleAdapter = Stub; | |
| 90 | export interface Player { | |
| 91 | readonly name: string; | |
| 92 | readonly uuid: string; | |
| 93 | } | |
| 94 | export interface Ban extends Player { | |
| 95 | readonly reason: string; | |
| 96 | readonly created: string; | |
| 97 | } | |
| 98 | export interface People { | |
| 99 | readonly whitelist: readonly Player[]; | |
| 100 | readonly ops: readonly (Player & { readonly level: number })[]; | |
| 101 | readonly bans: readonly Ban[]; | |
| 102 | readonly whitelistOn: boolean; | |
| 103 | } | |
| 104 | export interface PeopleEvent { | |
| 105 | readonly player: string; | |
| 106 | readonly kind: PlayerEventKind; | |
| 107 | readonly text: string; | |
| 108 | readonly at: string; | |
| 109 | } | |
| 110 | ||
| 111 | /** The same trouble, twice or more: what it is and what would end it. */ | |
| 112 | export interface GameFinding { | |
| 113 | readonly says: string; | |
| 114 | /** Each a line of its own, in plain words. */ | |
| 115 | readonly fix: readonly string[]; | |
| 116 | readonly at: string; | |
| 117 | } | |
| 118 | ||
| 119 | /** The result of queuing a change to a player: the command's id, or why not. */ | |
| 120 | export type Queued = { ok: true; id: string } | { ok: false; error: string }; | |
| 121 | ||
| 122 | /** | |
| 123 | * Part 3: who is on a server, and who may be (whitelist, ops), and what its log says of players. | |
| 124 | */ | |
| 125 | export interface PeopleAdapter { | |
| 126 | /** The changes a person may make to a player (whitelist, op, ban, kick, move). */ | |
| 127 | readonly ops: readonly string[]; | |
| 128 | /** Each change's opposite, its Undo; a kick and a move have none. */ | |
| 129 | readonly undo: Readonly<Record<string, string | undefined>>; | |
| 130 | isBedrock(name: string): boolean; | |
| 131 | /** Who is on a server now, and its lists. */ | |
| 132 | peopleOf(db: Database, boxId: string, service: string): { online: Player[]; lists: People }; | |
| 133 | /** Who is on which server across the box's network. */ | |
| 134 | networkOf(db: Database, boxId: string): Record<string, string[]>; | |
| 135 | /** What a sync says of people, kept. */ | |
| 136 | record(db: Database, box: Pick<GameBox, "id">, sent: unknown): void; | |
| 137 | /** Whether the forge has seen `uuid` on a box `user` sees. */ | |
| 138 | knowsPlayer(db: Database, user: User | undefined, uuid: string): boolean; | |
| 139 | /** Queue a change to a player; the caller has checked `by` operates `service`. */ | |
| 140 | queue(app: App, box: GameBox, service: string, op: string, player: string, by: User | undefined, to?: string): Promise<Queued>; | |
| 141 | /** A queued change in words. */ | |
| 142 | words(text: string): string; | |
| 143 | /** A server's latest player events, newest first. */ | |
| 144 | eventsOf(db: Database, boxId: string, service: string, limit?: number): PeopleEvent[]; | |
| 145 | /** An event in words. */ | |
| 146 | eventWords(e: PeopleEvent, service: string): string; | |
| 147 | /** Read the proxy's log for joins and refusals; how many were kept. */ | |
| 148 | recordProxyEvents(db: Database, box: Pick<GameBox, "id">, logs: Readonly<Record<string, unknown>> | undefined, proxy: string | undefined, now?: Date): number; | |
| 149 | /** Tell the box's people what a refused join needs. */ | |
| 150 | tellRefused(app: App, box: GameBox, metrics: Readonly<Record<string, unknown>> | undefined, now?: Date): Promise<void>; | |
| 151 | whyLines(db: Database, boxId: string, player: string, seen: readonly string[], now: Date): string[]; | |
| 152 | needLines(app: App, box: GameBox, service: string, version: string, now: Date): Promise<string[]>; | |
| 153 | /** The same trouble, twice or more, with what would end it. */ | |
| 154 | findingsOf(db: Database, boxId: string, service: string, now?: Date): GameFinding[]; | |
| 155 | /** What a player's game needs of a server's mods. */ | |
| 156 | playerMods(app: App, m: Mods): Promise<ModsResult<{ locked: Locked[]; unpinned: Project[] }>>; | |
| 157 | } | |
| 158 | ||
| 87 | 159 | /** |
| 88 | 160 | * Part 4: proof that a person owns a name in the game (#18490). The proof is one row of |
| 89 | 161 | * `account_link` keyed by this kind; the prover says what the kind's outside id is and writes and |
src/kinds/minecraft/index.ts +22 −2
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /** |
| 2 | * The Minecraft kind: its compose design, console and identity prover here; people and metrics | |
| 2 | * The Minecraft kind: its compose design, console, people adapter and identity prover here; metrics | |
| 3 | 3 | * still in `src/games`. |
| 4 | 4 | */ |
| 5 | 5 | |
| @@ -7,6 +7,8 @@ import type { Kind } from "../kind.ts"; | ||
| 7 | 7 | import { consoleHtml, consoleText, crashOf, shareOnMclogs } from "./console.ts"; |
| 8 | 8 | import { hear } from "./command.ts"; |
| 9 | 9 | import { minecraftDesign } from "./compose.ts"; |
| 10 | import { eventsOf, eventWords, isBedrock, knowsPlayer, networkOf, PEOPLE_OPS, peopleOf, peopleWords, queuePeople, recordPeople, UNDO } from "./people.ts"; | |
| 11 | import { findingsOf, needLines, playerMods, recordProxyEvents, tellRefused, whyLines } from "./player_events.ts"; | |
| 10 | 12 | import { minecraftProver } from "./prover.ts"; |
| 11 | 13 | import { say } from "./speak.ts"; |
| 12 | 14 | |
| @@ -14,7 +16,25 @@ export const minecraft: Kind = { | ||
| 14 | 16 | name: "minecraft", |
| 15 | 17 | compose: { design: minecraftDesign }, |
| 16 | 18 | console: { html: consoleHtml, text: consoleText, crash: crashOf, share: shareOnMclogs, forge: { hear, say } }, |
| 17 | people: { stub: true, livesIn: "src/games/people.ts" }, | |
| 19 | people: { | |
| 20 | ops: PEOPLE_OPS, | |
| 21 | undo: UNDO, | |
| 22 | isBedrock, | |
| 23 | peopleOf, | |
| 24 | networkOf, | |
| 25 | record: recordPeople, | |
| 26 | knowsPlayer, | |
| 27 | queue: queuePeople, | |
| 28 | words: peopleWords, | |
| 29 | eventsOf, | |
| 30 | eventWords, | |
| 31 | recordProxyEvents, | |
| 32 | tellRefused, | |
| 33 | whyLines, | |
| 34 | needLines, | |
| 35 | findingsOf, | |
| 36 | playerMods, | |
| 37 | }, | |
| 18 | 38 | identity: minecraftProver, |
| 19 | 39 | metrics: { stub: true, livesIn: "src/games/metrics.ts" }, |
| 20 | 40 | }; |
src/games/people.ts → src/kinds/minecraft/people.ts renamed +7 −26
| @@ -11,33 +11,14 @@ | ||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | import type { Database } from "bun:sqlite"; |
| 14 | import type { App } from "../app.ts"; | |
| 15 | import { readCompose } from "./compose.ts"; | |
| 16 | import { PLAYER, type PlayerEventKind } from "./metrics.ts"; | |
| 17 | import type { User } from "../core/users.ts"; | |
| 18 | import { isGameServer } from "./sleep.ts"; | |
| 19 | import { mayDo, queueCommand, roleOn, SERVICE_NAME, servicesOf, type GameBox } from "./store.ts"; | |
| 14 | import type { App } from "../../app.ts"; | |
| 15 | import { readCompose } from "../../games/compose.ts"; | |
| 16 | import { PLAYER } from "../../games/metrics.ts"; | |
| 17 | import type { People, PeopleEvent, Player } from "../kind.ts"; | |
| 18 | import type { User } from "../../core/users.ts"; | |
| 19 | import { isGameServer } from "../../games/sleep.ts"; | |
| 20 | import { mayDo, queueCommand, roleOn, SERVICE_NAME, servicesOf, type GameBox } from "../../games/store.ts"; | |
| 20 | 21 | |
| 21 | export interface Player { | |
| 22 | readonly name: string; | |
| 23 | readonly uuid: string; | |
| 24 | } | |
| 25 | export interface Ban extends Player { | |
| 26 | readonly reason: string; | |
| 27 | readonly created: string; | |
| 28 | } | |
| 29 | export interface People { | |
| 30 | readonly whitelist: readonly Player[]; | |
| 31 | readonly ops: readonly (Player & { readonly level: number })[]; | |
| 32 | readonly bans: readonly Ban[]; | |
| 33 | readonly whitelistOn: boolean; | |
| 34 | } | |
| 35 | export interface PeopleEvent { | |
| 36 | readonly player: string; | |
| 37 | readonly kind: PlayerEventKind; | |
| 38 | readonly text: string; | |
| 39 | readonly at: string; | |
| 40 | } | |
| 41 | 22 | |
| 42 | 23 | const NONE: People = { whitelist: [], ops: [], bans: [], whitelistOn: false }; |
| 43 | 24 | const UUID = /^[0-9a-f-]{32,36}$/; |
src/kinds/minecraft/plain.ts added +7
| @@ -0,0 +1,7 @@ | ||
| 1 | /** Somebody's text made safe to say in a game's chat: one line, no control characters or colour codes. */ | |
| 2 | ||
| 3 | /** One line of somebody's text: no control characters, no colour codes, cut. */ | |
| 4 | export const line = (text: string, most = 120): string => { | |
| 5 | const flat = text.replace(/§.?/gu, "").replace(/[\p{Cc}\s]+/gu, " ").trim(); | |
| 6 | return flat.length <= most ? flat : `${flat.slice(0, most - 3)}...`; | |
| 7 | }; |
src/games/player_events.ts → src/kinds/minecraft/player_events.ts renamed +20 −18
| @@ -14,13 +14,14 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | 16 | import type { Database } from "bun:sqlite"; |
| 17 | import type { App } from "../app.ts"; | |
| 18 | import { readCompose, serviceEnv } from "./compose.ts"; | |
| 19 | import { HEAD, NAME, parseList, plain } from "./metrics.ts"; | |
| 20 | import { clientProjects, playerSide, resolve, type Locked, type Project, type Result } from "./modrinth.ts"; | |
| 21 | import { modsOf, type Mods } from "./mods.ts"; | |
| 22 | import { synced } from "./notify.ts"; | |
| 23 | import { LINES_OUT, SERVICE_NAME, servicesOf, tell, type GameBox } from "./store.ts"; | |
| 17 | import type { App } from "../../app.ts"; | |
| 18 | import type { GameFinding } from "../kind.ts"; | |
| 19 | import { readCompose, serviceEnv } from "../../games/compose.ts"; | |
| 20 | import { HEAD, NAME, parseList, plain } from "../../games/metrics.ts"; | |
| 21 | import { clientProjects, playerSide, resolve, type Locked, type Project, type Result } from "../../games/modrinth.ts"; | |
| 22 | import { modsOf, type Mods } from "../../games/mods.ts"; | |
| 23 | import { synced } from "../../games/notify.ts"; | |
| 24 | import { LINES_OUT, SERVICE_NAME, servicesOf, tell, type GameBox } from "../../games/store.ts"; | |
| 24 | 25 | |
| 25 | 26 | /** How far back refusals count towards a finding. */ |
| 26 | 27 | const FINDING_MS = 24 * 3_600_000; |
| @@ -43,10 +44,18 @@ export interface ProxyFact { | ||
| 43 | 44 | /** Velocity's own words for a connection that closed before a reason came: no server said them. */ |
| 44 | 45 | const NO_REASON = "An internal server connection error occurred."; |
| 45 | 46 | const SERVER = "[A-Za-z0-9_.-]{1,64}"; |
| 46 | const CLOSED = new RegExp(`${HEAD}\\[server connection\\] (${NAME}) -> (${SERVER}) has disconnected$`); | |
| 47 | const REFUSED = new RegExp(`${HEAD}\\[connected player\\] (${NAME}) \\([^)]*\\): disconnected while connecting to (${SERVER}): (.*)$`); | |
| 48 | const LIFECYCLE = new RegExp(`${HEAD}AutoStopper lifecycle completed: op=(STARTUP|CONNECTION_WAIT) server=(${SERVER}) origin=[A-Z_]+ outcome=([A-Z_]+) elapsed_ms=(\\d{1,9}) waiters=\\d+$`); | |
| 49 | const ANY_HEAD = new RegExp(HEAD); | |
| 47 | /** | |
| 48 | * A pattern built on first use: it reads `HEAD` and `NAME` from `games/metrics.ts`, which may still | |
| 49 | * be loading when the kind pulls this module in. Never global, so it keeps no state between uses. | |
| 50 | */ | |
| 51 | const lazy = (build: () => RegExp): Pick<RegExp, "exec" | "test"> => { | |
| 52 | let re: RegExp | undefined; | |
| 53 | return { exec: (t) => (re ??= build()).exec(t), test: (t) => (re ??= build()).test(t) }; | |
| 54 | }; | |
| 55 | const CLOSED = lazy(() => new RegExp(`${HEAD}\\[server connection\\] (${NAME}) -> (${SERVER}) has disconnected$`)); | |
| 56 | const REFUSED = lazy(() => new RegExp(`${HEAD}\\[connected player\\] (${NAME}) \\([^)]*\\): disconnected while connecting to (${SERVER}): (.*)$`)); | |
| 57 | const LIFECYCLE = lazy(() => new RegExp(`${HEAD}AutoStopper lifecycle completed: op=(STARTUP|CONNECTION_WAIT) server=(${SERVER}) origin=[A-Z_]+ outcome=([A-Z_]+) elapsed_ms=(\\d{1,9}) waiters=\\d+$`)); | |
| 58 | const ANY_HEAD = lazy(() => new RegExp(HEAD)); | |
| 50 | 59 | const V4 = "\\d{1,3}(?:\\.\\d{1,3}){3}"; |
| 51 | 60 | const HEXES = "[0-9a-f]{1,4}(?::[0-9a-f]{1,4})*"; |
| 52 | 61 | /** |
| @@ -185,13 +194,6 @@ export function recordProxyEvents(db: Database, box: Pick<GameBox, "id">, logs: | ||
| 185 | 194 | })(); |
| 186 | 195 | } |
| 187 | 196 | |
| 188 | /** The same trouble, twice or more: what it is and what would end it. */ | |
| 189 | export interface GameFinding { | |
| 190 | readonly says: string; | |
| 191 | /** Each a line of its own, in plain words. */ | |
| 192 | readonly fix: readonly string[]; | |
| 193 | readonly at: string; | |
| 194 | } | |
| 195 | 197 | |
| 196 | 198 | /** What a player's own game needs to join a mod server. */ |
| 197 | 199 | export interface PlayerSet { |
src/kinds/minecraft/speak.ts +1 −1
src/tui/screens/games.ts +8 −8
| @@ -28,10 +28,8 @@ import { watchBox } from "../../games/notify.ts"; | ||
| 28 | 28 | import { containersIn, figuresOf } from "../../cloud/containers.ts"; |
| 29 | 29 | import { joinAddress, NO_ADDRESS, nowWords, powerNow, PREVIEW_WORDS, privateWords, SAVE_WORDS } from "../../games/gist.ts"; |
| 30 | 30 | import { findingLine, findingsOf as kickFindingsOf } from "../../games/findings.ts"; |
| 31 | import { eventsOf, eventWords, isBedrock, peopleOf, peopleWords, queuePeople } from "../../games/people.ts"; | |
| 32 | 31 | import { leaveCannotLock } from "../../games/door_leave.ts"; |
| 33 | 32 | import { openDoorWords } from "../../games/reach.ts"; |
| 34 | import { findingsOf } from "../../games/player_events.ts"; | |
| 35 | 33 | import { queueWorld, type WorldOp } from "../../games/worlds.ts"; |
| 36 | 34 | import { lendWords, lentRunnerOf, setLend } from "../../games/lend.ts"; |
| 37 | 35 | import { lendCannot } from "../../games/lend_why.ts"; |
| @@ -84,6 +82,8 @@ import { gameModsScreen } from "./game_mods.ts"; | ||
| 84 | 82 | import { gameSparkScreen } from "./game_spark.ts"; |
| 85 | 83 | import { principalOfUser } from "../../core/principal.ts"; |
| 86 | 84 | import { mayOnGame } from "../../games/game_may.ts"; |
| 85 | import { peopleAdapter } from "../../kinds/index.ts"; | |
| 86 | ||
| 87 | 87 | |
| 88 | 88 | /** "4 online · 19.8 TPS · 3.1 ms tick" from the last hour's numbers, or nothing before any. */ |
| 89 | 89 | function playersTps(f: Session, box: { id: string }, service: string): string[] { |
| @@ -367,20 +367,20 @@ export function gameServiceScreen(f: Session, ctx: Ctx, box: GameBox, service: s | ||
| 367 | 367 | // What still waits; an answer stands in the log, under the line it came after. |
| 368 | 368 | return blocks().filter((b) => b.at === "").flatMap(blockLines); |
| 369 | 369 | if (part === "people") { |
| 370 | const { online, lists } = peopleOf(f.app.db, box.id, service); | |
| 371 | const tag = (n: string) => `${n}${isBedrock(n) ? " (Bedrock)" : ""}${lists.ops.some((o) => o.name === n) ? " · op" : ""}`; | |
| 370 | const { online, lists } = peopleAdapter().peopleOf(f.app.db, box.id, service); | |
| 371 | const tag = (n: string) => `${n}${peopleAdapter().isBedrock(n) ? " (Bedrock)" : ""}${lists.ops.some((o) => o.name === n) ? " · op" : ""}`; | |
| 372 | 372 | return [ |
| 373 | 373 | ...held(), |
| 374 | 374 | nowWords(servicesOf(f.app.db, box.id).find((x) => x.name === service), powerNow(f.app.db, box.id, service)), |
| 375 | 375 | figuresOf(f.app.db, f.user, boxNamed(f.app.db, box.name) ?? box, service), |
| 376 | 376 | ...verdictsOf(f.app.db, box, service).map((v) => (v.takeBack === null ? v.says : `${v.says} In Mods, d then ${v.takeBack} previews it; nothing is taken back alone.`)), |
| 377 | ...findingsOf(f.app.db, box.id, service).flatMap((x) => [x.says, ...x.fix.map((l) => `Fix: ${l}`)]), | |
| 377 | ...peopleAdapter().findingsOf(f.app.db, box.id, service).flatMap((x) => [x.says, ...x.fix.map((l) => `Fix: ${l}`)]), | |
| 378 | 378 | online.length === 0 ? `Nobody is on ${service} right now.` : `Online: ${online.map((p) => tag(p.name)).join(", ")}`, |
| 379 | 379 | `${lists.whitelistOn ? "Only listed players may join" : "Anyone may join"} · ${lists.whitelist.length} listed · ${lists.ops.length} operators · ${lists.bans.length} banned`, |
| 380 | 380 | ...[openDoorWords(lists.whitelistOn) ?? []].flat(), |
| 381 | 381 | ...lists.bans.map((b) => `banned: ${b.name}${b.reason === "" ? "" : ` (${b.reason})`}`), |
| 382 | 382 | ...kickFindingsOf(f.app.db, box.id, service).map(findingLine), |
| 383 | ...eventsOf(f.app.db, box.id, service, 20).map((e) => `${e.at.slice(11, 16)} ${eventWords(e, service)}`), | |
| 383 | ...peopleAdapter().eventsOf(f.app.db, box.id, service, 20).map((e) => `${e.at.slice(11, 16)} ${peopleAdapter().eventWords(e, service)}`), | |
| 384 | 384 | "p: op (make operator), deop, whitelist-add (let in), whitelist-remove, ban, pardon (lift a ban), kick <player>, or move <player> <server>", |
| 385 | 385 | ]; |
| 386 | 386 | } |
| @@ -489,9 +489,9 @@ export function gameServiceScreen(f: Session, ctx: Ctx, box: GameBox, service: s | ||
| 489 | 489 | else if (e.key === "p") |
| 490 | 490 | ask("Player", "op | deop | whitelist-add | whitelist-remove | ban | pardon | kick <player>, or move <player> <server>", async (raw) => { |
| 491 | 491 | const [op = "", player = "", to = ""] = raw.trim().split(/\s+/); |
| 492 | const queued = await queuePeople(f.app, box, service, op, player, f.user, to); | |
| 492 | const queued = await peopleAdapter().queue(f.app, box, service, op, player, f.user, to); | |
| 493 | 493 | part = "people"; |
| 494 | return queued.ok ? `Asked: ${peopleWords(JSON.stringify({ op, player, server: to }))}; it shows on the server until the server answers.` : queued.error; | |
| 494 | return queued.ok ? `Asked: ${peopleAdapter().words(JSON.stringify({ op, player, server: to }))}; it shows on the server until the server answers.` : queued.error; | |
| 495 | 495 | }); |
| 496 | 496 | else if (e.key === "m") ctx.push(gameModsScreen(f, ctx, box, service)); |
| 497 | 497 | else if (e.key === "f") ctx.push(gameConfigScreen(f, ctx, box, service)); |
src/web/pages/games.ts +13 −13
| @@ -73,8 +73,9 @@ import { mapPathOf, mapWords } from "../../games/map_words.ts"; | ||
| 73 | 73 | import { notFoundPage, pageHead, signInFirst } from "../chrome.ts"; |
| 74 | 74 | import { field, readForm, type Form } from "../form.ts"; |
| 75 | 75 | import { html, type Html } from "../html.ts"; |
| 76 | import { defaultKind, peopleAdapter } from "../../kinds/index.ts"; | |
| 77 | import type { GameFinding } from "../../kinds/kind.ts"; | |
| 76 | 78 | import { containerPower } from "./container_power.ts"; |
| 77 | import { defaultKind } from "../../kinds/index.ts"; | |
| 78 | 79 | import { answerAfter, gameLogAfter, gameLogAge, gameLogPage } from "../../logs/game.ts"; |
| 79 | 80 | import { ageWords } from "../../logs/page.ts"; |
| 80 | 81 | import { LOG_GONE, logReader, LOG_READER_CSS, logReaderJs, logRows, logViewOf, placesAnswers } from "../log_reader.ts"; |
| @@ -91,12 +92,10 @@ import { doorBlock } from "./games_door.ts"; | ||
| 91 | 92 | import { passkeyJs } from "../passkey-client.ts"; |
| 92 | 93 | import { windowNote } from "../../games/write_window.ts"; |
| 93 | 94 | import { defaultHeadResponse, headResponse } from "../../games/heads.ts"; |
| 94 | import { eventsOf, eventWords, isBedrock, knowsPlayer, peopleOf, peopleWords, queuePeople, UNDO, type PeopleOp } from "../../games/people.ts"; | |
| 95 | 95 | import { openDoorWords } from "../../games/reach.ts"; |
| 96 | 96 | import { queueWorld, undoOf } from "../../games/worlds.ts"; |
| 97 | 97 | import { START_BOX } from "../../core/empty_words.ts"; |
| 98 | 98 | import { emptyLine, emptyNote } from "../empty_words.ts"; |
| 99 | import { findingsOf, type GameFinding } from "../../games/player_events.ts"; | |
| 100 | 99 | import { findingsOf as kickFindingsOf } from "../../games/findings.ts"; |
| 101 | 100 | import { containersIn, figuresOf } from "../../cloud/containers.ts"; |
| 102 | 101 | import { joinAddress, mainPower, NO_ADDRESS, PREVIEW_WORDS, privateWords, SAVE_WORDS, nowWords, PEOPLE_BUTTON, PEOPLE_CHOICES, powerNow, whoIsOn } from "../../games/gist.ts"; |
| @@ -105,6 +104,7 @@ import { daySpark } from "../studio/kpi_row.ts"; | ||
| 105 | 104 | import { principalOf } from "../../core/principal.ts"; |
| 106 | 105 | import { drawsOperator, mayOnGame, seesGameBox } from "../../games/game_may.ts"; |
| 107 | 106 | |
| 107 | ||
| 108 | 108 | /** A small line of a series (oldest first); nothing when no point is known. */ |
| 109 | 109 | const sparkOf = (points: readonly Point[], pick: (p: Point) => number | null, label: string): Html | null => |
| 110 | 110 | daySpark(points.map(pick), label); |
| @@ -607,7 +607,7 @@ export async function gameServicePage(ctx: Ctx): Promise<Response> { | ||
| 607 | 607 | return after === null ? [] : [{ ...b, after }]; |
| 608 | 608 | }); |
| 609 | 609 | const players = mods?.ok && mods.value.target.kind === "mod" ? await packRow(ctx.app, box, service) : undefined; |
| 610 | const findings = findingsOf(ctx.app.db, box.id, service); | |
| 610 | const findings = peopleAdapter().findingsOf(ctx.app.db, box.id, service); | |
| 611 | 611 | // Settings: each as the compose file says; a "Preview" (s.<key>=value in the query) planned on it. |
| 612 | 612 | const settings = compose === undefined ? [] : settingsOf(compose.text, service, env); |
| 613 | 613 | const wanted = settingsWanted(ctx.url.searchParams); |
| @@ -1292,10 +1292,10 @@ export async function gameSleepSubmit(ctx: Ctx): Promise<Response> { | ||
| 1292 | 1292 | |
| 1293 | 1293 | /** A player's head and name, with a Bedrock badge for a Floodgate player. */ |
| 1294 | 1294 | const who = (name: string, uuid: string): Html => |
| 1295 | html`<img src="/games/head/${uuid === "" || isBedrock(name) ? "none" : uuid}" alt="" width="20" height="20" loading="lazy" /> ${name}${isBedrock(name) ? html` ${badge("Bedrock", { tone: "default" })}` : null}`; | |
| 1295 | html`<img src="/games/head/${uuid === "" || peopleAdapter().isBedrock(name) ? "none" : uuid}" alt="" width="20" height="20" loading="lazy" /> ${name}${peopleAdapter().isBedrock(name) ? html` ${badge("Bedrock", { tone: "default" })}` : null}`; | |
| 1296 | 1296 | |
| 1297 | 1297 | /** One button that sends a people change for `player` on the service's form. */ |
| 1298 | const peopleButton = (base: string, op: PeopleOp, player: string, label: string): Html => | |
| 1298 | const peopleButton = (base: string, op: string, player: string, label: string): Html => | |
| 1299 | 1299 | html`<form method="post" action="${base}/people" class="row-fields"><input type="hidden" name="op" value="${op}" /><input type="hidden" name="player" value="${player}" />${btn(label, { variant: "secondary", size: "sm" })}</form>`; |
| 1300 | 1300 | |
| 1301 | 1301 | /** |
| @@ -1304,8 +1304,8 @@ const peopleButton = (base: string, op: PeopleOp, player: string, label: string) | ||
| 1304 | 1304 | * is seen by nobody without a grant. |
| 1305 | 1305 | */ |
| 1306 | 1306 | function peopleBlock(ctx: Ctx, box: GameBox, service: string, act: boolean): Html { |
| 1307 | const { online, lists } = peopleOf(ctx.app.db, box.id, service); | |
| 1308 | const events = eventsOf(ctx.app.db, box.id, service, 30); | |
| 1307 | const { online, lists } = peopleAdapter().peopleOf(ctx.app.db, box.id, service); | |
| 1308 | const events = peopleAdapter().eventsOf(ctx.app.db, box.id, service, 30); | |
| 1309 | 1309 | const base = `/games/${box.name}/${service}`; |
| 1310 | 1310 | const isOp = (n: string) => lists.ops.some((o) => o.name === n); |
| 1311 | 1311 | const listed = (n: string) => lists.whitelist.some((w) => w.name === n); |
| @@ -1335,7 +1335,7 @@ function peopleBlock(ctx: Ctx, box: GameBox, service: string, act: boolean): Htm | ||
| 1335 | 1335 | ${lists.whitelistOn && lists.whitelist.length > 0 ? html`<h3>Allowed to join</h3>${rowList(lists.whitelist.map((w) => row({ title: who(w.name, w.uuid), ...(act ? { after: peopleButton(base, "whitelist-remove", w.name, PEOPLE_BUTTON["whitelist-remove"]!) } : {}) })))}` : null} |
| 1336 | 1336 | ${events.length === 0 |
| 1337 | 1337 | ? null |
| 1338 | : html`<h3>Latest</h3>${rowList(events.map((e) => row({ title: e.kind === "chat" ? html`<span class="mono"><${e.player}></span> ${e.text}` : eventWords(e, service), meta: time(e.at) })))}`} | |
| 1338 | : html`<h3>Latest</h3>${rowList(events.map((e) => row({ title: e.kind === "chat" ? html`<span class="mono"><${e.player}></span> ${e.text}` : peopleAdapter().eventWords(e, service), meta: time(e.at) })))}`} | |
| 1339 | 1339 | </section>`; |
| 1340 | 1340 | } |
| 1341 | 1341 | |
| @@ -1345,12 +1345,12 @@ export async function gamePeopleSubmit(ctx: Ctx): Promise<Response> { | ||
| 1345 | 1345 | if (got instanceof Response) return got; |
| 1346 | 1346 | const op = field(got.form, "op"); |
| 1347 | 1347 | const player = field(got.form, "player").trim(); |
| 1348 | const queued = await queuePeople(ctx.app, got.box, got.service, op, player, ctx.auth.user, field(got.form, "to")); | |
| 1349 | const undo = UNDO[op as PeopleOp]; | |
| 1348 | const queued = await peopleAdapter().queue(ctx.app, got.box, got.service, op, player, ctx.auth.user, field(got.form, "to")); | |
| 1349 | const undo = peopleAdapter().undo[op]; | |
| 1350 | 1350 | return flashTo( |
| 1351 | 1351 | ctx, |
| 1352 | 1352 | `/games/${got.box.name}/${got.service}`, |
| 1353 | queued.ok ? { message: `Asked: ${peopleWords(JSON.stringify({ op, player, server: field(got.form, "to") }))}. It shows on the server until the server answers.${undo === undefined ? "" : " Its opposite undoes it."}` } : { tone: "danger", message: queued.error }, | |
| 1353 | queued.ok ? { message: `Asked: ${peopleAdapter().words(JSON.stringify({ op, player, server: field(got.form, "to") }))}. It shows on the server until the server answers.${undo === undefined ? "" : " Its opposite undoes it."}` } : { tone: "danger", message: queued.error }, | |
| 1354 | 1354 | ); |
| 1355 | 1355 | } |
| 1356 | 1356 | |
| @@ -1358,7 +1358,7 @@ export async function gamePeopleSubmit(ctx: Ctx): Promise<Response> { | ||
| 1358 | 1358 | // only, and only for a player the forge has seen on a server this person sees; anyone else's is the default. |
| 1359 | 1359 | export function gameHead(ctx: Ctx): Promise<Response> | Response { |
| 1360 | 1360 | const uuid = (ctx.params.uuid ?? "").toLowerCase(); |
| 1361 | if (!knowsPlayer(ctx.app.db, ctx.auth.user, uuid)) return defaultHeadResponse(); | |
| 1361 | if (!peopleAdapter().knowsPlayer(ctx.app.db, ctx.auth.user, uuid)) return defaultHeadResponse(); | |
| 1362 | 1362 | return headResponse(ctx.app, uuid); |
| 1363 | 1363 | } |
| 1364 | 1364 |
src/web/pages/games_topology.ts +5 −4
| @@ -8,13 +8,14 @@ | ||
| 8 | 8 | |
| 9 | 9 | import type { Ctx } from "../../http/context.ts"; |
| 10 | 10 | import { metricsSeries } from "../../games/metrics.ts"; |
| 11 | import { isBedrock, networkOf, peopleOf } from "../../games/people.ts"; | |
| 12 | 11 | import { isGameServer, proxyOf } from "../../games/sleep.ts"; |
| 13 | 12 | import { drawsOperator } from "../../games/game_may.ts"; |
| 14 | 13 | import { principalOf } from "../../core/principal.ts"; |
| 15 | 14 | import { servicesOf, type GameBox, type GameService } from "../../games/store.ts"; |
| 16 | 15 | import { html, type Html } from "../html.ts"; |
| 17 | 16 | import { btn } from "../ui.ts"; |
| 17 | import { peopleAdapter } from "../../kinds/index.ts"; | |
| 18 | ||
| 18 | 19 | |
| 19 | 20 | export const TOPOLOGY_CSS = `/* ---- the network (#17284 G5): the proxy, a line down, the servers under it ---- */ |
| 20 | 21 | .net { display: grid; gap: 16px; justify-items: center; } |
| @@ -70,11 +71,11 @@ export function topologyBlock(ctx: Ctx, box: GameBox, compose: string | undefine | ||
| 70 | 71 | if (compose === undefined || proxy === undefined) return html``; |
| 71 | 72 | const seen = servicesOf(ctx.app.db, box.id); |
| 72 | 73 | const servers = visible.filter((n) => isGameServer(compose, n)); |
| 73 | const network = networkOf(ctx.app.db, box.id); | |
| 74 | const network = peopleAdapter().networkOf(ctx.app.db, box.id); | |
| 74 | 75 | // Each player's UUID from the server they are on (its `list uuids`), for their head. |
| 75 | 76 | const uuidOf = new Map<string, string>(); |
| 76 | 77 | const onServer = (n: string): string[] => { |
| 77 | const { online } = peopleOf(ctx.app.db, box.id, n); | |
| 78 | const { online } = peopleAdapter().peopleOf(ctx.app.db, box.id, n); | |
| 78 | 79 | for (const p of online) uuidOf.set(p.name, p.uuid); |
| 79 | 80 | return network[n] ?? online.map((p) => p.name); |
| 80 | 81 | }; |
| @@ -83,7 +84,7 @@ export function topologyBlock(ctx: Ctx, box: GameBox, compose: string | undefine | ||
| 83 | 84 | const proxyState = netState(seen.find((s) => s.name === proxy)); |
| 84 | 85 | const head = (server: string, name: string, act: boolean): Html => { |
| 85 | 86 | const uuid = uuidOf.get(name) ?? ""; |
| 86 | const face = html`<img src="/games/head/${uuid === "" || isBedrock(name) ? "none" : uuid}" alt="" width="20" height="20" loading="lazy" />`; | |
| 87 | const face = html`<img src="/games/head/${uuid === "" || peopleAdapter().isBedrock(name) ? "none" : uuid}" alt="" width="20" height="20" loading="lazy" />`; | |
| 87 | 88 | // Only to a server this person operates too: the move's own rule (`queuePeople`). |
| 88 | 89 | const targets = servers.filter((t) => t !== server && netState(seen.find((s) => s.name === t)) !== "stopped" && drawsOperator(ctx.app.db, principalOf(ctx.auth), box.id, t)); |
| 89 | 90 | if (!act || targets.length === 0) return html`<span class="net-head">${face} ${name}</span>`; |
test/game-findings.test.ts +1 −1
| @@ -13,7 +13,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 13 | 13 | import { chatCommand } from "../src/games/chat.ts"; |
| 14 | 14 | import { findingsOf } from "../src/games/findings.ts"; |
| 15 | 15 | import { parseLogLine, recordMetrics } from "../src/games/metrics.ts"; |
| 16 | import { eventsOf, eventWords, keptPeople } from "../src/games/people.ts"; | |
| 16 | import { eventsOf, eventWords, keptPeople } from "../src/kinds/minecraft/people.ts"; | |
| 17 | 17 | import { AGENT_SH } from "../src/games/boot.ts"; |
| 18 | 18 | import { boxNamed, commandOf, createGameBox, logsOf, queueCommand, recordSync, type GameBox } from "../src/games/store.ts"; |
| 19 | 19 | import { forgeHttp, type ForgeHttp } from "../src/http/server.ts"; |
test/game-people.test.ts +1 −1
| @@ -16,7 +16,7 @@ import { createToken } from "../src/core/tokens.ts"; | ||
| 16 | 16 | import { createUser, type User } from "../src/core/users.ts"; |
| 17 | 17 | import { DEFAULT_HEAD, FETCHES_MAX, HEAD_KEPT_MS, headResponse, MISS_MS } from "../src/games/heads.ts"; |
| 18 | 18 | import { parseList, parseLogLine } from "../src/games/metrics.ts"; |
| 19 | import { eventsOf, keptPeople, knowsPlayer, networkOf, parseGlist, peopleOf, peopleWords, queuePeople } from "../src/games/people.ts"; | |
| 19 | import { eventsOf, keptPeople, knowsPlayer, networkOf, parseGlist, peopleOf, peopleWords, queuePeople } from "../src/kinds/minecraft/people.ts"; | |
| 20 | 20 | import { boxNamed, commandOf, createGameBox, grant, recentCommands } from "../src/games/store.ts"; |
| 21 | 21 | import { forgeHttp, type ForgeHttp } from "../src/http/server.ts"; |
| 22 | 22 | import { quietLogs } from "./helpers/globals.ts"; |
test/game-player-events.test.ts +2 −2
| @@ -12,8 +12,8 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 12 | 12 | import { createSession } from "../src/core/sessions.ts"; |
| 13 | 13 | import { createToken } from "../src/core/tokens.ts"; |
| 14 | 14 | import { createUser, type User } from "../src/core/users.ts"; |
| 15 | import { eventsOf } from "../src/games/people.ts"; | |
| 16 | import { findingsOf, proxyFacts, recordProxyEvents, refusedLines, tellRefused } from "../src/games/player_events.ts"; | |
| 15 | import { eventsOf } from "../src/kinds/minecraft/people.ts"; | |
| 16 | import { findingsOf, proxyFacts, recordProxyEvents, refusedLines, tellRefused } from "../src/kinds/minecraft/player_events.ts"; | |
| 17 | 17 | import { waitFor } from "./helpers/poll.ts"; |
| 18 | 18 | import { boxNamed, createGameBox, grant, type GameBox } from "../src/games/store.ts"; |
| 19 | 19 | import { forgeHttp, type ForgeHttp } from "../src/http/server.ts"; |
test/game-player-set.test.ts +1 −1
| @@ -14,7 +14,7 @@ import { getRepo } from "../src/core/repos.ts"; | ||
| 14 | 14 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; |
| 15 | 15 | import { clientProjects, playerSide, type Locked, type Project } from "../src/games/modrinth.ts"; |
| 16 | 16 | import { modsOf } from "../src/games/mods.ts"; |
| 17 | import { needLines, playerMods } from "../src/games/player_events.ts"; | |
| 17 | import { needLines, playerMods } from "../src/kinds/minecraft/player_events.ts"; | |
| 18 | 18 | import { boxNamed, createGameBox, type GameBox } from "../src/games/store.ts"; |
| 19 | 19 | import { quietLogs } from "./helpers/globals.ts"; |
| 20 | 20 |
test/game-topology.test.ts +1 −1
| @@ -13,7 +13,7 @@ import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | ||
| 13 | 13 | import { createSession } from "../src/core/sessions.ts"; |
| 14 | 14 | import { createToken } from "../src/core/tokens.ts"; |
| 15 | 15 | import { createUser, type User } from "../src/core/users.ts"; |
| 16 | import { queuePeople } from "../src/games/people.ts"; | |
| 16 | import { queuePeople } from "../src/kinds/minecraft/people.ts"; | |
| 17 | 17 | import { proxyOf, WAKER } from "../src/games/sleep.ts"; |
| 18 | 18 | import { createGameBox, grant, boxNamed, recentCommands } from "../src/games/store.ts"; |
| 19 | 19 | import { forgeHttp, type ForgeHttp } from "../src/http/server.ts"; |
test/kinds-people-identity.test.ts added +39
| @@ -0,0 +1,39 @@ | ||
| 1 | /** | |
| 2 | * The people adapter and the identity prover are reached through the Minecraft kind (#18531): the | |
| 3 | * kind's parts are the very functions that moved, and the prover is the Minecraft one. | |
| 4 | */ | |
| 5 | import { expect, test } from "bun:test"; | |
| 6 | import { readFileSync, readdirSync } from "node:fs"; | |
| 7 | import { kindNamed } from "../src/kinds/index.ts"; | |
| 8 | import { eventsOf, keptPeople, peopleOf, PEOPLE_OPS, UNDO } from "../src/kinds/minecraft/people.ts"; | |
| 9 | import { minecraftProver } from "../src/kinds/minecraft/prover.ts"; | |
| 10 | import { findingsOf } from "../src/kinds/minecraft/player_events.ts"; | |
| 11 | ||
| 12 | const minecraft = kindNamed("minecraft")!; | |
| 13 | ||
| 14 | test("the people adapter is the Minecraft one: whitelist, ops and player events", () => { | |
| 15 | const p = minecraft.people; | |
| 16 | expect(p.peopleOf).toBe(peopleOf); | |
| 17 | expect(p.eventsOf).toBe(eventsOf); | |
| 18 | expect(p.findingsOf).toBe(findingsOf); | |
| 19 | expect(p.ops).toBe(PEOPLE_OPS); | |
| 20 | expect(p.undo).toBe(UNDO); | |
| 21 | expect(p.undo["whitelist-add"]).toBe("whitelist-remove"); | |
| 22 | expect(p.isBedrock(".Steve")).toBe(true); | |
| 23 | expect(p.isBedrock("Steve")).toBe(false); | |
| 24 | expect(keptPeople({ whitelist: [{ name: "Alice", uuid: "" }], whitelistOn: true }).whitelist[0]?.name).toBe("Alice"); | |
| 25 | }); | |
| 26 | ||
| 27 | test("the identity prover is the Minecraft one, reached through the kind", () => { | |
| 28 | expect(minecraft.identity).toBe(minecraftProver); | |
| 29 | expect(minecraft.identity.kind).toBe("minecraft"); | |
| 30 | expect(minecraft.identity.clean("not a uuid")).toBeUndefined(); | |
| 31 | }); | |
| 32 | ||
| 33 | test("no module outside src/kinds imports the people or identity code of a kind", () => { | |
| 34 | const walk = (d: string): string[] => | |
| 35 | readdirSync(d, { withFileTypes: true }).flatMap((e) => (e.isDirectory() ? walk(`${d}/${e.name}`) : e.name.endsWith(".ts") ? [`${d}/${e.name}`] : [])); | |
| 36 | const root = new URL("../src", import.meta.url).pathname; | |
| 37 | const reaching = walk(root).filter((f) => !f.startsWith(`${root}/kinds/`) && /minecraft\/(people|player_events|prover)\.ts/.test(readFileSync(f, "utf8"))); | |
| 38 | expect(reaching).toEqual([]); | |
| 39 | }); |
test/kinds.test.ts +4 −2
| @@ -13,11 +13,13 @@ test("a kind is looked up by its name; an unknown name has none", () => { | ||
| 13 | 13 | expect(defaultKind()).toBe(kindNamed("minecraft")!); |
| 14 | 14 | }); |
| 15 | 15 | |
| 16 | test("a kind has all five parts, the unmoved two declared as stubs", () => { | |
| 16 | test("a kind has all five parts, the unmoved one declared as a stub", () => { | |
| 17 | 17 | const k = kindNamed("minecraft")!; |
| 18 | 18 | expect(typeof k.compose.design).toBe("function"); |
| 19 | 19 | expect(typeof k.console.html).toBe("function"); |
| 20 | for (const part of [k.people, k.metrics]) expect(part.stub).toBe(true); | |
| 20 | expect(typeof k.people.peopleOf).toBe("function"); | |
| 21 | expect(typeof k.identity.prove).toBe("function"); | |
| 22 | expect(k.metrics.stub).toBe(true); | |
| 21 | 23 | }); |
| 22 | 24 | |
| 23 | 25 | test("the compose design goes through the kind", () => { |
test/tui-games.test.ts +1 −1
| @@ -27,7 +27,7 @@ import { PINS } from "../src/games/proxy_jars.ts"; | ||
| 27 | 27 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 28 | 28 | import { sha256 } from "../src/kernel/hash.ts"; |
| 29 | 29 | import { synced } from "../src/games/notify.ts"; |
| 30 | import { recordProxyEvents } from "../src/games/player_events.ts"; | |
| 30 | import { recordProxyEvents } from "../src/kinds/minecraft/player_events.ts"; | |
| 31 | 31 | import { gameBoxScreen, gameGrantsScreen, gameServiceScreen, gamesScreen } from "../src/tui/screens/games.ts"; |
| 32 | 32 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| 33 | 33 | import { quietLogs } from "./helpers/globals.ts"; |
new above
offline