fix(server): persist selectable battle ratings
Validate the selected rank against owned modifications and return the saved profile. Use the saved rank delta for mode eligibility and room matchmaking. Verified with typecheck and a local 2.61.0.58 server run using temporary data. In-game acceptance is pending.
This commit is contained in:
1 parent
3f0e08c5b7
commit
899fb5d91b
8 files changed
+82
-17
No files matched your search
@@ -1,19 +1,24 @@
|
||||
/**
|
||||
* Owned vehicles in the profile, as in Gaijin's
|
||||
* config/default_user.blk: one empty sub-block per vehicle the player owns.
|
||||
* The profile's hangar has one sub-block per owned vehicle, as in config/default_user.blk.
|
||||
*
|
||||
* hangar{
|
||||
* bf2c_1{
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
import { ensureBlock, findBlock, type BlkBlock } from '@wto/blk';
|
||||
import { ensureBlock, findBlock, setParam, type BlkBlock } from '@wto/blk';
|
||||
import { intField } from './blk-fields.ts';
|
||||
|
||||
const HANGAR = 'hangar';
|
||||
const MRANK_DELTA = 'mrankDelta';
|
||||
|
||||
function ownedVehicle(profile: BlkBlock, vehicle: string): BlkBlock | undefined {
|
||||
const hangar = findBlock(profile, HANGAR);
|
||||
return hangar && findBlock(hangar, vehicle);
|
||||
}
|
||||
|
||||
export function ownsVehicle(profile: BlkBlock, vehicle: string): boolean {
|
||||
const hangar = findBlock(profile, HANGAR);
|
||||
return hangar !== undefined && findBlock(hangar, vehicle) !== undefined;
|
||||
return ownedVehicle(profile, vehicle) !== undefined;
|
||||
}
|
||||
|
||||
export function ownedVehicles(profile: BlkBlock): Set<string> {
|
||||
@@ -25,3 +30,13 @@ export function addOwnedVehicle(profile: BlkBlock, vehicle: string): void {
|
||||
const hangar = ensureBlock(profile, HANGAR);
|
||||
if (!hangar.blocks.some((owned) => owned.name === vehicle)) hangar.blocks.push({ name: vehicle, params: [], blocks: [] });
|
||||
}
|
||||
|
||||
/** The stock client uses the base rank until it has a non-negative selection. */
|
||||
export function vehicleMrankDelta(profile: BlkBlock, vehicle: string): number {
|
||||
return Math.max(0, intField(ownedVehicle(profile, vehicle), MRANK_DELTA));
|
||||
}
|
||||
|
||||
export function setVehicleMrankDelta(profile: BlkBlock, vehicle: string, delta: number): void {
|
||||
const entry = ownedVehicle(profile, vehicle);
|
||||
if (entry) setParam(entry, MRANK_DELTA, { type: 'int', value: delta });
|
||||
}
|
||||
Reference in new issue
Block a user