Add T6 Zombies fleet support with Plutainer configuration
This commit is contained in:
@@ -1,24 +1,22 @@
|
||||
import { readdir, mkdir, stat } from 'node:fs/promises';
|
||||
import { existsSync } from 'node:fs';
|
||||
import { config, destOf } from '../config.js';
|
||||
import { config, destOf, serverDir, rootOfServer } 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
|
||||
* All server folders under the game roots. Used by seedServerRegistry to backfill
|
||||
* the servers table for any on-disk server directory that isn't yet tracked.
|
||||
*/
|
||||
export async function serverDirectories(): Promise<string[]> {
|
||||
let entries;
|
||||
try {
|
||||
entries = await readdir(config.serversRoot, { withFileTypes: true });
|
||||
} catch {
|
||||
return [];
|
||||
const names = new Set<string>();
|
||||
for (const root of new Set([config.serversRoot, config.t6ServersRoot])) {
|
||||
const entries = await readdir(root, { withFileTypes: true }).catch(() => []);
|
||||
for (const entry of entries) {
|
||||
if (entry.isDirectory() && rootOfServer(entry.name) === root) names.add(entry.name);
|
||||
}
|
||||
}
|
||||
return entries
|
||||
.filter((e) => e.isDirectory())
|
||||
.map((e) => e.name)
|
||||
.sort();
|
||||
return [...names].sort();
|
||||
}
|
||||
|
||||
/** Fleet membership is owned by the database, independent of mounted files. */
|
||||
@@ -41,7 +39,7 @@ export function matchServers(all: string[], patterns: string[]): string[] {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a server has an sp/ destination. Creates it when create=true.
|
||||
* Ensure a server has a script destination. Creates it when create=true.
|
||||
*/
|
||||
export async function ensureDest(
|
||||
server: string,
|
||||
@@ -57,7 +55,7 @@ export async function ensureDest(
|
||||
}
|
||||
return { ok: true, path: dest };
|
||||
}
|
||||
if (!create) return { ok: false, reason: 'no sp folder — use create=true' };
|
||||
if (!create) return { ok: false, reason: 'no script folder — use create=true' };
|
||||
await mkdir(dest, { recursive: true });
|
||||
return { ok: true, path: dest };
|
||||
}
|
||||
@@ -127,7 +125,7 @@ export async function seedServerRegistry(): Promise<number> {
|
||||
const map = parsed?.mapCanonical ?? null;
|
||||
const gameMode = parsed?.gameMode ?? null;
|
||||
const mapSlug = parsed?.mapSlug ?? null;
|
||||
const hostDir = `${config.serversRoot}/${name}`;
|
||||
const hostDir = serverDir(name);
|
||||
const res = insert.run(name, name, game, map, gameMode, mapSlug, hostDir);
|
||||
if (res.changes > 0) {
|
||||
n++;
|
||||
@@ -136,7 +134,7 @@ export async function seedServerRegistry(): Promise<number> {
|
||||
}
|
||||
if (parsed && !parsed.mapCanonical) {
|
||||
console.warn(
|
||||
`[servers] unknown map slug '${parsed.mapSlug}' for ${name} — add to T5_ZOMBIE_MAPS`
|
||||
`[servers] unknown map slug '${parsed.mapSlug}' for ${name} — add to the game map catalog`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user