mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 14:50:44 +00:00
Attempt to fix bigint serialization issue (#1501)
## Description: Attempt to fix bigint serialization issue ## 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 - [ ] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [ ] I have read and accepted the CLA aggreement (only required once).
This commit is contained in:
@@ -103,7 +103,7 @@ export function joinLobby(
|
||||
if (message.type === "error") {
|
||||
showErrorModal(
|
||||
message.error,
|
||||
"",
|
||||
message.message,
|
||||
lobbyConfig.gameID,
|
||||
lobbyConfig.clientID,
|
||||
true,
|
||||
@@ -329,7 +329,7 @@ export class ClientGameRunner {
|
||||
if (message.type === "error") {
|
||||
showErrorModal(
|
||||
message.error,
|
||||
"",
|
||||
message.message,
|
||||
this.lobby.gameID,
|
||||
this.lobby.clientID,
|
||||
true,
|
||||
@@ -582,27 +582,31 @@ export class ClientGameRunner {
|
||||
}
|
||||
|
||||
function showErrorModal(
|
||||
errMsg: string,
|
||||
stack: string,
|
||||
error: string,
|
||||
message: string | undefined,
|
||||
gameID: GameID,
|
||||
clientID: ClientID,
|
||||
closable = false,
|
||||
showDiscord = true,
|
||||
heading = "error_modal.crashed",
|
||||
) {
|
||||
const errorText = `Error: ${errMsg}\nStack: ${stack}`;
|
||||
|
||||
if (document.querySelector("#error-modal")) {
|
||||
return;
|
||||
}
|
||||
|
||||
const modal = document.createElement("div");
|
||||
|
||||
modal.id = "error-modal";
|
||||
|
||||
const discord = showDiscord ? translateText("error_modal.paste_discord") : "";
|
||||
|
||||
const content = `${discord}\n${translateText(heading)}\n game id: ${gameID}, client id: ${clientID}\n${errorText}`;
|
||||
const content = [
|
||||
showDiscord ? translateText("error_modal.paste_discord") : null,
|
||||
translateText(heading),
|
||||
`game id: ${gameID}`,
|
||||
`client id: ${clientID}`,
|
||||
`Error: ${error}`,
|
||||
message ? `Message: ${message}` : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n");
|
||||
|
||||
// Create elements
|
||||
const pre = document.createElement("pre");
|
||||
|
||||
@@ -450,6 +450,7 @@ export const ServerDesyncSchema = z.object({
|
||||
export const ServerErrorSchema = z.object({
|
||||
type: z.literal("error"),
|
||||
error: z.string(),
|
||||
message: z.string().optional(),
|
||||
});
|
||||
|
||||
export const ServerMessageSchema = z.discriminatedUnion("type", [
|
||||
|
||||
@@ -89,7 +89,7 @@ export const OTHER_INDEX_LOST = 3; // Structures/warships destroyed/captured by
|
||||
export const OTHER_INDEX_UPGRADE = 4; // Structures upgraded
|
||||
|
||||
const BigIntStringSchema = z.preprocess((val) => {
|
||||
if (typeof val === "string" && /^\d+$/.test(val)) return BigInt(val);
|
||||
if (typeof val === "string" && /^-?\d+$/.test(val)) return BigInt(val);
|
||||
if (typeof val === "bigint") return val;
|
||||
return val;
|
||||
}, z.bigint());
|
||||
|
||||
@@ -199,7 +199,8 @@ export class GameServer {
|
||||
client.ws.send(
|
||||
JSON.stringify({
|
||||
type: "error",
|
||||
error: error.toString(),
|
||||
error,
|
||||
message,
|
||||
} satisfies ServerErrorMessage),
|
||||
);
|
||||
// Add a small delay before closing the connection to ensure the error message is received
|
||||
|
||||
Reference in New Issue
Block a user