diff --git a/src/server/Worker.ts b/src/server/Worker.ts index b15e5262b..c916530b2 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -316,6 +316,7 @@ export function startWorker() { error: error.toString(), } satisfies ServerErrorMessage), ); + ws.removeAllListeners(); ws.close(1002, "ClientJoinMessageSchema"); return; } @@ -333,6 +334,7 @@ export function startWorker() { error, } satisfies ServerErrorMessage), ); + ws.removeAllListeners(); ws.close(1002, "ClientJoinMessageSchema"); return; } @@ -350,6 +352,7 @@ export function startWorker() { const result = await verifyClientToken(clientMsg.token, config); if (result === false) { log.warn("Unauthorized: Invalid token"); + ws.removeAllListeners(); ws.close(1002, "Unauthorized"); return; } @@ -362,6 +365,7 @@ export function startWorker() { if (claims === null) { if (allowedFlares !== undefined) { log.warn("Unauthorized: Anonymous user attempted to join game"); + ws.removeAllListeners(); ws.close(1002, "Unauthorized"); return; } @@ -370,6 +374,7 @@ export function startWorker() { const result = await getUserMe(clientMsg.token, config); if (result === false) { log.warn("Unauthorized: Invalid session"); + ws.removeAllListeners(); ws.close(1002, "Unauthorized"); return; } @@ -384,6 +389,7 @@ export function startWorker() { log.warn( "Forbidden: player without an allowed flare attempted to join game", ); + ws.removeAllListeners(); ws.close(1002, "Forbidden"); return; } @@ -400,6 +406,7 @@ export function startWorker() { ); if (allowed !== true) { log.warn(`Custom flag ${allowed}: ${clientMsg.flag}`); + ws.removeAllListeners(); ws.close(1002, `Custom flag ${allowed}`); return; } @@ -415,6 +422,7 @@ export function startWorker() { ); if (allowed !== true) { log.warn(`Pattern ${allowed}: ${clientMsg.pattern}`); + ws.removeAllListeners(); ws.close(1002, `Pattern ${allowed}`); return; } @@ -460,6 +468,7 @@ export function startWorker() { ); ws.on("error", (error: Error) => { + ws.removeAllListeners(); if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") { ws.close(1002, "WS_ERR_UNEXPECTED_RSV_1"); }