Files
WT-Offline/apps/server/src/profile/client-profile.ts
T
N0VAN0M4LY d58ba9fb9b feat(saves)!: add offline crew editing
Add per-country crew slot controls and skill level previews to the launcher. Keep archived crews and their stable IDs in the save, update affected lineups, and back up the save before closing a slot.

Verified with both type checks, the launcher build, 2.61.0.64 patch checks, and temporary save read and write checks.

BREAKING CHANGE: The launcher automatically upgrades existing saves to format 4. Keep a pre-upgrade backup to use a save with an older launcher.
2026-12-06 15:34:24 +08:00

52 lines
2.8 KiB
TypeScript

/**
* The profile as the char service hands it to the client: the saved profile plus the
* account data, server clock, and active squadron season metadata the char server attaches
* on the wire.
*
* charDrivenNick: the client reads the player's nick from this top-level string when it
* loads a profile (name looked up at aces.exe 2.61.0.37 0x8fe0aa, value stored at 0x91874d).
*
* serverTime:i64: the char server's clock; without it the client
* takes the server time as 0 and every expiry and time limit is wrong.
*
* clanDuelNextReward:i64, clanSeasonStart:i64, clanSeasonOrdinal:i, clanSeasonInYear:i:
* parsed by GameSaveData::onAsyncEconTransComplete (aces.exe 2.61.0.58 0xebc728..0xebc7b4)
* on every profile-returning char response and exposed by clan_get_current_season_info
* (0x178aff0..0x178b227). Without them all fields default to 0, causing the squadron
* leaderboard to display "1970-I" and "1970-01-01".
*/
import { setParam, type BlkBlock } from '@wto/blk';
import type { Account } from '../accounts/account-store.ts';
import { currentClanSeason } from '../clans/clan-season.ts';
import { appearance, DEFAULT_PILOT_ICON } from './profile-appearance.ts';
import { CLOSED_CREWS, CREWS, crewsForClient } from './profile-crews.ts';
import { DAILY_SPARES_BLOCK } from './profile-daily-spares.ts';
import { clearStoreCart } from './profile-store-cart.ts';
import { clientHangarSpares } from './profile-vehicle-state.ts';
import { serverTimeFromUnixMs } from './server-time.ts';
export function clientProfile(saved: BlkBlock, account: Account, nowMs = Date.now()): BlkBlock {
// Clone the hangar entries whose spare count has a different wire representation.
const profile: BlkBlock = {
name: saved.name,
params: [...saved.params],
blocks: saved.blocks.filter((block) => block.name !== DAILY_SPARES_BLOCK && block.name !== CLOSED_CREWS)
.map((block) => {
if (block.name === 'hangar') return clientHangarSpares(block);
if (block.name === CREWS) return crewsForClient(saved, block);
return block;
}),
};
clearStoreCart(profile);
const pilotIcon = appearance(profile).pilotIcon || DEFAULT_PILOT_ICON;
const season = currentClanSeason(Math.floor(nowMs / 1000));
setParam(profile, 'pilotIcon', { type: 'string', value: pilotIcon });
setParam(profile, 'charDrivenNick', { type: 'string', value: account.nick });
setParam(profile, 'serverTime', { type: 'int64', value: serverTimeFromUnixMs(nowMs) });
setParam(profile, 'clanDuelNextReward', { type: 'int64', value: BigInt(season.rewardDaySec) });
setParam(profile, 'clanSeasonStart', { type: 'int64', value: BigInt(season.startDaySec) });
setParam(profile, 'clanSeasonOrdinal', { type: 'int', value: season.ordinalNumber });
setParam(profile, 'clanSeasonInYear', { type: 'int', value: season.numberInYear });
return profile;
}