Prevent replay
This commit is contained in:
parent
c0f2c4bbef
commit
4a55f5c11f
@ -49,6 +49,14 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
window.console.error(`Signature invalid! Ignoring packet ${data.id}.`);
|
window.console.error(`Signature invalid! Ignoring packet ${data.id}.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if the packet is replayed.
|
||||||
|
if (data.timestamp <= sender.lastPacket) {
|
||||||
|
window.console.error(`Replay detected! Ignoring packet ${data.id}.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.lastPacket = data.timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
|
@ -5,6 +5,7 @@ export class Packet {
|
|||||||
return {
|
return {
|
||||||
type: name,
|
type: name,
|
||||||
id: window.crypto.randomUUID(),
|
id: window.crypto.randomUUID(),
|
||||||
|
timestamp: Date.now(),
|
||||||
author: ID,
|
author: ID,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ export class Player {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
this.ready = false;
|
this.ready = false;
|
||||||
this.rsaPubKey = RsaPubKey.fromJSON(pubkey);
|
this.rsaPubKey = RsaPubKey.fromJSON(pubkey);
|
||||||
|
this.lastPacket = 0;
|
||||||
|
|
||||||
// Data which is reset every turn
|
// Data which is reset every turn
|
||||||
this.isPlaying = false;
|
this.isPlaying = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user