From 8a589695bd5ef0ce59789bacd23dc7bfd254328e Mon Sep 17 00:00:00 2001 From: jbob0 Date: Thu, 12 Nov 2026 11:01:20 -0500 Subject: [PATCH] Chat tab: read a Season 3 server's in-game chat Season 3 (CL-533689) serves the current map's chat over RCON: GET /v1/chat with ?after=, and Bulkhead's terms at GET/POST /v1/chat/terms. Three actions read and accept them: chat and chatTerms need Chat (never View alone, since chat is players' words under their real names), and chatTermsAccept needs Config & settings, as the game saves the acceptance in its config. The server's new Chat tab polls with after, newest last, and reads the map again from the start when the numbering goes back. Until the terms are accepted it shows them, with Accept for those who may apply the config. Nothing is stored. The demo server serves the three routes, and MOCK_LIVE_BUILD leaves them out. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DtMArSWCQVUG3qWgzi2Ebi --- README.md | 25 ++- docs/wardogs-api.md | 48 ++++- src/lib/capabilities.ts | 2 +- src/lib/chat.test.ts | 60 ++++++ src/lib/chat.ts | 60 ++++++ src/lib/server/actions.test.ts | 145 +++++++++++++ src/lib/server/actions.ts | 59 ++++++ src/lib/server/mockgame.ts | 81 +++++++- src/routes/(app)/server/[id]/+layout.svelte | 1 + .../(app)/server/[id]/chat/+page.svelte | 195 ++++++++++++++++++ src/test/action-matrix.test.ts | 3 + 11 files changed, 670 insertions(+), 9 deletions(-) create mode 100644 src/lib/chat.test.ts create mode 100644 src/routes/(app)/server/[id]/chat/+page.svelte diff --git a/README.md b/README.md index a2da77ff..5d6a0e3b 100644 --- a/README.md +++ b/README.md @@ -336,7 +336,7 @@ site owner hold every capability on every server in scope. | Capability | Unlocks | viewer | operator | admin | | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- | ----- | | View | what is happening on the server: status, players, kills, rotation, who is banned and who holds a reserved slot, analytics, leaderboards, player stats. Every role has it. | ✓ | ✓ | ✓ | -| Chat | broadcast; whisper one player, several, or everyone on a faction; pick from the organisation's saved messages | | ✓ | ✓ | +| Chat | broadcast; whisper one player, several, or everyone on a faction; pick from the organisation's saved messages; read the current map's in-game chat (Season 3) | | ✓ | ✓ | | Kick | kick a player; the rules that kick or flag players | | ✓ | ✓ | | Kill | kill a player's character; AFK protection, and a Kill distance watch that kills | | ✓ | ✓ | | Move | move a player to another team, which kills them so they respawn on it (a move to the side they are on is refused); arrange the teams on the Players tab, which moves without the kill; a Team balance rule | | ✓ | ✓ | @@ -505,6 +505,20 @@ their detail, which tells them from another sending of the same text, and a sear the message finds them. Each server counts as one of the 120 game actions a minute a person or key may send. +### In-game chat + +A server on Season 3 or later serves what its players say, and its **Chat** tab shows it: the +current map's lines, newest last, each with its time, channel, faction, the player's real name +(a link to their dossier) and the anonymised name other players see. The tab reads new lines every +5 seconds while it is open, and starts empty again when the map changes, because that is when the +game server empties its own. Warcon does not store chat: it is read from the game server while +someone has the tab open, and the audit trail keeps no line of it. + +Reading chat needs _Chat_, the capability that broadcasts and whispers, so a role with View alone +cannot. Bulkhead gives chat only on terms, which each server accepts once: until then the tab shows +the terms, with **Accept** for those whose role includes _Config & settings_ (the game server saves +the acceptance in its config), and everyone else is told an admin has to accept them. + ### Players online The **Players** page in the header lists everyone on the organisation's servers in one table: each @@ -1442,6 +1456,8 @@ game's (a 401 or a 5xx from it becomes a 502), and `error` carries the game's `c | `broadcast` | Chat | `message` | | `whisper` | Chat | `steamId`, `message` | | `whisperMany` | Chat | `message`, and either `faction` or `steamIds` (a list, up to 200) | +| `chat` | Chat | `after` (optional: only the lines numbered above it); the current map's in-game chat, Season 3 builds | +| `chatTerms` | Chat | none (Bulkhead's terms for reading chat, and whether they are accepted) | | `kick` | Kick | `steamId`, `reason` (optional) | | `kill` | Kill | `steamId` | | `changeTeam` | Move | `steamId`, `faction`; the player is killed so they respawn on that side, unless `kill` is `false` (the move alone) | @@ -1460,6 +1476,7 @@ game's (a 401 or a 5xx from it becomes a 502), and `error` carries the game's `c | `settings` | Config & settings | `scoreTick` (1 to 600), `rotationEnabled`, `rotationMode` | | `config` | Config & settings | none (the config document, credentials as `(hidden)`) | | `feed` | Config & settings | none (the game's report on its kill feed, Season 2 builds; see [Kill feed](#kill-feed)) | +| `chatTermsAccept` | Config & settings | `version` (the `requiredVersion` that `chatTerms` reads) | | `configValidate`, `configApply` | Config & settings | `text`; apply also `revision`, `force`, `fullApply` | | `serverLog` | Audit trail | `limit` (1 to 500, default 50) | | `raw` | Raw RCON | `method`, `path` (a `/v1` route), `body` | @@ -1946,11 +1963,11 @@ GET /api/steam/profiles?ids=a,b GET /api/health Actions, by the capability each needs: `capabilities status health serverId players maps lightings experiences alternators catalog rotation bans reserved sponsor` (View) · -`broadcast whisper whisperMany` (Chat) · `kick` (Kick) · `kill` (Kill) · `changeTeam` (Move) · `endMatch restartMatch +`broadcast whisper whisperMany chat chatTerms` (Chat) · `kick` (Kick) · `kill` (Kill) · `changeTeam` (Move) · `endMatch restartMatch changeMap setWeather setNextMap` (Match control) · `rotationAdd rotationRemove rotationMove rotationReorder` (Live rotation) · `ban unban` (Bans) · `reservedAdd reservedRemove` (Reserved -slots) · `rotationSave rotationSettings` (Save rotation) · `config feed settings configValidate configApply` (Config & -settings) · `serverLog` (Audit trail) · `raw` (Raw RCON). +slots) · `rotationSave rotationSettings` (Save rotation) · `config feed chatTermsAccept settings configValidate configApply` +(Config & settings) · `serverLog` (Audit trail) · `raw` (Raw RCON). ## Notes and limits diff --git a/docs/wardogs-api.md b/docs/wardogs-api.md index ca505320..fe53223f 100644 --- a/docs/wardogs-api.md +++ b/docs/wardogs-api.md @@ -76,6 +76,9 @@ Warcon, and Warcon's own process talks plain HTTP to the listener. | GET | `/v1/config` | | `{ revision, writable, text, sections:[{section, appliesWhen, description, allowedKeys[], keyOverrides:[{key, appliesWhen, description, writable, lockedBy}]}], warnings[] }` (+ `ETag`) | Whole `ServerSettings.ini`. **CL-501228** adds `writable` and `lockedBy` per key override: a key pinned by a launch argument (`ServerName` by `-RCON_FixedServerName`, `Port` by `-RCONPort` on the TLR host) comes back `writable:false` with the switch in `lockedBy` and "Pinned by -RCONPort on this server's command line. The value is shown but cannot be changed here." The console shows a "Fixed" badge and disables the input; Warcon does the same (`lockedFor` / `lockedKeys` in `src/lib/config-fields.ts`) and lists pinned keys under the document. CL-499480's schema (mirrored in `mockgame.ts`): `WDGameSession` applied (`ServerImageURL` pending, password and join limits applied on the next session update), `Engine.GameSession` next-restart, `WDGameStateSession` / `KOTH` / `PreMatch` next-match, rotation applied ("rebuilt immediately; used from the next map change"), `WDRCONSettings` and `WDServerFeed` next-restart. | | POST | `/v1/config/validate` | text/plain ini | apply result | Dry run. | | PUT | `/v1/config?force=true&fullApply=true` | text/plain ini, `If-Match: "rev"` | `{ ok, revision, outcomes:[{section,state,detail}], shadowed[], stripped[], errors[], changed[], conflict[], warnings[], timingsMs }` | `state` ∈ `applied`, `next-match`, `next-restart`, `pending`. 412 on revision mismatch unless `force`. | +| GET | `/v1/chat?after=N` | | `{ latestSeq, messages:[{seq, sentUtc, channel, faction, steamId, realName, hiddenName, anonymous, text, rawText, ping}], count }` | **New in Season 3 (CL-533689).** The current map's chat, from the server's memory: a map load empties it and `seq` starts again at 1. Empty until the chat terms are accepted. See [Season 3](#season-3-live-build-cl-533689-read-2026-11-12). Warcon action `chat`. | +| GET | `/v1/chat/terms` | | `{ requiredVersion, acceptedVersion, accepted, text }` | **Season 3.** Bulkhead's terms for reading chat. Warcon action `chatTerms`. | +| POST | `/v1/chat/terms` | `{ version }` | `{ ok, pending, message }` | **Season 3.** Accepts the terms; saved as `AcceptedChatTermsVersion`. Warcon action `chatTermsAccept`. | "Set as next map" is not a route: the console finds (or adds) the selection in the rotation and moves it into the slot after the `now` entry with repeated `/move` calls. Warcon does the same server-side. @@ -125,6 +128,48 @@ player list's fields were not seen (the server was empty). The RCON block's `all section allows one, so hosts set it outside `ServerSettings.ini`, and no route reports it. Whispers and broadcasts are capped (see `/v1/broadcast` above). +### Season 3, live build CL-533689 (read 2026-11-12) + +Season 3 serves what players say in chat. `GET /v1/capabilities` lists three new routes, +`GET /v1/chat`, `GET /v1/chat/terms` and `POST /v1/chat/terms`. Read on a live server: + +``` +GET /v1/chat +{ "latestSeq": 7, "count": 6, "messages": [ + { "seq": 7, "sentUtc": "2026-11-12T15:39:29.145Z", "channel": "Global", "faction": "Manticore", + "steamId": "7656119…", "realName": "…", "hiddenName": "Pig", "anonymous": false, + "text": "howdy, and yeah", "rawText": "howdy, and yeah", "ping": false } ] } +``` + +* `channel` was `Team` or `Global`. `hiddenName` is the anonymised name other players see; + `realName` is the player's own. What `anonymous`, `rawText` (beside `text`) and `ping` mean was + not seen: every line read had `anonymous:false`, `ping:false` and `rawText` the same as `text`. +* `?after=N` answers only the lines with `seq` above N (`after=5` gave 6 and 7). `?limit=n` + answers the **oldest** n, so it is no way to read the newest. `since`, `afterSeq`, `sinceSeq` + and `fromSeq` are ignored. +* The lines are held in the server's memory for the **current map only**. A map load empties + them and `seq` starts again at 1 (after a match restart, seq 1 was a new line). Nothing is kept + for the host by Bulkhead. A reader polling with `after` must notice the numbering going back: + Warcon asks from one before the last line it holds and checks that line comes back + (`mergeChat` in `src/lib/chat.ts`), which also catches a new map that has already passed the + old one's count. +* Reading chat is gated by Bulkhead's terms. `GET /v1/chat/terms` answers + `{ requiredVersion:1, acceptedVersion:0, accepted:false, text }`, the text beginning "Read these + terms before viewing this server's chat." and saying that chat is given only to moderate the + server, is not stored for the host, must not be recorded, stored, exported, published or shared + beyond what moderation needs, and that access may be revoked for misuse. + `POST /v1/chat/terms` with `{ "version": 1 }` answered + `{ ok:true, pending:false, message:"OK: chat terms accepted and saved." }`. Until then + `GET /v1/chat` is empty and `GET /v1/feed` reports `"pausedForTerms": true`. The accepted + version is kept as `AcceptedChatTermsVersion` under `[/Script/WDRCON.WDRCONSettings]` + (`next-restart` in `GET /v1/config`'s sections). + +Warcon reads chat with the `chat` action (Chat capability, the one that broadcasts and whispers), +shows it on the server's Chat tab while the tab is open, and stores none of it. The terms are +read with `chatTerms` (Chat) and accepted with `chatTermsAccept` (Config & settings). The demo +server serves the three routes (a line every 8 seconds, emptied at each map change) and +`MOCK_LIVE_BUILD=true` leaves them out. + ## ServerSettings.ini keys the server honours ``` @@ -136,7 +181,8 @@ Whispers and broadcasts are capped (see `/v1/broadcast` above). [/Script/WDGame.WDGameStateSession] bLockOverpopulatedTeamsConfig, OverpopulatedTeamThresholdConfig [/Script/WDGame.WDServerMapRotationSettings] bEnabled, RotationMode, +RotationEntries=(Map="",Experience(s)="",Lighting="",ZoneAlternator="") [/Script/WDRCON.WDRCONSettings] bEnabled, BindAddress, Port, Password, PasswordHash, AllowedOrigins, AllowedHosts (CL-507060; - CL-501228 had bWriteAuditLogFile instead) + CL-501228 had bWriteAuditLogFile instead), AcceptedChatTermsVersion + (Season 3, CL-533689; next-restart; set by POST /v1/chat/terms) [WDServerFeed] Url, Token (CL-499480: "kill-event feed endpoint and its ingest token") ``` diff --git a/src/lib/capabilities.ts b/src/lib/capabilities.ts index 0a8b435f..13833c61 100644 --- a/src/lib/capabilities.ts +++ b/src/lib/capabilities.ts @@ -54,7 +54,7 @@ export const CAPABILITY_INFO: Record = { }, 'chat.send': { label: 'Chat', - hint: 'Broadcast to everyone; whisper a player, several, or a faction.', + hint: "Broadcast to everyone; whisper a player, several, or a faction; read the current map's in-game chat.", group: 'play' }, 'players.kick': { label: 'Kick', hint: 'Kick a player off the server.', group: 'play' }, diff --git a/src/lib/chat.test.ts b/src/lib/chat.test.ts new file mode 100644 index 00000000..af821f8f --- /dev/null +++ b/src/lib/chat.test.ts @@ -0,0 +1,60 @@ +import { describe, expect, test } from 'bun:test'; +import { chatAfter, mergeChat, type ChatMessage } from './chat'; + +const line = (seq: number, sentUtc = `2026-11-12T15:00:0${seq % 10}.000Z`): ChatMessage => ({ + seq, + sentUtc, + channel: 'Team', + faction: 'Valkyra', + steamId: '76561198000000001', + realName: 'Real', + hiddenName: 'Pig', + anonymous: false, + text: `line ${seq}`, + rawText: `line ${seq}` +}); + +describe('chatAfter', () => { + test('asks from the start with nothing held', () => { + expect(chatAfter([])).toBe(0); + }); + test('asks from the line held last, so the answer starts with it again', () => { + expect(chatAfter([line(1)])).toBe(0); + expect(chatAfter([line(4), line(5)])).toBe(4); + }); +}); + +describe('mergeChat', () => { + test('takes the whole answer when nothing is held', () => { + expect(mergeChat([], { latestSeq: 2, messages: [line(1), line(2)] })).toEqual([ + line(1), + line(2) + ]); + }); + + test('adds the new lines after the one it already held', () => { + const held = [line(4), line(5)]; + const got = mergeChat(held, { latestSeq: 7, messages: [line(5), line(6), line(7)] }); + expect(got?.map((m) => m.seq)).toEqual([4, 5, 6, 7]); + }); + + test('keeps what it held when nothing is new', () => { + const held = [line(4), line(5)]; + expect(mergeChat(held, { latestSeq: 5, messages: [line(5)] })).toBe(held); + }); + + test('a lower latestSeq is a new map: read again from the start', () => { + expect(mergeChat([line(6), line(7)], { latestSeq: 2, messages: [] })).toBeNull(); + }); + + test('a new map that got past the old count is caught by the line held last', () => { + // The tab was hidden through a map change, and the new map reached seq 9 meanwhile. + const held = [line(6), line(7)]; + const got = { latestSeq: 9, messages: [line(7, '2026-11-12T16:30:00.000Z'), line(8), line(9)] }; + expect(mergeChat(held, got)).toBeNull(); + }); + + test('the line held last missing from the answer is a new map too', () => { + expect(mergeChat([line(3)], { latestSeq: 3, messages: [] })).toBeNull(); + }); +}); diff --git a/src/lib/chat.ts b/src/lib/chat.ts index 5519dfb8..1c0fa88f 100644 --- a/src/lib/chat.ts +++ b/src/lib/chat.ts @@ -4,3 +4,63 @@ /** The longest whisper or broadcast the game takes. */ export const MAX_CHAT = 256; + +// What players say, as Season 3 (CL-533689) serves it from GET /v1/chat: the current map's lines +// only, held in the game's memory and numbered from 1 again when a map loads (docs/wardogs-api.md). + +/** One line of in-game chat, in the fields the `chat` action keeps. */ +export interface ChatMessage { + seq: number; + sentUtc: string; + /** `Team` or `Global` */ + channel: string; + faction: string; + steamId: string; + realName: string; + /** the anonymised name other players see */ + hiddenName: string; + anonymous: boolean; + text: string; + rawText: string; +} + +export interface ChatPage { + latestSeq: number; + messages: ChatMessage[]; +} + +/** Bulkhead's terms for reading chat, which an admin accepts once per server and version. */ +export interface ChatTerms { + requiredVersion: number; + acceptedVersion: number; + accepted: boolean; + text: string; +} + +/** + * The `after` to ask for next: one before the last line held, so the answer starts with that line + * again and mergeChat can tell the same map from a new one. + */ +export const chatAfter = (lines: ChatMessage[]): number => + Math.max(0, (lines.at(-1)?.seq ?? 0) - 1); + +/** + * The lines held plus what a read with `after = chatAfter(lines)` brought, or null when the map + * has changed underneath (the numbering went down, or the line held last is not where it was), in + * which case the caller reads again from 0. Checking the line and not only the number also + * catches a new map that got past the old one's count while nobody was looking. + */ +export function mergeChat(lines: ChatMessage[], page: ChatPage): ChatMessage[] | null { + const last = lines.at(-1); + if (!last) return page.messages; + const [anchor, ...rest] = page.messages; + if ( + page.latestSeq < last.seq || + !anchor || + anchor.seq !== last.seq || + anchor.sentUtc !== last.sentUtc || + anchor.steamId !== last.steamId + ) + return null; + return rest.length ? [...lines, ...rest] : lines; +} diff --git a/src/lib/server/actions.test.ts b/src/lib/server/actions.test.ts index db944e9e..d612409e 100644 --- a/src/lib/server/actions.test.ts +++ b/src/lib/server/actions.test.ts @@ -1003,3 +1003,148 @@ test('setNextMap on the live build answers 404 no_route and leaves the rotation else process.env.MOCK_LIVE_BUILD = before; } }); + +// ---- in-game chat (Season 3) -------------------------------------------------------------------- + +// What GET /v1/chat answered on a live Season 3 server (CL-533689, 2026-11-12), one line of it. +const CHAT_LINE = { + seq: 7, + sentUtc: '2026-11-12T15:39:29.145Z', + channel: 'Global', + faction: 'Manticore', + steamId: '76561198872197128', + realName: 'sandyparrot3552', + hiddenName: 'Pig', + anonymous: false, + text: 'howdy, and yeah', + rawText: 'howdy, and yeah', + ping: false +}; + +function chatClient(answer: unknown) { + const calls: { method: string; path: string; body?: unknown }[] = []; + const client: any = { + json: async (method: string, path: string, body?: unknown) => { + calls.push({ method, path, body }); + return structuredClone(answer); + } + }; + return { client, calls }; +} + +test('chat reads the lines after the number given and keeps the known fields', async () => { + const { client, calls } = chatClient({ + latestSeq: 7, + messages: [CHAT_LINE, { seq: '8', text: 'gg', extra: 'x' }], + count: 2 + }); + const r: any = await ACTIONS.chat.run(client, { after: '5' }); + expect(calls.map((c) => `${c.method} ${c.path}`)).toEqual(['GET /v1/chat?after=5']); + const { ping: _, ...kept } = CHAT_LINE; + expect(r.latestSeq).toBe(7); + expect(r.messages[0]).toEqual(kept); + expect(r.messages[1]).toEqual({ + seq: 8, + sentUtc: '', + channel: '', + faction: '', + steamId: '', + realName: '', + hiddenName: '', + anonymous: false, + text: 'gg', + rawText: 'gg' + }); +}); + +test('chat asks from the start without an after, and never for a negative or odd one', async () => { + for (const after of [undefined, '', '-3', 'abc']) { + const { client, calls } = chatClient({ latestSeq: 0, messages: [] }); + await ACTIONS.chat.run(client, { after }); + expect(calls[0].path).toBe('/v1/chat?after=0'); + } +}); + +test('an answer that is not chat is an error, not an empty map', async () => { + const { client } = chatClient({ error: 'proxy page' }); + const err: any = await ACTIONS.chat.run(client, {}).catch((e) => e); + expect(err).toBeInstanceOf(GameError); + expect(err.code).toBe('bad_response'); +}); + +test('chatTerms reads the terms, and only accepted:true counts as accepted', async () => { + const terms = { + requiredVersion: 1, + acceptedVersion: 0, + accepted: false, + text: 'Read these terms before viewing this server chat.' + }; + const { client, calls } = chatClient(terms); + expect(await ACTIONS.chatTerms.run(client, {})).toEqual(terms); + expect(calls[0].path).toBe('/v1/chat/terms'); + const odd = chatClient({ accepted: 'yes' }); + expect(((await ACTIONS.chatTerms.run(odd.client, {})) as any).accepted).toBe(false); +}); + +test('chatTermsAccept posts the version, and refuses without one', async () => { + const { client, calls } = chatClient({ + ok: true, + pending: false, + message: 'OK: chat terms accepted and saved.' + }); + const r: any = await ACTIONS.chatTermsAccept.run(client, { version: 1 }); + expect(calls).toEqual([{ method: 'POST', path: '/v1/chat/terms', body: { version: 1 } }]); + expect(r.message).toContain('accepted'); + expect(ACTIONS.chatTermsAccept.target!({ version: 1 })).toBe('1'); + for (const version of [undefined, 0, 'x']) { + const none = chatClient({}); + await expect(ACTIONS.chatTermsAccept.run(none.client, { version })).rejects.toThrow( + 'version is required' + ); + expect(none.calls.length).toBe(0); + } +}); + +test('a 200 that says ok:false is a refusal, not an acceptance', async () => { + const { client } = chatClient({ ok: false, message: 'Error: terms version 1 is not current.' }); + const err: any = await ACTIONS.chatTermsAccept.run(client, { version: 1 }).catch((e) => e); + expect(err).toBeInstanceOf(GameError); + expect([err.code, err.message]).toEqual([ + 'terms_refused', + 'Error: terms version 1 is not current.' + ]); +}); + +test('reading chat needs Chat and accepting the terms Config & settings; a viewer has neither', async () => { + const { BUILTIN_CAPABILITIES } = await import('../capabilities'); + expect([ACTIONS.chat.cap, ACTIONS.chatTerms.cap, ACTIONS.chatTermsAccept.cap]).toEqual([ + 'chat.send', + 'chat.send', + 'config.apply' + ]); + expect(ACTIONS.chat.mutating || ACTIONS.chatTerms.mutating).toBe(false); + expect(ACTIONS.chatTermsAccept.mutating).toBe(true); + expect(BUILTIN_CAPABILITIES.viewer).not.toContain('chat.send'); + expect(BUILTIN_CAPABILITIES.operator).toContain('chat.send'); +}); + +test('on the demo server chat stays empty until the terms are accepted, and a pre-Season 3 build has none', async () => { + const { WardogsClient } = await import('./rcon'); + const server = { id: 'chat-demo', host: 'demo', port: 1, scheme: 'http' as const }; + const client = new WardogsClient({} as any, server, 'demo', 'chat-demo'); + expect(await ACTIONS.chat.run(client, {})).toEqual({ latestSeq: 0, messages: [] }); + const terms: any = await ACTIONS.chatTerms.run(client, {}); + expect([terms.accepted, terms.requiredVersion]).toEqual([false, 1]); + await ACTIONS.chatTermsAccept.run(client, { version: terms.requiredVersion }); + expect(((await ACTIONS.chatTerms.run(client, {})) as any).accepted).toBe(true); + + const before = process.env.MOCK_LIVE_BUILD; + process.env.MOCK_LIVE_BUILD = 'true'; + try { + const err: any = await ACTIONS.chat.run(client, {}).catch((e) => e); + expect([err.status, err.code]).toEqual([404, 'no_route']); + } finally { + if (before === undefined) delete process.env.MOCK_LIVE_BUILD; + else process.env.MOCK_LIVE_BUILD = before; + } +}); diff --git a/src/lib/server/actions.ts b/src/lib/server/actions.ts index 4c0e1431..9f30bec9 100644 --- a/src/lib/server/actions.ts +++ b/src/lib/server/actions.ts @@ -658,6 +658,65 @@ export const ACTIONS: Record = { : '', run: (c, p) => whisperMany(c, p) }, + // Season 3 (CL-533689) on: what players said on the current map, from the game's memory. Chat + // reads it, never View alone: it is players' words under their real names. Nothing of it is + // stored. `after` returns only the lines numbered above it, and a map load numbers from 1 again + // ($lib/chat mergeChat). Empty until the server's chat terms are accepted. + chat: { + cap: 'chat.send', + mutating: false, + run: async (c, p) => { + const d = await c.json('GET', `/v1/chat?after=${int(p.after, 0, 0, 1e9)}`); + if (!Array.isArray(d?.messages)) + throw new GameError(502, 'The server did not return its chat.', 'bad_response'); + const text = (v: unknown) => (v === null || v === undefined ? '' : String(v)); + return { + latestSeq: Number(d.latestSeq) || 0, + messages: d.messages.map((m: any) => ({ + seq: Number(m.seq) || 0, + sentUtc: text(m.sentUtc), + channel: text(m.channel), + faction: text(m.faction), + steamId: text(m.steamId), + realName: text(m.realName), + hiddenName: text(m.hiddenName), + anonymous: m.anonymous === true, + text: text(m.text), + rawText: text(m.rawText ?? m.text) + })) + }; + } + }, + // Bulkhead's terms for reading chat: the text, the version they need and the one accepted. + chatTerms: { + cap: 'chat.send', + mutating: false, + run: async (c) => { + const d = await c.json('GET', '/v1/chat/terms'); + return { + requiredVersion: Number(d.requiredVersion) || 0, + acceptedVersion: Number(d.acceptedVersion) || 0, + accepted: d.accepted === true, + text: String(d.text ?? '') + }; + } + }, + // Accepting binds the server's operator and is saved in its config (AcceptedChatTermsVersion), + // so it is for those who may apply the config. + chatTermsAccept: { + cap: 'config.apply', + mutating: true, + target: (p) => String(int(p.version, 0, 0, 1e6)), + run: async (c, p) => { + const version = int(p.version, 0, 0, 1e6); + if (!version) + throw new ApiError(400, 'version is required: the requiredVersion of the terms accepted.'); + const r = await c.json('POST', '/v1/chat/terms', { version }); + if (r?.ok === false) + throw new GameError(400, r.message || 'The server refused the terms.', 'terms_refused'); + return r; + } + }, kick: { cap: 'players.kick', mutating: true, diff --git a/src/lib/server/mockgame.ts b/src/lib/server/mockgame.ts index 3181a859..a2ad7800 100644 --- a/src/lib/server/mockgame.ts +++ b/src/lib/server/mockgame.ts @@ -83,6 +83,11 @@ interface State { startedAt: number; /** what GET /v1/feed reports (setMockFeed); null: a feed that is off */ feedReport: Record | null; + /** the current map's chat, numbered from 1 again at every map load, as Season 3's GET /v1/chat */ + chat: Record[]; + chatSeq: number; + /** the chat terms version accepted (POST /v1/chat/terms); 0 until then */ + chatTerms: number; } const MAPS = [ @@ -119,6 +124,17 @@ const ALTERNATORS_BY_MAP: Record { tag: 'ZoneAlternator.Factory.Split', displayName: 'Bakurani Factory Split' } ] }; +const CHAT_LINES = [ + 'gg', + 'need a medic at B', + 'push the hill', + 'tank on the road', + 'o7', + 'who has the drone' +]; +/** The anonymised names Season 3 shows other players in chat. */ +const HIDDEN_NAMES = ['Pig', 'Fox', 'Crow', 'Mule', 'Hare', 'Owl']; +const CHAT_TERMS_VERSION = 1; const JOINERS = [ 'Copperhead', 'Late_to_the_party', @@ -144,7 +160,11 @@ const LIVE_BUILD_MISSING = new Set([ 'POST /v1/rotation/save', 'PATCH /v1/settings', // Season 2 (CL-516586) on - 'GET /v1/feed' + 'GET /v1/feed', + // Season 3 (CL-533689) on + 'GET /v1/chat', + 'GET /v1/chat/terms', + 'POST /v1/chat/terms' ]); const liveBuild = () => /^(1|true|yes)$/i.test(process.env.MOCK_LIVE_BUILD || ''); // With MOCK_LIVE_ADDS=now as well, a slot added to the document is reserved at once while one taken @@ -231,7 +251,10 @@ const CAPABILITY_ROUTES = [ 'GET /v1/config', 'POST /v1/config/validate', 'PUT /v1/config', - 'GET /v1/feed' + 'GET /v1/feed', + 'GET /v1/chat', + 'GET /v1/chat/terms', + 'POST /v1/chat/terms' ]; // The schema live build CL-501228 reports from GET /v1/config (captured 2026-09-14; CL-499480's @@ -478,7 +501,10 @@ function seed(name: string): State { matchState: '', matchId: crypto.randomUUID(), startedAt: STARTED, - feedReport: null + feedReport: null, + chat: [], + chatSeq: 0, + chatTerms: 0 }; state.configText = seedConfig(state); return state; @@ -636,6 +662,27 @@ function tick(s: State): void { } p.pingMs = Math.max(5, p.pingMs + Math.floor(Math.random() * 9) - 4); } + // Someone says something every 8 s of the clock, picked without Math.random so the demo's other + // draws come out as they did before. + if (s.players.length && Math.floor(now / 8000) !== Math.floor((now - dt * 1000) / 8000)) { + const n = s.chatSeq + s.nextJoiner; + const p = s.players[n % s.players.length]; + const text = CHAT_LINES[n % CHAT_LINES.length]; + s.chat.push({ + seq: ++s.chatSeq, + sentUtc: utc(), + channel: n % 3 ? 'Team' : 'Global', + faction: p.faction, + steamId: p.steamId, + realName: p.name, + hiddenName: HIDDEN_NAMES[Number(BigInt(p.steamId) % BigInt(HIDDEN_NAMES.length))], + anonymous: false, + text, + rawText: text, + ping: false + }); + if (s.chat.length > 200) s.chat.splice(0, s.chat.length - 200); + } // One of the drifters leaves now and then once the server is busy, so a full demo server keeps // turning over (the seeded regulars stay, so tests can rely on them). if (s.players.length > 8 && Math.random() < 0.03) { @@ -769,6 +816,9 @@ function resetScores(s: State): void { p.deaths = 0; p.cash = 0; } + // A map load empties the game's chat and numbers it from 1 again. + s.chat = []; + s.chatSeq = 0; feedState(s, PRE_MATCH); } @@ -1205,6 +1255,31 @@ export function mockHandle( // Real listeners no longer have this route; ServerImageURL goes through PUT /v1/config. return fail(405, 'PUT is not supported on this endpoint', 'method_not_allowed'); } + // Season 3's chat: empty until the terms are accepted. + if (route === 'GET chat') { + const after = Number(qs.get('after')) || 0; + const messages = s.chatTerms ? s.chat.filter((m) => Number(m.seq) > after) : []; + return ok({ latestSeq: s.chatTerms ? s.chatSeq : 0, messages, count: messages.length }); + } + if (route === 'GET chat/terms') { + return ok({ + requiredVersion: CHAT_TERMS_VERSION, + acceptedVersion: s.chatTerms, + accepted: s.chatTerms >= CHAT_TERMS_VERSION, + text: "Read these terms before viewing this server's chat. (Demo server: Bulkhead's text stands here.)" + }); + } + if (route === 'POST chat/terms') { + if (b.version !== CHAT_TERMS_VERSION) + return fail( + 400, + `Error: the terms to accept are version ${CHAT_TERMS_VERSION}.`, + 'bad_request' + ); + s.chatTerms = CHAT_TERMS_VERSION; + log(s, 'COMMAND', `chat terms accepted v${CHAT_TERMS_VERSION}`); + return ok({ ok: true, pending: false, message: 'OK: chat terms accepted and saved.' }); + } if (route === 'GET audit') { const limit = Math.min(500, Math.max(1, Number(qs.get('limit')) || 50)); return ok({ entries: s.audit.slice(-limit) }); diff --git a/src/routes/(app)/server/[id]/+layout.svelte b/src/routes/(app)/server/[id]/+layout.svelte index 8f368667..b9c22834 100644 --- a/src/routes/(app)/server/[id]/+layout.svelte +++ b/src/routes/(app)/server/[id]/+layout.svelte @@ -18,6 +18,7 @@ ['', 'Overview'], ['/players', 'Players'], ['/kills', 'Kills'], + ['/chat', 'Chat', 'chat.send'], ['/matches', 'Matches'], ['/bans', 'Bans'], ['/slots', 'Reserved slots'], diff --git a/src/routes/(app)/server/[id]/chat/+page.svelte b/src/routes/(app)/server/[id]/chat/+page.svelte new file mode 100644 index 00000000..2babadde --- /dev/null +++ b/src/routes/(app)/server/[id]/chat/+page.svelte @@ -0,0 +1,195 @@ + + +{#if unsupported} +
+ This server's build has no in-game chat routes. Chat came with Season 3. +
+{:else if terms && !terms.accepted} +
+

Chat terms

+

{terms.text}

+ {#if mayAccept} +
+ +
+

+ The game server keeps the acceptance in its config, so it holds for everyone who reads this + server's chat, here or in any other tool. +

+ {:else} +

+ The server's chat cannot be read until someone who may change its config and settings + accepts these terms. +

+ {/if} +
+{:else} +
+
+ + + {search.trim() || channel ? `${rows.length} of ` : ''}{lines.length} + {lines.length === 1 ? 'line' : 'lines'} this map (newest last) +
+
+ + + + {#each rows as m, i (i)} + + + + + + + {:else} + + {/each} + +
TimeChannelPlayerMessage
{timeOf(m.sentUtc)}{m.channel} + {#if /^\d{17}$/.test(m.steamId)} + {m.realName || m.steamId} + {:else}{m.realName}{/if} + {#if m.hiddenName && m.hiddenName !== m.realName}as {m.hiddenName}{/if} + {#if m.faction}{/if} + {m.text}
{!loaded + ? 'Loading…' + : lines.length + ? 'Nothing matches.' + : 'Nobody has said anything on this map yet.'}
+
+

+ What players said on the current map, as the game server holds it in memory: a new map starts + it empty. Warcon does not store chat; it is read from the server while this page is open. +

+
+{/if} diff --git a/src/test/action-matrix.test.ts b/src/test/action-matrix.test.ts index 1832d8a0..963e69c1 100644 --- a/src/test/action-matrix.test.ts +++ b/src/test/action-matrix.test.ts @@ -28,6 +28,8 @@ const ACTION_CAPS: Record = { broadcast: 'chat.send', whisper: 'chat.send', whisperMany: 'chat.send', + chat: 'chat.send', + chatTerms: 'chat.send', kick: 'players.kick', kill: 'players.kill', changeTeam: 'players.move', @@ -50,6 +52,7 @@ const ACTION_CAPS: Record = { serverLog: 'audit.read', config: 'config.apply', feed: 'config.apply', + chatTermsAccept: 'config.apply', settings: 'config.apply', configValidate: 'config.apply', configApply: 'config.apply',