Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:
apps/server the local server (was packages/local-service),
package @wto/server
packages/patcher builds the game copy (was packages/build),
package @wto/patcher
patches/exe exe patch definitions (was exe-patches)
patches/gui GUI script patches (was gui-patches)
Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".
The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.
The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.
Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.
BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
254 lines
8.2 KiB
TypeScript
254 lines
8.2 KiB
TypeScript
/**
|
|
* DataBlock serializers for squadron (clan) char actions:
|
|
* - `cln_clan_get` full clan info (`clanInfoTable.nut` + `0xeb9f60`)
|
|
* - `cln_clan_get_leaderboard` /
|
|
* `cln_clan_find_by_prefix` leaderboard / search rows (`clansModalHandler.nut`)
|
|
* - `cln_clans_list_get_short_info` short info blocks (`clanInfo.nut`)
|
|
* - `cln_clan_get_log` paginated clan event log (`clanRequests.nut`)
|
|
*/
|
|
import type { BlkBlock, BlkParam } from '@wto/blk';
|
|
import type { ClanTuning } from './clan-tuning.ts';
|
|
import {
|
|
totalPeriodActivityOf,
|
|
type ClanLogEntry,
|
|
type ClanMemberRecord,
|
|
type ClanRecord,
|
|
type ClanStats,
|
|
} from './clan-types.ts';
|
|
|
|
const CLAN_STAT_KEYS: ReadonlyArray<keyof ClanStats> = [
|
|
'dr_era5_arc', 'dr_era5_hist', 'dr_era5_sim',
|
|
'akills_arc', 'akills_hist', 'akills_sim',
|
|
'gkills_arc', 'gkills_hist', 'gkills_sim',
|
|
'deaths_arc', 'deaths_hist', 'deaths_sim',
|
|
'ftime_arc', 'ftime_hist', 'ftime_sim',
|
|
];
|
|
|
|
const OPTIONAL_LOG_STRING_KEYS: ReadonlyArray<keyof Omit<ClanLogEntry, 'id' | 'ev' | 'timeSec' | 'uId' | 'uN'>> = [
|
|
'uid', 'nick', 'role', 'old', 'new', 'name', 'type', 'tag', 'desc', 'slogan', 'region', 'announcement', 'status', 'comments',
|
|
];
|
|
|
|
export function toClanInfoBlk(clan: ClanRecord, tuning: ClanTuning, nowSec = Math.floor(Date.now() / 1000)): BlkBlock {
|
|
const todayDay = Math.floor(nowSec / 86400);
|
|
const { maxPerPeriod, squadronRpPerFullPeriod, rewardPeriodDays, historyDepthDays } = tuning.activity;
|
|
return {
|
|
name: '',
|
|
params: [
|
|
str('_id', clan.id),
|
|
str('name', clan.name),
|
|
str('tag', clan.tag),
|
|
str('lastPaidTag', clan.lastPaidTag),
|
|
str('slogan', clan.slogan),
|
|
str('desc', clan.desc),
|
|
str('region', clan.region),
|
|
str('announcement', clan.announcement),
|
|
int('cdate', clan.cdateSec),
|
|
str('status', clan.status),
|
|
int('mlimit', clan.mlimit),
|
|
str('changed_by_nick', clan.changedByNick),
|
|
str('changed_by_uid', clan.changedByUid),
|
|
int('changed_time', clan.changedTimeSec),
|
|
int('mspent', clan.mspent),
|
|
int('region_last_updated', clan.regionLastUpdatedSec),
|
|
str('type', clan.type),
|
|
bool('autoaccept', clan.autoaccept),
|
|
int('maxActivityPerPeriod', maxPerPeriod),
|
|
int('maxClanActivity', squadronRpPerFullPeriod),
|
|
int('rewardPeriodDays', rewardPeriodDays),
|
|
bool('expRewardEnabled', true),
|
|
int('historyDepth', historyDepthDays),
|
|
int('nextRewardDayId', todayDay + rewardPeriodDays),
|
|
],
|
|
blocks: [
|
|
buildAstatBlock(clan, tuning),
|
|
buildMembershipReqBlock(clan),
|
|
...clan.members.map(memberToBlk),
|
|
buildMemberRatingsBlock(clan),
|
|
{ name: 'activity', params: [], blocks: clan.members.map((m) => buildMemberActivityBlock(m, todayDay)) },
|
|
...clan.candidates.map((c) => ({
|
|
name: 'candidates',
|
|
params: [str('uid', c.uid), str('nick', c.nick), str('comment', c.comment), int('date', c.dateSec)],
|
|
blocks: [],
|
|
})),
|
|
...clan.blacklist.map((b) => ({
|
|
name: 'blacklist',
|
|
params: [
|
|
str('uid', b.uid), str('nick', b.nick),
|
|
str('initiator_uid', b.initiatorUid), str('initiator_nick', b.initiatorNick),
|
|
str('comments', b.comments), int('date', b.dateSec),
|
|
],
|
|
blocks: [],
|
|
})),
|
|
...clan.bestRewards.map((r) => ({
|
|
name: 'clanBestRewards',
|
|
params: [str('seasonName', r.seasonName), str('title', r.title)],
|
|
blocks: [],
|
|
})),
|
|
],
|
|
};
|
|
}
|
|
|
|
export function toClanLeaderboardRowBlk(clan: ClanRecord, pos: number, tuning: ClanTuning): BlkBlock {
|
|
const periodAct = totalPeriodActivityOf(clan, tuning);
|
|
return {
|
|
name: 'clan',
|
|
params: [
|
|
str('_id', clan.id),
|
|
str('name', clan.name),
|
|
str('tag', clan.tag),
|
|
str('slogan', clan.slogan),
|
|
str('desc', clan.desc),
|
|
str('region', clan.region),
|
|
str('type', clan.type),
|
|
str('status', clan.status),
|
|
bool('autoaccept', clan.autoaccept),
|
|
int('mlimit', clan.mlimit),
|
|
int('members_cnt', clan.members.length),
|
|
int('pos', pos),
|
|
int('activity', periodAct),
|
|
int('clan_activity_by_periods', periodAct),
|
|
...statParams(clan.stats),
|
|
],
|
|
blocks: [buildAstatBlock(clan, tuning), buildMembershipReqBlock(clan)],
|
|
};
|
|
}
|
|
|
|
export function toClanShortInfoBlk(clan: ClanRecord, tuning: ClanTuning): BlkBlock {
|
|
return {
|
|
name: clan.id,
|
|
params: [
|
|
str('_id', clan.id),
|
|
str('name', clan.name),
|
|
str('tag', clan.tag),
|
|
str('type', clan.type),
|
|
str('slogan', clan.slogan),
|
|
str('region', clan.region),
|
|
str('status', clan.status),
|
|
int('mlimit', clan.mlimit),
|
|
int('members_cnt', clan.members.length),
|
|
],
|
|
blocks: [buildAstatBlock(clan, tuning)],
|
|
};
|
|
}
|
|
|
|
export function toClanLogBlk(
|
|
clan: ClanRecord,
|
|
count: number,
|
|
eventsFilter?: string,
|
|
lastMark?: string,
|
|
): BlkBlock {
|
|
const allowedEvents = eventsFilter
|
|
? new Set(eventsFilter.split(';').map((s) => s.trim()).filter(Boolean))
|
|
: undefined;
|
|
const maxId = lastMark && /^\d+$/.test(lastMark) ? Number(lastMark) : Number.MAX_SAFE_INTEGER;
|
|
|
|
const sorted = [...clan.logs]
|
|
.filter((entry) => entry.id < maxId && (!allowedEvents || allowedEvents.has(entry.ev)))
|
|
.sort((a, b) => b.id - a.id);
|
|
|
|
const page = sorted.slice(0, Math.max(1, count));
|
|
const nextMark = sorted.length > page.length ? String(page[page.length - 1]!.id) : '';
|
|
return {
|
|
name: '',
|
|
params: nextMark ? [str('lastMark', nextMark)] : [],
|
|
blocks: page.map(logEntryToBlk),
|
|
};
|
|
}
|
|
|
|
function memberToBlk(m: ClanMemberRecord): BlkBlock {
|
|
return {
|
|
name: 'members',
|
|
params: [str('uid', m.uid), str('nick', m.nick), int('role', m.role), int('date', m.joinDateSec)],
|
|
blocks: [],
|
|
};
|
|
}
|
|
|
|
function buildMemberRatingsBlock(clan: ClanRecord): BlkBlock {
|
|
return {
|
|
name: 'member_ratings',
|
|
params: [],
|
|
blocks: clan.members.map((m) => ({
|
|
name: m.uid,
|
|
params: [int('dr_era5_arc', m.ratingArc), int('dr_era5_hist', m.ratingHist), int('dr_era5_sim', m.ratingSim)],
|
|
blocks: [],
|
|
})),
|
|
};
|
|
}
|
|
|
|
function buildMembershipReqBlock(clan: ClanRecord): BlkBlock {
|
|
return clan.membershipReqBlk
|
|
? { ...structuredClone(clan.membershipReqBlk), name: 'membership_req' }
|
|
: { name: 'membership_req', params: [], blocks: [] };
|
|
}
|
|
|
|
function logEntryToBlk(entry: ClanLogEntry): BlkBlock {
|
|
const params: BlkParam[] = [
|
|
str('ev', entry.ev),
|
|
int('time', entry.timeSec),
|
|
str('uId', entry.uId),
|
|
str('uN', entry.uN),
|
|
];
|
|
for (const key of OPTIONAL_LOG_STRING_KEYS) {
|
|
const val = entry[key];
|
|
if (val !== undefined) params.push(str(key, val));
|
|
}
|
|
return { name: 'log', params, blocks: [] };
|
|
}
|
|
|
|
function buildAstatBlock(clan: ClanRecord, tuning: ClanTuning): BlkBlock {
|
|
const periodAct = totalPeriodActivityOf(clan, tuning);
|
|
return {
|
|
name: 'astat',
|
|
params: [
|
|
int('activity', periodAct),
|
|
int('clan_activity_by_periods', periodAct),
|
|
...statParams(clan.stats),
|
|
],
|
|
blocks: [],
|
|
};
|
|
}
|
|
|
|
function statParams(stats: ClanStats): BlkParam[] {
|
|
return CLAN_STAT_KEYS.map((key) => int(key, stats[key]));
|
|
}
|
|
|
|
function buildMemberActivityBlock(member: ClanMemberRecord, todayDay: number): BlkBlock {
|
|
const periods = member.periods.length > 0
|
|
? member.periods
|
|
: [{ day: todayDay, activity: member.curActivity, exp: 20000 }];
|
|
|
|
return {
|
|
name: member.uid,
|
|
params: [
|
|
int('cur', member.curActivity),
|
|
int('total', member.totalActivity),
|
|
int('activity', member.curActivity),
|
|
int('exp', member.earnedSquadronExp),
|
|
],
|
|
blocks: [
|
|
{ name: 'history', params: periods.map((p) => int(String(p.day), p.activity)), blocks: [] },
|
|
{
|
|
name: 'expActivity',
|
|
params: [],
|
|
blocks: periods.map((p) => ({
|
|
name: String(p.day),
|
|
params: [int('activity', p.activity), int('exp', p.exp), int('expRewardBase', p.exp), int('expBoost', 0)],
|
|
blocks: [],
|
|
})),
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
function str(name: string, value: string): BlkParam {
|
|
return { name, value: { type: 'string', value } };
|
|
}
|
|
|
|
function int(name: string, value: number): BlkParam {
|
|
return { name, value: { type: 'int', value: Math.trunc(value) } };
|
|
}
|
|
|
|
function bool(name: string, value: boolean): BlkParam {
|
|
return { name, value: { type: 'bool', value } };
|
|
}
|