feat(rust): Teams from first-party clans (phase 9, protocol 6)
A first-party Rust clan is a Team (R5). This module becomes the site's Team provider and answers core from the plugin's `clans` board. Design of record: docs/modules/rust/PLAN.md §24, D47-D58. - The store: rust_clans, rust_clan_members and rust_clan_boards. A clan's identity is <serverId>:<clanId>:<createdMs> (D52), because the game restarts clan ids whenever its clan database version changes. - The provider (D53): getTeams is complete only when every server's board is fresh, supported and untruncated. It is partial when some are, and refuses when none are. Freshness is judged by the website's clock, from when the board's `t` last advanced. - Only a complete board may mark a clan gone. A board at the game's 100-clan ceiling (D55), or one with an unreadable row, proves nothing about what it leaves out. - Leadership is diffed board to board and published (D54). The five clan events are published as team.* kinds, and written to the Team feed as members-only lines (D49). - Core only writes feed items for a Team it already holds. So the last 10 minutes of clan events are re-offered on each board refresh, deduped by a sha1 key: core clamps a dedupeKey to 40 characters, and a readable key would be truncated into collisions. - projectRoster and the clan page share one audience rule (D48): the clan's linked members and staff by default, re-read from the users row. The setting lives on Admin > Rust visibility, which also warns about uMod Clans (D47) and the ceiling. - Public: GET servers/:id/clans (the list is public, D58) and GET clans/:externalId. The client adds a Clans tab and /rust/clans/:externalId, with three module slots for core's notify, activity and forum contributions (D56). - Linking and unlinking an account ask core to reconcile Teams (D57). - The clan kinds are staff-class in the public feed allowlist. - PROTOCOL_VERSION is now 6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
const core = require('../../core')
|
||||
|
||||
const clans = require('../../model/clans/clans.model')
|
||||
const events = require('../../model/events/events.model')
|
||||
const servers = require('../../model/servers/servers.model')
|
||||
const visibility = require('../../model/visibility/visibility.model')
|
||||
@@ -160,4 +161,59 @@ async function listOnline(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { listServers, getServer, listEvents, listLeaderboard, listWipes, listOnline }
|
||||
/**
|
||||
* Who is asking, as core describes a viewer to `projectRoster`: `{ userId, role }`
|
||||
* or null. Only the id is trusted — `model/clans` re-reads the row — so a token
|
||||
* that cannot be decoded is simply nobody.
|
||||
*/
|
||||
function viewerOf(req) {
|
||||
try {
|
||||
const claimed = req.user || core.auth.getUserFromRequest(req)
|
||||
if (!claimed || claimed.id == null) return null
|
||||
return { userId: claimed.id, role: claimed.role || null }
|
||||
} catch (err) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One server's clans (D58): name, colour, score and member count, best first.
|
||||
*
|
||||
* Public at every setting, because none of it names a player. `board` says
|
||||
* whether the list can be trusted — a server whose plugin predates protocol 6,
|
||||
* or whose clans the bridge cannot read, answers an empty list AND the reason,
|
||||
* so the tab can say "unavailable" rather than "no clans".
|
||||
*/
|
||||
async function listClans(req, res) {
|
||||
try {
|
||||
res.json(await clans.listForServer(req.params.id))
|
||||
} catch (err) {
|
||||
log.error('failed to read clans', { server: req.params.id, error: err.message })
|
||||
res.status(500).json({ message: 'Failed to read clans' })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One clan, and its roster when the viewer is inside the roster audience (D48).
|
||||
*
|
||||
* The same decision core's `projectRoster` makes, from the same function, so
|
||||
* this page and core's roster cannot disagree about who may look. Below the
|
||||
* audience the clan is still described — its name and its count are public —
|
||||
* and `roster.visible` is false with no names at all.
|
||||
*/
|
||||
async function getClan(req, res) {
|
||||
try {
|
||||
const answer = await clans.getForViewer(req.params.externalId, viewerOf(req))
|
||||
perViewer(res)
|
||||
if (!answer) {
|
||||
res.status(404).json({ message: 'No such clan' })
|
||||
return
|
||||
}
|
||||
res.json(answer)
|
||||
} catch (err) {
|
||||
log.error('failed to read a clan', { clan: req.params.externalId, error: err.message })
|
||||
res.status(500).json({ message: 'Failed to read the clan' })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { listServers, getServer, listEvents, listLeaderboard, listWipes, listOnline, listClans, getClan }
|
||||
|
||||
Reference in New Issue
Block a user