diff --git a/package-lock.json b/package-lock.json index 236574ed45..3223dfaeff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1049,7 +1049,6 @@ "integrity": "sha512-bXYxrXFubeYdvB0NhD/NBB3Qi6aZeV20GOWVI47t2dkecCEoneR4NPVcb7abpXDEvejgrUfFtG6vG/zxAKmg+g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.27.1", @@ -2922,7 +2921,6 @@ } ], "license": "MIT", - "peer": true, "engines": { "node": ">=18" }, @@ -2946,7 +2944,6 @@ } ], "license": "MIT", - "peer": true, "engines": { "node": ">=18" } @@ -5101,7 +5098,6 @@ "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==", "license": "Apache-2.0", - "peer": true, "engines": { "node": ">=8.0.0" } @@ -6420,6 +6416,7 @@ "os": [ "darwin" ], + "peer": true, "engines": { "node": ">=10" } @@ -6436,6 +6433,7 @@ "os": [ "darwin" ], + "peer": true, "engines": { "node": ">=10" } @@ -6452,6 +6450,7 @@ "os": [ "linux" ], + "peer": true, "engines": { "node": ">=10" } @@ -6468,6 +6467,7 @@ "os": [ "linux" ], + "peer": true, "engines": { "node": ">=10" } @@ -6484,6 +6484,7 @@ "os": [ "linux" ], + "peer": true, "engines": { "node": ">=10" } @@ -6500,6 +6501,7 @@ "os": [ "linux" ], + "peer": true, "engines": { "node": ">=10" } @@ -6516,6 +6518,7 @@ "os": [ "linux" ], + "peer": true, "engines": { "node": ">=10" } @@ -6532,6 +6535,7 @@ "os": [ "win32" ], + "peer": true, "engines": { "node": ">=10" } @@ -6548,6 +6552,7 @@ "os": [ "win32" ], + "peer": true, "engines": { "node": ">=10" } @@ -6564,6 +6569,7 @@ "os": [ "win32" ], + "peer": true, "engines": { "node": ">=10" } @@ -6599,6 +6605,7 @@ "integrity": "sha512-u1iIVZV9Q0jxY+yM2vw/hZGDNudsN85bBpTqzAQ9rzkxW9D+e3aEM4Han+ow518gSewkXgjmEK0BD79ZcNVgPw==", "devOptional": true, "license": "Apache-2.0", + "peer": true, "dependencies": { "@swc/counter": "^0.1.3" } @@ -7253,7 +7260,6 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.32.tgz", "integrity": "sha512-3jigKqgSjsH6gYZv2nEsqdXfZqIFGAV36XYYjf9KGZ3PSG+IhLecqPnI310RvjutyMwifE2hhhNEklOUrvx/wA==", "license": "MIT", - "peer": true, "dependencies": { "undici-types": "~6.21.0" } @@ -7488,7 +7494,6 @@ "integrity": "sha512-4O3idHxhyzjClSMJ0a29AcoK0+YwnEqzI6oz3vlRf3xw0zbzt15MzXwItOlnr5nIth6zlY2RENLsOPvhyrKAQA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.34.1", "@typescript-eslint/types": "8.34.1", @@ -8259,7 +8264,6 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -8318,7 +8322,6 @@ "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -8884,7 +8887,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001718", "electron-to-chromium": "^1.5.160", @@ -9063,7 +9065,6 @@ "dev": true, "hasInstallScript": true, "license": "MIT", - "peer": true, "dependencies": { "node-addon-api": "^7.0.0", "prebuild-install": "^7.1.1" @@ -9085,7 +9086,6 @@ "integrity": "sha512-mCuXncKXk5iCLhfhwTc0izo0gtEmpz5CtG2y8GiOINBlMVS6v8TMRc5TaLWKS6692m9+dVVfzgeVxR5UxWHTYw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "assertion-error": "^2.0.1", "check-error": "^2.1.1", @@ -9690,7 +9690,6 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -10278,7 +10277,6 @@ "integrity": "sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==", "dev": true, "license": "ISC", - "peer": true, "engines": { "node": ">=12" } @@ -11021,7 +11019,6 @@ "integrity": "sha512-GsGizj2Y1rCWDu6XoEekL3RLilp0voSePurjZIkxL3wlm5o5EC9VpgaP7lrCvjnkuLvzFBQWB3vWB3K5KQTveQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", @@ -11191,7 +11188,6 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -11550,7 +11546,6 @@ "resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz", "integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==", "license": "MIT", - "peer": true, "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", @@ -12451,7 +12446,6 @@ "integrity": "sha512-QSf1yjtSAsmf7rYBV7XX86uua4W/vkhIt0xNXKbsi2foEeW7vjJQz4bhnpL3xH+l1ryl1680uNv968Z+X6jSYg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/html-minifier-terser": "^6.0.0", "html-minifier-terser": "^6.0.2", @@ -14981,7 +14975,6 @@ "integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "cssstyle": "^4.2.1", "data-urls": "^5.0.0", @@ -16695,7 +16688,6 @@ "integrity": "sha512-dyuThzncsgEgJZnvd/A/5x6IkUERbK+phXqUQrI+0C6WE+8xqGH5VChRTLecemhgZF0kQ+gZOM3tJTX9937xpg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@pixi/colord": "^2.9.6", "@types/css-font-loading-module": "^0.0.12", @@ -16753,7 +16745,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -17092,7 +17083,6 @@ "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==", "dev": true, "license": "MIT", - "peer": true, "bin": { "prettier": "bin/prettier.cjs" }, @@ -18362,7 +18352,6 @@ "integrity": "sha512-TOgRcwFPbfGtpqvZw+hyqJDvqfapr1qUlOizROIk4bBLjlsjlB00Pg6wMFXNtJRpu+eCZuVOaLatG7M8105kAw==", "dev": true, "license": "BSD-3-Clause", - "peer": true, "dependencies": { "@sinonjs/commons": "^3.0.1", "@sinonjs/fake-timers": "^13.0.5", @@ -19075,7 +19064,6 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -19307,7 +19295,6 @@ "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -19495,7 +19482,6 @@ "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "license": "MIT", - "peer": true, "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -19578,8 +19564,7 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "license": "0BSD", - "peer": true + "license": "0BSD" }, "node_modules/tsx": { "version": "4.20.3", @@ -19668,7 +19653,6 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -19963,7 +19947,6 @@ "integrity": "sha512-QaNKAvGCDRh3wW1dsDjeMdDXwZm2vqq3zn6Pvq4rHOEOGSaUMgOOjG2Y9ZbIGzpfkJk9ZYTHpDqgDfeBDcnLaw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/eslint-scope": "^3.7.7", "@types/estree": "^1.0.8", @@ -20013,7 +19996,6 @@ "integrity": "sha512-MfwFQ6SfwinsUVi0rNJm7rHZ31GyTcpVE5pgVA3hwFRb7COD4TzjUUwhGWKfO50+xdc2MQPuEBBJoqIMGt3JDw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@discoveryjs/json-ext": "^0.6.1", "@webpack-cli/configtest": "^3.0.1", @@ -20097,7 +20079,6 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -20213,7 +20194,6 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -20306,7 +20286,6 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", diff --git a/resources/lang/en.json b/resources/lang/en.json index 074a35c4ad..11003d35b2 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -229,10 +229,12 @@ "player": "Player", "players": "Players", "join_lobby": "Join Lobby", + "join_as_spectator": "Join as Spectator", "checking": "Checking lobby...", "not_found": "Lobby not found. Please check the ID and try again.", "error": "An error occurred. Please try again or contact support.", "joined_waiting": "Joined successfully! Waiting for game to start...", + "joined_as_spectator": "Joined as spectator! You will be able to view the match.", "version_mismatch": "This game was created with a different version. Cannot join." }, "public_lobby": { @@ -286,7 +288,8 @@ "assigned_teams": "Assigned Teams", "empty_teams": "Empty Teams", "empty_team": "Empty", - "remove_player": "Remove {username}" + "remove_player": "Remove {{username}}", + "spectators_count": "{count} spectator(s) watching" }, "team_colors": { "red": "Red", @@ -558,7 +561,9 @@ "warships": "Warships", "cities": "Cities", "show_control": "Show Control", - "show_units": "Show Units" + "show_units": "Show Units", + "spectator": "spectator watching", + "spectators": "spectators watching" }, "player_info_overlay": { "type": "Type", diff --git a/src/client/ClientGameRunner.ts b/src/client/ClientGameRunner.ts index ecfb4c6ead..14db48000d 100644 --- a/src/client/ClientGameRunner.ts +++ b/src/client/ClientGameRunner.ts @@ -59,6 +59,7 @@ export interface LobbyConfig { gameID: GameID; token: string; turnstileToken: string | null; + isSpectator?: boolean; // GameStartInfo only exists when playing a singleplayer game. gameStartInfo?: GameStartInfo; // GameRecord exists when replaying an archived game. @@ -347,6 +348,13 @@ export class ClientGameRunner { if (message.type === "start") { console.log("starting game! in client game runner"); + if (this.lobby.isSpectator) { + this.transport.publishIntent({ + type: "join_spectator", + clientID: this.lobby.clientID, + }); + } + if (this.gameView.config().isRandomSpawn()) { const goToPlayer = () => { const myPlayer = this.gameView.myPlayer(); diff --git a/src/client/HostLobbyModal.ts b/src/client/HostLobbyModal.ts index 5d94324e92..6e3568918f 100644 --- a/src/client/HostLobbyModal.ts +++ b/src/client/HostLobbyModal.ts @@ -54,6 +54,7 @@ export class HostLobbyModal extends LitElement { @state() private lobbyId = ""; @state() private copySuccess = false; @state() private clients: ClientInfo[] = []; + @state() private spectators: ClientInfo[] = []; @state() private useRandomMap: boolean = false; @state() private disabledUnits: UnitType[] = []; @state() private lobbyCreatorClientID: string = ""; @@ -572,6 +573,18 @@ export class HostLobbyModal extends LitElement { .nationCount=${this.disableNPCs ? 0 : this.nationCount} .onKickPlayer=${(clientID: string) => this.kickPlayer(clientID)} > + + ${ + this.spectators.length > 0 + ? html` +
+ ${translateText("host_modal.spectators_count", { + count: this.spectators.length, + })} +
+ ` + : null + }
@@ -854,6 +867,7 @@ export class HostLobbyModal extends LitElement { console.log(`got game info response: ${JSON.stringify(data)}`); this.clients = data.clients ?? []; + this.spectators = data.spectators ?? []; }); } diff --git a/src/client/JoinPrivateLobbyModal.ts b/src/client/JoinPrivateLobbyModal.ts index 2c89e9804e..52fd6ef76a 100644 --- a/src/client/JoinPrivateLobbyModal.ts +++ b/src/client/JoinPrivateLobbyModal.ts @@ -18,6 +18,7 @@ export class JoinPrivateLobbyModal extends LitElement { @state() private message: string = ""; @state() private hasJoined = false; @state() private players: string[] = []; + @state() private spectatorCount: number = 0; private playersInterval: NodeJS.Timeout | null = null; @@ -86,16 +87,33 @@ export class JoinPrivateLobbyModal extends LitElement { (player) => html`${player}`, )}
+ ${this.spectatorCount > 0 + ? html` +
+ ${translateText("host_modal.spectators_count", { + count: this.spectatorCount, + })} +
+ ` + : null} ` : ""} -
+
${!this.hasJoined - ? html` ` + ? html` + + + ` : ""}
@@ -170,16 +188,31 @@ export class JoinPrivateLobbyModal extends LitElement { } private async joinLobby(): Promise { + await this.joinLobbyInternal(false); + } + + private async joinAsSpectator(): Promise { + await this.joinLobbyInternal(true); + } + + private async joinLobbyInternal(isSpectator: boolean): Promise { const lobbyId = this.lobbyIdInput.value; - console.log(`Joining lobby with ID: ${lobbyId}`); + console.log( + `Joining lobby with ID: ${lobbyId} as ${isSpectator ? "spectator" : "player"}`, + ); this.message = `${translateText("private_lobby.checking")}`; try { // First, check if the game exists in active lobbies - const gameExists = await this.checkActiveLobby(lobbyId); + const gameExists = await this.checkActiveLobby(lobbyId, isSpectator); if (gameExists) return; - // If not active, check archived games + // If not active, check archived games (spectators cannot join archived games) + if (isSpectator) { + this.message = `${translateText("private_lobby.not_found")}`; + return; + } + switch (await this.checkArchivedGame(lobbyId)) { case "success": return; @@ -199,7 +232,10 @@ export class JoinPrivateLobbyModal extends LitElement { } } - private async checkActiveLobby(lobbyId: string): Promise { + private async checkActiveLobby( + lobbyId: string, + isSpectator: boolean = false, + ): Promise { const config = await getServerConfigFromClient(); const url = `/${config.workerPath(lobbyId)}/api/game/${lobbyId}/exists`; @@ -211,7 +247,9 @@ export class JoinPrivateLobbyModal extends LitElement { const gameInfo = await response.json(); if (gameInfo.exists) { - this.message = translateText("private_lobby.joined_waiting"); + this.message = isSpectator + ? translateText("private_lobby.joined_as_spectator") + : translateText("private_lobby.joined_waiting"); this.hasJoined = true; this.dispatchEvent( @@ -219,6 +257,7 @@ export class JoinPrivateLobbyModal extends LitElement { detail: { gameID: lobbyId, clientID: generateID(), + isSpectator: isSpectator, } as JoinLobbyEvent, bubbles: true, composed: true, @@ -315,6 +354,7 @@ export class JoinPrivateLobbyModal extends LitElement { .then((response) => response.json()) .then((data: GameInfo) => { this.players = data.clients?.map((p) => p.username) ?? []; + this.spectatorCount = data.spectators?.length ?? 0; }) .catch((error) => { console.error("Error polling players:", error); diff --git a/src/client/Main.ts b/src/client/Main.ts index 1cf5ff5436..88f54949d6 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -85,6 +85,7 @@ export interface JoinLobbyEvent { clientID: string; // Multiplayer games only have gameID, gameConfig is not known until game starts. gameID: string; + isSpectator?: boolean; // GameConfig only exists when playing a singleplayer game. gameStartInfo?: GameStartInfo; // GameRecord exists when replaying an archived game. @@ -500,6 +501,7 @@ class Client { playerName: this.usernameInput?.getCurrentUsername() ?? "", token: getPlayToken(), clientID: lobby.clientID, + isSpectator: lobby.isSpectator, gameStartInfo: lobby.gameStartInfo ?? lobby.gameRecord?.info, gameRecord: lobby.gameRecord, }, diff --git a/src/client/Transport.ts b/src/client/Transport.ts index 9f4f1f5a7f..1029b619d9 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -659,6 +659,10 @@ export class Transport { }); } + public publishIntent(intent: Intent) { + this.sendIntent(intent); + } + private sendIntent(intent: Intent) { if (this.isLocal || this.socket?.readyState === WebSocket.OPEN) { const msg = { diff --git a/src/client/graphics/layers/Leaderboard.ts b/src/client/graphics/layers/Leaderboard.ts index 21aee6e32f..451cfba7ea 100644 --- a/src/client/graphics/layers/Leaderboard.ts +++ b/src/client/graphics/layers/Leaderboard.ts @@ -2,6 +2,7 @@ import { LitElement, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import { repeat } from "lit/directives/repeat.js"; import { translateText } from "../../../client/Utils"; +import { getServerConfigFromClient } from "../../../core/configuration/ConfigLoader"; import { EventBus, GameEvent } from "../../../core/EventBus"; import { GameView, PlayerView, UnitView } from "../../../core/game/GameView"; import { renderNumber } from "../../Utils"; @@ -49,6 +50,9 @@ export class Leaderboard extends LitElement implements Layer { @state() private _sortOrder: "asc" | "desc" = "desc"; + @state() + private spectatorCount: number = 0; + createRenderRoot() { return this; // use light DOM for Tailwind support } @@ -61,6 +65,28 @@ export class Leaderboard extends LitElement implements Layer { if (this.game.ticks() % 10 === 0) { this.updateLeaderboard(); } + // Update spectator count every 5 seconds (300 ticks) + if (this.game.ticks() % 300 === 0) { + this.updateSpectatorCount(); + } + } + + private async updateSpectatorCount() { + if (this.game === null) return; + try { + const gameID = this.game.gameID(); + const config = await getServerConfigFromClient(); + const response = await fetch( + `/${config.workerPath(gameID)}/api/game/${gameID}`, + ); + if (response.ok) { + const data = await response.json(); + this.spectatorCount = data.spectators?.length ?? 0; + } + } catch (error) { + // Silently fail - spectator count is not critical + console.debug("Failed to fetch spectator count:", error); + } } private setSort(key: "tiles" | "gold" | "troops") { @@ -172,6 +198,18 @@ export class Leaderboard extends LitElement implements Layer { return html``; } return html` + ${this.spectatorCount > 0 + ? html` +
+ 👁️ ${this.spectatorCount} + ${this.spectatorCount === 1 + ? translateText("leaderboard.spectator") + : translateText("leaderboard.spectators")} +
+ ` + : null}
({ - username: c.username, - clientID: c.clientID, - })), + clients: this.activeClients + .filter((c) => !c.isSpectator) + .map((c) => ({ + username: c.username, + clientID: c.clientID, + })), + spectators: this.activeClients + .filter((c) => c.isSpectator) + .map((c) => ({ + username: c.username, + clientID: c.clientID, + isSpectator: true, + })), gameConfig: this.gameConfig, msUntilStart: this.isPublic() ? this.createdAt + this.config.gameCreationRate() @@ -699,6 +708,9 @@ export class GameServer { const now = Date.now(); for (const [clientID, client] of this.allClients) { + if (client.isSpectator) { + continue; + } const isDisconnected = this.isClientDisconnected(clientID); if (!isDisconnected && now - client.lastPing > this.disconnectedTimeout) { this.markClientDisconnected(clientID, true); diff --git a/src/server/Worker.ts b/src/server/Worker.ts index 87b3e1d659..6b7325e745 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -444,6 +444,7 @@ export async function startWorker() { clientMsg.username, ws, cosmeticResult.cosmetics, + clientMsg.isSpectator ?? false, ); const wasFound = gm.joinClient(client, clientMsg.gameID);