feat(accounts): implement local login

Route login and character requests by their original host names on one
loopback port. Add local accounts, saves, and credential redaction.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 05:01:26 +08:00
1 parent c3914ec0d6
commit 7f482ae530
55 files changed
+1559 -58

No files matched your search

@@ -0,0 +1,27 @@
/**
* The game files the local service reads, opened lazily from the player's game folder.
*/
import { join } from 'node:path';
import type { BlkBlock } from '@wto/blk';
import { GamePack } from './game-pack.ts';
/** Gaijin's template for a new account's profile. */
const NEW_ACCOUNT_TEMPLATE = 'config/default_user.blk';
export class GameFiles {
readonly #gameFolder: string;
#charPack: GamePack | undefined;
constructor(gameFolder: string) {
this.#gameFolder = gameFolder;
}
newAccountTemplate(): BlkBlock {
return this.#char().readBlk(NEW_ACCOUNT_TEMPLATE);
}
#char(): GamePack {
this.#charPack ??= GamePack.open(join(this.#gameFolder, 'char.vromfs.bin'));
return this.#charPack;
}
}
@@ -0,0 +1,33 @@
/**
* Read BLK documents out of one of the player's game data packs (implementation notes: the
* game's own files are the source of every static fact; nothing is shipped with us).
*/
import { readFileSync } from 'node:fs';
import { decodeBlk, parseSharedNameMap, type BlkBlock, type SharedNameContext } from '@wto/blk';
import { getFile, NAME_MAP_PATH, readArchive, type Archive } from '@wto/vromfs';
export class GamePack {
readonly #archive: Archive;
readonly #shared: SharedNameContext;
private constructor(archive: Archive) {
this.#archive = archive;
const dictionary = findDictionary(archive);
const names = archive.files.has(NAME_MAP_PATH) ? parseSharedNameMap(getFile(archive, NAME_MAP_PATH), dictionary).names : [];
this.#shared = { names, dictionary };
}
static open(packPath: string): GamePack {
return new GamePack(readArchive(readFileSync(packPath)));
}
readBlk(pathInPack: string): BlkBlock {
return decodeBlk(getFile(this.#archive, pathInPack), this.#shared);
}
}
function findDictionary(archive: Archive): Uint8Array | undefined {
const dictionaries = [...archive.files.keys()].filter((path) => path.endsWith('.dict'));
if (dictionaries.length > 1) throw new Error(`the data pack has several zstd dictionaries: ${dictionaries.join(', ')}`);
return dictionaries.length ? archive.files.get(dictionaries[0]!) : undefined;
}