mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-19 02:04:39 +00:00
Merge commit from fork
This commit is contained in:
@@ -59,7 +59,12 @@ export class GameManager {
|
|||||||
creatorPersistentID?: string,
|
creatorPersistentID?: string,
|
||||||
startsAt?: number,
|
startsAt?: number,
|
||||||
publicGameType?: PublicGameType,
|
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(
|
const game = new GameServer(
|
||||||
id,
|
id,
|
||||||
this.log,
|
this.log,
|
||||||
|
|||||||
@@ -200,6 +200,10 @@ export async function startWorker() {
|
|||||||
|
|
||||||
// Pass creatorPersistentID to createGame
|
// Pass creatorPersistentID to createGame
|
||||||
const game = gm.createGame(id, gc, creatorPersistentID);
|
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(
|
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)}...` : ""}`,
|
`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);
|
log.info(`Lobby poll successful:`, data);
|
||||||
|
|
||||||
if (data.assignment) {
|
if (data.assignment) {
|
||||||
gm.createGame(
|
const game = gm.createGame(
|
||||||
gameId,
|
gameId,
|
||||||
playlist.get1v1Config(),
|
playlist.get1v1Config(),
|
||||||
undefined,
|
undefined,
|
||||||
Date.now() + 7000,
|
Date.now() + 7000,
|
||||||
);
|
);
|
||||||
|
if (game === null) {
|
||||||
|
log.warn(`Failed to create matchmaking game ${gameId}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error && error.name === "AbortError") {
|
if (error instanceof Error && error.name === "AbortError") {
|
||||||
|
|||||||
@@ -44,20 +44,24 @@ export class WorkerLobbyService {
|
|||||||
// Update master with my lobby info
|
// Update master with my lobby info
|
||||||
this.sendMyLobbiesToMaster();
|
this.sendMyLobbiesToMaster();
|
||||||
break;
|
break;
|
||||||
case "createGame":
|
case "createGame": {
|
||||||
if (this.gm.game(msg.gameID) !== null) {
|
if (this.gm.game(msg.gameID) !== null) {
|
||||||
this.log.warn(`Game ${msg.gameID} already exists, skipping create`);
|
this.log.warn(`Game ${msg.gameID} already exists, skipping create`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.log.info(`Creating public game ${msg.gameID} from master`);
|
this.log.info(`Creating public game ${msg.gameID} from master`);
|
||||||
this.gm.createGame(
|
const game = this.gm.createGame(
|
||||||
msg.gameID,
|
msg.gameID,
|
||||||
msg.gameConfig,
|
msg.gameConfig,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
msg.publicGameType,
|
msg.publicGameType,
|
||||||
);
|
);
|
||||||
|
if (game === null) {
|
||||||
|
this.log.warn(`Game ${msg.gameID} already exists, skipping create`);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "updateLobby": {
|
case "updateLobby": {
|
||||||
const game = this.gm.game(msg.gameID);
|
const game = this.gm.game(msg.gameID);
|
||||||
if (!game) {
|
if (!game) {
|
||||||
|
|||||||
Reference in New Issue
Block a user