Files
Module-Rust/server/model/visibility/visibility.db.js
wtclaude 1b70cef5be 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
2026-09-25 17:48:22 -05:00

78 lines
2.9 KiB
JavaScript

// ── SQL for the visibility settings ───────────────────────────────────────
//
// Two stores for one decision: the fleet default in `rust_settings`, and an
// optional per-server override on `rust_servers`. See `schema.sql` for why each
// lives where it does.
const core = require('../../core')
const SETTINGS = 'rust_settings'
const SERVERS = 'rust_servers'
/** One setting's stored value, or `null` when nobody has ever set it. */
async function getSetting(key) {
const rows = await core.query(`SELECT value FROM ${SETTINGS} WHERE setting_key = ?`, [key])
return rows[0] ? rows[0].value : null
}
async function setSetting(key, value, userId = null) {
await core.query(
`INSERT INTO ${SETTINGS} (setting_key, value, updated_by, updated_at)
VALUES (?, ?, ?, CURRENT_TIMESTAMP)
ON DUPLICATE KEY UPDATE value = VALUES(value), updated_by = VALUES(updated_by),
updated_at = CURRENT_TIMESTAMP`,
[key, value, userId],
)
}
/** One server's override, `null` for "inherit", or `undefined` when there is no such server. */
async function getServerPresence(serverId) {
const rows = await core.query(`SELECT presence_audience AS presence FROM ${SERVERS} WHERE id = ?`, [serverId])
return rows[0] ? rows[0].presence : undefined
}
/** Every configured server with its override, in the operator's own order. */
async function listServerPresence() {
return core.query(
`SELECT id, name, enabled, presence_audience AS presence, announce_news AS announceNews,
news_delivery AS newsDelivery
FROM ${SERVERS}
ORDER BY sort_order ASC, id ASC`,
)
}
/**
* Sets or clears (`null`) one server's override.
*
* Returns nothing, deliberately. `affectedRows` would look like a way to tell
* "no such server" from success, and it is not one: without `foundRows` an
* UPDATE writing the value already there reports 0, and whether core's pool sets
* that flag is core's business. The model checks existence with a read first.
*/
async function setServerPresence(serverId, value) {
await core.query(`UPDATE ${SERVERS} SET presence_audience = ? WHERE id = ?`, [value, serverId])
}
/**
* Turns one server's news switch on or off (D104). Existence is the model's
* question, asked with a read first, for the reason given above.
*/
async function setServerNews(serverId, on) {
await core.query(`UPDATE ${SERVERS} SET announce_news = ? WHERE id = ?`, [on ? 1 : 0, serverId])
}
/** Where one server's news goes when its switch is on: `chat` or `popup` (D142). */
async function setServerNewsDelivery(serverId, delivery) {
await core.query(`UPDATE ${SERVERS} SET news_delivery = ? WHERE id = ?`, [delivery, serverId])
}
module.exports = {
getSetting,
setSetting,
getServerPresence,
listServerPresence,
setServerPresence,
setServerNews,
setServerNewsDelivery,
}