Remove clientID, persistentID, gameID from ClientBaseMessageSchema, TurnSchema (#666)

## Description:

Remove the devils `clientID`, `persistentID`, and `gameID` from
`ClientBaseMessageSchema`, as well as `gameID` from `TurnSchema`. These
values are already known through the `Client` object that is hoisted
into the relevant handler.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

---------

Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
This commit is contained in:
Scott Anderson
2025-05-07 14:11:18 -04:00
committed by GitHub
parent a62bbbc6b1
commit cb9b5a7a17
4 changed files with 10 additions and 37 deletions
-1
View File
@@ -275,7 +275,6 @@ export class ClientGameRunner {
while (turn.turnNumber - 1 > this.turnsSeen) {
this.worker.sendTurn({
turnNumber: this.turnsSeen,
gameID: turn.gameID,
intents: [],
});
this.turnsSeen++;
-1
View File
@@ -127,7 +127,6 @@ export class LocalServer {
}
const pastTurn: Turn = {
turnNumber: this.turns.length,
gameID: this.lobbyConfig.gameStartInfo.gameID,
intents: this.intents,
};
this.turns.push(pastTurn);
-4
View File
@@ -290,7 +290,6 @@ const IntentSchema = z.union([
export const TurnSchema = z.object({
turnNumber: z.number(),
gameID: ID,
intents: z.array(IntentSchema),
// The hash of the game state at the end of the turn.
hash: z.number().nullable().optional(),
@@ -357,9 +356,6 @@ export const ServerMessageSchema = z.union([
const ClientBaseMessageSchema = z.object({
type: z.enum(["winner", "join", "intent", "ping", "log", "hash"]),
clientID: ID,
persistentID: SafeString.nullable(), // WARNING: persistent id is private.
gameID: ID,
});
export const ClientSendWinnerSchema = ClientBaseMessageSchema.extend({
+10 -31
View File
@@ -128,10 +128,14 @@ export class GameServer {
(c) => c.clientID == client.clientID,
);
if (existing != null) {
if (client.persistentID != existing.persistentID) {
console.warn(
`client ${client.clientID} cannot rejoin game, persistent id mismatch: exist pid: ${existing.persistentID}, new pid: ${client.persistentID}`,
);
if (client.persistentID !== existing.persistentID) {
this.log.error("persistent ids do not match", {
clientID: client.clientID,
clientIP: client.ip,
clientPersistentID: client.persistentID,
existingIP: existing.ip,
existingPersistentID: existing.persistentID,
});
return;
}
existing.ws.removeAllListeners("message");
@@ -154,34 +158,10 @@ export class GameServer {
} 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) {
this.log.warn(
`Client ID ${clientMsg.clientID} sent incorrect id ${clientMsg.persistentID}, does not match persistent id ${client.persistentID}`,
{
clientID: clientMsg.clientID,
persistentID: clientMsg.persistentID,
},
);
return;
}
}
// Clear out persistent id to make sure it doesn't get sent to other clients.
clientMsg.persistentID = null;
if (clientMsg.type == "intent") {
if (clientMsg.gameID != this.id) {
this.log.warn("client sent to wrong game", {
clientID: clientMsg.clientID,
persistentID: clientMsg.persistentID,
});
return;
}
if (clientMsg.intent.clientID != clientMsg.clientID) {
if (clientMsg.intent.clientID != client.clientID) {
this.log.warn(
`client id mismatch, client message: ${clientMsg.clientID}, intent client id ${clientMsg.intent.clientID}`,
`client id mismatch, client: ${client.clientID}, intent: ${clientMsg.intent.clientID}`,
);
return;
}
@@ -335,7 +315,6 @@ export class GameServer {
private endTurn() {
const pastTurn: Turn = {
turnNumber: this.turns.length,
gameID: this.id,
intents: this.intents,
};
this.turns.push(pastTurn);