From 7ba66340b625de07a9fe83f4367047a0a072cac7 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Tue, 1 Dec 2026 12:05:42 +0800 Subject: [PATCH] fix(battle): enforce single-sortie Air Realistic rules Carry the queued aircraft and crew index into LocalMP, apply the native single-spawn limits to players and aircraft bots, and disable spares for single-slot modes. Verified with root and launcher type checks, check-patches and check-gui for 2.61.0.37 and 2.61.0.43, and an isolated launch-payload check. --- apps/server/src/battle/battle-extra-slots.ts | 2 +- apps/server/src/battle/battle-matchmaker.ts | 67 ++++++------------- .../src/battle/battle-mission-settings.ts | 9 ++- apps/server/src/battle/battle-ranks.ts | 34 +++++++++- apps/server/src/game-modes/mode-definition.ts | 4 ++ .../src/matching/battle-launch-notify.ts | 8 ++- .../src/matching/battle-queue-requests.ts | 13 ++-- .../find-crew-check.nut | 2 + .../lock-single-slot-lineup/find-import.nut | 1 + .../lock-single-slot-lineup/find-mask.nut | 1 + .../lock-single-slot-lineup/patch.jsonc | 19 ++++++ .../replace-crew-check.nut | 6 ++ .../replace-import.nut | 1 + .../lock-single-slot-lineup/replace-mask.nut | 11 +++ 14 files changed, 122 insertions(+), 56 deletions(-) create mode 100644 patches/gui/battle/lock-single-slot-lineup/find-crew-check.nut create mode 100644 patches/gui/battle/lock-single-slot-lineup/find-import.nut create mode 100644 patches/gui/battle/lock-single-slot-lineup/find-mask.nut create mode 100644 patches/gui/battle/lock-single-slot-lineup/patch.jsonc create mode 100644 patches/gui/battle/lock-single-slot-lineup/replace-crew-check.nut create mode 100644 patches/gui/battle/lock-single-slot-lineup/replace-import.nut create mode 100644 patches/gui/battle/lock-single-slot-lineup/replace-mask.nut diff --git a/apps/server/src/battle/battle-extra-slots.ts b/apps/server/src/battle/battle-extra-slots.ts index 960535d..6f0451f 100644 --- a/apps/server/src/battle/battle-extra-slots.ts +++ b/apps/server/src/battle/battle-extra-slots.ts @@ -32,7 +32,7 @@ import type { BattleTuning } from './battle-tuning.ts'; import { vehicleMrank } from './battle-ranks.ts'; /** The LocalMP host tracks crew slots in a 32-bit mask (native LMP_MP_OFF_BROKEN_SLOTS_MASK). */ -const MAX_BATTLE_CREW_SLOTS = 32; +export const MAX_BATTLE_CREW_SLOTS = 32; export interface ExtraBattleSlot { readonly unitName: string; diff --git a/apps/server/src/battle/battle-matchmaker.ts b/apps/server/src/battle/battle-matchmaker.ts index f1c56d0..a9eacd7 100644 --- a/apps/server/src/battle/battle-matchmaker.ts +++ b/apps/server/src/battle/battle-matchmaker.ts @@ -10,28 +10,33 @@ import type { BattleSpawnRulesData } from '../game-data/datasets/battle-spawn-ru import type { MissionHeader } from '../game-data/datasets/multiplayer-missions.ts'; import type { CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.ts'; import type { GameModes, OfferedGameMode } from '../game-modes/game-modes.ts'; -import { MISSION_DIFFICULTY } from '../game-modes/mode-definition.ts'; +import { MISSION_DIFFICULTY, SINGLE_SPAWN } from '../game-modes/mode-definition.ts'; import { serverTimeNow, serverTimeToUnixSeconds } from '../profile/server-time.ts'; import { selectBattleCoalitions, type CoalitionPairing } from './battle-coalitions.ts'; import { selectExtraBattleSlots, type ExtraBattleSlot } from './battle-extra-slots.ts'; import { + activeVehiclesForMode, + isModeEligibleForLineup, lineupMrank, selectCustomBots, - unitClassOfExpClass, - vehicleMrank, type CustomBotsPool, } from './battle-ranks.ts'; import type { BattleSessionStore } from './battle-session-store.ts'; import { battleSpawnScore, type BattleSpawnScore } from './battle-spawn-score.ts'; import type { BattleTuning } from './battle-tuning.ts'; +export interface BattleCrewSlot { + readonly idInCountry: number; + readonly unitName: string; +} + export interface EnqueueBattleInput { readonly userId: string; readonly mode: OfferedGameMode; readonly modes?: readonly OfferedGameMode[]; readonly country: string; readonly slotVehicles: readonly string[]; - readonly selectedSlotVehicle?: string; + readonly selectedSlot?: BattleCrewSlot; readonly bannedMissions: ReadonlySet; readonly dislikedMissions: ReadonlySet; } @@ -68,6 +73,7 @@ export interface BattleLaunchPlan { readonly useSpawnScore: boolean; readonly spawnScore?: BattleSpawnScore; readonly customBots: CustomBotsPool; + readonly selectedSlot?: BattleCrewSlot; readonly extraBattleSlots: readonly ExtraBattleSlot[]; } @@ -103,11 +109,15 @@ export class BattleMatchmaker { if (!knownCountries.includes(input.country)) return { ok: false, error: 'BAD_PARAMS' }; const candidates = input.modes && input.modes.length > 0 ? input.modes : [input.mode]; - const chosenMode = this.#pickQueuedMode(candidates, input.slotVehicles, input.selectedSlotVehicle); - if (!chosenMode) return { ok: false, error: 'PVE_NOT_SUPPORTED' }; + const pvpModes = candidates.filter( + (mode) => mode.declaration.displayType !== 'pve_battle' && twoSidedMissionsOf(mode).length > 0, + ); + if (pvpModes.length === 0) return { ok: false, error: 'PVE_NOT_SUPPORTED' }; + const chosenMode = this.#pickQueuedMode(pvpModes, input.slotVehicles, input.selectedSlot?.unitName); + if (!chosenMode) return { ok: false, error: 'BAD_PARAMS' }; const { declaration } = chosenMode; - const activeVehicles = activeVehiclesForMode(declaration, input.slotVehicles, input.selectedSlotVehicle, this.#vehiclesByName); + const activeVehicles = activeVehiclesForMode(declaration, input.slotVehicles, input.selectedSlot?.unitName, this.#vehiclesByName); const playerMrank = lineupMrank( activeVehicles, this.#vehiclesByName, declaration.difficulty, declaration.requiredClass, declaration.allowedClasses, ); @@ -146,14 +156,9 @@ export class BattleMatchmaker { slotVehicles: readonly string[], selectedSlotVehicle: string | undefined, ): OfferedGameMode | undefined { - const pvpModes = candidates.filter( - (mode) => mode.declaration.displayType !== 'pve_battle' && twoSidedMissionsOf(mode).length > 0, - ); - if (pvpModes.length === 0) return undefined; - const eligible = pvpModes.filter((mode) => + const pool = candidates.filter((mode) => isModeEligibleForLineup(mode.declaration, slotVehicles, selectedSlotVehicle, this.#vehiclesByName)); - const pool = eligible.length > 0 ? eligible : pvpModes.filter((mode) => !mode.declaration.tag); - if (pool.length === 0) return pvpModes[0]; + if (pool.length === 0) return candidates.find((mode) => mode.declaration.multiSlot !== false); const classics = pool.filter((mode) => !mode.declaration.tag); const subModes = pool.filter((mode) => Boolean(mode.declaration.tag)); if (subModes.length > 0 && classics.length > 0) { @@ -231,7 +236,7 @@ export class BattleMatchmaker { maxPlayers, maxBots, tankBotRespawns: this.#tuning.tankBotRespawns, - airBotRespawns: this.#tuning.airBotRespawns, + airBotRespawns: declaration.multiSlot === false ? SINGLE_SPAWN : this.#tuning.airBotRespawns, useTankBots: allowedSet.has('tank'), useShipBots: allowedSet.has('ship'), useSpawnScore, @@ -239,6 +244,7 @@ export class BattleMatchmaker { spawnScore: battleSpawnScore(input.slotVehicles, extraBattleSlots, maxMrank, this.#vehiclesByName, this.#spawnRules.spawnScore), } : {}), customBots, + ...(declaration.multiSlot === false && input.selectedSlot ? { selectedSlot: input.selectedSlot } : {}), extraBattleSlots, }; } @@ -248,37 +254,6 @@ function twoSidedMissionsOf(mode: OfferedGameMode): MissionHeader[] { return mode.missions.filter((m) => m.playerSlots.teamA > 0 && m.playerSlots.teamB > 0); } -function activeVehiclesForMode( - declaration: OfferedGameMode['declaration'], - slotVehicles: readonly string[], - selectedSlotVehicle: string | undefined, - byName: ReadonlyMap, -): readonly string[] { - if (declaration.multiSlot !== false || !selectedSlotVehicle) return slotVehicles; - const selected = byName.get(selectedSlotVehicle); - return selected && unitClassOfExpClass(selected.unitClass) === declaration.requiredClass - ? [selectedSlotVehicle] - : slotVehicles; -} - -function isModeEligibleForLineup( - declaration: OfferedGameMode['declaration'], - slotVehicles: readonly string[], - selectedSlotVehicle: string | undefined, - byName: ReadonlyMap, -): boolean { - if (!declaration.tag) return true; - const active = activeVehiclesForMode(declaration, slotVehicles, selectedSlotVehicle, byName); - const minMrank = declaration.minQueueMrank ?? 0; - const minCrafts = declaration.minCraftsToPlay ?? 1; - const matchingCount = active.filter((name) => { - const vehicle = byName.get(name); - if (!vehicle || unitClassOfExpClass(vehicle.unitClass) !== declaration.requiredClass) return false; - return vehicleMrank(vehicle, declaration.difficulty, declaration.requiredClass) >= minMrank; - }).length; - return matchingCount >= minCrafts; -} - function pickMission(missions: readonly MissionHeader[], banned: ReadonlySet, disliked: ReadonlySet): MissionHeader { const unbanned = missions.filter((mission) => !banned.has(mission.name)); const poolAfterBan = unbanned.length > 0 ? unbanned : missions; diff --git a/apps/server/src/battle/battle-mission-settings.ts b/apps/server/src/battle/battle-mission-settings.ts index 2aea229..216b019 100644 --- a/apps/server/src/battle/battle-mission-settings.ts +++ b/apps/server/src/battle/battle-mission-settings.ts @@ -8,6 +8,7 @@ * difficulty. `_gameMode` is left to the client, which takes it from its own native constants. */ import { emptyBlock, ensureBlock, setParam, appendParam, type BlkBlock, type BlkParam, type BlkValue } from '@wto/blk'; +import { SINGLE_SPAWN } from '../game-modes/mode-definition.ts'; import type { ExtraBattleSlot } from './battle-extra-slots.ts'; import type { BattleLaunchPlan } from './battle-matchmaker.ts'; import type { CustomBotsPool } from './battle-ranks.ts'; @@ -27,7 +28,7 @@ const RULE_KEYS: readonly string[] = [ /** Game type switches of a versus battle with tickets, capture zones and session rewards. */ const VERSUS_SWITCHES: readonly string[] = [ 'gt_versus', 'gt_mp_tickets', 'gt_mp_capture', 'gt_use_wp', 'gt_use_xp', 'gt_use_stats', 'gt_use_unlocks', - 'allowSpare', 'isLimitedAmmo', 'allowUseArtillerySupport', 'isBotsAllowed', 'autoBalance', + 'isLimitedAmmo', 'allowUseArtillerySupport', 'isBotsAllowed', 'autoBalance', ]; /** @@ -59,6 +60,12 @@ export function battleMissionSettings(plan: BattleLaunchPlan, scores: Readonly, +): readonly string[] { + if (declaration.multiSlot !== false) return slotVehicles; + if (!selectedSlotVehicle) return []; + const selected = byName.get(selectedSlotVehicle); + return selected && unitClassOfExpClass(selected.unitClass) === declaration.requiredClass + ? [selectedSlotVehicle] + : []; +} + +export function isModeEligibleForLineup( + declaration: GameModeDeclaration, + slotVehicles: readonly string[], + selectedSlotVehicle: string | undefined, + byName: ReadonlyMap, +): boolean { + if (!declaration.tag && declaration.multiSlot !== false) return true; + const active = activeVehiclesForMode(declaration, slotVehicles, selectedSlotVehicle, byName); + const minMrank = declaration.minQueueMrank ?? 0; + const minCrafts = declaration.minCraftsToPlay ?? 1; + const matchingCount = active.filter((name) => { + const vehicle = byName.get(name); + if (!vehicle || unitClassOfExpClass(vehicle.unitClass) !== declaration.requiredClass) return false; + return vehicleMrank(vehicle, declaration.difficulty, declaration.requiredClass) >= minMrank; + }).length; + return matchingCount >= minCrafts; +} diff --git a/apps/server/src/game-modes/mode-definition.ts b/apps/server/src/game-modes/mode-definition.ts index 5c1de4b..37725de 100644 --- a/apps/server/src/game-modes/mode-definition.ts +++ b/apps/server/src/game-modes/mode-definition.ts @@ -40,6 +40,9 @@ export const MISSION_DIFFICULTY: Readonly> = { simulator: 'hardcore', }; +// globals/missions/respawnCountModes.nut: RESPAWN_COUNT_MODE.SINGLE_SPAWN. +export const SINGLE_SPAWN = 1; + export type ModeDefinition = Readonly>; export function buildModeDefinition(mode: GameModeDeclaration, missions: readonly MissionHeader[], @@ -79,6 +82,7 @@ export function buildModeDefinition(mode: GameModeDeclaration, missions: readonl teamB: structuredClone(team), mission_decl: { difficulty: MISSION_DIFFICULTY[mode.difficulty], + ...(mode.multiSlot === false ? { maxRespawns: SINGLE_SPAWN } : {}), missions_list: Object.fromEntries(missions.map((mission) => [mission.name, {}])), }, }; diff --git a/apps/server/src/matching/battle-launch-notify.ts b/apps/server/src/matching/battle-launch-notify.ts index c081fc1..4e0a6e9 100644 --- a/apps/server/src/matching/battle-launch-notify.ts +++ b/apps/server/src/matching/battle-launch-notify.ts @@ -16,6 +16,7 @@ import type { BlkBlock, BlkValue } from '@wto/blk'; import type { BannerParams } from '../battle/battle-economy.ts'; import type { BattleLaunchPlan } from '../battle/battle-matchmaker.ts'; import { battleMissionSettings } from '../battle/battle-mission-settings.ts'; +import { SINGLE_SPAWN } from '../game-modes/mode-definition.ts'; type WireParam = readonly [name: string, type: 't' | 'i' | 'r' | 'b', value: string | number | boolean]; @@ -48,7 +49,11 @@ export function battleLaunchNotify( symmetricTeams: plan.symmetricTeams, country_allies: plan.countriesAllies.map(withCountryPrefix), country_axis: plan.countriesAxis.map(withCountryPrefix), - mission: { name: plan.missionName, difficulty: plan.difficulty }, + mission: { + name: plan.missionName, + difficulty: plan.difficulty, + ...(plan.selectedSlot ? { maxRespawns: SINGLE_SPAWN } : {}), + }, }, battle: { sessionId: plan.sessionId, @@ -56,6 +61,7 @@ export function battleLaunchNotify( economicName: plan.economicName, country: plan.country, missionName: plan.missionName, + ...(plan.selectedSlot ? { selectedSlot: plan.selectedSlot } : {}), extraBattleSlots: plan.extraBattleSlots, ...(plan.spawnScore ? { spawnScore: plan.spawnScore } : {}), awards, diff --git a/apps/server/src/matching/battle-queue-requests.ts b/apps/server/src/matching/battle-queue-requests.ts index 4edc0aa..040df02 100644 --- a/apps/server/src/matching/battle-queue-requests.ts +++ b/apps/server/src/matching/battle-queue-requests.ts @@ -5,6 +5,7 @@ * - `match.leave_queue` (scripts/queue/queuestate.nut:28) * - `match.check_reconnect` */ +import { MAX_BATTLE_CREW_SLOTS } from '../battle/battle-extra-slots.ts'; import { economyDifficulty, type BattleEconomy } from '../battle/battle-economy.ts'; import type { BattleMatchmaker } from '../battle/battle-matchmaker.ts'; import { maxModeMrank, unitClassOfExpClass, unitClassOfTypeCode, type CraftRankEntry } from '../battle/battle-ranks.ts'; @@ -81,16 +82,15 @@ function handleEnqueue( } const profile = deps.profiles.profileOf(userId); const slotVehicles = crewVehiclesOfCountry(profile, playerEntry.country); - const selectedSlotVehicle = playerEntry.selectedSlot !== undefined - ? crewSlotVehicleOfCountry(profile, playerEntry.country, playerEntry.selectedSlot) - : undefined; + const idInCountry = playerEntry.selectedSlot; + const selectedSlotVehicle = idInCountry === undefined ? undefined : crewSlotVehicleOfCountry(profile, playerEntry.country, idInCountry); const outcome = deps.matchmaker.enqueue({ userId, mode: modes[0]!, modes, country: playerEntry.country, slotVehicles, - ...(selectedSlotVehicle !== undefined ? { selectedSlotVehicle } : {}), + ...(idInCountry !== undefined && selectedSlotVehicle ? { selectedSlot: { idInCountry, unitName: selectedSlotVehicle } } : {}), bannedMissions: playerEntry.bannedMissions, dislikedMissions: playerEntry.dislikedMissions, }); @@ -101,7 +101,7 @@ function handleEnqueue( const { launch } = outcome; session.note(`mode=${launch.modeName}, mission=${launch.missionName}, mrank=${launch.minMrank}..${launch.maxMrank}`); const playerVehicles = new Set([ - ...slotVehicles, + ...(launch.selectedSlot ? [launch.selectedSlot.unitName] : slotVehicles), ...launch.extraBattleSlots.map((slot) => slot.unitName), ]); const awards = deps.economy.bannerParams(playerVehicles, economyDifficulty(modes[0]!.declaration.difficulty)); @@ -163,7 +163,8 @@ function extractPlayerEntry( const country = rawCountry.startsWith('country_') ? rawCountry : `country_${rawCountry}`; const slots = isRecord(entry?.slots) ? entry.slots : undefined; const rawSlot = slots?.[country] ?? slots?.[rawCountry]; - const selectedSlot = typeof rawSlot === 'number' && Number.isInteger(rawSlot) && rawSlot >= 0 ? rawSlot : undefined; + const selectedSlot = typeof rawSlot === 'number' && Number.isInteger(rawSlot) && rawSlot >= 0 && rawSlot < MAX_BATTLE_CREW_SLOTS + ? rawSlot : undefined; return { country, ...(selectedSlot !== undefined ? { selectedSlot } : {}), diff --git a/patches/gui/battle/lock-single-slot-lineup/find-crew-check.nut b/patches/gui/battle/lock-single-slot-lineup/find-crew-check.nut new file mode 100644 index 0000000..da24b51 --- /dev/null +++ b/patches/gui/battle/lock-single-slot-lineup/find-crew-check.nut @@ -0,0 +1,2 @@ +function isCrewAvailableInSession(crew, unit = null, needDebug = false) { + let { idInCountry } = crew diff --git a/patches/gui/battle/lock-single-slot-lineup/find-import.nut b/patches/gui/battle/lock-single-slot-lineup/find-import.nut new file mode 100644 index 0000000..ed59f6b --- /dev/null +++ b/patches/gui/battle/lock-single-slot-lineup/find-import.nut @@ -0,0 +1 @@ +from "guiRespawn" import getWasReadySlotsMask, getSpareSlotsMask, getDisabledSlotsMask, getBrokenSlotsMask, getDisabledByMatchingSlotsMask, getNumFreeSparesUsed, getNumFreeSparesPerDay diff --git a/patches/gui/battle/lock-single-slot-lineup/find-mask.nut b/patches/gui/battle/lock-single-slot-lineup/find-mask.nut new file mode 100644 index 0000000..8bd4091 --- /dev/null +++ b/patches/gui/battle/lock-single-slot-lineup/find-mask.nut @@ -0,0 +1 @@ +let isSpareAircraftInSlot = @(idInCountry) is_bit_set(getSpareSlotsMask(), idInCountry) diff --git a/patches/gui/battle/lock-single-slot-lineup/patch.jsonc b/patches/gui/battle/lock-single-slot-lineup/patch.jsonc new file mode 100644 index 0000000..2cb2cd0 --- /dev/null +++ b/patches/gui/battle/lock-single-slot-lineup/patch.jsonc @@ -0,0 +1,19 @@ +// Feed the matched crew slot into the stock respawn and slot bar availability checks. +// The queued aircraft is known to the offline server, but LocalMP does not receive a matchmaking slot mask. +// Without this bridge, the LocalMP host can offer the rest of the player's lineup in a single-slot battle. +{ + "id": "battle/lock-single-slot-lineup", + "title": "Restrict single-slot battles to the queued aircraft", + "features": ["K-Spawn score and respawns"], + "variants": [ + { + "written_for": "2.61.0.37", + "file": "scripts/respawn/respawnstate.nut", + "edits": [ + { "find": "find-import.nut", "replace": "replace-import.nut" }, + { "find": "find-mask.nut", "replace": "replace-mask.nut" }, + { "find": "find-crew-check.nut", "replace": "replace-crew-check.nut" } + ] + } + ] +} diff --git a/patches/gui/battle/lock-single-slot-lineup/replace-crew-check.nut b/patches/gui/battle/lock-single-slot-lineup/replace-crew-check.nut new file mode 100644 index 0000000..1800d7c --- /dev/null +++ b/patches/gui/battle/lock-single-slot-lineup/replace-crew-check.nut @@ -0,0 +1,6 @@ +function isCrewAvailableInSession(crew, unit = null, needDebug = false) { + let { idInCountry } = crew + let selected = getWtoSelectedSlot() + if (selected != null) + return idInCountry == selected.idInCountry && (unit?.name ?? crew?.aircraft) == selected.unitName + && !is_bit_set(getNativeDisabledSlotsMask(), idInCountry) diff --git a/patches/gui/battle/lock-single-slot-lineup/replace-import.nut b/patches/gui/battle/lock-single-slot-lineup/replace-import.nut new file mode 100644 index 0000000..53b1f1d --- /dev/null +++ b/patches/gui/battle/lock-single-slot-lineup/replace-import.nut @@ -0,0 +1 @@ +from "guiRespawn" import getWasReadySlotsMask, getSpareSlotsMask, getDisabledSlotsMask as getNativeDisabledSlotsMask, getBrokenSlotsMask, getDisabledByMatchingSlotsMask, getNumFreeSparesUsed, getNumFreeSparesPerDay diff --git a/patches/gui/battle/lock-single-slot-lineup/replace-mask.nut b/patches/gui/battle/lock-single-slot-lineup/replace-mask.nut new file mode 100644 index 0000000..706a53c --- /dev/null +++ b/patches/gui/battle/lock-single-slot-lineup/replace-mask.nut @@ -0,0 +1,11 @@ +function getWtoSelectedSlot() { + return require("nestdb").ndbTryRead(["wto", "activeBattle"])?.selectedSlot +} + +function getDisabledSlotsMask() { + let mask = getNativeDisabledSlotsMask() + let selected = getWtoSelectedSlot() + return selected == null ? mask : mask | ~(1 << selected.idInCountry) +} + +let isSpareAircraftInSlot = @(idInCountry) is_bit_set(getSpareSlotsMask(), idInCountry)