PLAN.md §33, D134-D143. Protocol 12. - Chat titles (D135-D137): per-server rules (stat, top N, text, colour) that rank the current wipe, and a mode (first | all | up to N). Worked out once in model/titles and read three ways: pushed whole to the game by a new titleSync loop (on change, restart or wipe), and on every leaderboard row as `titles`. Admin: PUT /servers/:id/titles. - Group styles (D138, D139): a site group may carry all twelve BetterChat fields (rust_perm_group_chat). They ride perm.sync with `expect` from the pushed ledger, which gains a value column; a field changed in game is a `chat-field` drift row with the game's value, adopted into the style or put back. A withdrawn style is one `chat-group` retirement, never for `default`, cleared from the ledger only once BetterChat removed it. - The voice (D140): one fleet setting naming a styled group; news and rust.announce chat lines carry its format and the plugin says them with no sender. Admin: GET/PUT /voice. - Popups (D141, D142): rust.announce gains `delivery` (still version 1, from rust.options.delivery); each server gains news_delivery beside the news switch; `popup-unavailable` is not retried. - GET /servers/:id/integrations reads, live, which optional mods a server has loaded. README lists BetterChat and PopupNotifications as optional. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
189 lines
14 KiB
JavaScript
189 lines
14 KiB
JavaScript
// ── Public · Rust ─────────────────────────────────────────────────────────
|
||
//
|
||
// Mounted at `/api/v1/public/rust` by `index.js`. One express Router, built from
|
||
// CORE's express (`core.express`) — never from a `require('express')` of your
|
||
// own, which would not resolve from here anyway (MODULE_API.md §7.2).
|
||
//
|
||
// **The tier's gate is already on.** This router sits inside core's public tier,
|
||
// which is behind nothing by design. Per-route middleware goes on top, and
|
||
// `siteMode` is the one worth understanding: it is what makes a route respect the
|
||
// operator's maintenance switch. Core applies it to its own content routes and
|
||
// deliberately does not apply it to its status endpoints, because status is
|
||
// exactly what an operator wants visible *during* maintenance.
|
||
//
|
||
// The server list is content, not status — it is the module's landing page — so
|
||
// it takes `siteMode`.
|
||
//
|
||
// ── About the `#swagger` comments ─────────────────────────────────────────
|
||
//
|
||
// They are not documentation *of* the code; they are the source the OpenAPI
|
||
// fragment is generated from (`npm run swagger`, §2.8). swagger-autogen reads
|
||
// them as JavaScript literals it evaluates, so a QUOTE CHARACTER inside a
|
||
// single-quoted description ends the string early — and the failure is silent:
|
||
// the value is truncated at that character while the generator prints success.
|
||
// Use a typographic apostrophe (’) in prose. A backtick is fine.
|
||
|
||
const core = require('../../core')
|
||
|
||
const express = core.express
|
||
const servers = require('./rust.controller')
|
||
const { siteMode } = core.middleware
|
||
|
||
const rustRouter = express.Router()
|
||
|
||
rustRouter.get(
|
||
'/servers',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'Every Rust server this site follows'
|
||
// #swagger.description = 'The operator’s configured Rust servers and what each one last reported. Answers with `online: false` and `stale: true` rather than failing when a game server or its sidecar is unreachable — the site’s availability does not depend on the game’s.'
|
||
/* #swagger.responses[200] = { description: 'The server list', content: { "application/json": { schema: { $ref: "#/components/schemas/RustServerList" } } } } */
|
||
siteMode,
|
||
servers.listServers,
|
||
)
|
||
|
||
// ── One server's read path ────────────────────────────────────────────────
|
||
//
|
||
// Every route below is public, and every one of them answers from this module's
|
||
// own tables — never from a live call to a sidecar. That is what lets the
|
||
// killfeed and the leaderboard render while every game server in the fleet is
|
||
// off, which is the same promise the server list makes.
|
||
//
|
||
// **The events route serves an ALLOWLIST, default-deny** (`catalogue.js`).
|
||
// Protocol 2 carries IP addresses and player reports; they are stored, and they
|
||
// do not come out here.
|
||
|
||
rustRouter.get(
|
||
'/servers/:id',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'One Rust server'
|
||
// #swagger.description = 'The same shape the list answers with, for one server, and a `404` when there is no such server or an operator has disabled it. The detail page needs the difference: every other route under this path answers an empty list for an id that does not exist, because an unknown server genuinely has no events and nobody online.'
|
||
// #swagger.parameters['id'] = { in: 'path', required: true, description: 'The server’s slug', schema: { type: 'string' } }
|
||
/* #swagger.responses[200] = { description: 'The server' } */
|
||
/* #swagger.responses[404] = { description: 'No such server, or it is disabled' } */
|
||
siteMode,
|
||
servers.getServer,
|
||
)
|
||
|
||
rustRouter.get(
|
||
'/servers/:id/events',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'Recent events on one Rust server'
|
||
// #swagger.description = 'The killfeed and everything else public that happened on a server, newest first. Narrow with `kind` (comma-separated) and `wipe`. Only publicly classified kinds are ever returned — moderation events, login attempts and anything carrying an IP address are stored but never served here. Kinds that name a player who was on the server (connects, respawns, deaths, chat, tallies) are served only to viewers inside the operator’s presence audience, which defaults to staff; `presenceHidden` says when they were withheld.'
|
||
// #swagger.parameters['id'] = { in: 'path', required: true, description: 'The server’s slug', schema: { type: 'string' } }
|
||
// #swagger.parameters['kind'] = { in: 'query', required: false, description: 'One kind, or several comma-separated', schema: { type: 'string' } }
|
||
// #swagger.parameters['wipe'] = { in: 'query', required: false, description: 'Restrict to one wipe id', schema: { type: 'string' } }
|
||
// #swagger.parameters['limit'] = { in: 'query', required: false, description: 'Rows to return, capped at 200', schema: { type: 'integer' } }
|
||
/* #swagger.responses[200] = { description: 'Recent events, newest first' } */
|
||
siteMode,
|
||
servers.listEvents,
|
||
)
|
||
|
||
rustRouter.get(
|
||
'/servers/:id/leaderboard',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'The leaderboard for one Rust server'
|
||
// #swagger.description = 'Per-wipe when `wipe` is given, all-time otherwise. All-time is the per-wipe rows summed rather than a second set of counters, so a wipe splits a player’s history without ending it. `lastSeen` is withheld below the operator’s presence audience: a gather tally refreshes it every minute a player is on, so it would name who is online. Each row carries `titles`: the chat titles that player holds now, as `[{ text, color }]` in the order the game shows them, and an empty list for a player with none. Titles rank the CURRENT wipe whichever wipe the page asks for, and are set by the operator’s rules.'
|
||
// #swagger.parameters['id'] = { in: 'path', required: true, description: 'The server’s slug', schema: { type: 'string' } }
|
||
// #swagger.parameters['wipe'] = { in: 'query', required: false, description: 'Restrict to one wipe id', schema: { type: 'string' } }
|
||
// #swagger.parameters['sort'] = { in: 'query', required: false, description: 'kills, deaths, npcKills or playtime', schema: { type: 'string' } }
|
||
// #swagger.parameters['limit'] = { in: 'query', required: false, description: 'Rows to return, capped at 200', schema: { type: 'integer' } }
|
||
/* #swagger.responses[200] = { description: 'The leaderboard' } */
|
||
siteMode,
|
||
servers.listLeaderboard,
|
||
)
|
||
|
||
rustRouter.get(
|
||
'/servers/:id/wipes',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'Every wipe this server has had'
|
||
// #swagger.description = 'Newest first. A wipe id is derived by the bridge plugin from the save’s creation time and stamped on every frame, so it is the same id the events and the leaderboard are filtered by.'
|
||
// #swagger.parameters['id'] = { in: 'path', required: true, description: 'The server’s slug', schema: { type: 'string' } }
|
||
/* #swagger.responses[200] = { description: 'The wipes' } */
|
||
siteMode,
|
||
servers.listWipes,
|
||
)
|
||
|
||
rustRouter.get(
|
||
'/servers/:id/online',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'Who is on one Rust server right now'
|
||
// #swagger.description = 'Read from the presence board the bridge re-sends on every connect and every minute, rather than counted from connect and disconnect events — so it is correct even after the website has missed one. **Nothing names who is online by default**: below the operator’s presence audience (staff unless widened) the names are withheld and only `count` is answered.'
|
||
// #swagger.parameters['id'] = { in: 'path', required: true, description: 'The server’s slug', schema: { type: 'string' } }
|
||
/* #swagger.responses[200] = { description: 'Who is online — or, below the operator’s presence audience, only how many', content: { "application/json": { schema: { $ref: "#/components/schemas/RustOnline" } } } } */
|
||
siteMode,
|
||
servers.listOnline,
|
||
)
|
||
|
||
// ── Clans (phase 9) ───────────────────────────────────────────────────────
|
||
//
|
||
// Rust's own clans, which this module also answers core's Team questions from.
|
||
// The list is public (D58); a roster is not (D48).
|
||
|
||
rustRouter.get(
|
||
'/servers/:id/clans',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'The clans on one Rust server'
|
||
// #swagger.description = 'Every clan on the server’s clan board, best score first: name, colour, score and member count. Public, because none of it names a player. `board` says whether the list is current and complete — a server whose bridge cannot read its clans answers an empty list and the reason, and a server at the game’s 100-clan ceiling says `truncated`.'
|
||
// #swagger.parameters['id'] = { in: 'path', required: true, description: 'The server’s slug', schema: { type: 'string' } }
|
||
/* #swagger.responses[200] = { description: 'The clans', content: { "application/json": { schema: { $ref: "#/components/schemas/RustClanList" } } } } */
|
||
siteMode,
|
||
servers.listClans,
|
||
)
|
||
|
||
rustRouter.get(
|
||
'/clans/:externalId',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'One Rust clan'
|
||
// #swagger.description = 'A clan and, when the viewer is inside the operator’s clan roster audience, its roster. The audience defaults to the clan’s own members (a website account linked to one of them) and staff. Below it the clan is still described and `roster.visible` is false with no names. The roster never carries a Steam id or a website account id. `externalId` is `<server>:<clan>:<created>`, the same identity the site’s Team pages use.'
|
||
// #swagger.parameters['externalId'] = { in: 'path', required: true, description: 'The clan’s identity: server, clan id and creation time in epoch ms, joined by colons', schema: { type: 'string' } }
|
||
/* #swagger.responses[200] = { description: 'The clan', content: { "application/json": { schema: { $ref: "#/components/schemas/RustClan" } } } } */
|
||
/* #swagger.responses[404] = { description: 'No such clan' } */
|
||
siteMode,
|
||
servers.getClan,
|
||
)
|
||
|
||
// ── The map (phase 14) ────────────────────────────────────────────────────
|
||
//
|
||
// The picture is public at every setting; what moves on it is not. Each of the
|
||
// four layers has its own audience, and a layer the viewer may not see is
|
||
// removed on the server — never sent and hidden by the page (PLAN.md §30.2).
|
||
|
||
rustRouter.get(
|
||
'/servers/:id/map',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'One Rust server’s map'
|
||
// #swagger.description = 'Where the picture of the current map is, the geometry to draw it with (world size, the picture’s size and ocean margin in pixels, and the game’s own grid), the monuments when the viewer may see the world layer, and which of the four layers — `world`, `events`, `players`, `bases` — this viewer gets. A hidden layer says which audience can see it and never what it holds. The players layer can never be wider than who may see who is online (`cappedByPresence`). `mates` says whether this viewer gets their own position and their online clan mates’. `picture` is null when the game has no picture of its map; `geometry` is null when the server has never described its map.'
|
||
// #swagger.parameters['id'] = { in: 'path', required: true, description: 'The server’s slug', schema: { type: 'string' } }
|
||
/* #swagger.responses[200] = { description: 'The map, as this viewer may see it', content: { "application/json": { schema: { $ref: "#/components/schemas/RustMap" } } } } */
|
||
/* #swagger.responses[404] = { description: 'No such server, or it is disabled' } */
|
||
siteMode,
|
||
servers.getMap,
|
||
)
|
||
|
||
rustRouter.get(
|
||
'/servers/:id/map/image',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'The picture of one Rust server’s map'
|
||
// #swagger.description = 'The JPEG, cached as immutable for a year because the picture’s SHA-256 is in the URL. A hash that is not the stored picture’s answers 404, so a replaced picture is never served under an old address. Public at every setting: the picture is rendered from the map seed and says nothing about who plays.'
|
||
// #swagger.parameters['id'] = { in: 'path', required: true, description: 'The server’s slug', schema: { type: 'string' } }
|
||
// #swagger.parameters['v'] = { in: 'query', required: true, description: 'The picture’s SHA-256, as the map route names it', schema: { type: 'string' } }
|
||
/* #swagger.responses[200] = { description: 'The picture', content: { "image/jpeg": { schema: { type: "string", format: "binary" } } } } */
|
||
/* #swagger.responses[404] = { description: 'No such server, or no picture with that hash' } */
|
||
siteMode,
|
||
servers.getMapImage,
|
||
)
|
||
|
||
rustRouter.get(
|
||
'/servers/:id/map/live',
|
||
// #swagger.tags = ['Public · Rust']
|
||
// #swagger.summary = 'What moves on one Rust server’s map'
|
||
// #swagger.description = 'The positions this viewer may see, asked of the game while somebody is looking and held for five seconds, so any number of viewers cost one ask. **A layer the viewer may not see is absent from the answer**, not empty: `world` (world events and locked crates), `events` (what the site’s events placed), `players` (online players and sleepers, with names) and `bases` (tool cupboards and vending machines, positions only). `mates` is the viewer’s own position and their online first-party clan mates’, for a linked viewer when the server allows it. `live: false` with a `reason` when the game did not answer. Positions are never stored.'
|
||
// #swagger.parameters['id'] = { in: 'path', required: true, description: 'The server’s slug', schema: { type: 'string' } }
|
||
/* #swagger.responses[200] = { description: 'The positions this viewer may see', content: { "application/json": { schema: { $ref: "#/components/schemas/RustMapLive" } } } } */
|
||
/* #swagger.responses[404] = { description: 'No such server, or it is disabled' } */
|
||
siteMode,
|
||
servers.getMapLive,
|
||
)
|
||
|
||
module.exports = rustRouter
|