change around pings, fix main.js so the actual real fucking number shows instead of it freaking out.

This commit is contained in:
KingKDot
2026-07-09 13:55:36 -05:00
parent f96b3d0721
commit 43ee5a7d4b
12 changed files with 293 additions and 32 deletions
+13 -4
View File
@@ -171,19 +171,28 @@ export function handlePing(info: ClientInfo, payload: Ping, ws: any) {
isAdmin: info.isAdmin,
});
}
ws.send(encodeMessage({ type: "pong", ts: payload.ts || Date.now() }));
const ts = typeof payload.ts === "number" && Number.isFinite(payload.ts)
? payload.ts
: Date.now();
ws.send(encodeMessage({ type: "pong", ts }));
}
export function sendPingRequest(info: ClientInfo, ws: any, reason: string) {
export function sendPingRequest(
info: ClientInfo,
ws: any,
reason: string,
minIntervalMs = 1_000,
): boolean {
const now = Date.now();
if (info.lastPingSent && now - info.lastPingSent < 1_000) {
return;
if (minIntervalMs > 0 && info.lastPingSent && now - info.lastPingSent < minIntervalMs) {
return false;
}
const nonce = now + Math.floor(Math.random() * 1000);
info.lastPingSent = now;
info.lastPingNonce = nonce;
//console.log(`[ping] send ping to client=${info.id} reason=${reason} nonce=${nonce}`);
ws.send(encodeMessage({ type: "ping", ts: nonce }));
return true;
}
export function handlePong(info: ClientInfo, payload: WireMessage) {