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:
1 parent
5421268fbf
commit
18f63bf33e
55 files changed
+1559
-58
No files matched your search
@@ -11,3 +11,4 @@ export { BlkFormatError } from './errors.ts';
|
||||
export { BlkLabel, decodeBlk, encodeBlk, type SharedNameContext } from './binary/format.ts';
|
||||
export { parseSharedNameMap, type SharedNameMap } from './shared-name-map.ts';
|
||||
export { ensureBlock, findBlock, findParam, setParam, visitParams } from './tree.ts';
|
||||
export { formatBlkText } from './text/format-text.ts';
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Write a BLK document in the engine's text syntax, for people to read (request logs, save
|
||||
* inspection). The game reads binary BLK from us, so this module only writes text.
|
||||
*
|
||||
* Syntax source: DagorEngine prog/engine/ioSys/dataBlock/blk_writer.cpp (type suffixes,
|
||||
* `~` escapes inside quoted strings, `yes`/`no` booleans).
|
||||
*/
|
||||
import type { BlkBlock, BlkValue } from '../model.ts';
|
||||
|
||||
const INDENT = ' ';
|
||||
|
||||
export function formatBlkText(root: BlkBlock): string {
|
||||
const lines: string[] = [];
|
||||
writeBody(root, '', lines);
|
||||
return lines.join('\n') + (lines.length ? '\n' : '');
|
||||
}
|
||||
|
||||
function writeBody(block: BlkBlock, indent: string, lines: string[]): void {
|
||||
for (const param of block.params) lines.push(`${indent}${name(param.name)}:${formatValue(param.value)}`);
|
||||
for (const child of block.blocks) {
|
||||
lines.push(`${indent}${name(child.name)}{`);
|
||||
writeBody(child, indent + INDENT, lines);
|
||||
lines.push(`${indent}}`);
|
||||
}
|
||||
}
|
||||
|
||||
function formatValue(value: BlkValue): string {
|
||||
switch (value.type) {
|
||||
case 'string': return `t=${quote(value.value)}`;
|
||||
case 'int': return `i=${value.value}`;
|
||||
case 'real': return `r=${real(value.value)}`;
|
||||
case 'point2': return `p2=${value.value.map(real).join(', ')}`;
|
||||
case 'point3': return `p3=${value.value.map(real).join(', ')}`;
|
||||
case 'point4': return `p4=${value.value.map(real).join(', ')}`;
|
||||
case 'ipoint2': return `ip2=${value.value.join(', ')}`;
|
||||
case 'ipoint3': return `ip3=${value.value.join(', ')}`;
|
||||
case 'ipoint4': return `ip4=${value.value.join(', ')}`;
|
||||
case 'bool': return `b=${value.value ? 'yes' : 'no'}`;
|
||||
case 'color': return `c=${color(value.value)}`;
|
||||
case 'matrix': return `m=${matrix(value.value)}`;
|
||||
case 'int64': return `i64=${value.value}`;
|
||||
}
|
||||
}
|
||||
|
||||
/** E3DCOLOR is stored as 0xAARRGGBB; the text form is r, g, b, a. */
|
||||
function color(packed: number): string {
|
||||
const channel = (shift: number) => (packed >>> shift) & 0xff;
|
||||
return [channel(16), channel(8), channel(0), channel(24)].join(', ');
|
||||
}
|
||||
|
||||
/** A TMatrix is four rows of three reals. */
|
||||
function matrix(values: readonly number[]): string {
|
||||
const rows: string[] = [];
|
||||
for (let row = 0; row < values.length; row += 3) rows.push(`[${values.slice(row, row + 3).map(real).join(', ')}]`);
|
||||
return `[${rows.join(' ')}]`;
|
||||
}
|
||||
|
||||
function real(value: number): string {
|
||||
return Number.isInteger(value) ? value.toFixed(1) : String(value);
|
||||
}
|
||||
|
||||
function name(text: string): string {
|
||||
return /^[A-Za-z0-9_.\-]+$/.test(text) ? text : quote(text);
|
||||
}
|
||||
|
||||
function quote(text: string): string {
|
||||
const escaped = text
|
||||
.replaceAll('~', '~~')
|
||||
.replaceAll('"', '~"')
|
||||
.replaceAll('\r', '~r')
|
||||
.replaceAll('\n', '~n')
|
||||
.replaceAll('\t', '~t');
|
||||
return `"${escaped}"`;
|
||||
}
|
||||
Reference in new issue
Block a user