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

opened this

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

Review

Sign in to review this change.
33 files changed +270 −135
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:
5050
5151 `/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.
5252
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.
5454
5555 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.
5656
src/games/ask.ts +5 −5
@@ -10,11 +10,11 @@
1010 import type { App } from "../app.ts";
1111 import type { User } from "../core/users.ts";
1212 import { composeServices, serviceEnv } from "./compose.ts";
13 import { peopleOf } from "./people.ts";
14 import { needLines, whyLines } from "./player_events.ts";
1513 import { forcedHosts } from "./presets.ts";
1614 import { proxyOf, proxyPort } from "./sleep.ts";
1715 import { mayDo, roleOn, servicesOf, type GameBox } from "./store.ts";
16 import { peopleAdapter } from "../kinds/index.ts";
17
1818
1919 export type Question =
2020 | { readonly kind: "who" }
@@ -53,16 +53,16 @@ const some = (names: readonly string[]): string =>
5353 export async function answerTo(app: App, user: User, box: GameBox, compose: string, player: string, q: Question, now: Date): Promise<string[]> {
5454 const seen = serversSeen(app, user, box, compose);
5555 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();
5757 if (q.kind === "who") {
5858 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))}.`);
5959 return lines.length === 0 ? ["Nobody is on now."] : lines;
6060 }
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);
6262 if (q.kind === "address") return addressLines(compose, seen);
6363 // Asked again here: the role can go while the question waits.
6464 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);
6666 const s = services.find((x) => x.name === q.service);
6767 if (s?.asleep === true) {
6868 const woke = app.db
src/games/chat.ts +3 −3
@@ -39,14 +39,14 @@ import { composeServices, readCompose, serviceEnv } from "./compose.ts";
3939 import { asksIn, keepAsk, say, takeConfirmed, type Confirmed, type Where } from "./door.ts";
4040 import { holdBuild, type Holding } from "./door_hold.ts";
4141 import { doorOf, lockDoor, windowUsed } from "./write_window.ts";
42 import { defaultKind } from "../kinds/index.ts";
42 import { defaultKind, peopleAdapter } from "../kinds/index.ts";
4343 import { readLines, readOf } from "./forge_read.ts";
4444 import { commitServer, planServer, wishOn } from "./presets.ts";
45 import { peopleOf } from "./people.ts";
4645 import { checksAccounts, OFFLINE_WORDS } from "./reach.ts";
4746 import { proxyOf } from "./sleep.ts";
4847 import { LINES_OUT, listBoxes, mayDo, roleOn, SERVICE_NAME, type GameBox, type Role } from "./store.ts";
4948
49
5050 export const CODE_MS = 10 * 60_000;
5151 /** Said where `newLinkCode` gives none. */
5252 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
147147 * who is online), or "" when the name is not listed there with one.
148148 */
149149 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 ?? "";
151151
152152 /**
153153 * 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";
1919 import { id as newId, secret } from "../kernel/id.ts";
2020 import { sha256 } from "../kernel/hash.ts";
2121 import { versionById, type Result } from "./modrinth.ts";
22 import { playerMods } from "./player_events.ts";
2322 import { modsOf, type Mods } from "./mods.ts";
2423 import { LOG_KEEP, logsOf, type GameBox } from "./store.ts";
24 import { peopleAdapter } from "../kinds/index.ts";
25
2526
2627 export const LINK_DAYS = 30;
2728
@@ -162,7 +163,7 @@ async function buildPack(app: App, box: GameBox, service: string, m: Mods): Prom
162163 : { 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.` };
163164 const loader = loaderOf(m, startLines(app.db, box.id, service));
164165 if (!loader.ok) return loader;
165 const need = await playerMods(app, m);
166 const need = await peopleAdapter().playerMods(app, m);
166167 if (!need.ok) return need;
167168 const mine = need.value.locked.filter((l) => l.path.startsWith("mods/"));
168169 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";
2323 import { composeServices, readCompose } from "./compose.ts";
2424 import { helpLines } from "./chat.ts";
2525 import { readLines } from "./forge_read.ts";
26 import { peopleOf } from "./people.ts";
2726 import { whoMayReach } from "./reach.ts";
2827 import { proxyOf } from "./sleep.ts";
2928 import { mayDo, roleOn, type GameBox } from "./store.ts";
29 import { peopleAdapter } from "../kinds/index.ts";
30
3031
3132 /** How long an answer in the file is good for once it is in place, and how often the file is made again. */
3233 export const SNAPSHOT_TTL_MS = 120_000;
@@ -136,7 +137,7 @@ async function make(app: App, box: GameBox, origin: string, now: number): Promis
136137 );
137138 const on: { uuid: string; userId: string; service: string; player: string }[] = [];
138139 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) {
140141 const link = links.get(bare(p.uuid));
141142 if (link !== undefined && !on.some((o) => o.uuid === link.uuid)) on.push({ uuid: link.uuid, userId: link.user_id, service, player: link.player });
142143 }
src/games/door_leave.ts +4 −3
@@ -9,9 +9,10 @@
99
1010 import type { Database } from "bun:sqlite";
1111 import { createLog } from "../kernel/log.ts";
12 import { networkOf, peopleOf } from "./people.ts";
1312 import { SERVICE_NAME } from "./store.ts";
1413 import { doorOf, lockDoor, locksOnLeave } from "./write_window.ts";
14 import { peopleAdapter } from "../kinds/index.ts";
15
1516
1617 const log = createLog("games");
1718
@@ -22,8 +23,8 @@ export const LEFT_WORDS = "locked: the player who opened the window left the net
2223 function onNetwork(db: Database, boxId: string): Set<string> {
2324 const names = new Set<string>();
2425 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());
2728 return names;
2829 }
2930
src/games/findings.ts +3 −2
@@ -11,7 +11,8 @@
1111 */
1212
1313 import type { Database } from "bun:sqlite";
14 import { peopleOf } from "./people.ts";
14 import { peopleAdapter } from "../kinds/index.ts";
15
1516
1617 export interface Finding {
1718 /**
@@ -97,7 +98,7 @@ export function findingsOf(db: Database, boxId: string, service: string): Findin
9798 // Who is an operator is known only once the agent has read the lists; before that nobody is
9899 // told they were not one.
99100 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));
101102 const groups = new Map<string, { cause: Pick<Cause, "key" | "says" | "fix">; rows: Row[] }>();
102103 // One group a cause; an unnamed cause is one group a reason, so two different strangers' words
103104 // are not "the same trouble".
src/games/forge_read.ts +4 −8
@@ -9,9 +9,11 @@ import type { User } from "../core/users.ts";
99 import type { Ctx } from "../http/context.ts";
1010 import { loadMcp } from "../http/mcp/load.ts";
1111 import { visible } from "../http/mcp/shared.ts";
12 import { peopleOf } from "./people.ts";
1312 import { serversSeen } from "./ask.ts";
1413 import { servicesOf, type GameBox } from "./store.ts";
14 import { peopleAdapter } from "../kinds/index.ts";
15 import { line } from "../kinds/minecraft/plain.ts";
16
1517
1618 export type Read = "status" | "servers";
1719
@@ -21,12 +23,6 @@ export function readOf(words: string): Read | undefined {
2123 return w === "status" || w === "servers" ? w : undefined;
2224 }
2325
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
3026 /** A read-only tool's answer as `user` gets it at /mcp; undefined when it refuses them. */
3127 async function readTool(app: App, user: User, origin: string, name: "now" | "releases", args: Record<string, unknown>): Promise<unknown> {
3228 const { TOOLS } = await loadMcp();
@@ -56,7 +52,7 @@ function serverLines(app: App, user: User, box: GameBox, compose: string): strin
5652 return rows.map((s) => {
5753 if (s.asleep) return `${s.name}: asleep, wakes when someone joins`;
5854 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;
6056 // 0 MiB while running is a reading the agent could not take.
6157 const memory = s.memMiB > 0 ? `, ${(s.memMiB / 1024).toFixed(1)} GB` : "";
6258 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 @@
88 import type { Database } from "bun:sqlite";
99 import { isIP } from "node:net";
1010 import { isPublicAddress } from "../apps/egress.ts";
11 import { peopleOf } from "./people.ts";
1211 import type { Power } from "./power.ts";
1312 import { commandOf, type GameService } from "./store.ts";
13 import { peopleAdapter } from "../kinds/index.ts";
14
1415
1516 const DOING: Record<Power, string> = { start: "Starting", stop: "Stopping", restart: "Restarting", recreate: "Rebuilding", pull: "Updating" };
1617 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
104105
105106 /** Who is on, server by server. Servers nobody is on are left out. */
106107 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);
108109 }
109110
110111 /**
src/games/heal.ts +3 −2
@@ -9,9 +9,10 @@
99
1010 import type { Database } from "bun:sqlite";
1111 import { playerEvents } from "./metrics.ts";
12 import { networkOf } from "./people.ts";
1312 import { proxyOf } from "./sleep.ts";
1413 import { queueCommand, servicesOf, SERVICE_NAME, type GameBox } from "./store.ts";
14 import { peopleAdapter } from "../kinds/index.ts";
15
1516
1617 /** Tries a service gets in `WINDOW_MS`. */
1718 export const TRIES = 2;
@@ -104,7 +105,7 @@ export function heal(db: Database, box: Pick<GameBox, "id">, composeText: string
104105 const asleep = services.filter((s) => s.asleep).map((s) => s.name);
105106 const proxy = composeText === undefined ? undefined : proxyOf(composeText);
106107 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);
108109 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);
109110 }
110111 const lost = db
src/games/plugin_config.ts +3 −2
@@ -37,8 +37,9 @@ import type { User } from "../core/users.ts";
3737 import { lineDiff, type DiffLine } from "../web/render/json-doc.ts";
3838 import { commitCompose, composeHistory, readCompose, readRepoFile, setServiceEnv, setServiceLabels, setServiceListItem, setTopEntry } from "./compose.ts";
3939 import type { Result } from "./modrinth.ts";
40 import { peopleOf } from "./people.ts";
4140 import type { GameBox } from "./store.ts";
41 import { peopleAdapter } from "../kinds/index.ts";
42
4243
4344 /** Where a file lives: the compose file and a pointer into it. */
4445 export interface ConfigRef {
@@ -319,7 +320,7 @@ const count = (n: number, one: string, many: string): string => `${String(n)} ${
319320
320321 /** The sentence before a commit: the server restarts to read the file, and who is on it. */
321322 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);
323324 const who =
324325 online.length === 0
325326 ? "nobody is online"
src/games/reach.ts +3 −2
@@ -14,9 +14,10 @@ import type { Database } from "bun:sqlite";
1414 import type { User } from "../core/users.ts";
1515 import { getUserById, isActive } from "../core/users.ts";
1616 import { composeServices, serviceEnv } from "./compose.ts";
17 import { peopleOf } from "./people.ts";
1817 import { proxyOf } from "./sleep.ts";
1918 import { mayDo, queueCommand, roleOn, type GameBox } from "./store.ts";
19 import { peopleAdapter } from "../kinds/index.ts";
20
2021
2122 /** The words a player hears when the network lets any name in. */
2223 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
102103 );
103104 const plan: { service: string; op: "whitelist-add" | "whitelist-remove"; player: string }[] = [];
104105 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);
106107 const has = new Set(listed.map((n) => n.toLowerCase()));
107108 const allowed = new Set(may.map((n) => n.toLowerCase()));
108109 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 @@
77 import type { App } from "../app.ts";
88 import { getUserById } from "../core/users.ts";
99 import { readCompose } from "./compose.ts";
10 import { peopleOf } from "./people.ts";
1110 import { commitJar, pinOf } from "./proxy_jars.ts";
1211 import { proxyOf } from "./sleep.ts";
1312 import { mayDo, roleOn, servicesOf, type GameBox } from "./store.ts";
13 import { peopleAdapter } from "../kinds/index.ts";
14
1415
1516 export const QUIET_MINUTES = 30;
1617 const QUIET_MS = QUIET_MINUTES * 60_000;
@@ -55,7 +56,7 @@ export function isQuiet(app: App, box: Pick<GameBox, "id">, now = Date.now()): b
5556 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);
5657 const fresh = (at: string | null): boolean => at !== null && now - Date.parse(at) <= FRESH_MS;
5758 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;
5960 // The event's time is the forge's own receive time, not the box's clock; one that does not read is not quiet.
6061 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;
6162 if (last === null || last === undefined) return true;
src/http/games_routes.ts +5 −5
@@ -13,14 +13,12 @@ import { heal } from "../games/heal.ts";
1313 import { synced } from "../games/notify.ts";
1414 import { auditShellResults } from "../games/shell.ts";
1515 import { recordMetrics } from "../games/metrics.ts";
16 import { recordPeople } from "../games/people.ts";
1716 import { followGrants } from "../games/reach.ts";
1817 import { gameAsk, gameChat, runChat } from "../games/chat.ts";
1918 import { snapshotFor } from "../games/desk_snapshot.ts";
2019 import { toldGot, toldTo } from "../games/door.ts";
2120 import { packChecks } from "../games/pack_check.ts";
2221 import { lendAnswer } from "../games/lend.ts";
23 import { recordProxyEvents, tellRefused } from "../games/player_events.ts";
2422 import { proxyOf, sleeping } from "../games/sleep.ts";
2523 import { jarsOf } from "../games/proxy_jars.ts";
2624 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";
4038 import { InvalidJson } from "./json_body.ts";
4139 import { apiError, boundedMachineBody, json } from "./respond.ts";
4240 import type { Router } from "./router.ts";
41 import { peopleAdapter } from "../kinds/index.ts";
42
4343
4444 /**
4545 * 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> {
103103 } catch (e) {
104104 ctx.app.log.warn("game agent watch failed", { error: String(e) });
105105 }
106 recordPeople(ctx.app.db, box, body.people);
106 peopleAdapter().record(ctx.app.db, box, body.people);
107107 // A pack server's files against its lockfile: the answers judged, a check asked where one is due.
108108 if (body.boot === undefined) await packChecks(ctx.app, box, body);
109109 const compose = await readCompose(ctx.app, box);
@@ -112,9 +112,9 @@ export async function gameAgentSync(ctx: Ctx): Promise<Response> {
112112 // A server its sleep stopped is asleep, not down: the compose file says which sleep.
113113 markAsleep(ctx.app.db, box.id, compose === undefined ? [] : sleeping(compose.text));
114114 // 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));
116116 // 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) }));
118118 // What is safe is mended alone and said (`games/heal.ts`): a stuck wake, a lost start, with a
119119 // limit.
120120 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";
1818 import { ALIASES, commitServer, LEVELS, planRemoveServer, planServer, wishOn, type Level } from "../../../games/presets.ts";
1919 import { commitPolicy } from "../../../games/sleep.ts";
2020 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";
2321 import { linkShown } from "../../../games/snapshots.ts";
2422 import { verdictsOf } from "../../../games/set_verdict.ts";
2523 import { takeBack } from "../../../games/take_back.ts";
@@ -28,6 +26,8 @@ import { queueWorld } from "../../../games/worlds.ts";
2826 import { principalOf } from "../../../core/principal.ts";
2927 import { mayOnGame, seesGameBox } from "../../../games/game_may.ts";
3028 import { neutralArgs } from "../../../games/neutral_args.ts";
29 import { peopleAdapter } from "../../../kinds/index.ts";
30
3131
3232 export const tool: Tool = {
3333 name: "games",
@@ -38,7 +38,7 @@ export const tool: Tool = {
3838 type: "object",
3939 properties: {
4040 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"] },
4242 player: { type: "string", maxLength: 17 },
4343 to: { type: "string", maxLength: 64 },
4444 window: { type: "string", enum: Object.keys(WINDOWS) },
@@ -263,11 +263,11 @@ export const tool: Tool = {
263263 if (action === "people") {
264264 const op = str(args["op"]);
265265 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) });
268268 }
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);
271271 }
272272 if (action === "config_set") {
273273 const plan = await previewSettings(ctx.app, box, service, { [str(args["key"])]: str(args["value"]) });
src/kinds/index.ts +7 −1
@@ -1,6 +1,6 @@
11 /** The kinds the forge knows, found by name. The only door the general layer uses to reach one. */
22
3 import type { Kind } from "./kind.ts";
3 import type { Kind, PeopleAdapter } from "./kind.ts";
44 import { minecraft } from "./minecraft/index.ts";
55
66 const KINDS: readonly Kind[] = [minecraft];
@@ -16,3 +16,9 @@ export function kindNamed(name: string): Kind | undefined {
1616 export function defaultKind(): Kind {
1717 return kindNamed("minecraft") ?? minecraft;
1818 }
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 @@
44 * a kind's directory, so what is specific to one game (Minecraft's compose design, its console,
55 * RCON) stays in `src/kinds/<name>/`.
66 *
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.
1010 */
1111
1212 import type { Database } from "bun:sqlite";
1313 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";
1419 import type { AccountLink } from "../core/account_link.ts";
1520 import type { DnsWant, MachineWant } from "../cloud/plan.ts";
1621 import type { Result } from "../kernel/result.ts";
@@ -82,8 +87,75 @@ export interface Stub {
8287 readonly livesIn: string;
8388 }
8489
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
87159 /**
88160 * Part 4: proof that a person owns a name in the game (#18490). The proof is one row of
89161 * `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 @@
11 /**
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
33 * still in `src/games`.
44 */
55
@@ -7,6 +7,8 @@ import type { Kind } from "../kind.ts";
77 import { consoleHtml, consoleText, crashOf, shareOnMclogs } from "./console.ts";
88 import { hear } from "./command.ts";
99 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";
1012 import { minecraftProver } from "./prover.ts";
1113 import { say } from "./speak.ts";
1214
@@ -14,7 +16,25 @@ export const minecraft: Kind = {
1416 name: "minecraft",
1517 compose: { design: minecraftDesign },
1618 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 },
1838 identity: minecraftProver,
1939 metrics: { stub: true, livesIn: "src/games/metrics.ts" },
2040 };
src/games/people.ts → src/kinds/minecraft/people.ts renamed +7 −26
@@ -11,33 +11,14 @@
1111 */
1212
1313 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";
2021
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 }
4122
4223 const NONE: People = { whitelist: [], ops: [], bans: [], whitelistOn: false };
4324 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 @@
1414 */
1515
1616 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";
2425
2526 /** How far back refusals count towards a finding. */
2627 const FINDING_MS = 24 * 3_600_000;
@@ -43,10 +44,18 @@ export interface ProxyFact {
4344 /** Velocity's own words for a connection that closed before a reason came: no server said them. */
4445 const NO_REASON = "An internal server connection error occurred.";
4546 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));
5059 const V4 = "\\d{1,3}(?:\\.\\d{1,3}){3}";
5160 const HEXES = "[0-9a-f]{1,4}(?::[0-9a-f]{1,4})*";
5261 /**
@@ -185,13 +194,6 @@ export function recordProxyEvents(db: Database, box: Pick<GameBox, "id">, logs:
185194 })();
186195 }
187196
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 }
195197
196198 /** What a player's own game needs to join a mod server. */
197199 export interface PlayerSet {
src/kinds/minecraft/speak.ts +1 −1
@@ -7,7 +7,7 @@
77 * ever a `text` field: never a command or an event.
88 */
99
10 import { line as plain } from "../../games/forge_read.ts";
10 import { line as plain } from "./plain.ts";
1111
1212 interface Component {
1313 readonly text: string;
src/tui/screens/games.ts +8 −8
@@ -28,10 +28,8 @@ import { watchBox } from "../../games/notify.ts";
2828 import { containersIn, figuresOf } from "../../cloud/containers.ts";
2929 import { joinAddress, NO_ADDRESS, nowWords, powerNow, PREVIEW_WORDS, privateWords, SAVE_WORDS } from "../../games/gist.ts";
3030 import { findingLine, findingsOf as kickFindingsOf } from "../../games/findings.ts";
31 import { eventsOf, eventWords, isBedrock, peopleOf, peopleWords, queuePeople } from "../../games/people.ts";
3231 import { leaveCannotLock } from "../../games/door_leave.ts";
3332 import { openDoorWords } from "../../games/reach.ts";
34 import { findingsOf } from "../../games/player_events.ts";
3533 import { queueWorld, type WorldOp } from "../../games/worlds.ts";
3634 import { lendWords, lentRunnerOf, setLend } from "../../games/lend.ts";
3735 import { lendCannot } from "../../games/lend_why.ts";
@@ -84,6 +82,8 @@ import { gameModsScreen } from "./game_mods.ts";
8482 import { gameSparkScreen } from "./game_spark.ts";
8583 import { principalOfUser } from "../../core/principal.ts";
8684 import { mayOnGame } from "../../games/game_may.ts";
85 import { peopleAdapter } from "../../kinds/index.ts";
86
8787
8888 /** "4 online · 19.8 TPS · 3.1 ms tick" from the last hour's numbers, or nothing before any. */
8989 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
367367 // What still waits; an answer stands in the log, under the line it came after.
368368 return blocks().filter((b) => b.at === "").flatMap(blockLines);
369369 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" : ""}`;
372372 return [
373373 ...held(),
374374 nowWords(servicesOf(f.app.db, box.id).find((x) => x.name === service), powerNow(f.app.db, box.id, service)),
375375 figuresOf(f.app.db, f.user, boxNamed(f.app.db, box.name) ?? box, service),
376376 ...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}`)]),
378378 online.length === 0 ? `Nobody is on ${service} right now.` : `Online: ${online.map((p) => tag(p.name)).join(", ")}`,
379379 `${lists.whitelistOn ? "Only listed players may join" : "Anyone may join"} · ${lists.whitelist.length} listed · ${lists.ops.length} operators · ${lists.bans.length} banned`,
380380 ...[openDoorWords(lists.whitelistOn) ?? []].flat(),
381381 ...lists.bans.map((b) => `banned: ${b.name}${b.reason === "" ? "" : ` (${b.reason})`}`),
382382 ...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)}`),
384384 "p: op (make operator), deop, whitelist-add (let in), whitelist-remove, ban, pardon (lift a ban), kick <player>, or move <player> <server>",
385385 ];
386386 }
@@ -489,9 +489,9 @@ export function gameServiceScreen(f: Session, ctx: Ctx, box: GameBox, service: s
489489 else if (e.key === "p")
490490 ask("Player", "op | deop | whitelist-add | whitelist-remove | ban | pardon | kick <player>, or move <player> <server>", async (raw) => {
491491 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);
493493 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;
495495 });
496496 else if (e.key === "m") ctx.push(gameModsScreen(f, ctx, box, service));
497497 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";
7373 import { notFoundPage, pageHead, signInFirst } from "../chrome.ts";
7474 import { field, readForm, type Form } from "../form.ts";
7575 import { html, type Html } from "../html.ts";
76 import { defaultKind, peopleAdapter } from "../../kinds/index.ts";
77 import type { GameFinding } from "../../kinds/kind.ts";
7678 import { containerPower } from "./container_power.ts";
77 import { defaultKind } from "../../kinds/index.ts";
7879 import { answerAfter, gameLogAfter, gameLogAge, gameLogPage } from "../../logs/game.ts";
7980 import { ageWords } from "../../logs/page.ts";
8081 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";
9192 import { passkeyJs } from "../passkey-client.ts";
9293 import { windowNote } from "../../games/write_window.ts";
9394 import { defaultHeadResponse, headResponse } from "../../games/heads.ts";
94 import { eventsOf, eventWords, isBedrock, knowsPlayer, peopleOf, peopleWords, queuePeople, UNDO, type PeopleOp } from "../../games/people.ts";
9595 import { openDoorWords } from "../../games/reach.ts";
9696 import { queueWorld, undoOf } from "../../games/worlds.ts";
9797 import { START_BOX } from "../../core/empty_words.ts";
9898 import { emptyLine, emptyNote } from "../empty_words.ts";
99 import { findingsOf, type GameFinding } from "../../games/player_events.ts";
10099 import { findingsOf as kickFindingsOf } from "../../games/findings.ts";
101100 import { containersIn, figuresOf } from "../../cloud/containers.ts";
102101 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";
105104 import { principalOf } from "../../core/principal.ts";
106105 import { drawsOperator, mayOnGame, seesGameBox } from "../../games/game_may.ts";
107106
107
108108 /** A small line of a series (oldest first); nothing when no point is known. */
109109 const sparkOf = (points: readonly Point[], pick: (p: Point) => number | null, label: string): Html | null =>
110110 daySpark(points.map(pick), label);
@@ -607,7 +607,7 @@ export async function gameServicePage(ctx: Ctx): Promise<Response> {
607607 return after === null ? [] : [{ ...b, after }];
608608 });
609609 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);
611611 // Settings: each as the compose file says; a "Preview" (s.<key>=value in the query) planned on it.
612612 const settings = compose === undefined ? [] : settingsOf(compose.text, service, env);
613613 const wanted = settingsWanted(ctx.url.searchParams);
@@ -1292,10 +1292,10 @@ export async function gameSleepSubmit(ctx: Ctx): Promise<Response> {
12921292
12931293 /** A player's head and name, with a Bedrock badge for a Floodgate player. */
12941294 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}`;
12961296
12971297 /** 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 =>
12991299 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>`;
13001300
13011301 /**
@@ -1304,8 +1304,8 @@ const peopleButton = (base: string, op: PeopleOp, player: string, label: string)
13041304 * is seen by nobody without a grant.
13051305 */
13061306 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);
13091309 const base = `/games/${box.name}/${service}`;
13101310 const isOp = (n: string) => lists.ops.some((o) => o.name === n);
13111311 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
13351335 ${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}
13361336 ${events.length === 0
13371337 ? null
1338 : html`<h3>Latest</h3>${rowList(events.map((e) => row({ title: e.kind === "chat" ? html`<span class="mono">&lt;${e.player}&gt;</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">&lt;${e.player}&gt;</span> ${e.text}` : peopleAdapter().eventWords(e, service), meta: time(e.at) })))}`}
13391339 </section>`;
13401340 }
13411341
@@ -1345,12 +1345,12 @@ export async function gamePeopleSubmit(ctx: Ctx): Promise<Response> {
13451345 if (got instanceof Response) return got;
13461346 const op = field(got.form, "op");
13471347 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];
13501350 return flashTo(
13511351 ctx,
13521352 `/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 },
13541354 );
13551355 }
13561356
@@ -1358,7 +1358,7 @@ export async function gamePeopleSubmit(ctx: Ctx): Promise<Response> {
13581358 // only, and only for a player the forge has seen on a server this person sees; anyone else's is the default.
13591359 export function gameHead(ctx: Ctx): Promise<Response> | Response {
13601360 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();
13621362 return headResponse(ctx.app, uuid);
13631363 }
13641364
src/web/pages/games_topology.ts +5 −4
@@ -8,13 +8,14 @@
88
99 import type { Ctx } from "../../http/context.ts";
1010 import { metricsSeries } from "../../games/metrics.ts";
11 import { isBedrock, networkOf, peopleOf } from "../../games/people.ts";
1211 import { isGameServer, proxyOf } from "../../games/sleep.ts";
1312 import { drawsOperator } from "../../games/game_may.ts";
1413 import { principalOf } from "../../core/principal.ts";
1514 import { servicesOf, type GameBox, type GameService } from "../../games/store.ts";
1615 import { html, type Html } from "../html.ts";
1716 import { btn } from "../ui.ts";
17 import { peopleAdapter } from "../../kinds/index.ts";
18
1819
1920 export const TOPOLOGY_CSS = `/* ---- the network (#17284 G5): the proxy, a line down, the servers under it ---- */
2021 .net { display: grid; gap: 16px; justify-items: center; }
@@ -70,11 +71,11 @@ export function topologyBlock(ctx: Ctx, box: GameBox, compose: string | undefine
7071 if (compose === undefined || proxy === undefined) return html``;
7172 const seen = servicesOf(ctx.app.db, box.id);
7273 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);
7475 // Each player's UUID from the server they are on (its `list uuids`), for their head.
7576 const uuidOf = new Map<string, string>();
7677 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);
7879 for (const p of online) uuidOf.set(p.name, p.uuid);
7980 return network[n] ?? online.map((p) => p.name);
8081 };
@@ -83,7 +84,7 @@ export function topologyBlock(ctx: Ctx, box: GameBox, compose: string | undefine
8384 const proxyState = netState(seen.find((s) => s.name === proxy));
8485 const head = (server: string, name: string, act: boolean): Html => {
8586 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" />`;
8788 // Only to a server this person operates too: the move's own rule (`queuePeople`).
8889 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));
8990 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";
1313 import { chatCommand } from "../src/games/chat.ts";
1414 import { findingsOf } from "../src/games/findings.ts";
1515 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";
1717 import { AGENT_SH } from "../src/games/boot.ts";
1818 import { boxNamed, commandOf, createGameBox, logsOf, queueCommand, recordSync, type GameBox } from "../src/games/store.ts";
1919 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";
1616 import { createUser, type User } from "../src/core/users.ts";
1717 import { DEFAULT_HEAD, FETCHES_MAX, HEAD_KEPT_MS, headResponse, MISS_MS } from "../src/games/heads.ts";
1818 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";
2020 import { boxNamed, commandOf, createGameBox, grant, recentCommands } from "../src/games/store.ts";
2121 import { forgeHttp, type ForgeHttp } from "../src/http/server.ts";
2222 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";
1212 import { createSession } from "../src/core/sessions.ts";
1313 import { createToken } from "../src/core/tokens.ts";
1414 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";
1717 import { waitFor } from "./helpers/poll.ts";
1818 import { boxNamed, createGameBox, grant, type GameBox } from "../src/games/store.ts";
1919 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";
1414 import { createUser, getUserByName, type User } from "../src/core/users.ts";
1515 import { clientProjects, playerSide, type Locked, type Project } from "../src/games/modrinth.ts";
1616 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";
1818 import { boxNamed, createGameBox, type GameBox } from "../src/games/store.ts";
1919 import { quietLogs } from "./helpers/globals.ts";
2020
test/game-topology.test.ts +1 −1
@@ -13,7 +13,7 @@ import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1313 import { createSession } from "../src/core/sessions.ts";
1414 import { createToken } from "../src/core/tokens.ts";
1515 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";
1717 import { proxyOf, WAKER } from "../src/games/sleep.ts";
1818 import { createGameBox, grant, boxNamed, recentCommands } from "../src/games/store.ts";
1919 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", () => {
1313 expect(defaultKind()).toBe(kindNamed("minecraft")!);
1414 });
1515
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", () => {
1717 const k = kindNamed("minecraft")!;
1818 expect(typeof k.compose.design).toBe("function");
1919 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);
2123 });
2224
2325 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";
2727 import { createForgeApp } from "../src/tui/forge.ts";
2828 import { sha256 } from "../src/kernel/hash.ts";
2929 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";
3131 import { gameBoxScreen, gameGrantsScreen, gameServiceScreen, gamesScreen } from "../src/tui/screens/games.ts";
3232 import { headlessTerminal } from "../src/tui/term/terminal.ts";
3333 import { quietLogs } from "./helpers/globals.ts";

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs