feat(server): handle matching login and decorative content manifests

Add matching frame and message handling, per-connection session
encryption, and loopback traffic dispatch. Serve the decorative content
manifest and empty indices to remove startup download waits.

Resolve character requests to their explicit account ID, include the
nickname in profile replies, and redact matching traffic logs.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 08:12:40 +08:00
1 parent 7f482ae530
commit 27754122fc
24 files changed
+857 -37

No files matched your search

@@ -1,15 +1,18 @@
/** Char action names mapped to their handlers (full list of names: research-data/char_actions_37.json). */
import type { AccountStore } from '../../accounts/account-store.ts';
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
import type { CharActionHandler } from '../char-action.ts';
import { initialMeta, legacyUserData } from './online-init-actions.ts';
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
export interface ActionDependencies {
readonly profiles: PlayerProfiles;
readonly accounts: AccountStore;
}
export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharActionHandler> {
return new Map<string, CharActionHandler>([
['cln_get_initial_meta', initialMeta()],
['cln_legacy_get_userdata', legacyUserData(deps.profiles)],
['cln_upd_entitlements_full', entitlementsFull(deps.profiles, deps.accounts)],
['cln_legacy_get_userdata', legacyUserData(deps.profiles, deps.accounts)],
]);
}
@@ -3,6 +3,8 @@
*.
*/
import { emptyBlock } from '@wto/blk';
import type { Account, AccountStore } from '../../accounts/account-store.ts';
import { clientProfile } from '../../profile/client-profile.ts';
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
import type { CharAnswer } from '../char-answers.ts';
import type { CharActionContext, CharActionHandler } from '../char-action.ts';
@@ -21,11 +23,31 @@ export function initialMeta(): CharActionHandler {
};
}
/** cln_legacy_get_userdata: the whole profile (ClientEconomicState::loadOnline, aces.exe 0x2a23b0). */
export function legacyUserData(profiles: PlayerProfiles): CharActionHandler {
return (context) => withUser(context, (userId) => ({ kind: 'data', blk: profiles.profileOf(userId) }));
/**
* cln_upd_entitlements_full: the profile request of the online initialisation stage
* CHAR_PROFILE_RECEIVED (sent at aces.exe 0x29f920 with headers onLogin and resetToken; the
* request body is the client's machine description). The answer is the whole profile: the
* job (EconomicSerializeJob, type 4) loads it as a BLK, and EconomicSerializeAction::
* performAction (0x295ef0) reads it into the client's profile with the profile serializer
* (0x917740) when it is not empty.
*/
export function entitlementsFull(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
return profileAnswer(profiles, accounts);
}
function withUser(context: CharActionContext, run: (userId: string) => CharAnswer): CharAnswer {
return context.userId ? run(context.userId) : { kind: 'error', code: 'AUTH_REQ_ERROR' };
/** cln_legacy_get_userdata: the whole profile (ClientEconomicState::loadOnline, aces.exe 0x2a23b0). */
export function legacyUserData(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
return profileAnswer(profiles, accounts);
}
function profileAnswer(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
return (context) => withAccount(context, accounts, (account) => ({
kind: 'data',
blk: clientProfile(profiles.profileOf(account.userId), account),
}));
}
function withAccount(context: CharActionContext, accounts: AccountStore, run: (account: Account) => CharAnswer): CharAnswer {
const account = context.userId === undefined ? undefined : accounts.byUserId(context.userId);
return account ? run(account) : { kind: 'error', code: 'AUTH_REQ_ERROR' };
}
@@ -3,7 +3,7 @@ import type { BlkBlock } from '@wto/blk';
import type { CharAnswer } from './char-answers.ts';
export interface CharActionContext {
/** From the request's userid header; undefined when the client sent none. */
/** From the request's uidhint header; undefined when the client sent none. */
readonly userId: string | undefined;
/** The request's BLK parameters, when the body carried a BLK. */
readonly payload: BlkBlock | undefined;
@@ -1,9 +1,11 @@
/**
* char service: profiles and player actions.
*
* The client names the action in the request header "action" and identifies the player in
* "userid" (request headers assembled at aces.exe 0x336c590). The local service trusts
* userid as it is: there is nothing to protect on a single-player machine.
* The client names the action in the request header "action" (request headers assembled at
* aces.exe 0x336c590). Requests carry no "userid" header; the player is identified by
* "uidhint", the user id from the sign-in answer (implementation notes; added by
* EconomicSerializeJob::doJob, 0x2968a5). The local service trusts uidhint as it is: there
* is nothing to protect on a single-player machine.
*
* An action with no handler yet gets a data answer holding an empty BLK and is marked
* unhandled in the traffic log. handleReqResult treats any 200 answer that is not "!ERROR:"
@@ -35,7 +37,7 @@ export class CharService implements Service {
const payload = decodeRequestPayload(request.body);
const handler = this.#actions.get(action);
const answer: CharAnswer = handler
? handler({ userId: header(request, 'userid'), payload: payload.blk })
? handler({ userId: header(request, 'uidhint'), payload: payload.blk })
: { kind: 'data', blk: emptyBlock() };
const response = toResponse(answer);
return {