mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 11:20:45 +00:00
Merge commit from fork
This commit is contained in:
@@ -59,7 +59,12 @@ export class GameManager {
|
||||
creatorPersistentID?: string,
|
||||
startsAt?: number,
|
||||
publicGameType?: PublicGameType,
|
||||
) {
|
||||
): GameServer | null {
|
||||
if (this.games.has(id)) {
|
||||
this.log.warn("cannot create game, id already exists", { gameID: id });
|
||||
return null;
|
||||
}
|
||||
|
||||
const game = new GameServer(
|
||||
id,
|
||||
this.log,
|
||||
|
||||
@@ -200,6 +200,10 @@ export async function startWorker() {
|
||||
|
||||
// Pass creatorPersistentID to createGame
|
||||
const game = gm.createGame(id, gc, creatorPersistentID);
|
||||
if (game === null) {
|
||||
log.warn(`cannot create game, id ${id} already exists`);
|
||||
return res.status(409).json({ error: "Game ID already exists" });
|
||||
}
|
||||
|
||||
log.info(
|
||||
`Worker ${workerId}: IP ${ipAnonymize(clientIP)} creating ${game.isPublic() ? GameType.Public : GameType.Private}${gc?.gameMode ? ` ${gc.gameMode}` : ""} game with id ${id}${creatorPersistentID ? `, creator: ${creatorPersistentID.substring(0, 8)}...` : ""}`,
|
||||
@@ -599,12 +603,15 @@ async function startMatchmakingPolling(gm: GameManager) {
|
||||
log.info(`Lobby poll successful:`, data);
|
||||
|
||||
if (data.assignment) {
|
||||
gm.createGame(
|
||||
const game = gm.createGame(
|
||||
gameId,
|
||||
playlist.get1v1Config(),
|
||||
undefined,
|
||||
Date.now() + 7000,
|
||||
);
|
||||
if (game === null) {
|
||||
log.warn(`Failed to create matchmaking game ${gameId}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.name === "AbortError") {
|
||||
|
||||
@@ -44,20 +44,24 @@ export class WorkerLobbyService {
|
||||
// Update master with my lobby info
|
||||
this.sendMyLobbiesToMaster();
|
||||
break;
|
||||
case "createGame":
|
||||
case "createGame": {
|
||||
if (this.gm.game(msg.gameID) !== null) {
|
||||
this.log.warn(`Game ${msg.gameID} already exists, skipping create`);
|
||||
return;
|
||||
}
|
||||
this.log.info(`Creating public game ${msg.gameID} from master`);
|
||||
this.gm.createGame(
|
||||
const game = this.gm.createGame(
|
||||
msg.gameID,
|
||||
msg.gameConfig,
|
||||
undefined,
|
||||
undefined,
|
||||
msg.publicGameType,
|
||||
);
|
||||
if (game === null) {
|
||||
this.log.warn(`Game ${msg.gameID} already exists, skipping create`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "updateLobby": {
|
||||
const game = this.gm.game(msg.gameID);
|
||||
if (!game) {
|
||||
|
||||
Reference in New Issue
Block a user