mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-25 17:04:36 +00:00
refactor: collapse per-env Configs into ClientEnv + ServerEnv (#3906)
## Description: This is a refactor to simplify config handling. Replaces the per-environment DevConfig/PreprodConfig/ProdConfig class hierarchy with two static classes: ClientEnv (browser main thread, reads from window.BOOTSTRAP_CONFIG) and ServerEnv (Node server, reads from process.env). The four config classes are deleted, the abstract DefaultServerConfig is gone, and DefaultConfig is renamed to Config. The values that flow server → client (gameEnv, numWorkers, turnstileSiteKey, jwtAudience, instanceId) used to be baked into the hardcoded per-env classes. They're now real env vars on the server, embedded into a single window.BOOTSTRAP_CONFIG object in index.html at request time (alongside the existing gitCommit/assetManifest/cdnBase globals, which moved into the same object), and read back by ClientEnv on the client. The dev defaults previously hidden inside DevServerConfig are now explicit in start:server-dev (NUM_WORKERS=2, TURNSTILE_SITE_KEY=1x..., JWT_AUDIENCE=localhost, etc.) and in vite.config.ts's html plugin inject.data. Production deploys plumb NUM_WORKERS and TURNSTILE_SITE_KEY through deploy.yml (GitHub vars) into the remote env file; JWT_AUDIENCE is derived from DOMAIN in deploy.sh. The dynamic /api/instance endpoint is gone — INSTANCE_ID rides along in BOOTSTRAP_CONFIG now. ServerEnv is the only thing server code touches; ClientEnv is browser-only. The two classes have intentional overlap (env, numWorkers, jwtIssuer, gameCreationRate, workerIndex, etc.) since they derive identical logic from different sources — there's a TODO in each to consolidate via a shared helper later. The game-logic Config no longer stores a ServerConfig/ClientEnv reference and its serverConfig() getter is gone; the one caller (MultiTabModal) now reads ClientEnv.env() directly. Worker init no longer carries server-config values since nothing in the worker actually reads them. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { html, TemplateResult } from "lit";
|
||||
import { customElement, state } from "lit/decorators.js";
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import {
|
||||
PlayerGame,
|
||||
PlayerStatsTree,
|
||||
UserMeResponse,
|
||||
} from "../core/ApiSchemas";
|
||||
import { assetUrl } from "../core/AssetUrls";
|
||||
import { getRuntimeClientServerConfig } from "../core/configuration/ConfigLoader";
|
||||
import { fetchPlayerById, getUserMe } from "./Api";
|
||||
import { discordLogin, logOut, sendMagicLink } from "./Auth";
|
||||
import "./components/baseComponents/stats/DiscordUserHeader";
|
||||
@@ -229,9 +229,8 @@ export class AccountModal extends BaseModal {
|
||||
|
||||
private async viewGame(gameId: string): Promise<void> {
|
||||
this.close();
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
const encodedGameId = encodeURIComponent(gameId);
|
||||
const newUrl = `/${config.workerPath(gameId)}/game/${encodedGameId}`;
|
||||
const newUrl = `/${ClientEnv.workerPath(gameId)}/game/${encodedGameId}`;
|
||||
|
||||
history.pushState({ join: gameId }, "", newUrl);
|
||||
window.dispatchEvent(
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import { JWK } from "jose";
|
||||
import { z } from "zod";
|
||||
import { GameID } from "../core/Schemas";
|
||||
import { simpleHash } from "../core/Util";
|
||||
import {
|
||||
GameEnv,
|
||||
JwksSchema,
|
||||
parseGameEnv,
|
||||
} from "../core/configuration/Config";
|
||||
|
||||
export class ClientEnv {
|
||||
private static values: ClientEnvValues | null = null;
|
||||
private static publicKey: JWK | null = null;
|
||||
|
||||
/** Test-only. */
|
||||
static reset(): void {
|
||||
ClientEnv.values = null;
|
||||
ClientEnv.publicKey = null;
|
||||
}
|
||||
|
||||
private static get(): ClientEnvValues {
|
||||
if (ClientEnv.values) return ClientEnv.values;
|
||||
if (typeof window === "undefined") {
|
||||
throw new Error("ClientEnv is only available on the browser main thread");
|
||||
}
|
||||
const bc = window.BOOTSTRAP_CONFIG;
|
||||
if (
|
||||
!bc ||
|
||||
bc.gameEnv === undefined ||
|
||||
bc.numWorkers === undefined ||
|
||||
bc.turnstileSiteKey === undefined ||
|
||||
bc.jwtAudience === undefined ||
|
||||
bc.instanceId === undefined ||
|
||||
bc.gitCommit === undefined
|
||||
) {
|
||||
throw new Error("Missing BOOTSTRAP_CONFIG");
|
||||
}
|
||||
ClientEnv.values = {
|
||||
gameEnv: parseGameEnv(bc.gameEnv),
|
||||
numWorkers: bc.numWorkers,
|
||||
turnstileSiteKey: bc.turnstileSiteKey,
|
||||
jwtAudience: bc.jwtAudience,
|
||||
instanceId: bc.instanceId,
|
||||
gitCommit: bc.gitCommit,
|
||||
};
|
||||
return ClientEnv.values;
|
||||
}
|
||||
|
||||
// TODO: the following methods are duplicated on ServerEnv. The two classes
|
||||
// read from different sources (window.BOOTSTRAP_CONFIG vs process.env) but
|
||||
// the derived logic is identical. Consolidate into a shared helper that
|
||||
// takes a source so we don't have to keep them in sync by hand.
|
||||
static env(): GameEnv {
|
||||
return ClientEnv.get().gameEnv;
|
||||
}
|
||||
static numWorkers(): number {
|
||||
return ClientEnv.get().numWorkers;
|
||||
}
|
||||
static turnstileSiteKey(): string {
|
||||
return ClientEnv.get().turnstileSiteKey;
|
||||
}
|
||||
static jwtAudience(): string {
|
||||
return ClientEnv.get().jwtAudience;
|
||||
}
|
||||
static instanceId(): string {
|
||||
return ClientEnv.get().instanceId;
|
||||
}
|
||||
static gitCommit(): string {
|
||||
return ClientEnv.get().gitCommit;
|
||||
}
|
||||
static jwtIssuer(): string {
|
||||
const audience = ClientEnv.jwtAudience();
|
||||
return audience === "localhost"
|
||||
? "http://localhost:8787"
|
||||
: `https://api.${audience}`;
|
||||
}
|
||||
static async jwkPublicKey(): Promise<JWK> {
|
||||
if (ClientEnv.publicKey) return ClientEnv.publicKey;
|
||||
const jwksUrl = ClientEnv.jwtIssuer() + "/.well-known/jwks.json";
|
||||
console.log(`Fetching JWKS from ${jwksUrl}`);
|
||||
const response = await fetch(jwksUrl);
|
||||
if (!response.ok) {
|
||||
const body = await response.text();
|
||||
throw new Error(`JWKS fetch failed: ${response.status} ${body}`);
|
||||
}
|
||||
const result = JwksSchema.safeParse(await response.json());
|
||||
if (!result.success) {
|
||||
const error = z.prettifyError(result.error);
|
||||
console.error("Error parsing JWKS", error);
|
||||
throw new Error("Invalid JWKS");
|
||||
}
|
||||
ClientEnv.publicKey = result.data.keys[0];
|
||||
return ClientEnv.publicKey;
|
||||
}
|
||||
static turnIntervalMs(): number {
|
||||
return 100;
|
||||
}
|
||||
static gameCreationRate(): number {
|
||||
return ClientEnv.env() === GameEnv.Dev ? 5 * 1000 : 2 * 60 * 1000;
|
||||
}
|
||||
static workerIndex(gameID: GameID): number {
|
||||
return simpleHash(gameID) % ClientEnv.numWorkers();
|
||||
}
|
||||
static workerPath(gameID: GameID): string {
|
||||
return `w${ClientEnv.workerIndex(gameID)}`;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Values that flow from server → client via index.html. Set on the server from
|
||||
* process.env, then re-hydrated on the client from window.BOOTSTRAP_CONFIG.
|
||||
*/
|
||||
|
||||
export interface ClientEnvValues {
|
||||
gameEnv: GameEnv;
|
||||
numWorkers: number;
|
||||
turnstileSiteKey: string;
|
||||
jwtAudience: string;
|
||||
instanceId: string;
|
||||
gitCommit: string;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Config } from "src/core/configuration/Config";
|
||||
import { translateText } from "../client/Utils";
|
||||
import { EventBus } from "../core/EventBus";
|
||||
import {
|
||||
@@ -11,8 +12,6 @@ import {
|
||||
ServerMessage,
|
||||
} from "../core/Schemas";
|
||||
import { createPartialGameRecord, findClosestBy, replacer } from "../core/Util";
|
||||
import { ServerConfig } from "../core/configuration/Config";
|
||||
import { getGameLogicConfig } from "../core/configuration/ConfigLoader";
|
||||
import {
|
||||
BuildableUnit,
|
||||
PlayerType,
|
||||
@@ -63,7 +62,6 @@ import { GoToPlayerEvent } from "./graphics/TransformHandler";
|
||||
import { SoundManager } from "./sound/SoundManager";
|
||||
|
||||
export interface LobbyConfig {
|
||||
serverConfig: ServerConfig;
|
||||
cosmetics: PlayerCosmeticRefs;
|
||||
playerName: string;
|
||||
playerClanTag: string | null;
|
||||
@@ -238,7 +236,7 @@ async function createClientGame(
|
||||
if (lobbyConfig.gameStartInfo === undefined) {
|
||||
throw new Error("missing gameStartInfo");
|
||||
}
|
||||
const config = await getGameLogicConfig(
|
||||
const config = new Config(
|
||||
lobbyConfig.gameStartInfo.config,
|
||||
userSettings,
|
||||
lobbyConfig.gameRecord !== undefined,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { html, LitElement, nothing, type TemplateResult } from "lit";
|
||||
import { customElement, state } from "lit/decorators.js";
|
||||
import { getRuntimeClientServerConfig } from "src/core/configuration/ConfigLoader";
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import {
|
||||
Duos,
|
||||
GameMapType,
|
||||
@@ -59,9 +59,7 @@ export class GameModeSelector extends LitElement {
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this.lobbySocket.start();
|
||||
getRuntimeClientServerConfig().then((config) => {
|
||||
this.defaultLobbyTime = config.gameCreationRate() / 1000;
|
||||
});
|
||||
this.defaultLobbyTime = ClientEnv.gameCreationRate() / 1000;
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators.js";
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import { translateText } from "../client/Utils";
|
||||
import { getRuntimeClientServerConfig } from "../core/configuration/ConfigLoader";
|
||||
import { EventBus } from "../core/EventBus";
|
||||
import {
|
||||
Difficulty,
|
||||
@@ -121,8 +121,7 @@ export class HostLobbyModal extends BaseModal {
|
||||
return link;
|
||||
}
|
||||
}
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
return `${window.location.origin}/${config.workerPath(this.lobbyId)}/game/${this.lobbyId}?lobby&s=${encodeURIComponent(this.lobbyUrlSuffix)}`;
|
||||
return `${window.location.origin}/${ClientEnv.workerPath(this.lobbyId)}/game/${this.lobbyId}?lobby&s=${encodeURIComponent(this.lobbyUrlSuffix)}`;
|
||||
}
|
||||
|
||||
private async constructUrl(): Promise<string> {
|
||||
@@ -1050,13 +1049,12 @@ export class HostLobbyModal extends BaseModal {
|
||||
}
|
||||
|
||||
async function createLobby(gameID: string): Promise<GameInfo> {
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
// Send JWT token for creator identification - server extracts persistentID from it
|
||||
// persistentID should never be exposed to other clients
|
||||
const token = await getPlayToken();
|
||||
try {
|
||||
const response = await fetch(
|
||||
`/${config.workerPath(gameID)}/api/create_game/${gameID}`,
|
||||
`/${ClientEnv.workerPath(gameID)}/api/create_game/${gameID}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { html, TemplateResult } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators.js";
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import {
|
||||
calculateServerTimeOffset,
|
||||
getMapName,
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
LobbyInfoEvent,
|
||||
PublicGameInfo,
|
||||
} from "../core/Schemas";
|
||||
import { getRuntimeClientServerConfig } from "../core/configuration/ConfigLoader";
|
||||
import {
|
||||
Difficulty,
|
||||
GameMapSize,
|
||||
@@ -967,8 +967,7 @@ export class JoinLobbyModal extends BaseModal {
|
||||
}
|
||||
|
||||
private async checkActiveLobby(lobbyId: string): Promise<boolean> {
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
const url = `/${config.workerPath(lobbyId)}/api/game/${lobbyId}/exists`;
|
||||
const url = `/${ClientEnv.workerPath(lobbyId)}/api/game/${lobbyId}/exists`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
@@ -1037,10 +1036,8 @@ export class JoinLobbyModal extends BaseModal {
|
||||
return "version_mismatch";
|
||||
}
|
||||
|
||||
if (
|
||||
window.GIT_COMMIT !== "DEV" &&
|
||||
parsed.data.gitCommit !== window.GIT_COMMIT
|
||||
) {
|
||||
const gitCommit = ClientEnv.gitCommit();
|
||||
if (gitCommit !== "DEV" && parsed.data.gitCommit !== gitCommit) {
|
||||
const safeLobbyId = this.sanitizeForLog(lobbyId);
|
||||
console.warn(
|
||||
`Git commit hash mismatch for game ${safeLobbyId}`,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getRuntimeClientServerConfig } from "../core/configuration/ConfigLoader";
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import { PublicGames, PublicGamesSchema } from "../core/Schemas";
|
||||
|
||||
interface LobbySocketOptions {
|
||||
@@ -35,8 +35,7 @@ export class PublicLobbySocket {
|
||||
this.stopped = false;
|
||||
this.wsConnectionAttempts = 0;
|
||||
// Get config to determine number of workers, then pick a random one
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
this.workerPath = getRandomWorkerPath(config.numWorkers());
|
||||
this.workerPath = getRandomWorkerPath(ClientEnv.numWorkers());
|
||||
this.connectWebSocket();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import { z } from "zod";
|
||||
import { EventBus } from "../core/EventBus";
|
||||
import {
|
||||
@@ -81,8 +82,7 @@ export class LocalServer {
|
||||
console.log("local server starting");
|
||||
this.turnCheckInterval = setInterval(() => {
|
||||
const turnIntervalMs =
|
||||
this.lobbyConfig.serverConfig.turnIntervalMs() *
|
||||
this.replaySpeedMultiplier;
|
||||
ClientEnv.turnIntervalMs() * this.replaySpeedMultiplier;
|
||||
const backlog = Math.max(0, this.turns.length - this.turnsExecuted);
|
||||
const allowReplayBacklog =
|
||||
this.replaySpeedMultiplier === ReplaySpeedMultiplier.fastest &&
|
||||
@@ -297,7 +297,7 @@ export class LocalServer {
|
||||
console.error("Error parsing game record", error);
|
||||
return;
|
||||
}
|
||||
const workerPath = this.lobbyConfig.serverConfig.workerPath(
|
||||
const workerPath = ClientEnv.workerPath(
|
||||
this.lobbyConfig.gameStartInfo.gameID,
|
||||
);
|
||||
|
||||
|
||||
+7
-15
@@ -1,4 +1,5 @@
|
||||
import version from "resources/version.txt?raw";
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import { UserMeResponse } from "../core/ApiSchemas";
|
||||
import { assetUrl } from "../core/AssetUrls";
|
||||
import { EventBus } from "../core/EventBus";
|
||||
@@ -10,7 +11,6 @@ import {
|
||||
PublicGameInfo,
|
||||
} from "../core/Schemas";
|
||||
import { GameEnv } from "../core/configuration/Config";
|
||||
import { getRuntimeClientServerConfig } from "../core/configuration/ConfigLoader";
|
||||
import { GameType } from "../core/game/Game";
|
||||
import {
|
||||
DARK_MODE_KEY,
|
||||
@@ -169,7 +169,6 @@ function updateAccountNavButton(userMeResponse: UserMeResponse | false) {
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
GIT_COMMIT: string;
|
||||
turnstile: any;
|
||||
adsEnabled: boolean;
|
||||
PageOS: {
|
||||
@@ -770,16 +769,14 @@ class Client {
|
||||
if (lobby.source === "public") {
|
||||
this.joinModal?.open(lobby.gameID, lobby.publicLobbyInfo);
|
||||
}
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
// Only update URL immediately for private lobbies, not public ones
|
||||
if (lobby.source !== "public") {
|
||||
this.updateJoinUrlForShare(lobby.gameID, config);
|
||||
this.updateJoinUrlForShare(lobby.gameID);
|
||||
}
|
||||
const auth = await userAuth();
|
||||
const playerRole = auth !== false ? (auth.claims.role ?? null) : null;
|
||||
const newLobbyHandle = joinLobby(this.eventBus, {
|
||||
gameID: lobby.gameID,
|
||||
serverConfig: config,
|
||||
cosmetics: await getPlayerCosmeticsRefs(),
|
||||
turnstileToken: await this.getTurnstileToken(lobby),
|
||||
playerName: this.usernameInput?.getUsername() ?? genAnonUsername(),
|
||||
@@ -881,7 +878,7 @@ class Client {
|
||||
"",
|
||||
lobbyIdHidden
|
||||
? "/streamer-mode"
|
||||
: `/${config.workerPath(lobby.gameID)}/game/${lobby.gameID}?live`,
|
||||
: `/${ClientEnv.workerPath(lobby.gameID)}/game/${lobby.gameID}?live`,
|
||||
);
|
||||
|
||||
// Store current URL for popstate confirmation
|
||||
@@ -889,14 +886,11 @@ class Client {
|
||||
});
|
||||
}
|
||||
|
||||
private updateJoinUrlForShare(
|
||||
lobbyId: string,
|
||||
config: Awaited<ReturnType<typeof getRuntimeClientServerConfig>>,
|
||||
) {
|
||||
private updateJoinUrlForShare(lobbyId: string) {
|
||||
const lobbyIdHidden = !this.userSettings.lobbyIdVisibility();
|
||||
const targetUrl = lobbyIdHidden
|
||||
? "/streamer-mode"
|
||||
: `/${config.workerPath(lobbyId)}/game/${lobbyId}`;
|
||||
: `/${ClientEnv.workerPath(lobbyId)}/game/${lobbyId}`;
|
||||
const currentUrl = window.location.pathname;
|
||||
|
||||
if (currentUrl !== targetUrl) {
|
||||
@@ -970,9 +964,8 @@ class Client {
|
||||
private async getTurnstileToken(
|
||||
lobby: JoinLobbyEvent,
|
||||
): Promise<string | null> {
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
if (
|
||||
config.env() === GameEnv.Dev ||
|
||||
ClientEnv.env() === GameEnv.Dev ||
|
||||
lobby.gameStartInfo?.config.gameType === GameType.Singleplayer
|
||||
) {
|
||||
return null;
|
||||
@@ -1048,9 +1041,8 @@ async function getTurnstileToken(): Promise<{
|
||||
throw new Error("Failed to load Turnstile script");
|
||||
}
|
||||
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
const widgetId = window.turnstile.render("#turnstile-container", {
|
||||
sitekey: config.turnstileSiteKey(),
|
||||
sitekey: ClientEnv.turnstileSiteKey(),
|
||||
size: "normal",
|
||||
appearance: "interaction-only",
|
||||
theme: "light",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { html, LitElement } from "lit";
|
||||
import { customElement, state } from "lit/decorators.js";
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import { UserMeResponse } from "../core/ApiSchemas";
|
||||
import { getRuntimeClientServerConfig } from "../core/configuration/ConfigLoader";
|
||||
import { getUserMe, hasLinkedAccount } from "./Api";
|
||||
import { getPlayToken } from "./Auth";
|
||||
import { BaseModal } from "./components/BaseModal";
|
||||
@@ -12,7 +12,6 @@ import { translateText } from "./Utils";
|
||||
|
||||
@customElement("matchmaking-modal")
|
||||
export class MatchmakingModal extends BaseModal {
|
||||
private static instanceIdPromise: Promise<string> | null = null;
|
||||
private gameCheckInterval: ReturnType<typeof setInterval> | null = null;
|
||||
private connectTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
@state() private connected = false;
|
||||
@@ -86,11 +85,8 @@ export class MatchmakingModal extends BaseModal {
|
||||
}
|
||||
|
||||
private async connect() {
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
const instanceId = await MatchmakingModal.getInstanceId();
|
||||
|
||||
this.socket = new WebSocket(
|
||||
`${config.jwtIssuer()}/matchmaking/join?instance_id=${encodeURIComponent(instanceId)}`,
|
||||
`${ClientEnv.jwtIssuer()}/matchmaking/join?instance_id=${encodeURIComponent(ClientEnv.instanceId())}`,
|
||||
);
|
||||
this.socket.onopen = async () => {
|
||||
console.log("Connected to matchmaking server");
|
||||
@@ -131,32 +127,6 @@ export class MatchmakingModal extends BaseModal {
|
||||
};
|
||||
}
|
||||
|
||||
private static async getInstanceId(): Promise<string> {
|
||||
MatchmakingModal.instanceIdPromise ??= fetch("/api/instance", {
|
||||
cache: "no-store",
|
||||
})
|
||||
.then(async (response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to load instance id: ${response.status} ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as { instanceId?: string };
|
||||
if (!data.instanceId) {
|
||||
throw new Error("Missing instance id");
|
||||
}
|
||||
|
||||
return data.instanceId;
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
MatchmakingModal.instanceIdPromise = null;
|
||||
throw error;
|
||||
});
|
||||
|
||||
return MatchmakingModal.instanceIdPromise;
|
||||
}
|
||||
|
||||
protected async onOpen(): Promise<void> {
|
||||
const userMe = await getUserMe();
|
||||
// Early return if modal was closed during async operation
|
||||
@@ -209,8 +179,7 @@ export class MatchmakingModal extends BaseModal {
|
||||
if (this.gameID === null) {
|
||||
return;
|
||||
}
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
const url = `/${config.workerPath(this.gameID)}/api/game/${this.gameID}/exists`;
|
||||
const url = `/${ClientEnv.workerPath(this.gameID)}/api/game/${this.gameID}/exists`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import { z } from "zod";
|
||||
import { EventBus, GameEvent } from "../core/EventBus";
|
||||
import {
|
||||
@@ -330,9 +331,7 @@ export class Transport {
|
||||
this.killExistingSocket();
|
||||
const wsHost = window.location.host;
|
||||
const wsProtocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
||||
const workerPath = this.lobbyConfig.serverConfig.workerPath(
|
||||
this.lobbyConfig.gameID,
|
||||
);
|
||||
const workerPath = ClientEnv.workerPath(this.lobbyConfig.gameID);
|
||||
this.socket = new WebSocket(`${wsProtocol}//${wsHost}/${workerPath}`);
|
||||
this.onconnect = onconnect;
|
||||
this.onmessage = onmessage;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { LitElement, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators.js";
|
||||
import { getRuntimeClientServerConfig } from "../../core/configuration/ConfigLoader";
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import { UserSettings } from "../../core/game/UserSettings";
|
||||
import { crazyGamesSDK } from "../CrazyGamesSDK";
|
||||
import { copyToClipboard, translateText } from "../Utils";
|
||||
@@ -63,8 +63,7 @@ export class CopyButton extends LitElement {
|
||||
}
|
||||
|
||||
private async buildCopyUrl(): Promise<string> {
|
||||
const config = await getRuntimeClientServerConfig();
|
||||
let url = `${window.location.origin}/${config.workerPath(this.lobbyId)}/game/${this.lobbyId}`;
|
||||
let url = `${window.location.origin}/${ClientEnv.workerPath(this.lobbyId)}/game/${this.lobbyId}`;
|
||||
if (this.includeLobbyQuery) {
|
||||
url += `?lobby&s=${encodeURIComponent(this.lobbySuffix)}`;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import miniBigSmoke from "../../../resources/sprites/bigsmoke.png";
|
||||
import buildingExplosion from "../../../resources/sprites/buildingExplosion.png";
|
||||
import conquestSword from "../../../resources/sprites/conquestSword.png";
|
||||
@@ -10,7 +11,6 @@ import sinkingShip from "../../../resources/sprites/sinkingShip.png";
|
||||
import miniSmoke from "../../../resources/sprites/smoke.png";
|
||||
import miniSmokeAndFire from "../../../resources/sprites/smokeAndFire.png";
|
||||
import unitExplosion from "../../../resources/sprites/unitExplosion.png";
|
||||
import { Theme } from "../../core/configuration/Config";
|
||||
import { PlayerView } from "../../core/game/GameView";
|
||||
import { AnimatedSprite } from "./AnimatedSprite";
|
||||
import { FxType } from "./fx/Fx";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Colord } from "colord";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { assetUrl } from "../../core/AssetUrls";
|
||||
import { Theme } from "../../core/configuration/Config";
|
||||
import { TrainType, UnitType } from "../../core/game/Game";
|
||||
import { UnitView } from "../../core/game/GameView";
|
||||
const atomBombSprite = assetUrl("sprites/atombomb.png");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { PlayerView } from "../../../core/game/GameView";
|
||||
import { AnimatedSprite } from "../AnimatedSprite";
|
||||
import { AnimatedSpriteLoader } from "../AnimatedSpriteLoader";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { UnitType } from "../../../core/game/Game";
|
||||
import { TileRef } from "../../../core/game/GameMap";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { LitElement, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators.js";
|
||||
import { ClientEnv } from "src/client/ClientEnv";
|
||||
import { GameEnv } from "../../../core/configuration/Config";
|
||||
import { GameType } from "../../../core/game/Game";
|
||||
import { GameView } from "../../../core/game/GameView";
|
||||
@@ -31,7 +32,7 @@ export class MultiTabModal extends LitElement implements Layer {
|
||||
if (
|
||||
this.game.inSpawnPhase() ||
|
||||
this.game.config().gameConfig().gameType === GameType.Singleplayer ||
|
||||
this.game.config().serverConfig().env() === GameEnv.Dev ||
|
||||
ClientEnv.env() === GameEnv.Dev ||
|
||||
this.game.config().isReplay()
|
||||
) {
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { assetUrl } from "src/core/AssetUrls";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { PseudoRandom } from "../../../core/PseudoRandom";
|
||||
import { Config, Theme } from "../../../core/configuration/Config";
|
||||
import { Config } from "../../../core/configuration/Config";
|
||||
import { Cell } from "../../../core/game/Game";
|
||||
import { GameView, PlayerView } from "../../../core/game/GameView";
|
||||
import { UserSettings } from "../../../core/game/UserSettings";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as PIXI from "pixi.js";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { assetUrl } from "../../../core/AssetUrls";
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import {
|
||||
Cell,
|
||||
PlayerBuildableUnitType,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { extend } from "colord";
|
||||
import a11yPlugin from "colord/plugins/a11y";
|
||||
import { OutlineFilter } from "pixi-filters";
|
||||
import * as PIXI from "pixi.js";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { assetUrl } from "../../../core/AssetUrls";
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { wouldNukeBreakAlliance } from "../../../core/execution/Util";
|
||||
import {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { colord, Colord } from "colord";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { assetUrl } from "../../../core/AssetUrls";
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { TransformHandler } from "../TransformHandler";
|
||||
import { Layer } from "./Layer";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Config, Theme } from "../../../core/configuration/Config";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { Config } from "../../../core/configuration/Config";
|
||||
import { GameView } from "../../../core/game/GameView";
|
||||
import { TransformHandler } from "../TransformHandler";
|
||||
import { Layer } from "./Layer";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PriorityQueue } from "@datastructures-js/priority-queue";
|
||||
import { Colord } from "colord";
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import {
|
||||
Cell,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Colord } from "colord";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { UnitType } from "../../../core/game/Game";
|
||||
import { GameUpdateType } from "../../../core/game/GameUpdates";
|
||||
import { GameView, UnitView } from "../../../core/game/GameView";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { colord, Colord } from "colord";
|
||||
import { Theme } from "src/core/configuration/Theme";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { Cell, UnitType } from "../../../core/game/Game";
|
||||
import { TileRef } from "../../../core/game/GameMap";
|
||||
import { GameView, UnitView } from "../../../core/game/GameView";
|
||||
|
||||
Reference in New Issue
Block a user