From 431999542ee9812fa9e9c54ae56fb052cae1d691 Mon Sep 17 00:00:00 2001
From: 1brucben <1benjbruce@gmail.com>
Date: Thu, 19 Jun 2025 00:43:38 +0200
Subject: [PATCH 1/3] pingfix
---
nginx.conf | 2 +-
src/client/Transport.ts | 26 ++++-----
src/client/index.html | 2 +-
src/server/Worker.ts | 116 +++++++++++++++++++++-------------------
supervisord.conf | 2 +-
5 files changed, 78 insertions(+), 70 deletions(-)
diff --git a/nginx.conf b/nginx.conf
index 25c09b3d..57288cdd 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -297,4 +297,4 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
-}
\ No newline at end of file
+}
diff --git a/src/client/Transport.ts b/src/client/Transport.ts
index f208a55a..4b66acea 100644
--- a/src/client/Transport.ts
+++ b/src/client/Transport.ts
@@ -14,7 +14,6 @@ import {
AllPlayersStats,
ClientHashMessage,
ClientIntentMessage,
- ClientJoinMessage,
ClientPingMessage,
ClientSendWinnerMessage,
Intent,
@@ -334,17 +333,20 @@ export class Transport {
}
joinGame(numTurns: number) {
- this.sendMsg(
- JSON.stringify({
- type: "join",
- gameID: this.lobbyConfig.gameID,
- clientID: this.lobbyConfig.clientID,
- lastTurn: numTurns,
- token: this.lobbyConfig.token,
- username: this.lobbyConfig.playerName,
- flag: this.lobbyConfig.flag,
- } satisfies ClientJoinMessage),
- );
+ const msg = {
+ type: "join",
+ gameID: this.lobbyConfig.gameID,
+ clientID: this.lobbyConfig.clientID,
+ lastTurn: numTurns,
+ token: this.lobbyConfig.token,
+ username: this.lobbyConfig.playerName,
+ flag: this.lobbyConfig.flag,
+ };
+
+ console.log("[JOIN] Sending join message object:", msg);
+ console.log("[JOIN] JSON stringified:", JSON.stringify(msg));
+
+ this.sendMsg(JSON.stringify(msg));
}
leaveGame(saveFullGame: boolean = false) {
diff --git a/src/client/index.html b/src/client/index.html
index ae94e0ae..be22fefc 100644
--- a/src/client/index.html
+++ b/src/client/index.html
@@ -203,7 +203,7 @@
/>
-
+
diff --git a/src/server/Worker.ts b/src/server/Worker.ts
index 5bee6b60..13110598 100644
--- a/src/server/Worker.ts
+++ b/src/server/Worker.ts
@@ -294,72 +294,78 @@ export function startWorker() {
try {
// Parse and handle client messages
- const parsed = ClientJoinMessageSchema.safeParse(
- JSON.parse(message.toString()),
- );
- if (!parsed.success) {
- const error = z.prettifyError(parsed.error);
- log.warn("Error parsing join message client", error);
- ws.close();
- return;
- }
- const clientMsg = parsed.data;
-
- if (clientMsg.type === "join") {
- // Verify this worker should handle this game
- const expectedWorkerId = config.workerIndex(clientMsg.gameID);
- if (expectedWorkerId !== workerId) {
- log.warn(
- `Worker mismatch: Game ${clientMsg.gameID} should be on worker ${expectedWorkerId}, but this is worker ${workerId}`,
- );
+ log.warn(`Raw WebSocket message: ${message.toString()}`);
+ const raw = JSON.parse(message.toString());
+
+ if (raw?.type === "join") {
+ const parsed = ClientJoinMessageSchema.safeParse(
+ JSON.parse(message.toString()),
+ );
+ if (!parsed.success) {
+ log.warn("ClientJoinMessage parsing failed:");
+ for (const issue of parsed.error.errors) {
+ log.warn(` → [${issue.path.join(".")}] ${issue.message}`);
+ }
+ ws.close();
return;
}
+ const clientMsg = parsed.data;
+
+ if (clientMsg.type === "join") {
+ // Verify this worker should handle this game
+ const expectedWorkerId = config.workerIndex(clientMsg.gameID);
+ if (expectedWorkerId !== workerId) {
+ log.warn(
+ `Worker mismatch: Game ${clientMsg.gameID} should be on worker ${expectedWorkerId}, but this is worker ${workerId}`,
+ );
+ return;
+ }
- const { persistentId, claims } = await verifyClientToken(
- clientMsg.token,
- config,
- );
+ const { persistentId, claims } = await verifyClientToken(
+ clientMsg.token,
+ config,
+ );
- let roles: string[] | undefined;
+ let roles: string[] | undefined;
- // Check user roles
- if (claims !== null) {
- const result = await getUserMe(clientMsg.token, config);
- if (result === false) {
- log.warn("Token is not valid", claims);
- return;
+ // Check user roles
+ if (claims !== null) {
+ const result = await getUserMe(clientMsg.token, config);
+ if (result === false) {
+ log.warn("Token is not valid", claims);
+ return;
+ }
+ roles = result.player.roles;
}
- roles = result.player.roles;
- }
- // TODO: Validate client settings based on roles
-
- // Create client and add to game
- const client = new Client(
- clientMsg.clientID,
- persistentId,
- claims,
- roles,
- ip,
- clientMsg.username,
- ws,
- clientMsg.flag,
- );
-
- const wasFound = gm.addClient(
- client,
- clientMsg.gameID,
- clientMsg.lastTurn,
- );
+ // TODO: Validate client settings based on roles
+
+ // Create client and add to game
+ const client = new Client(
+ clientMsg.clientID,
+ persistentId,
+ claims,
+ roles,
+ ip,
+ clientMsg.username,
+ ws,
+ clientMsg.flag,
+ );
- if (!wasFound) {
- log.info(
- `game ${clientMsg.gameID} not found on worker ${workerId}`,
+ const wasFound = gm.addClient(
+ client,
+ clientMsg.gameID,
+ clientMsg.lastTurn,
);
- // Handle game not found case
+
+ if (!wasFound) {
+ log.info(
+ `game ${clientMsg.gameID} not found on worker ${workerId}`,
+ );
+ // Handle game not found case
+ }
}
}
-
// Handle other message types
} catch (error) {
log.warn(
diff --git a/supervisord.conf b/supervisord.conf
index c31d0429..086622a6 100644
--- a/supervisord.conf
+++ b/supervisord.conf
@@ -22,4 +22,4 @@ user=node
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
-stderr_logfile_maxbytes=0
\ No newline at end of file
+stderr_logfile_maxbytes=0
From ab7414744775da417111382fd245797e835e14e6 Mon Sep 17 00:00:00 2001
From: 1brucben <1benjbruce@gmail.com>
Date: Thu, 19 Jun 2025 00:56:22 +0200
Subject: [PATCH 2/3] restore transport
---
src/client/Transport.ts | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/src/client/Transport.ts b/src/client/Transport.ts
index 4b66acea..f208a55a 100644
--- a/src/client/Transport.ts
+++ b/src/client/Transport.ts
@@ -14,6 +14,7 @@ import {
AllPlayersStats,
ClientHashMessage,
ClientIntentMessage,
+ ClientJoinMessage,
ClientPingMessage,
ClientSendWinnerMessage,
Intent,
@@ -333,20 +334,17 @@ export class Transport {
}
joinGame(numTurns: number) {
- const msg = {
- type: "join",
- gameID: this.lobbyConfig.gameID,
- clientID: this.lobbyConfig.clientID,
- lastTurn: numTurns,
- token: this.lobbyConfig.token,
- username: this.lobbyConfig.playerName,
- flag: this.lobbyConfig.flag,
- };
-
- console.log("[JOIN] Sending join message object:", msg);
- console.log("[JOIN] JSON stringified:", JSON.stringify(msg));
-
- this.sendMsg(JSON.stringify(msg));
+ this.sendMsg(
+ JSON.stringify({
+ type: "join",
+ gameID: this.lobbyConfig.gameID,
+ clientID: this.lobbyConfig.clientID,
+ lastTurn: numTurns,
+ token: this.lobbyConfig.token,
+ username: this.lobbyConfig.playerName,
+ flag: this.lobbyConfig.flag,
+ } satisfies ClientJoinMessage),
+ );
}
leaveGame(saveFullGame: boolean = false) {
From 3ff9f55f33cbdf8b4dd913ceb08313c5fd8f507b Mon Sep 17 00:00:00 2001
From: 1brucben <1benjbruce@gmail.com>
Date: Thu, 19 Jun 2025 02:02:34 +0200
Subject: [PATCH 3/3] fix webpack config
---
webpack.config.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/webpack.config.js b/webpack.config.js
index 70ee9452..3f6d2893 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -159,7 +159,7 @@ export default async (env, argv) => {
},
historyApiFallback: true,
compress: true,
- port: 3000,
+ port: 9000,
proxy: [
// WebSocket proxies
{