Skip to content

Commit

Permalink
Add scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
BeepIsla committed Aug 28, 2020
1 parent b7ef44d commit cc84db1
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ You can forcefully parse a demo by running `node force.js`, it will ask you for
- `verdict`
- `writeLog`: Should we write our logs to a folder called `cases/<CaseID>`?
- `backupDemo`: Should we backup the Overwatch demo in a folder called `cases/<CaseID>`?
- `printScoreboard`: Should we print a scoreboard with player statistics to console?
- `maxVerdicts`: Maximum amount of Overwatch cases to do before stopping. `0` for unlimited.

- `minAimbot`: Minimum amount of aimbot infractions required to convict for aimbotting
Expand Down
1 change: 1 addition & 0 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"verdict": {
"writeLog": true,
"backupDemo": true,
"printScoreboard": true,
"maxVerdicts": 1,

"minAimbot": 10,
Expand Down
3 changes: 3 additions & 0 deletions force.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ new Promise((resolve, reject) => {
process.stdout.write("Parsing: 0%");
demo.parse().then((data) => {
process.stdout.write("\n");
if (config.verdict.printScoreboard) {
demo.logScoreboard();
}
demo.logResults();

if (result.outpath) {
Expand Down
124 changes: 124 additions & 0 deletions helpers/Demo.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
const fs = require("fs");
const path = require("path");
const demofile = require("demofile");
const CliTable = require("cli-table3");
const colors = require("colors");
const Helper = require("./Helper.js");
const modes = [
undefined,
"competitive",
"scrimcomp2v2"
];
const playerStats = [
"assists",
"deaths",
"kills",
"mvps",
"name",
"score",
"teamNumber"
];
const teams = {
NONE: 0,
SPECTATOR: 1,
TERRORIST: 2,
COUNTERTERRORIST: 3
};
const teamName = [
"None",
"Spectator",
"Terrorists",
"Counter-Terrorists"
];

const detectors = fs.readdirSync(path.join(__dirname, "..", "detectors")).filter((file) => {
return file.endsWith(".js") && !file.startsWith("_");
Expand Down Expand Up @@ -37,6 +60,7 @@ module.exports = class Demo {
}
};
this.detectors = [];
this.players = {};

this.demo = new demofile.DemoFile();
}
Expand All @@ -62,6 +86,64 @@ module.exports = class Demo {
console.log("\t- Griefing: " + (this.obj.verdict.teamharm ? "✔️" : "❌"));
}

logScoreboard() {
let teams = Object.keys(this.players).reduce((prev, cur) => {
prev[this.players[cur].teamNumber].push({
...this.players[cur],
steamID64: cur
});

prev[this.players[cur].teamNumber] = prev[this.players[cur].teamNumber].sort((a, b) => {
return b.score - a.score;
});

return prev;
}, [
[], // None
[], // Spectator
[], // Terrorist
[] // Counter-Terrorist
]);

let table = new CliTable({
head: [
"SteamID",
"Name",
"Kills",
"Assists",
"Deaths",
"MVPs",
"Score",
"Team"
]
});

// CTs at top - Ts at bottom
// CT is higher number than T so go reverse
for (let i = 3; i >= 2; i--) {
for (let player of teams[i]) {
table.push([
player.steamID64,
player.name,
player.kills,
player.assists,
player.deaths,
player.mvps,
player.score,
teamName[player.teamNumber]
].map((text) => {
if (player.steamID64 === this.suspect64Id) {
return colors.yellow(text);
}

return text;
}));
}
}

console.log(table.toString());
}

parse(steam = undefined) {
return new Promise((resolve, reject) => {
this.demo.on("start", () => {
Expand Down Expand Up @@ -89,6 +171,8 @@ module.exports = class Demo {
});
});

this.demo.gameEvents.on("round_officially_ended", this.updateScoreboard.bind(this));

// Parse suspect information
this.demo.gameEvents.on("player_disconnect", this.findSuspect.bind(this));
this.demo.gameEvents.on("player_connect", this.findSuspect.bind(this));
Expand Down Expand Up @@ -223,4 +307,44 @@ module.exports = class Demo {

this.suspectPlayer.arrayIndex = Helper.ShiftNumber(this.suspectPlayer.index);
}

updateScoreboard() {
// If this is half time swap all existing players "teamNumber"
let mp_maxrounds = Number(this.demo.conVars.vars.get("mp_maxrounds"));
if (this.demo.gameRules.roundsPlayed === (mp_maxrounds / 2)) {
// While the "Update all players" below resets this due to you still being on your
// old team during the 15 seconds of halftime we have to do this for disconnected players
// If you disconnect round 12 and don't reconnect it would never update your "teamNumber" again
for (let key in this.players) {
switch (this.players[key].teamNumber) {
case teams.COUNTERTERRORIST: {
this.players[key].teamNumber = teams.TERRORIST;
break;
}
case teams.TERRORIST: {
this.players[key].teamNumber = teams.COUNTERTERRORIST;
break;
}
default: {
break;
}
}
}
}

// Update all players
for (let player of this.demo.players) {
if (player.isFakePlayer) {
continue;
}

if (!this.players[player.steam64Id]) {
this.players[player.steam64Id] = {};
}

for (let key of playerStats) {
this.players[player.steam64Id][key] = player[key];
}
}
}
};
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ coordinator.on("receivedFromGC", async (msgType, payload) => {
fs.writeFileSync("cases/" + body.caseid + "/data.json", JSON.stringify(data, null, "\t"));
}

// Log verdict
// Demo logs
if (config.verdict.printScoreboard) {
demo.logScoreboard();
}
demo.logResults();

// Log timings
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"almost-equal": "^1.1.0",
"bytebuffer": "^5.0.1",
"cheerio": "^1.0.0-rc.3",
"cli-table3": "^0.6.0",
"colors": "^1.4.0",
"demofile": "^1.5.0",
"inquirer": "^7.3.3",
"node-fetch": "^2.6.0",
Expand Down

0 comments on commit cc84db1

Please sign in to comment.