Auto-derive server.game and server.map from the server name
Server folders encode the game and map (e.g. t5_ascension_1 = game t5, map alias ascension, lobby 1). A T5_MAP_ALIASES table translates the friendly alias to the canonical mapname RCON reports (ascension → zombie_cosmodrome), covering every base + Rezurrection map. seedServerRegistry now populates game and map at insert time and backfills existing NULL rows on every boot; unknown aliases log a warning so we know when to add them. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { readdir, mkdir, stat } from 'node:fs/promises';
|
||||
import { existsSync } from 'node:fs';
|
||||
import { config, destOf } from '../config.js';
|
||||
import { db } from '../db/index.js';
|
||||
import { parseServerName } from './map-aliases.js';
|
||||
|
||||
/**
|
||||
* All server folders under SERVERS_ROOT. Used by seedServerRegistry to backfill
|
||||
@@ -81,13 +82,28 @@ export interface ServerRow {
|
||||
export async function seedServerRegistry(): Promise<number> {
|
||||
const rows = await allServers();
|
||||
const insert = db().prepare(
|
||||
'INSERT OR IGNORE INTO servers (name, komodo_type, komodo_name) VALUES (?, ?, ?)'
|
||||
'INSERT OR IGNORE INTO servers (name, komodo_type, komodo_name, game, map) VALUES (?, ?, ?, ?, ?)'
|
||||
);
|
||||
// Also backfill existing rows where game/map were never set (upgrade path
|
||||
// from before name-based auto-derivation existed).
|
||||
const backfill = db().prepare(
|
||||
'UPDATE servers SET game = COALESCE(game, ?), map = COALESCE(map, ?) WHERE name = ? AND (game IS NULL OR map IS NULL)'
|
||||
);
|
||||
let n = 0;
|
||||
const tx = db().transaction((names: string[]) => {
|
||||
for (const name of names) {
|
||||
const res = insert.run(name, 'deployment', name.replace(/_/g, '-'));
|
||||
if (res.changes > 0) n++;
|
||||
const parsed = parseServerName(name);
|
||||
const game = parsed?.game ?? null;
|
||||
const map = parsed?.mapCanonical ?? null;
|
||||
const res = insert.run(name, 'deployment', name.replace(/_/g, '-'), game, map);
|
||||
if (res.changes > 0) {
|
||||
n++;
|
||||
} else {
|
||||
backfill.run(game, map, name);
|
||||
}
|
||||
if (parsed && !parsed.mapCanonical) {
|
||||
console.warn(`[servers] unknown map alias '${parsed.mapAlias}' for ${name} — add to T5_MAP_ALIASES`);
|
||||
}
|
||||
}
|
||||
});
|
||||
tx(rows);
|
||||
|
||||
Reference in New Issue
Block a user