send game hash to server each second

This commit is contained in:
Evan
2025-02-25 11:49:07 -08:00
parent 393ed64ab5
commit 3fa97ed686
11 changed files with 93 additions and 25 deletions
+3
View File
@@ -1,9 +1,12 @@
import WebSocket from "ws";
import { ClientID } from "../core/Schemas";
import { Tick } from "../core/game/Game";
export class Client {
public lastPing: number;
public hashes: Map<Tick, number> = new Map();
constructor(
public readonly clientID: ClientID,
public readonly persistentID: string,
+6 -3
View File
@@ -3,11 +3,8 @@ import {
ClientMessage,
ClientMessageSchema,
GameConfig,
GameRecordSchema,
Intent,
PlayerRecord,
ServerPingMessageSchema,
ServerStartGameMessage,
ServerStartGameMessageSchema,
ServerTurnMessageSchema,
Turn,
@@ -162,6 +159,12 @@ export class GameServer {
this.lastPingUpdate = Date.now();
client.lastPing = Date.now();
}
if (clientMsg.type == "hash") {
console.log(
`client ${clientMsg.clientID} got hash ${clientMsg.hash} on tick ${clientMsg.tick}`,
);
client.hashes.set(clientMsg.tick, clientMsg.hash);
}
if (clientMsg.type == "winner") {
this.winner = clientMsg.winner;
}