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}.`);
|
||||
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) {
|
||||
|
@ -5,6 +5,7 @@ export class Packet {
|
||||
return {
|
||||
type: name,
|
||||
id: window.crypto.randomUUID(),
|
||||
timestamp: Date.now(),
|
||||
author: ID,
|
||||
};
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ export class Player {
|
||||
this.id = id;
|
||||
this.ready = false;
|
||||
this.rsaPubKey = RsaPubKey.fromJSON(pubkey);
|
||||
this.lastPacket = 0;
|
||||
|
||||
// Data which is reset every turn
|
||||
this.isPlaying = false;
|
||||
|
Loading…
Reference in New Issue
Block a user