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

4
package-lock.json generated
View file

@ -665,9 +665,7 @@
"dev": true
},
"text-encoding-shim": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/text-encoding-shim/-/text-encoding-shim-1.0.0.tgz",
"integrity": "sha1-3C8y0Kb2IeOalsShWo7NzTGHwNY="
"version": "git+https://gitlab.com/hongaar/text-encoding-shim.git#83ff0f77f48d05b8ce83ddc7ca49d8df61363b31"
},
"through2": {
"version": "2.0.3",

View file

@ -11,7 +11,7 @@
"dependencies": {
"bit-buffer": "^0.2.3",
"snappyjs": "^0.6.0",
"text-encoding-shim": "^1.0.0"
"text-encoding-shim": "git+https://gitlab.com/hongaar/text-encoding-shim.git#83ff0f77f48d05b8ce83ddc7ca49d8df61363b31"
},
"devDependencies": {
"@types/node": "^8.0.31",

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;
}
}