Skip to content

Commit

Permalink
fix: ignore and log encountered CommandDataBlocks for unknown players…
Browse files Browse the repository at this point in the history
… (nwg) (#72)
  • Loading branch information
PBug90 authored Dec 18, 2020
1 parent cd4994d commit 7a09b79
Show file tree
Hide file tree
Showing 6 changed files with 2,382 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/W3GReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default class W3GReplay extends EventEmitter {
buffer: Buffer;
msElapsed = 0;
slotToPlayerId = new Map<number, number>();
knownPlayerIds: Set<string>;

constructor() {
super();
Expand Down Expand Up @@ -172,6 +173,8 @@ export default class W3GReplay extends EventEmitter {
);
}
});

this.knownPlayerIds = new Set(Object.keys(this.players));
}

processGameDataBlock(block: GameDataBlock): void {
Expand Down Expand Up @@ -220,6 +223,12 @@ export default class W3GReplay extends EventEmitter {
}

processCommandDataBlock(block: CommandBlock): void {
if (this.knownPlayerIds.has(String(block.playerId)) === false) {
console.log(
`detected unknown playerId in CommandBlock: ${block.playerId} - time elapsed: ${this.totalTimeTracker}`
);
return;
}
const currentPlayer = this.players[block.playerId];
currentPlayer.currentTimePlayed = this.totalTimeTracker;
currentPlayer._lastActionWasDeselect = false;
Expand Down
Binary file added test/replays/132/1582070968.nwg
Binary file not shown.
Binary file added test/replays/132/1582161008.nwg
Binary file not shown.
Loading

0 comments on commit 7a09b79

Please sign in to comment.