feat(accounts): persist EULA acceptance
Persist the accepted EULA version before responding and return both agreement fields in the profile. Respond to matching heartbeats.
This commit is contained in:
1 parent
6233a64835
commit
ac2c185d4c
7 files changed
+108
-10
No files matched your search
@@ -0,0 +1,10 @@
|
||||
/** Resolving the player a char request is for (the uidhint header, implementation notes). */
|
||||
import type { Account, AccountStore } from '../../accounts/account-store.ts';
|
||||
import type { CharAnswer } from '../char-answers.ts';
|
||||
import type { CharActionContext } from '../char-action.ts';
|
||||
|
||||
/** Run the handler for the request's account; an unknown or missing user id is an authorisation error. */
|
||||
export 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' };
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { acceptEula } from './agreement-actions.ts';
|
||||
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
|
||||
|
||||
export interface ActionDependencies {
|
||||
@@ -14,5 +15,6 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharA
|
||||
['cln_get_initial_meta', initialMeta()],
|
||||
['cln_upd_entitlements_full', entitlementsFull(deps.profiles, deps.accounts)],
|
||||
['cln_legacy_get_userdata', legacyUserData(deps.profiles, deps.accounts)],
|
||||
['cln_accept_eula', acceptEula(deps.profiles, deps.accounts)],
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* The player's acceptance of the end-user licence agreement.
|
||||
*
|
||||
* The client keeps the accepted version in its save object (offset 0xe970, read by the
|
||||
* script function getAgreedEulaVersion at aces.exe 2.61.0.37 0x1c3e580) and fills it from
|
||||
* exactly two places:
|
||||
* - the profile's top-level int eulaVersionAccepted, when a profile is loaded (0x917870,
|
||||
* called by the profile serializer 0x917740);
|
||||
* - the answer to cln_accept_eula: GameSaveData::onAsyncEconTransComplete (0xeb5f60) reads
|
||||
* eulaVersionAccepted and ndaVersionAccepted from the answer's top level when the job
|
||||
* (type 12) succeeds (0xeb79bd..0xeb7a05).
|
||||
* The stock login script (scripts/login/loginpseudothreadsconfig.nut) waits until the
|
||||
* accepted version reaches the current one, so the acceptance has to be stored in the save
|
||||
* and sent back.
|
||||
*/
|
||||
import { emptyBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
|
||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { withAccount } from './account-context.ts';
|
||||
|
||||
const EULA_VERSION = 'eulaVersionAccepted';
|
||||
const NDA_VERSION = 'ndaVersionAccepted';
|
||||
|
||||
/**
|
||||
* The only sender is the script function setAgreedEulaVersion (0x1c3e560), which always
|
||||
* passes agreement type 0 (the EULA) to the request builder 0x298ea0; the body is
|
||||
* {version:i, type:i}. Other types have no sender in 2.61.0.37 and are refused.
|
||||
*/
|
||||
const EULA_AGREEMENT_TYPE = 0;
|
||||
|
||||
/** cln_accept_eula: store the accepted EULA version and answer with the accepted versions. */
|
||||
export function acceptEula(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
|
||||
return (context) => withAccount(context, accounts, (account) => {
|
||||
const version = intParam(context.payload, 'version');
|
||||
const type = intParam(context.payload, 'type');
|
||||
if (version === undefined || type !== EULA_AGREEMENT_TYPE) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
|
||||
const profile = profiles.update(account.userId, (saved) => {
|
||||
setParam(saved, EULA_VERSION, { type: 'int', value: version });
|
||||
});
|
||||
return { kind: 'data', blk: acceptedVersions(profile) };
|
||||
});
|
||||
}
|
||||
|
||||
/** Both versions, because the client overwrites both from the answer (a missing one reads as 0). */
|
||||
function acceptedVersions(profile: BlkBlock): BlkBlock {
|
||||
const answer = emptyBlock();
|
||||
setParam(answer, EULA_VERSION, { type: 'int', value: intParam(profile, EULA_VERSION) ?? 0 });
|
||||
setParam(answer, NDA_VERSION, { type: 'int', value: intParam(profile, NDA_VERSION) ?? 0 });
|
||||
return answer;
|
||||
}
|
||||
|
||||
function intParam(block: BlkBlock | undefined, name: string): number | undefined {
|
||||
const value = block ? findParam(block, name)?.value : undefined;
|
||||
return value?.type === 'int' ? value.value : undefined;
|
||||
}
|
||||
@@ -3,11 +3,11 @@
|
||||
*.
|
||||
*/
|
||||
import { emptyBlock } from '@wto/blk';
|
||||
import type { Account, AccountStore } from '../../accounts/account-store.ts';
|
||||
import type { 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';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { withAccount } from './account-context.ts';
|
||||
|
||||
/**
|
||||
* cln_get_initial_meta: server-side metadata the client reads in GameSaveData's initial-meta
|
||||
@@ -47,7 +47,3 @@ function profileAnswer(profiles: PlayerProfiles, accounts: AccountStore): CharAc
|
||||
}));
|
||||
}
|
||||
|
||||
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' };
|
||||
}
|
||||
@@ -49,6 +49,25 @@ export interface MatchingRequest {
|
||||
readonly params: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value of "type" in the client's keep-alive: about 30 s after the last traffic the client
|
||||
* sends {"id", "type": 100} through the same request sender as named requests (0x44ea0e0,
|
||||
* called at 0x44edf0b) with its own completion callback (0x44f21d0). The answer handler
|
||||
* finds it by "id" like any request; status 0 logs "got CLN_PING response", and no answer
|
||||
* within 15 s closes the connection ("CLN_PING got no response").
|
||||
*/
|
||||
export const PING_TYPE = 100;
|
||||
|
||||
/** The ping's id, or undefined when the message is not a keep-alive. */
|
||||
export function asPing(message: MatchingMessage): number | undefined {
|
||||
const { id, type } = message.json;
|
||||
return message.kind === MessageKind.Request && type === PING_TYPE && typeof id === 'number' ? id : undefined;
|
||||
}
|
||||
|
||||
export function pingAnswer(id: number): MatchingMessage {
|
||||
return { kind: MessageKind.Answer, json: { id, type: PING_TYPE } };
|
||||
}
|
||||
|
||||
/** Undefined when the message is not a request the client expects an answer to. */
|
||||
export function asRequest(message: MatchingMessage): MatchingRequest | undefined {
|
||||
if (message.kind !== MessageKind.Request) return undefined;
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
*
|
||||
* Every request gets an answer. A request with no handler yet is answered with success and
|
||||
* empty data and marked unhandled in the traffic log, so the client carries on and shows
|
||||
* what it asks for next (the same policy as the char service). Messages that are not
|
||||
* requests are only logged.
|
||||
* what it asks for next (the same policy as the char service). Keep-alive pings are
|
||||
* answered with their id (matching-message.ts). Other messages are only logged.
|
||||
*/
|
||||
import type { Socket } from 'node:net';
|
||||
import type { TrafficLog } from '../traffic-log/traffic-log.ts';
|
||||
import { encodePacket, PacketReader } from './matching-frame.ts';
|
||||
import { answerTo, asRequest, decodeMessage, encodeMessage, type MatchingMessage } from './matching-message.ts';
|
||||
import { answerTo, asPing, asRequest, decodeMessage, encodeMessage, pingAnswer, type MatchingMessage } from './matching-message.ts';
|
||||
import { MATCHING_REQUESTS, type MatchingSessionControl } from './matching-requests.ts';
|
||||
import { messageLogText } from './message-redaction.ts';
|
||||
import { EnvelopeReader, sealEnvelope } from './session-crypto/encrypted-envelope.ts';
|
||||
@@ -78,6 +78,12 @@ class MatchingSession {
|
||||
}
|
||||
|
||||
#handle(message: MatchingMessage): void {
|
||||
const pingId = asPing(message);
|
||||
if (pingId !== undefined) {
|
||||
this.#record('in', message, `ping #${pingId}`, false);
|
||||
this.#send(pingAnswer(pingId));
|
||||
return;
|
||||
}
|
||||
const request = asRequest(message);
|
||||
if (!request) {
|
||||
this.#record('in', message, 'not a request', false);
|
||||
|
||||
@@ -23,4 +23,12 @@ export class PlayerProfiles {
|
||||
this.#saves.saveProfile(userId, created);
|
||||
return created;
|
||||
}
|
||||
|
||||
/** Change the player's profile and write it to the save before returning it. */
|
||||
update(userId: string, change: (profile: BlkBlock) => void): BlkBlock {
|
||||
const profile = this.profileOf(userId);
|
||||
change(profile);
|
||||
this.#saves.saveProfile(userId, profile);
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user