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
62 lines
2.1 KiB
JavaScript
62 lines
2.1 KiB
JavaScript
// ── SQL for chat titles (phase 17) ────────────────────────────────────────
|
|
//
|
|
// The rules an operator writes, per server, and the two columns on
|
|
// `rust_servers` that say how many titles a player shows. The titles themselves
|
|
// are never stored — see `schema.sql` and `titles.js`.
|
|
|
|
const core = require('../../core')
|
|
|
|
const RULES = 'rust_title_rules'
|
|
const SERVERS = 'rust_servers'
|
|
|
|
/** One server's rules, in precedence order. */
|
|
async function listRules(serverId) {
|
|
return core.query(
|
|
`SELECT id, stat, top_n AS topN, text, color
|
|
FROM ${RULES}
|
|
WHERE server_id = ?
|
|
ORDER BY position ASC, id ASC`,
|
|
[serverId],
|
|
)
|
|
}
|
|
|
|
/** Every server's rules, for the admin list — one read rather than one per server. */
|
|
async function listAllRules() {
|
|
return core.query(
|
|
`SELECT server_id AS serverId, stat, top_n AS topN, text, color
|
|
FROM ${RULES}
|
|
ORDER BY server_id ASC, position ASC, id ASC`,
|
|
)
|
|
}
|
|
|
|
async function getMode(serverId) {
|
|
const rows = await core.query(
|
|
`SELECT title_mode AS mode, title_max AS max FROM ${SERVERS} WHERE id = ?`,
|
|
[serverId],
|
|
)
|
|
return rows[0] || null
|
|
}
|
|
|
|
async function listModes() {
|
|
return core.query(`SELECT id AS serverId, title_mode AS mode, title_max AS max FROM ${SERVERS}`)
|
|
}
|
|
|
|
/**
|
|
* Replace one server's rules and mode whole. The form edits a list, so the
|
|
* write is a list — and a rule's position is its place in that list.
|
|
*/
|
|
async function saveSettings(serverId, { mode, max, rules }) {
|
|
await core.query(`UPDATE ${SERVERS} SET title_mode = ?, title_max = ? WHERE id = ?`, [mode, max, serverId])
|
|
await core.query(`DELETE FROM ${RULES} WHERE server_id = ?`, [serverId])
|
|
|
|
if (!rules.length) return
|
|
|
|
await core.query(
|
|
`INSERT INTO ${RULES} (server_id, position, stat, top_n, text, color)
|
|
VALUES ${rules.map(() => '(?, ?, ?, ?, ?, ?)').join(',')}`,
|
|
rules.flatMap((r, i) => [serverId, i, r.stat, r.topN, r.text, r.color]),
|
|
)
|
|
}
|
|
|
|
module.exports = { RULES, listRules, listAllRules, getMode, listModes, saveSettings }
|