move lobby websockets to worker (#2974)

## Description:

Currently only the master process sends public lobby updates to clients.
This is not scalable since it could overload the master process.

In this PR, the master uses IPC to send public lobby info to all
workers. Then clients connect to a random worker to get public lobby
updates via websocket. This way clients never connect directly to the
master websocket.

The flow looks like this:

Every 100ms:
1. Master schedules a public game on a random worker if new games are
needed
2. Master broadcasts public lobby info to all workers (all public games
& num clients connected to each game)
3. Each worker responds to that update with the number of clients
connected to its own public games
4. Master then updates its public lobby state so it knows how many
clients are connected to each public game

## 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:
Evan
2026-02-03 18:26:38 -08:00
committed by GitHub
parent 9294b73a88
commit 294a1b4784
15 changed files with 437 additions and 472 deletions
+9 -22
View File
@@ -70,7 +70,7 @@ export class JoinLobbyModal extends BaseModal {
}
this.updateFromLobby({
...lobby,
msUntilStart: lobby.msUntilStart ?? undefined,
startsAt: lobby.startsAt ?? undefined,
});
};
@@ -94,7 +94,7 @@ export class JoinLobbyModal extends BaseModal {
})
: translateText("public_lobby.started");
const maxPlayers = this.gameConfig?.maxPlayers ?? 0;
const playerCount = this.playerCount;
const playerCount = this.players?.length ?? 0;
const hostClientID = this.isPrivateLobby()
? (this.lobbyCreatorClientID ?? "")
: "";
@@ -283,13 +283,13 @@ export class JoinLobbyModal extends BaseModal {
`;
}
public open(lobbyId: string = "", lobbyInfo?: GameInfo) {
public open(lobbyId: string = "", isPublic: boolean = false) {
super.open();
if (lobbyId) {
this.startTrackingLobby(lobbyId, lobbyInfo);
this.startTrackingLobby(lobbyId);
// If opened with lobbyInfo (public lobby case), auto-join the lobby
if (lobbyInfo) {
this.joinPublicLobby(lobbyId, lobbyInfo);
if (isPublic) {
this.joinPublicLobby(lobbyId);
} else {
// If opened with lobbyId but no lobbyInfo (URL join case), check if active and join
this.handleUrlJoin(lobbyId);
@@ -329,14 +329,13 @@ export class JoinLobbyModal extends BaseModal {
}
}
private joinPublicLobby(lobbyId: string, lobbyInfo: GameInfo) {
private joinPublicLobby(lobbyId: string) {
// Dispatch join-lobby event to actually connect to the lobby
this.dispatchEvent(
new CustomEvent("join-lobby", {
detail: {
gameID: lobbyId,
clientID: this.currentClientID,
publicLobbyInfo: lobbyInfo,
} as JoinLobbyEvent,
bubbles: true,
composed: true,
@@ -349,7 +348,6 @@ export class JoinLobbyModal extends BaseModal {
this.currentClientID = getClientIDForGame(lobbyId);
this.gameConfig = null;
this.players = [];
this.playerCount = 0;
this.nationCount = 0;
this.lobbyStartAt = null;
this.lobbyCreatorClientID = null;
@@ -397,7 +395,6 @@ export class JoinLobbyModal extends BaseModal {
if (this.lobbyIdInput) this.lobbyIdInput.value = "";
this.gameConfig = null;
this.players = [];
this.playerCount = 0;
this.currentLobbyId = "";
this.currentClientID = "";
this.nationCount = 0;
@@ -536,18 +533,8 @@ export class JoinLobbyModal extends BaseModal {
// --- Lobby event handling ---
private updateFromLobby(lobby: GameInfo) {
if (lobby.clients) {
this.players = lobby.clients;
this.playerCount = lobby.clients.length;
} else {
this.players = [];
this.playerCount = lobby.numClients ?? 0;
}
if (lobby.msUntilStart !== undefined) {
this.lobbyStartAt = lobby.msUntilStart + Date.now();
} else {
this.lobbyStartAt = null;
}
this.players = lobby.clients ?? [];
this.lobbyStartAt = lobby.startsAt ?? null;
this.syncCountdownTimer();
if (lobby.gameConfig) {
const mapChanged = this.gameConfig?.gameMap !== lobby.gameConfig.gameMap;