fixed duplication of maps config and prettier format

This commit is contained in:
Trajkov Dimitar
2025-11-01 17:29:39 +01:00
parent 5027083c48
commit f0ff31f95a
6 changed files with 40 additions and 51 deletions
+23 -9
View File
@@ -279,15 +279,29 @@ export class RankedQueue extends LitElement {
// Connect WebSocket if not connected
await this.connectWebSocket();
// Send join queue message
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
this.ws.send(
JSON.stringify({
type: "join_queue",
queueType: this.queueType,
gameMode: this.gameMode,
}),
);
// Function to send join queue message
const sendJoinMessage = () => {
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
this.ws.send(
JSON.stringify({
type: "join_queue",
queueType: this.queueType,
gameMode: this.gameMode,
}),
);
}
};
// Send join queue message immediately if connected, or wait for connection
if (this.ws) {
if (this.ws.readyState === WebSocket.OPEN) {
sendJoinMessage();
} else if (this.ws.readyState === WebSocket.CONNECTING) {
// Wait for connection to open before sending join message
this.ws.addEventListener("open", () => sendJoinMessage(), {
once: true,
});
}
}
}
+3 -1
View File
@@ -46,7 +46,9 @@ const JwksSchema = z.object({
.min(1),
});
const numPlayersConfig = {
// Map capacity configuration: [large, medium, small] player counts
// Used by both lobby creation and ranked matchmaking
export const numPlayersConfig = {
[GameMapType.Africa]: [100, 70, 50],
[GameMapType.Asia]: [50, 40, 30],
[GameMapType.Australia]: [70, 40, 30],
+8 -35
View File
@@ -1,38 +1,7 @@
import { numPlayersConfig } from "../core/configuration/DefaultConfig";
import { GameMapType, GameMode } from "../core/game/Game";
// import { TeamCountConfig } from "../core/Schemas";
const MAP_CAPACITIES: Record<GameMapType, [number, number, number]> = {
[GameMapType.Africa]: [100, 70, 50],
[GameMapType.Asia]: [50, 40, 30],
[GameMapType.Australia]: [70, 40, 30],
[GameMapType.Baikal]: [100, 70, 50],
[GameMapType.BetweenTwoSeas]: [70, 50, 40],
[GameMapType.BlackSea]: [50, 30, 30],
[GameMapType.Britannia]: [50, 30, 20],
[GameMapType.DeglaciatedAntarctica]: [50, 40, 30],
[GameMapType.EastAsia]: [50, 30, 20],
[GameMapType.Europe]: [100, 70, 50],
[GameMapType.EuropeClassic]: [50, 30, 30],
[GameMapType.FalklandIslands]: [50, 30, 20],
[GameMapType.FaroeIslands]: [20, 15, 10],
[GameMapType.GatewayToTheAtlantic]: [100, 70, 50],
[GameMapType.GiantWorldMap]: [100, 70, 50],
[GameMapType.Halkidiki]: [100, 50, 40],
[GameMapType.Iceland]: [50, 40, 30],
[GameMapType.Italia]: [50, 30, 20],
[GameMapType.Japan]: [20, 15, 10],
[GameMapType.Mars]: [70, 40, 30],
[GameMapType.Mena]: [70, 50, 40],
[GameMapType.Montreal]: [60, 40, 30],
[GameMapType.NorthAmerica]: [70, 40, 30],
[GameMapType.Oceania]: [10, 10, 10],
[GameMapType.Pangaea]: [20, 15, 10],
[GameMapType.Pluto]: [100, 70, 50],
[GameMapType.SouthAmerica]: [70, 50, 40],
[GameMapType.StraitOfGibraltar]: [100, 70, 50],
[GameMapType.World]: [50, 30, 20],
[GameMapType.Yenisei]: [150, 100, 70],
};
const MAP_CAPACITIES = numPlayersConfig;
export interface MapSelectionCriteria {
playerCount: number;
@@ -68,8 +37,11 @@ export function selectMapForRanked(
// Find intersection
const viableMaps = suitableMaps.filter((map) => rankedMaps.includes(map));
// Use ranked maps if available, otherwise fall back to all suitable maps
const candidates = viableMaps.length > 0 ? viableMaps : suitableMaps;
// Pick best fit (prefer maps closest to player count)
return pickBestFit(viableMaps, playerCount);
return pickBestFit(candidates, playerCount);
}
/**
@@ -95,8 +67,9 @@ function getSuitableMaps(playerCount: number): GameMapType[] {
* Selects map where player count is closest to the middle of its capacity range
*/
function pickBestFit(maps: GameMapType[], playerCount: number): GameMapType {
// This should never happen now due to fallback in selectMapForRanked,
// but keep a safe fallback just in case
if (maps.length === 0) {
// Fallback to World if no perfect match
return GameMapType.World;
}
+3 -2
View File
@@ -1,5 +1,6 @@
import { Logger } from "winston";
import { ServerConfig } from "../core/configuration/Config";
import { TeamCountConfig } from "../core/Schemas";
import { generateID, simpleHash } from "../core/Util";
export interface MatchAssignment {
@@ -8,7 +9,7 @@ export interface MatchAssignment {
queueType: "ranked" | "unranked";
gameMode: "ffa" | "team";
playerCount: number;
teamConfig?: unknown; // TODO: define team config
teamConfig?: TeamCountConfig;
};
}
@@ -79,7 +80,7 @@ export class MatchmakingPoller {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": process.env.GAME_SERVER_API_KEY ?? "",
"X-API-Key": process.env.API_KEY ?? "",
},
body: JSON.stringify({
id: workerId,
+2 -2
View File
@@ -11,7 +11,7 @@ export interface RankedMatchConfig {
queueType: "ranked" | "unranked";
gameMode: "ffa" | "team";
playerCount: number;
teamConfig?: unknown;
teamConfig?: TeamCountConfig;
}
/**
@@ -51,7 +51,7 @@ export function buildRankedGameConfig(
disabledUnits: [],
// Team configuration
playerTeams: matchConfig.teamConfig as TeamCountConfig | undefined,
playerTeams: matchConfig.teamConfig,
};
}
+1 -2
View File
@@ -8,7 +8,7 @@ import { fileURLToPath } from "url";
import { WebSocket, WebSocketServer } from "ws";
import { z } from "zod";
import { getServerConfigFromServer } from "../core/configuration/ConfigLoader";
import { GameType } from "../core/game/Game";
import { GameMode, GameType } from "../core/game/Game";
import {
ClientMessageSchema,
GameID,
@@ -25,7 +25,6 @@ import { getUserMe, verifyClientToken } from "./jwt";
import { logger } from "./Logger";
import { GameEnv } from "../core/configuration/Config";
import { GameMode } from "../core/game/Game";
import { MapPlaylist } from "./MapPlaylist";
import { selectMapForRanked } from "./MapSelection";
import { MatchmakingPoller } from "./MatchmakingPoller";