/** * `cln_update` (aces.exe 2.61.0.37 0x29f3ee, job type 3 -> `onUpdateProfile`): * triggered by `save_online_single_job` when the client marks seen user logs as disabled * (`scripts/userLog/userlogUtils.nut` `disableSeenUserlogs`, tag 223) or updates hangar * auto-repair / auto-refill / auto-buy-modifications, map preferences, and per-vehicle * preferences (`hangar/` `lastSkin`, `lastWeapon`, `lastBullets0..5`, and flight * trims `aileronTrim`/`elevatorTrim`/`rudderTrim`). On returning from * a stock training mission, the client also reports completion in `missionAwards` while * `pveProgress` is empty. Answers the whole updated profile. */ import { findBlock, findParam, type BlkBlock } from '@wto/blk'; import type { AccountStore } from '../../accounts/account-store.ts'; import { boolField, stringField } from '../../game-data/datasets/blk-fields.ts'; import { applyClientProfileUpdate } from '../../profile/profile-client-settings.ts'; import type { PlayerProfiles } from '../../profile/player-profiles.ts'; import { ACCEPTED } from '../../research/rule-outcome.ts'; import type { TrainingCatalogue, TrainingCompletionReport } from '../../training/training-completion.ts'; import type { CharActionHandler } from '../char-action.ts'; import { ruleAction } from './rule-answer.ts'; export function clientUpdateAction( profiles: PlayerProfiles, accounts: AccountStore, training?: TrainingCatalogue, ): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const completion = training ? readTrainingCompletion(payload) : undefined; return (profile) => { applyClientProfileUpdate(profile, payload); if (completion && training) training.applyCompletion(profile, completion); return ACCEPTED; }; }); } function readTrainingCompletion(request: BlkBlock): TrainingCompletionReport | undefined { const awards = findBlock(request, 'missionAwards'); if (!awards || stringField(awards, 'gameModeName') !== 'training' || boolField(awards, 'success') !== true || boolField(awards, 'early') !== false || boolField(awards, 'onlineGame') !== false) return undefined; const chapter = stringField(awards, 'chapterName'); const mission = stringField(awards, 'missionName'); const difficulty = findParam(awards, 'difficulty')?.value; if (!chapter || !mission || difficulty?.type !== 'int' || (difficulty.value !== 0 && difficulty.value !== 1 && difficulty.value !== 2)) return undefined; return { chapter, mission, difficulty: difficulty.value }; }