mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-25 00:02:44 +00:00
fix lobby duration at 60s now that we limit lobby size. remove "high traffic time"
This commit is contained in:
@@ -89,7 +89,7 @@ function getServerConfig(gameEnv: string) {
|
||||
|
||||
export interface ServerConfig {
|
||||
turnIntervalMs(): number;
|
||||
gameCreationRate(highTraffic: boolean): number;
|
||||
gameCreationRate(): number;
|
||||
lobbyMaxPlayers(map: GameMapType): number;
|
||||
discordRedirectURI(): string;
|
||||
numWorkers(): number;
|
||||
|
||||
@@ -48,12 +48,8 @@ export abstract class DefaultServerConfig implements ServerConfig {
|
||||
turnIntervalMs(): number {
|
||||
return 100;
|
||||
}
|
||||
gameCreationRate(highTraffic: boolean): number {
|
||||
if (highTraffic) {
|
||||
return 20 * 1000;
|
||||
} else {
|
||||
return 50 * 1000;
|
||||
}
|
||||
gameCreationRate(): number {
|
||||
return 60 * 1000;
|
||||
}
|
||||
lobbyMaxPlayers(map: GameMapType): number {
|
||||
if (map == GameMapType.World) {
|
||||
|
||||
@@ -16,7 +16,7 @@ export class DevServerConfig extends DefaultServerConfig {
|
||||
return GameEnv.Dev;
|
||||
}
|
||||
|
||||
gameCreationRate(highTraffic: boolean): number {
|
||||
gameCreationRate(): number {
|
||||
return 5 * 1000;
|
||||
}
|
||||
|
||||
|
||||
+11
-18
@@ -3,7 +3,6 @@ import { GameConfig, GameID } from "../core/Schemas";
|
||||
import { Client } from "./Client";
|
||||
import { GamePhase, GameServer } from "./GameServer";
|
||||
import { Difficulty, GameMapType, GameType } from "../core/game/Game";
|
||||
import { isHighTrafficTime } from "./Util";
|
||||
|
||||
export class GameManager {
|
||||
private games: Map<GameID, GameServer> = new Map();
|
||||
@@ -26,23 +25,17 @@ export class GameManager {
|
||||
}
|
||||
|
||||
createGame(id: GameID, gameConfig: GameConfig | undefined) {
|
||||
const game = new GameServer(
|
||||
id,
|
||||
Date.now(),
|
||||
isHighTrafficTime(),
|
||||
this.config,
|
||||
{
|
||||
gameMap: GameMapType.World,
|
||||
gameType: GameType.Private,
|
||||
difficulty: Difficulty.Medium,
|
||||
disableNPCs: false,
|
||||
infiniteGold: false,
|
||||
infiniteTroops: false,
|
||||
instantBuild: false,
|
||||
bots: 400,
|
||||
...gameConfig,
|
||||
},
|
||||
);
|
||||
const game = new GameServer(id, Date.now(), this.config, {
|
||||
gameMap: GameMapType.World,
|
||||
gameType: GameType.Private,
|
||||
difficulty: Difficulty.Medium,
|
||||
disableNPCs: false,
|
||||
infiniteGold: false,
|
||||
infiniteTroops: false,
|
||||
instantBuild: false,
|
||||
bots: 400,
|
||||
...gameConfig,
|
||||
});
|
||||
this.games.set(id, game);
|
||||
return game;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ export class GameServer {
|
||||
constructor(
|
||||
public readonly id: string,
|
||||
public readonly createdAt: number,
|
||||
public readonly highTraffic: boolean,
|
||||
private config: ServerConfig,
|
||||
public gameConfig: GameConfig,
|
||||
) {}
|
||||
@@ -201,7 +200,7 @@ export class GameServer {
|
||||
return this._startTime;
|
||||
} else {
|
||||
//game hasn't started yet, only works for public games
|
||||
return this.createdAt + this.config.gameCreationRate(this.highTraffic);
|
||||
return this.createdAt + this.config.gameCreationRate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,8 +380,7 @@ export class GameServer {
|
||||
}
|
||||
|
||||
const msSinceCreation = now - this.createdAt;
|
||||
const lessThanLifetime =
|
||||
msSinceCreation < this.config.gameCreationRate(this.highTraffic);
|
||||
const lessThanLifetime = msSinceCreation < this.config.gameCreationRate();
|
||||
const notEnoughPlayers =
|
||||
this.gameConfig.gameType == GameType.Public &&
|
||||
this.gameConfig.maxPlayers &&
|
||||
@@ -391,10 +389,7 @@ export class GameServer {
|
||||
return GamePhase.Lobby;
|
||||
}
|
||||
const warmupOver =
|
||||
now >
|
||||
this.createdAt +
|
||||
this.config.gameCreationRate(this.highTraffic) +
|
||||
30 * 1000;
|
||||
now > this.createdAt + this.config.gameCreationRate() + 30 * 1000;
|
||||
if (noActive && warmupOver && noRecentPings) {
|
||||
return GamePhase.Finished;
|
||||
}
|
||||
@@ -415,7 +410,7 @@ export class GameServer {
|
||||
})),
|
||||
gameConfig: this.gameConfig,
|
||||
msUntilStart: this.isPublic()
|
||||
? this.createdAt + this.config.gameCreationRate(this.highTraffic)
|
||||
? this.createdAt + this.config.gameCreationRate()
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import { GameConfig, GameInfo } from "../core/Schemas";
|
||||
import path from "path";
|
||||
import rateLimit from "express-rate-limit";
|
||||
import { fileURLToPath } from "url";
|
||||
import { isHighTrafficTime } from "./Util";
|
||||
import { gatekeeper, LimiterType } from "./Gatekeeper";
|
||||
|
||||
const config = getServerConfigFromServer();
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
export function isHighTrafficTime(): boolean {
|
||||
// More traffic from 4am to 4pm
|
||||
const now = new Date();
|
||||
|
||||
// Convert current time to PST (America/Los_Angeles timezone)
|
||||
// Using a more compatible approach
|
||||
const formatter = new Intl.DateTimeFormat("en-US", {
|
||||
timeZone: "America/Los_Angeles",
|
||||
hour: "numeric",
|
||||
hour12: false,
|
||||
});
|
||||
|
||||
const formattedTime = formatter.format(now);
|
||||
const hourPST = parseInt(formattedTime.split(":")[0], 10);
|
||||
|
||||
return hourPST >= 4 && hourPST < 16;
|
||||
}
|
||||
Reference in New Issue
Block a user