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

fix invalid user ids in some cases

This commit is contained in:
Robin Appelman 2015-09-04 20:32:06 +02:00
commit ab7807c356
2 changed files with 20 additions and 15 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "tf2-demo", "name": "tf2-demo",
"description": "A parser for TF2 demo files", "description": "A parser for TF2 demo files",
"version": "0.2.1", "version": "0.2.2",
"bin": { "bin": {
"demo-analyse": "./bin/analyse.js" "demo-analyse": "./bin/analyse.js"
}, },

View file

@ -15,6 +15,7 @@ State.prototype.get = function () {
}; };
State.prototype.updateState = function (packet) { State.prototype.updateState = function (packet) {
var userState;
switch (packet.packetType) { switch (packet.packetType) {
case 'netTick': case 'netTick':
if (this.state.startTick === 0) { if (this.state.startTick === 0) {
@ -40,9 +41,9 @@ State.prototype.updateState = function (packet) {
var name = packet.tables.userinfo[j].extraData[0]; var name = packet.tables.userinfo[j].extraData[0];
var steamId = packet.tables.userinfo[j].extraData[2]; var steamId = packet.tables.userinfo[j].extraData[2];
var userId = packet.tables.userinfo[j].extraData[1].charCodeAt(0); var userId = packet.tables.userinfo[j].extraData[1].charCodeAt(0);
this.initUser(userId); userState = this.getUserState(userId);
this.state.users[userId].name= name; userState.name = name;
this.state.users[userId].steamId = steamId; userState.steamId = steamId;
} }
} }
} }
@ -71,24 +72,27 @@ State.prototype.updateState = function (packet) {
break; break;
case 'player_spawn': case 'player_spawn':
userId = packet.event.values.userid; userId = packet.event.values.userid;
this.initUser(userId); userState = this.getUserState(userId);
if (this.state.users[userId]) { if (!userState.team) { //only register first spawn
if (!this.state.users[userId].team) { //only register first spawn userState.team = packet.event.values.team === 2 ? 'red' : 'blue'
this.state.users[userId].team = packet.event.values.team === 2 ? 'red' : 'blue'
}
var classId = packet.event.values.class;
if (!this.state.users[userId].classes[classId]) {
this.state.users[userId].classes[classId] = 0;
}
this.state.users[userId].classes[classId]++;
} }
var classId = packet.event.values.class;
if (!userState.classes[classId]) {
userState.classes[classId] = 0;
}
userState.classes[classId]++;
break; break;
} }
break; break;
} }
}; };
State.prototype.initUser = function (userId) { State.prototype.getUserState = function (userId) {
// no clue why it does this
// only seems to be the case with per user ready
if (userId > 256) {
userId -= 256;
}
if (!this.state.users[userId]) { if (!this.state.users[userId]) {
this.state.users[userId] = { this.state.users[userId] = {
name : null, name : null,
@ -97,6 +101,7 @@ State.prototype.initUser = function (userId) {
classes: {} classes: {}
} }
} }
return this.state.users[userId];
}; };
module.exports = State; module.exports = State;