1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 00:54:14 +02:00

minor fixes

This commit is contained in:
Robin Appelman 2017-12-09 18:39:26 +01:00
commit aae67aec9c
4 changed files with 23 additions and 10 deletions

View file

@ -2,14 +2,17 @@ import {EventEmitter} from 'events';
import {Header} from './Data/Header';
import {Match} from './Data/Match';
import {Parser} from './Parser';
import {Packet} from './Data/Packet';
export class Analyser extends EventEmitter {
private parser: Parser;
private match: Match;
private readonly parser: Parser;
public readonly match: Match;
private analysed: boolean = false;
constructor(parser: Parser) {
super();
this.parser = parser;
this.match = new Match(this.parser.parserState);
}
public getHeader(): Header {
@ -17,14 +20,20 @@ export class Analyser extends EventEmitter {
}
public getBody(): Match {
if (!this.match) {
this.match = new Match(this.parser.parserState);
for (const packet of this.parser.getPackets()) {
this.match.handlePacket(packet);
if (!this.analysed) {
for (const packet of this.getPackets()) {
this.emit('packet', packet);
}
this.emit('done');
}
this.analysed = true;
return this.match;
}
public * getPackets(): IterableIterator<Packet> {
for (const packet of this.parser.getPackets()) {
this.match.handlePacket(packet);
yield packet;
}
}
}

View file

@ -130,4 +130,10 @@ export class Match {
}
return null;
}
public getPlayerByUserId(userId: number): Player | null {
const user = this.getUserInfo(userId);
const player = this.playerEntityMap.get(user.entityId);
return player || null;
}
}