The org lead's rule, settled 2026-09-22: who is online is always the
narrowest audience - staff - unless an operator deliberately widens it,
and a count is fine where a list of names is not.
The public site broke that in three places since phase 4. The Online
tab named every player, the feed carried joins, respawns, deaths, chat
and tallies, and the leaderboard's lastSeen - refreshed every minute by
a gather tally - said who was on as plainly as either. All three now
sit behind one setting:
* PRESENCE_KINDS, a subset of the public allowlist, gated per request.
Below the audience the feed keeps the server's own story (wipe, start,
shutdown) and says presenceHidden rather than looking quiet.
* the Online route answers { players: [], hidden, count, audience } -
same shape, so an older client renders empty rather than breaking.
* rungs staff / signed_in / public, fleet-wide default in a new
rust_settings table with an optional per-server override on
rust_servers; an unknown stored word narrows to staff.
* the viewer's standing is RE-READ from the users row (ctx.users.getById),
not taken from the token, so a demotion or a ban applies on the next
request. Walked: a moderator demoted mid-session lost the roll call on
the same cookie.
* per-viewer answers are Cache-Control: private, no-store.
* GET/PUT /admin/rust/visibility (requireRole admin) and an admin page,
Rust visibility; every save is one activity-log row.
The browser walk also found every empty state in this module rendering
as a blank box. Core's EmptyState renders children only; this module
passed title/message (the shape the Integration Kit template teaches)
and React dropped both without a word. Fixed module-side with a small
Empty wrapper - nothing core or module-uo renders changes - and a client
test that refuses a titled EmptyState or a PageHeader subtitle.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
164 lines
6.0 KiB
JavaScript
164 lines
6.0 KiB
JavaScript
// ── Public · Rust — the handlers ──────────────────────────────────────────
|
|
//
|
|
// Thin on purpose: read the request, call a model, answer. Everything worth
|
|
// testing is in the model, which needs no express and no database to test.
|
|
//
|
|
// **A handler must not throw past express.** Core mounts this router inside its
|
|
// own tier router, so an unhandled rejection here reaches core's error handler
|
|
// and answers 500 — survivable, but it means an operator sees core blamed for a
|
|
// fault in this module. Catch, log through `core.logger` (so the line carries the
|
|
// module id), and answer something honest.
|
|
|
|
const core = require('../../core')
|
|
|
|
const events = require('../../model/events/events.model')
|
|
const servers = require('../../model/servers/servers.model')
|
|
const visibility = require('../../model/visibility/visibility.model')
|
|
|
|
const log = core.logger('public')
|
|
|
|
/**
|
|
* Marks a response as depending on who asked.
|
|
*
|
|
* Three routes below answer differently for a moderator and for a stranger, and
|
|
* a shared cache in front of the site that stored the moderator's answer would
|
|
* hand the roll call to the next anonymous visitor. `private` keeps it out of
|
|
* every cache but the viewer's own; `Vary` says why, for any cache that reads it.
|
|
*/
|
|
function perViewer(res) {
|
|
res.set('Cache-Control', 'private, no-store')
|
|
res.vary('Cookie')
|
|
res.vary('Authorization')
|
|
}
|
|
|
|
async function listServers(req, res) {
|
|
try {
|
|
res.json({ servers: await servers.listPublic() })
|
|
} catch (err) {
|
|
log.error('failed to read the server list', { error: err.message })
|
|
res.status(500).json({ message: 'Failed to read the server list' })
|
|
}
|
|
}
|
|
|
|
/**
|
|
* One server, or a 404.
|
|
*
|
|
* **The 404 is the feature.** Everything else under `/servers/:id` answers an
|
|
* empty list for a server that does not exist — an unknown id has no events, no
|
|
* leaderboard and nobody online, and each of those is a perfectly good answer to
|
|
* the question it was asked. Only this route can tell the page that the server
|
|
* itself is not there, which is what stops `/rust/servers/typo` rendering as a
|
|
* quiet server with nothing to say.
|
|
*/
|
|
async function getServer(req, res) {
|
|
try {
|
|
const server = await servers.getPublic(req.params.id)
|
|
if (!server) {
|
|
res.status(404).json({ message: 'No such server' })
|
|
return
|
|
}
|
|
res.json({ server })
|
|
} catch (err) {
|
|
log.error('failed to read a server', { server: req.params.id, error: err.message })
|
|
res.status(500).json({ message: 'Failed to read the server' })
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The killfeed, and everything else public that happened on one server.
|
|
*
|
|
* **`admin` is not passed, and that is the whole security posture of this
|
|
* handler.** `events.recent` takes the viewer explicitly and defaults to the
|
|
* public allowlist, so the way to leak an IP address from here is to add an
|
|
* argument rather than to forget one.
|
|
*
|
|
* `presence` is resolved per request from the operator's setting. Below it, the
|
|
* feed carries only what names nobody — a wipe, a start, a shutdown — and says
|
|
* so with `presenceHidden`, so a page can explain a quiet feed instead of
|
|
* implying a quiet server.
|
|
*/
|
|
async function listEvents(req, res) {
|
|
try {
|
|
const presence = await visibility.canSeePresence(req, req.params.id)
|
|
perViewer(res)
|
|
res.json({
|
|
events: await events.recent({
|
|
serverId: req.params.id,
|
|
presence: presence.visible,
|
|
kind: req.query.kind,
|
|
wipeId: req.query.wipe || null,
|
|
limit: req.query.limit,
|
|
}),
|
|
presenceHidden: !presence.visible,
|
|
presenceAudience: presence.required,
|
|
})
|
|
} catch (err) {
|
|
log.error('failed to read events', { server: req.params.id, error: err.message })
|
|
res.status(500).json({ message: 'Failed to read events' })
|
|
}
|
|
}
|
|
|
|
async function listLeaderboard(req, res) {
|
|
try {
|
|
const presence = await visibility.canSeePresence(req, req.params.id)
|
|
perViewer(res)
|
|
res.json({
|
|
leaderboard: await events.leaderboard({
|
|
serverId: req.params.id,
|
|
wipeId: req.query.wipe || null,
|
|
sort: req.query.sort,
|
|
limit: req.query.limit,
|
|
presence: presence.visible,
|
|
}),
|
|
})
|
|
} catch (err) {
|
|
log.error('failed to read the leaderboard', { server: req.params.id, error: err.message })
|
|
res.status(500).json({ message: 'Failed to read the leaderboard' })
|
|
}
|
|
}
|
|
|
|
async function listWipes(req, res) {
|
|
try {
|
|
res.json({ wipes: await events.wipes(req.params.id) })
|
|
} catch (err) {
|
|
log.error('failed to read wipes', { server: req.params.id, error: err.message })
|
|
res.status(500).json({ message: 'Failed to read wipes' })
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Who is on the server right now — or, below the operator's audience, how many.
|
|
*
|
|
* The count stays public: it is already on the server list and in the footer,
|
|
* and a number names nobody. The names do not, by default (the org lead's rule,
|
|
* `model/visibility`). A hidden answer is still a 200 with the same shape — an
|
|
* empty `players` array — plus `hidden` and `count`, so a client that predates
|
|
* the flag renders an empty list rather than breaking, and a current one can say
|
|
* "12 online" instead of "nobody".
|
|
*/
|
|
async function listOnline(req, res) {
|
|
try {
|
|
const presence = await visibility.canSeePresence(req, req.params.id)
|
|
perViewer(res)
|
|
|
|
if (!presence.visible) {
|
|
const server = await servers.getPublic(req.params.id)
|
|
res.json({
|
|
players: [],
|
|
hidden: true,
|
|
count: server ? server.players : 0,
|
|
audience: presence.required,
|
|
})
|
|
return
|
|
}
|
|
|
|
const players = await events.online(req.params.id)
|
|
res.json({ players, hidden: false, count: players.length, audience: presence.required })
|
|
} catch (err) {
|
|
log.error('failed to read presence', { server: req.params.id, error: err.message })
|
|
res.status(500).json({ message: 'Failed to read who is online' })
|
|
}
|
|
}
|
|
|
|
module.exports = { listServers, getServer, listEvents, listLeaderboard, listWipes, listOnline }
|