import { env } from 'node:process'; function req(name: string, fallback?: string): string { const v = env[name] ?? fallback; if (v === undefined) throw new Error(`missing env: ${name}`); return v; } function num(name: string, fallback: number): number { const raw = env[name]; if (!raw) return fallback; const n = Number(raw); if (!Number.isFinite(n)) throw new Error(`env ${name}=${raw} is not a number`); return n; } export const config = { serversRoot: req('SERVERS_ROOT', '/root/zombies/t5'), relDest: req('REL_DEST', 'runtime/plutonium/storage/t5/raw/scripts/sp'), // Per-kind destination sub-paths under each server's directory. `relDest` // above stays as the script fallback so existing deploys keep working. relDestScript: env.REL_DEST_SCRIPT ?? env.REL_DEST ?? 'runtime/plutonium/storage/t5/raw/scripts/sp', relDestConfig: env.REL_DEST_CONFIG ?? 'configs', relDestPlugin: env.REL_DEST_PLUGIN ?? 'runtime/plutonium/plugins', // Filename the baseline+overlays compose into. Same for every scope today. configTargetFile: env.CONFIG_TARGET_FILE ?? 'dedicated_sp.cfg', // Where on-disk copies of active beta files live for operator visibility. // Cleared per-beta on promote/rollback. betaArchiveDir: req('BETA_ARCHIVE_DIR', '/root/zombies/beta-archive'), dbPath: req('DB_PATH', './data/cherry.db'), deployKeepDays: num('DEPLOY_KEEP_DAYS', 7), httpTimeoutMs: num('HTTP_TIMEOUT_MS', 10_000), komodo: { address: env.KOMODO_ADDRESS ?? '', apiKey: env.KOMODO_API_KEY ?? '', apiSecret: env.KOMODO_API_SECRET ?? '' }, rcon: { // Host every RCON packet is sent to. Defaults to the Docker // host-gateway alias so the electric-cherry container can reach // Plutonium servers running on the same host without knowing each // container's internal IP. host: env.RCON_HOST ?? 'host.docker.internal', // Shared across the fleet — every server uses the same rcon_password. password: env.RCON_PASSWORD ?? '', timeoutMs: num('RCON_TIMEOUT_MS', 3_000) } } as const; export function komodoConfigured(): boolean { return !!(config.komodo.address && config.komodo.apiKey && config.komodo.apiSecret); } export function rconConfigured(): boolean { return !!config.rcon.password; } export type ArtifactKind = 'script' | 'config' | 'plugin' | 'baseline'; export function relDestForKind(kind: ArtifactKind): string { switch (kind) { case 'script': return config.relDestScript; case 'config': return config.relDestConfig; case 'baseline': return config.relDestConfig; case 'plugin': return config.relDestPlugin; } } export const destOfKind = (server: string, kind: ArtifactKind) => `${config.serversRoot}/${server}/${relDestForKind(kind)}`; // Back-compat: existing call sites written before the multi-kind refactor // resolve to the script destination. export const destOf = (server: string) => destOfKind(server, 'script'); export const betaArchiveOf = (betaId: number) => `${config.betaArchiveDir}/beta-${betaId}`;