The module half of the read path. Seven tables, an ingest cursor, four public routes, and one file whose only job is deciding who may see what. **The record and the window are different things.** `rust_player_wipe_stats` and `rust_gather_totals` are permanent and per-wipe, so all-time is those rows SUMmed rather than a second set of counters that can disagree with them — that is R12's "per-wipe detail plus all-time rollups" in one table instead of two. `rust_events` is a bounded 30-day window of raw frames for the killfeed, and `rust_presence` is a board: replaced wholesale, never appended. **The feed is a cursor, not a socket, and the header says why.** Core runs Node 20, where a global WebSocket is still behind a flag, so a socket means taking `ws` — against a release that asserts it has no runtime dependencies (D5). The deciding argument is the other one though: a socket needs a cursor anyway, for whatever it missed while the module was restarting, and the catch-up path is the one that has to be right. A cursor alone is one mechanism exercised every five seconds rather than two where the second only runs after an outage. **The cursor advances after the batch, never before.** A crash between the two re-reads events already counted, which inflates a total; the other order loses them silently and for ever. One is visible and bounded, the other is invisible and permanent, so the code fails in the visible direction. A server with no cursor starts at the sidecar's current END rather than at zero — replaying a fortnight of deaths into stats for wipes the site never saw is not a catch-up. **`catalogue.js` is a security boundary, default-deny.** Protocol 2 carries IP addresses (login attempts, approvals, bans), one player's report about another, and the grid reference of somebody's base. They are stored, because an operator chasing ban evasion needs them; they are not served below the admin tier. The allowlist lives here rather than as a field on the wire, because a boundary declared by the sender is one a compromised or merely out-of-date game host can widen — the same reason core's own shard fan-out filters on the serving side. A kind this build has never heard of is not public, and a test holds the list against PROTOCOL.md §8.4 so that adding a kind to the protocol without classifying it fails a build. `PROTOCOL_VERSION` goes to 2 here in the same change as the emitters, though this module consumes none of the new frames yet: the sidecar refuses a mismatched client with a 409, so a module left on 1 would stop being able to read the board it has been reading all along. A constant that lags the deployment is an outage with a version number on it. 95 server tests, 20 client tests, every guard green, and `routes.manifest.json` regenerated against a real core at the pinned ref: 10 routes, all documented, none of core's moved. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016wDDVXWMDz82WqE1i969r4
119 lines
4.5 KiB
JavaScript
119 lines
4.5 KiB
JavaScript
// ── What the bridge can say, and who may hear it ──────────────────────────
|
|
//
|
|
// One file, because these two questions have to be answered together or the
|
|
// second one rots: which frame kinds exist, and which of them a member of the
|
|
// public may see.
|
|
//
|
|
// ── The boundary ──────────────────────────────────────────────────────────
|
|
//
|
|
// Protocol 2's catalogue includes frames carrying **IP addresses** (a login
|
|
// attempt, an approval, a ban) and **one player's complaint about another** (a
|
|
// report), and one — a destroyed structure — that names where somebody lives.
|
|
// They are stored, because an operator chasing ban evasion needs them and
|
|
// because the sidecar persists what it is told. They must never reach a public
|
|
// page.
|
|
//
|
|
// **The boundary is enforced HERE, on the side that serves, and not on the wire.**
|
|
// The plugin could have stamped a `class` on every frame and saved this file the
|
|
// trouble; it deliberately does not (PROTOCOL.md §8.5). A boundary declared by
|
|
// the sender is a boundary a compromised — or merely out-of-date — game host can
|
|
// widen. Core's own shard fan-out works the same way: a public stream with an
|
|
// allowlist of kinds, and an admin stream that adds the rest.
|
|
//
|
|
// ── Default deny, and why it is not paranoia ──────────────────────────────
|
|
//
|
|
// `isPublic` answers `false` for a kind it has never heard of. That matters
|
|
// because of the shape of the mistake it prevents: the next protocol version
|
|
// adds a kind, this module ingests it happily (`rust_events` stores what it is
|
|
// given), and a page that filtered by a DENY list would publish it the day it
|
|
// first arrived — before anybody had decided whether it should be public. With
|
|
// an allowlist the new kind is invisible until somebody adds it here, which is
|
|
// the same moment they think about it.
|
|
//
|
|
// The test holds this list against `docs/rust-link/PROTOCOL.md` §8.4's table, so
|
|
// adding a kind to the spec without classifying it fails a build rather than
|
|
// shipping an address to a public page.
|
|
|
|
/**
|
|
* Kinds a public, signed-out visitor may see.
|
|
*
|
|
* Each entry is a decision. `player.chat` is here because a shard's chat is
|
|
* public by the same logic that makes a killfeed public — it happened in front
|
|
* of everyone who was on the server — and an operator who disagrees turns the
|
|
* feature off rather than relying on this list being wrong.
|
|
*/
|
|
const PUBLIC_KINDS = Object.freeze([
|
|
'player.connected',
|
|
'player.disconnected',
|
|
'player.respawned',
|
|
'player.death',
|
|
'player.chat',
|
|
'player.tally',
|
|
'server.wipe',
|
|
'server.initialized',
|
|
'server.shutdown',
|
|
])
|
|
|
|
/**
|
|
* Kinds an admin may see and nobody else.
|
|
*
|
|
* Listed rather than implied by absence, so that "we know about this kind and it
|
|
* is restricted" is distinguishable from "nobody has classified this kind" — the
|
|
* second is a finding, and a bare allowlist cannot tell you which you are
|
|
* looking at.
|
|
*/
|
|
const STAFF_KINDS = Object.freeze([
|
|
'entity.destroyed',
|
|
'player.reported',
|
|
'player.banned',
|
|
'player.unbanned',
|
|
'player.login.attempt',
|
|
'player.approved',
|
|
])
|
|
|
|
/** Every kind protocol 2 defines. */
|
|
const ALL_KINDS = Object.freeze([...PUBLIC_KINDS, ...STAFF_KINDS])
|
|
|
|
const PUBLIC = new Set(PUBLIC_KINDS)
|
|
const STAFF = new Set(STAFF_KINDS)
|
|
|
|
/**
|
|
* May a signed-out visitor see this kind?
|
|
*
|
|
* Default deny: an unknown kind is not public. Callers pass whatever arrived on
|
|
* the wire, including a kind from a newer protocol this build has never seen.
|
|
*/
|
|
function isPublic(kind) {
|
|
return PUBLIC.has(kind)
|
|
}
|
|
|
|
/** Is this a kind this build knows about at all? */
|
|
function isKnown(kind) {
|
|
return PUBLIC.has(kind) || STAFF.has(kind)
|
|
}
|
|
|
|
/**
|
|
* Narrows a list of requested kinds to the ones a viewer may have.
|
|
*
|
|
* Returning the allowlist itself when nothing was requested is what makes the
|
|
* public route safe by construction rather than by remembering to filter: there
|
|
* is no code path where "no filter" means "everything".
|
|
*/
|
|
function kindsFor({ admin = false, requested = null } = {}) {
|
|
const permitted = admin ? ALL_KINDS : PUBLIC_KINDS
|
|
|
|
if (!requested || requested.length === 0) return [...permitted]
|
|
|
|
const allowed = new Set(permitted)
|
|
return requested.filter((k) => allowed.has(k))
|
|
}
|
|
|
|
module.exports = {
|
|
PUBLIC_KINDS,
|
|
STAFF_KINDS,
|
|
ALL_KINDS,
|
|
isPublic,
|
|
isKnown,
|
|
kindsFor,
|
|
}
|