mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 11:30:43 +00:00
Revert "Close socket on ClientMessageSchema, improve zod error (#1003)"
This reverts commit 14ab1bcbba.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import ipAnonymize from "ip-anonymize";
|
||||
import { Logger } from "winston";
|
||||
import WebSocket from "ws";
|
||||
import { z } from "zod/v4";
|
||||
import {
|
||||
ClientID,
|
||||
ClientMessage,
|
||||
ClientMessageSchema,
|
||||
ClientSendWinnerMessage,
|
||||
GameConfig,
|
||||
@@ -178,16 +178,12 @@ export class GameServer {
|
||||
"message",
|
||||
gatekeeper.wsHandler(client.ip, async (message: string) => {
|
||||
try {
|
||||
const parsed = ClientMessageSchema.safeParse(JSON.parse(message));
|
||||
if (!parsed.success) {
|
||||
const error = z.prettifyError(parsed.error);
|
||||
this.log.error("Failed to parse client message", error, {
|
||||
clientID: client.clientID,
|
||||
});
|
||||
client.ws.close();
|
||||
return;
|
||||
let clientMsg: ClientMessage | null = null;
|
||||
try {
|
||||
clientMsg = ClientMessageSchema.parse(JSON.parse(message));
|
||||
} catch (error) {
|
||||
throw Error(`error parsing schema for ${ipAnonymize(client.ip)}`);
|
||||
}
|
||||
const clientMsg = parsed.data;
|
||||
if (clientMsg.type === "intent") {
|
||||
if (clientMsg.intent.clientID !== client.clientID) {
|
||||
this.log.warn(
|
||||
|
||||
+3
-10
@@ -10,8 +10,7 @@ import { GameEnv } from "../core/configuration/Config";
|
||||
import { getServerConfigFromServer } from "../core/configuration/ConfigLoader";
|
||||
import { GameType } from "../core/game/Game";
|
||||
import {
|
||||
ClientJoinMessageSchema,
|
||||
GameConfig,
|
||||
ClientMessageSchema,
|
||||
GameRecord,
|
||||
GameRecordSchema,
|
||||
} from "../core/Schemas";
|
||||
@@ -294,17 +293,11 @@ export function startWorker() {
|
||||
: forwarded || req.socket.remoteAddress || "unknown";
|
||||
|
||||
try {
|
||||
// Process WebSocket messages as in your original code
|
||||
// Parse and handle client messages
|
||||
const parsed = ClientJoinMessageSchema.safeParse(
|
||||
const clientMsg = ClientMessageSchema.parse(
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user