Fix squadron persistence and align inventory wire formats

Read squadron action parameters from the request headers and persist
squadron state on profile refresh. Use floating-point trophy weights
to match the client probability display and assign unique log IDs
when opening multiple chests.

Tighten shop, marketplace, squadron, and cloud settings validation.
Move PBBD and inventory encoding into the protocol modules and share
CSV reading. Update the research and acceptance instructions.

Type checking and all eight executable patch checks passed.
In-game acceptance is pending.
This commit is contained in:
N0VAN0M4LY committed 2026-11-25 09:10:09 +08:00
1 parent 0b604c76f1
commit 8012cf7954
40 files changed
+1347 -1248

No files matched your search

@@ -1,17 +1,63 @@
/** Typed reads of a char request's BLK parameters; a missing or differently typed parameter reads as undefined. */
/** Read typed parameters from a char action's BLK payload or HTTP request headers. */
import { findParam, type BlkBlock } from '@wto/blk';
import type { CharActionContext } from '../char-action.ts';
export function stringParam(payload: BlkBlock, name: string): string | undefined {
const value = findParam(payload, name)?.value;
return value?.type === 'string' ? value.value : undefined;
const param = findParam(payload, name)?.value;
return param?.type === 'string' ? param.value : undefined;
}
export function intParam(payload: BlkBlock, name: string): number | undefined {
const value = findParam(payload, name)?.value;
return value?.type === 'int' ? value.value : undefined;
const param = findParam(payload, name)?.value;
return param?.type === 'int' ? param.value : undefined;
}
export function boolParam(payload: BlkBlock, name: string): boolean | undefined {
const value = findParam(payload, name)?.value;
return value?.type === 'bool' ? value.value : undefined;
const param = findParam(payload, name)?.value;
return param?.type === 'bool' ? param.value : undefined;
}
export function headerOrPayloadString(context: CharActionContext, name: string): string | undefined {
const fromPayload = context.payload ? stringParam(context.payload, name) : undefined;
return fromPayload ?? context.headerParam(name);
}
export function headerOrPayloadInt(context: CharActionContext, name: string): number | undefined {
if (context.payload) {
const fromPayload = intParam(context.payload, name);
if (fromPayload !== undefined) return fromPayload;
}
const hdr = context.headerParam(name)?.trim();
if (hdr !== undefined && /^-?\d+$/.test(hdr)) {
const parsed = Number(hdr);
if (Number.isSafeInteger(parsed)) return parsed;
}
return undefined;
}
export function headerOrPayloadBool(context: CharActionContext, name: string): boolean | undefined {
if (context.payload) {
const fromBool = boolParam(context.payload, name);
if (fromBool !== undefined) return fromBool;
const fromStr = stringParam(context.payload, name);
if (fromStr !== undefined) return parseTruthyFlag(fromStr);
}
const hdr = context.headerParam(name);
return hdr !== undefined ? parseTruthyFlag(hdr) : undefined;
}
export function headerOrPayloadId(context: CharActionContext, name: string): string | undefined {
if (context.payload) {
const param = findParam(context.payload, name)?.value;
if (param?.type === 'string' && param.value !== '') return param.value;
if (param?.type === 'int64') return param.value.toString();
if (param?.type === 'int') return String(param.value);
}
const hdr = context.headerParam(name);
return hdr && hdr !== '' ? hdr : undefined;
}
function parseTruthyFlag(raw: string): boolean {
const lower = raw.trim().toLowerCase();
return lower === 'yes' || lower === 'true' || lower === 'on' || lower === '1';
}