A switch per monument label, a fleet default and a per-server override, on Admin -> Rust visibility's live map card. Substations, caves, train tunnels, wells and the other minor labels start hidden; every other label is drawn, so a monument a game update adds appears. GET /map leaves hidden labels out of the answer, so the website and the app both lose them. No schema change: rows are map.marker.<label key> in rust_settings and rust_map_overrides. No wire change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
96 lines
3.4 KiB
JavaScript
96 lines
3.4 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],
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Every stored setting whose key starts with `prefix`, as `{ setting, value }`
|
|
* rows: the map's per-label marker switches are one row each (D196).
|
|
*/
|
|
async function listSettings(prefix) {
|
|
return core.query(
|
|
`SELECT setting_key AS setting, value FROM ${SETTINGS} WHERE setting_key LIKE CONCAT(?, '%')`,
|
|
[prefix.replace(/[\\%_]/g, '\\$&')],
|
|
)
|
|
}
|
|
|
|
/** Forget one setting, so it follows the built-in default again. */
|
|
async function clearSetting(key) {
|
|
await core.query(`DELETE FROM ${SETTINGS} WHERE setting_key = ?`, [key])
|
|
}
|
|
|
|
/** 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,
|
|
listSettings,
|
|
clearSetting,
|
|
getServerPresence,
|
|
listServerPresence,
|
|
setServerPresence,
|
|
setServerNews,
|
|
setServerNewsDelivery,
|
|
}
|