diff --git a/src/client/index.html b/src/client/index.html
index 1d8438468..e8672e485 100644
--- a/src/client/index.html
+++ b/src/client/index.html
@@ -153,7 +153,7 @@
- v0.16.0
+ v0.16.5
diff --git a/src/server/Archive.ts b/src/server/Archive.ts
index 1c08b33d2..ad4fd3656 100644
--- a/src/server/Archive.ts
+++ b/src/server/Archive.ts
@@ -121,9 +121,13 @@ async function archiveToGCS(gameRecord: GameRecord) {
});
const file = bucket.file(recordCopy.id);
- await file.save(JSON.stringify(GameRecordSchema.parse(recordCopy)), {
- contentType: "application/json",
- });
+ try {
+ await file.save(JSON.stringify(recordCopy), {
+ contentType: "application/json",
+ });
+ } catch (error) {
+ console.log(`error saving game ${gameRecord.id}`);
+ }
console.log(`${gameRecord.id}: game record successfully written to GCS`);
}
@@ -142,11 +146,7 @@ export async function readGameRecord(gameId: GameID): Promise {
const [content] = await file.download();
const gameRecord = JSON.parse(content.toString());
- // Validate the parsed content against the schema
- const validatedRecord = GameRecordSchema.parse(gameRecord);
-
- console.log(`${gameId}: Successfully read game record from GCS`);
- return validatedRecord;
+ return gameRecord as GameRecord;
} catch (error) {
console.error(`${gameId}: Error reading game record from GCS: ${error}`, {
message: error?.message || error,
diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts
index 570a3c90c..46434563a 100644
--- a/src/server/GameServer.ts
+++ b/src/server/GameServer.ts
@@ -130,9 +130,12 @@ export class GameServer {
return;
}
try {
- const clientMsg: ClientMessage = ClientMessageSchema.parse(
- JSON.parse(message),
- );
+ let clientMsg: ClientMessage = null;
+ try {
+ clientMsg = ClientMessageSchema.parse(JSON.parse(message));
+ } catch (error) {
+ throw Error(`error parsing schema for ${client.ip}`);
+ }
if (this.allClients.has(clientMsg.clientID)) {
const client = this.allClients.get(clientMsg.clientID);
if (client.persistentID != clientMsg.persistentID) {
@@ -221,15 +224,19 @@ export class GameServer {
}
private sendStartGameMsg(ws: WebSocket, lastTurn: number) {
- ws.send(
- JSON.stringify(
- ServerStartGameMessageSchema.parse({
- type: "start",
- turns: this.turns.slice(lastTurn),
- config: this.gameConfig,
- }),
- ),
- );
+ try {
+ ws.send(
+ JSON.stringify(
+ ServerStartGameMessageSchema.parse({
+ type: "start",
+ turns: this.turns.slice(lastTurn),
+ config: this.gameConfig,
+ }),
+ ),
+ );
+ } catch (error) {
+ throw new Error(`error sending start message for game ${this.id}`);
+ }
}
private endTurn() {
@@ -241,12 +248,18 @@ export class GameServer {
this.turns.push(pastTurn);
this.intents = [];
- const msg = JSON.stringify(
- ServerTurnMessageSchema.parse({
- type: "turn",
- turn: pastTurn,
- }),
- );
+ let msg = "";
+ try {
+ msg = JSON.stringify(
+ ServerTurnMessageSchema.parse({
+ type: "turn",
+ turn: pastTurn,
+ }),
+ );
+ } catch (error) {
+ console.log(`error sending message for game ${this.id}`);
+ return;
+ }
this.activeClients.forEach((c) => {
c.ws.send(msg);
});
diff --git a/src/server/Server.ts b/src/server/Server.ts
index a8a46cf14..08c722d3e 100644
--- a/src/server/Server.ts
+++ b/src/server/Server.ts
@@ -200,7 +200,6 @@ app.post(
return;
}
gameRecord.players.forEach((p) => (p.ip = clientIP));
- GameRecordSchema.parse(gameRecord);
archive(gameRecord);
res.json({
success: true,
@@ -305,9 +304,12 @@ wss.on("connection", (ws, req) => {
return;
}
try {
- const clientMsg: ClientMessage = ClientMessageSchema.parse(
- JSON.parse(message.toString()),
- );
+ let clientMsg: ClientMessage = null;
+ try {
+ clientMsg = ClientMessageSchema.parse(JSON.parse(message.toString()));
+ } catch (error) {
+ throw new Error(`error parsing zod schema for ip: ${ip}`);
+ }
if (clientMsg.type == "join") {
const forwarded = req.headers["x-forwarded-for"];
let ip = Array.isArray(forwarded)
@@ -338,15 +340,18 @@ wss.on("connection", (ws, req) => {
if (!wasFound) {
console.log(`game ${clientMsg.gameID} not found, loading from gcs`);
const record = await readGameRecord(clientMsg.gameID);
- ws.send(
- JSON.stringify(
- ServerStartGameMessageSchema.parse({
- type: "start",
- turns: record.turns,
- config: record.gameConfig,
- }),
- ),
- );
+
+ let startGame = null;
+ try {
+ startGame = ServerStartGameMessageSchema.parse({
+ type: "start",
+ turns: record.turns,
+ config: record.gameConfig,
+ });
+ } catch (error) {
+ console.log(`error validating schema for ip ${ip}`);
+ }
+ ws.send(JSON.stringify(startGame));
}
}
if (clientMsg.type == "log") {
@@ -360,7 +365,12 @@ wss.on("connection", (ws, req) => {
});
}
} catch (error) {
- console.warn(`errror handling websocket message for ${ip}: ${error}`);
+ console.warn(
+ `error handling websocket message for ${ip}: ${error}`.substring(
+ 0,
+ 250,
+ ),
+ );
}
});
ws.on("error", (error: Error) => {