diff --git a/src/client/ClientGameRunner.ts b/src/client/ClientGameRunner.ts index b09d8198b..3f351be99 100644 --- a/src/client/ClientGameRunner.ts +++ b/src/client/ClientGameRunner.ts @@ -100,17 +100,6 @@ export function joinLobby( terrainLoad, ).then((r) => r.start()); } - if (message.type === "error") { - showErrorModal( - message.error, - message.message, - lobbyConfig.gameID, - lobbyConfig.clientID, - true, - false, - "error_modal.connection_error", - ); - } }; transport.connect(onconnect, onmessage); return () => { @@ -326,17 +315,6 @@ export class ClientGameRunner { "error_modal.desync_notice", ); } - if (message.type === "error") { - showErrorModal( - message.error, - message.message, - this.lobby.gameID, - this.lobby.clientID, - true, - false, - "error_modal.connection_error", - ); - } if (message.type === "turn") { if (!this.hasJoined) { this.transport.joinGame(0); diff --git a/src/core/Schemas.ts b/src/core/Schemas.ts index f439ea5fa..6dddeda52 100644 --- a/src/core/Schemas.ts +++ b/src/core/Schemas.ts @@ -88,8 +88,7 @@ export type ServerMessage = | ServerStartGameMessage | ServerPingMessage | ServerDesyncMessage - | ServerPrestartMessage - | ServerErrorMessage; + | ServerPrestartMessage; export type ServerTurnMessage = z.infer; export type ServerStartGameMessage = z.infer< @@ -98,7 +97,6 @@ export type ServerStartGameMessage = z.infer< export type ServerPingMessage = z.infer; export type ServerDesyncMessage = z.infer; export type ServerPrestartMessage = z.infer; -export type ServerErrorMessage = z.infer; export type ClientSendWinnerMessage = z.infer; export type ClientPingMessage = z.infer; export type ClientIntentMessage = z.infer; @@ -445,19 +443,12 @@ export const ServerDesyncSchema = z.object({ yourHash: z.number().optional(), }); -export const ServerErrorSchema = z.object({ - type: z.literal("error"), - error: z.string(), - message: z.string().optional(), -}); - export const ServerMessageSchema = z.discriminatedUnion("type", [ ServerTurnMessageSchema, ServerPrestartMessageSchema, ServerStartGameMessageSchema, ServerPingMessageSchema, ServerDesyncSchema, - ServerErrorSchema, ]); // diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index e8480e7d0..69acb9c8d 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -13,7 +13,6 @@ import { Intent, PlayerRecord, ServerDesyncSchema, - ServerErrorMessage, ServerPrestartMessageSchema, ServerStartGameMessage, ServerTurnMessage, @@ -194,17 +193,8 @@ export class GameServer { this.log.error("Failed to parse client message", error, { clientID: client.clientID, }); - client.ws.send( - JSON.stringify({ - type: "error", - error, - message, - } satisfies ServerErrorMessage), - ); - // Add a small delay before closing the connection to ensure the error message is received - setTimeout(() => { - client.ws.close(1002, "ClientMessageSchema"); - }, 100); + client.ws.removeAllListeners(); + client.ws.close(1002, `Invalid client message: ${error}`); return; } const clientMsg = parsed.data; @@ -545,21 +535,15 @@ export class GameServer { clientID: client.clientID, persistentID: client.persistentID, }); - client.ws.send( - JSON.stringify({ - type: "error", - error: "Kicked from game (you may have been playing on another tab)", - } satisfies ServerErrorMessage), + client.ws.close( + 1002, + "Kicked from game (you may have been playing on another tab)", ); - // Add a small delay before closing the connection to ensure the error message is received - setTimeout(() => { - client.ws.close(1000, "Kicked from game"); - this.activeClients = this.activeClients.filter( - (c) => c.clientID !== clientID, - ); - client.ws.removeAllListeners(); - this.kickedClients.add(clientID); - }, 100); + this.activeClients = this.activeClients.filter( + (c) => c.clientID !== clientID, + ); + client.ws.removeAllListeners(); + this.kickedClients.add(clientID); } else { this.log.warn(`cannot kick client, not found in game`, { clientID, diff --git a/src/server/Worker.ts b/src/server/Worker.ts index 96efde652..27d2fee93 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -15,7 +15,6 @@ import { ClientMessageSchema, GameRecord, GameRecordSchema, - ServerErrorMessage, } from "../core/Schemas"; import { CreateGameInputSchema, GameInputSchema } from "../core/WorkerSchemas"; import { archive, readGameRecord } from "./Archive"; @@ -310,14 +309,8 @@ export function startWorker() { if (!parsed.success) { const error = z.prettifyError(parsed.error); log.warn("Error parsing client message", error); - ws.send( - JSON.stringify({ - type: "error", - error: error.toString(), - } satisfies ServerErrorMessage), - ); ws.removeAllListeners(); - ws.close(1002, "ClientJoinMessageSchema"); + ws.close(1002, `Failed to parse client message: ${error}`); return; } const clientMsg = parsed.data; @@ -328,14 +321,8 @@ export function startWorker() { } else if (clientMsg.type !== "join") { const error = `Invalid message before join: ${JSON.stringify(clientMsg)}`; log.warn(error); - ws.send( - JSON.stringify({ - type: "error", - error, - } satisfies ServerErrorMessage), - ); ws.removeAllListeners(); - ws.close(1002, "ClientJoinMessageSchema"); + ws.close(1002, error); return; }