Harden gameplay timing and map loading

This commit is contained in:
2026-10-05 15:15:35 +05:00
parent 8b31891776
commit dcc3779262
36 changed files with 1050 additions and 205 deletions

19
shared/round-clock.ts Normal file
View File

@@ -0,0 +1,19 @@
// Synchronize at receipt using a bounded estimate of the return journey. The
// countdown uses performance.now(), so changing the OS clock cannot extend it.
export function roundClock(
serverNow: number,
sentAt: number,
receivedAt: number,
) {
const serverAtReceipt = serverNow + Math.max(0, receivedAt - sentAt) / 2;
return {
remaining(deadline: string, now: number) {
return Math.max(
0,
Math.ceil(
(Date.parse(deadline) - serverAtReceipt - (now - receivedAt)) / 1000,
),
);
},
};
}