fix duplicate websocket handler (#1124)

## Description:
Turns out ws.on adds a new listener, it doesn't remove the existing
listener. so it turns out we had both worker & game server listening to
messages. this only got noticed because we close web socket connection
on parsing failure.

## 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
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

evan
This commit is contained in:
evanpelle
2025-06-09 14:53:34 -07:00
committed by evanpelle
parent 892a6552d4
commit 0ff4ff25b7
+3
View File
@@ -182,6 +182,7 @@ export class GameServer {
this.allClients.set(client.clientID, client);
client.ws.removeAllListeners("message");
client.ws.on(
"message",
gatekeeper.wsHandler(client.ip, async (message: string) => {
@@ -239,6 +240,7 @@ export class GameServer {
}
}),
);
client.ws.removeAllListeners("close");
client.ws.on("close", () => {
this.log.info("client disconnected", {
clientID: client.clientID,
@@ -248,6 +250,7 @@ export class GameServer {
(c) => c.clientID !== client.clientID,
);
});
client.ws.removeAllListeners("error");
client.ws.on("error", (error: Error) => {
if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") {
client.ws.close(1002);