feat(rust): chat titles, BetterChat group styles, the voice and popups (phase 17)
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
This commit is contained in:
@@ -17,12 +17,25 @@ const mapImages = require('../../mapImages')
|
||||
const nextWipe = require('../../model/servers/nextWipe')
|
||||
const servers = require('../../model/servers/servers.model')
|
||||
const sidecar = require('../../sidecarClient')
|
||||
const titleSync = require('../../titleSync')
|
||||
const titles = require('../../model/titles/titles')
|
||||
const titlesModel = require('../../model/titles/titles.model')
|
||||
const voice = require('../../model/permissions/voice')
|
||||
|
||||
const log = core.logger('admin')
|
||||
|
||||
async function listServers(req, res) {
|
||||
try {
|
||||
res.json({ servers: await servers.listForAdmin() })
|
||||
const [rows, settings] = await Promise.all([servers.listForAdmin(), titlesModel.settingsByServer()])
|
||||
|
||||
// Phase 17: each server's chat titles, and what the last push of them found.
|
||||
res.json({
|
||||
servers: rows.map((row) => ({
|
||||
...row,
|
||||
titles: settings.get(row.id) || { mode: 'first', max: 2, rules: [] },
|
||||
titlePush: titleSync.lastPush(row.id),
|
||||
})),
|
||||
})
|
||||
} catch (err) {
|
||||
log.error('failed to read the server list', { error: err.message })
|
||||
res.status(500).json({ message: 'Failed to read the server list' })
|
||||
@@ -218,4 +231,96 @@ async function renderMap(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { scheduleFrom, listServers, putServer, deleteServer, testServer, fetchMap, renderMap }
|
||||
// ── The optional mods (phase 17) ─────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Replace one server's chat titles: the rules, the mode and N (D135, D136).
|
||||
* Validated whole, so a bad rule saves nothing. The titles reach the game on
|
||||
* the push loop's next tick, and the web the next time it reads.
|
||||
*/
|
||||
async function putTitles(req, res) {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const existing = await db.getServer(id)
|
||||
if (!existing) return res.status(404).json({ message: 'No such server' })
|
||||
|
||||
const checked = titles.validateSettings(req.body)
|
||||
if (!checked.ok) return res.status(400).json({ message: checked.errors.join(' '), errors: checked.errors })
|
||||
|
||||
await titlesModel.saveSettings(id, checked.value)
|
||||
await core.activity.log({
|
||||
req,
|
||||
action: 'rust.titles.save',
|
||||
detail: { server: id, mode: checked.value.mode, max: checked.value.max, rules: checked.value.rules },
|
||||
})
|
||||
|
||||
return res.json({ titles: await titlesModel.settingsFor(id) })
|
||||
} catch (err) {
|
||||
log.error('failed to save chat titles', { server: id, error: err.message })
|
||||
return res.status(500).json({ message: 'Failed to save the chat titles' })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Which optional mods one server has loaded right now, read live from the game
|
||||
* (`integrations` on `server.status`). Live, because an operator installs
|
||||
* BetterChat and then looks here, and the board the site keeps is from the last
|
||||
* time the plugin connected.
|
||||
*/
|
||||
async function integrations(req, res) {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const server = await servers.getForCalling(id)
|
||||
if (!server) return res.status(404).json({ message: 'No such server, or it is disabled' })
|
||||
|
||||
const result = await sidecar.liveStatus(server)
|
||||
const data = result.ok && result.data ? result.data : null
|
||||
|
||||
return res.json({
|
||||
ok: Boolean(data),
|
||||
status: result.status,
|
||||
integrations: data && data.integrations ? data.integrations : null,
|
||||
})
|
||||
} catch (err) {
|
||||
log.error('failed to read integrations', { server: id, error: err.message })
|
||||
return res.status(500).json({ message: 'Failed to ask the server what it has loaded' })
|
||||
}
|
||||
}
|
||||
|
||||
async function getVoice(req, res) {
|
||||
try {
|
||||
res.json(await voice.describe())
|
||||
} catch (err) {
|
||||
log.error('failed to read the voice', { error: err.message })
|
||||
res.status(500).json({ message: 'Failed to read the announcement voice' })
|
||||
}
|
||||
}
|
||||
|
||||
async function putVoice(req, res) {
|
||||
try {
|
||||
const result = await voice.choose(req.body.group || '', req.user ? req.user.id : null)
|
||||
if (!result.ok) return res.status(400).json({ message: result.message })
|
||||
|
||||
await core.activity.log({ req, action: 'rust.voice.save', detail: { group: result.voice || null } })
|
||||
return res.json(await voice.describe())
|
||||
} catch (err) {
|
||||
log.error('failed to save the voice', { error: err.message })
|
||||
return res.status(500).json({ message: 'Failed to save the announcement voice' })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
scheduleFrom,
|
||||
listServers,
|
||||
putServer,
|
||||
deleteServer,
|
||||
testServer,
|
||||
fetchMap,
|
||||
renderMap,
|
||||
putTitles,
|
||||
integrations,
|
||||
getVoice,
|
||||
putVoice,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user