* Properly handle non-indexed team names in gamespy1 Fixes #213

* Rename raw.steamappid and raw.gameid to raw.appId in steam protocol
* Don't query valve rules by default, unless requestRules option is set Fixes #176
This commit is contained in:
Michael Morrison 2021-02-25 01:58:35 -06:00
parent 7f08381b17
commit f70112d092
9 changed files with 143 additions and 122 deletions

View file

@ -35,9 +35,14 @@ class Gamespy1 extends Core {
teamNamesById[id] = value;
} else {
if (!(id in playersById)) playersById[id] = {};
if (key === 'playername') key = 'name';
else if (key === 'team') value = parseInt(value);
else if (key === 'score' || key === 'ping' || key === 'deaths' || key === 'kills') value = parseInt(value);
if (key === 'playername') {
key = 'name';
} else if (key === 'team' && !isNaN(parseInt(value))) {
key = 'teamId';
value = parseInt(value);
} else if (key === 'score' || key === 'ping' || key === 'deaths' || key === 'kills') {
value = parseInt(value);
}
playersById[id][key] = value;
}
}
@ -45,28 +50,6 @@ class Gamespy1 extends Core {
const players = Object.values(playersById);
// Determine which team id might be for spectators
let specTeamId = null;
for (const player of players) {
if (!player.team) {
continue;
} else if (teamNamesById[player.team]) {
continue;
} else if (teamNamesById[player.team-1] && (specTeamId === null || specTeamId === player.team)) {
specTeamId = player.team;
} else {
specTeamId = null;
break;
}
}
this.logger.debug(log => {
if (specTeamId === null) {
log("Could not detect a team ID for spectators");
} else {
log("Detected that team ID " + specTeamId + " is probably for spectators");
}
});
const seenHashes = new Set();
for (const player of players) {
// Some servers (bf1942) report the same player multiple times (bug?)
@ -81,11 +64,12 @@ class Gamespy1 extends Core {
}
// Convert player's team ID to team name if possible
if (player.team) {
if (teamNamesById[player.team]) {
player.team = teamNamesById[player.team];
} else if (player.team === specTeamId) {
player.team = "spec";
if (player.hasOwnProperty('teamId')) {
if (Object.keys(teamNamesById).length) {
player.team = teamNamesById[player.teamId - 1] || '';
} else {
player.team = player.teamId;
delete player.teamId;
}
}