From 999d253910592827be10d45b784c994f986270d9 Mon Sep 17 00:00:00 2001 From: Trajkov Dimitar Date: Thu, 25 Dec 2025 13:23:44 +0100 Subject: [PATCH] fix: new comments code rabbit --- src/server/MapSelection.ts | 8 +++++--- src/server/RankedGameConfig.ts | 22 +++++++++++----------- src/server/Worker.ts | 28 ++++++++++------------------ 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/server/MapSelection.ts b/src/server/MapSelection.ts index 955b20d54..555246b2f 100644 --- a/src/server/MapSelection.ts +++ b/src/server/MapSelection.ts @@ -1,13 +1,13 @@ import { numPlayersConfig } from "../core/configuration/DefaultConfig"; import { GameMapType, GameMode } from "../core/game/Game"; +import { MatchMode, matchModeToGameMode } from "./RankedGameConfig"; const MAP_CAPACITIES = numPlayersConfig; export interface MapSelectionCriteria { playerCount: number; - gameMode: GameMode; + matchMode: MatchMode; queueType: "ranked" | "unranked"; - matchMode?: "ffa" | "team" | "duel" | "duos" | "trios" | "quads"; } /** @@ -17,12 +17,14 @@ export interface MapSelectionCriteria { export function selectMapForRanked( criteria: MapSelectionCriteria, ): GameMapType { - const { playerCount, gameMode, matchMode } = criteria; + const { playerCount, matchMode } = criteria; if (matchMode === "duel") { return GameMapType.Australia; } + const gameMode = matchModeToGameMode(matchMode); + // Get maps that can handle this player count const suitableMaps = getSuitableMaps(playerCount); diff --git a/src/server/RankedGameConfig.ts b/src/server/RankedGameConfig.ts index 9abfa4c3f..8e2dd80b9 100644 --- a/src/server/RankedGameConfig.ts +++ b/src/server/RankedGameConfig.ts @@ -10,13 +10,21 @@ import { } from "../core/game/Game"; import { GameConfig, TeamCountConfig } from "../core/Schemas"; +export type MatchMode = "ffa" | "team" | "duel" | "duos" | "trios" | "quads"; + export interface RankedMatchConfig { queueType: "ranked" | "unranked"; - gameMode: "ffa" | "team" | "duel" | "duos" | "trios" | "quads"; + gameMode: MatchMode; playerCount: number; teamConfig?: TeamCountConfig; } +export function matchModeToGameMode(matchMode: MatchMode): GameMode { + if (matchMode === "duel") return GameMode.Duel; + if (matchMode === "ffa") return GameMode.FFA; + return GameMode.Team; +} + /** * Build a complete GameConfig for a ranked match * Uses the same bot rules as public games (400 bots) @@ -29,16 +37,8 @@ export function buildRankedGameConfig( const { gameMode, playerCount } = matchConfig; const isDuel = gameMode === "duel"; const isFFA = gameMode === "ffa"; - const isTeamMode = - gameMode === "team" || - gameMode === "duos" || - gameMode === "trios" || - gameMode === "quads"; - const mode = isDuel - ? GameMode.Duel - : isTeamMode - ? GameMode.Team - : GameMode.FFA; + const isTeamMode = !isDuel && !isFFA; + const mode = matchModeToGameMode(gameMode); // Determine team configuration based on game mode let teamConfig: TeamCountConfig | undefined = matchConfig.teamConfig; diff --git a/src/server/Worker.ts b/src/server/Worker.ts index c3da6b214..7a49d0f3c 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -8,7 +8,7 @@ import { fileURLToPath } from "url"; import { WebSocket, WebSocketServer } from "ws"; import { z } from "zod"; import { getServerConfigFromServer } from "../core/configuration/ConfigLoader"; -import { GameMode, GameType } from "../core/game/Game"; +import { GameType } from "../core/game/Game"; import { ClientMessageSchema, GameID, @@ -80,16 +80,10 @@ export async function startWorker() { config, log, async (gameId, assignment) => { - // Select map based on player count and mode const selectedMap = selectMapForRanked({ playerCount: assignment.config.playerCount, - gameMode: - assignment.config.gameMode === "ffa" || - assignment.config.gameMode === "duel" - ? GameMode.FFA - : GameMode.Team, - queueType: assignment.config.queueType, matchMode: assignment.config.gameMode, + queueType: assignment.config.queueType, }); // Build full game config @@ -98,7 +92,6 @@ export async function startWorker() { assignment.config, ); - // Create game gm.createGame(gameId, gameConfig); log.info("Created ranked match", { @@ -108,8 +101,13 @@ export async function startWorker() { players: assignment.config.playerCount, }); - // TODO: Notify players to connect to this game - // Players already have gameId from Lobby websocket + setTimeout(() => { + const game = gm.game(gameId); + if (game && !game.hasStarted()) { + log.info(`Starting ranked match ${gameId}`); + game.start(); + } + }, 5000); }, () => gm.activeClients(), // Get CCU from GameManager ); @@ -586,16 +584,10 @@ async function pollLobby(gm: GameManager) { const assignment = data.assignment; log.info(`Creating game ${gameId} with assignment`, assignment.config); - // Select map based on player count and mode const selectedMap = selectMapForRanked({ playerCount: assignment.config.playerCount, - gameMode: - assignment.config.gameMode === "ffa" || - assignment.config.gameMode === "duel" - ? GameMode.FFA - : GameMode.Team, - queueType: assignment.config.queueType, matchMode: assignment.config.gameMode, + queueType: assignment.config.queueType, }); // Build full game config using assignment config