Skip to content

Commit

Permalink
Fix kills tracking logic, hopefully
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Dec 10, 2024
1 parent 26bf6fb commit 4a7eaf3
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions referee/referee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,18 @@ global.playerConnected = async (addr: number, player: number) => {
global.playerDisconnected = async (addr: number, player: number) => {
console.log(`Someone disconnected, ending the game`);
done = true;
let [player1Key, player1] = Object.entries(players).find(([_, p]) => p.playerNumber === 0) ?? [];
let [player2Key, player2] = Object.entries(players).find(([_, p]) => p.playerNumber === 1) ?? [];
await reportResults(gameId, {
gameId: gameId,
result: "disconnect",
playerOne: {
pkh: Object.values(players).find(p => p.playerNumber === 0)?.ephemeralKey,
kills: hydra.clients[0]?.kills,
pkh: player1?.ephemeralKey,
kills: hydra.clients[player1Key]?.kills,
},
playerTwo: {
pkh: Object.values(players).find(p => p.playerNumber === 1)?.ephemeralKey,
kills: hydra.clients[1]?.kills,
pkh: player2?.ephemeralKey,
kills: hydra.clients[player2Key]?.kills,
}
})
if (!RECORD_STATS) return;
Expand Down Expand Up @@ -350,32 +352,36 @@ while (!done) {
if (timer <= 0) {
console.log("Game ended.");
done = true;
let [player1Key, player1] = Object.entries(players).find(([_, p]) => p.playerNumber === 0) ?? [];
let [player2Key, player2] = Object.entries(players).find(([_, p]) => p.playerNumber === 1) ?? [];
await reportResults(gameId, {
gameId: gameId,
result: "finished",
playerOne: {
pkh: Object.values(players).find(p => p.playerNumber === 0)?.ephemeralKey,
kills: hydra.clients[0]?.kills,
pkh: player1?.ephemeralKey,
kills: hydra.clients[player1Key]?.kills,
},
playerTwo: {
pkh: Object.values(players).find(p => p.playerNumber === 1)?.ephemeralKey,
kills: hydra.clients[1]?.kills,
pkh: player2?.ephemeralKey,
kills: hydra.clients[player2Key]?.kills,
}
});
}
if (timeout <= 0) {
console.log("Game timed out.");
done = true;
let [player1Key, player1] = Object.entries(players).find(([_, p]) => p.playerNumber === 0) ?? [];
let [player2Key, player2] = Object.entries(players).find(([_, p]) => p.playerNumber === 1) ?? [];
await reportResults(gameId, {
gameId: gameId,
result: "timeout",
playerOne: {
pkh: Object.values(players).find(p => p.playerNumber === 0)?.ephemeralKey,
kills: hydra.clients[0]?.kills,
pkh: player1?.ephemeralKey,
kills: hydra.clients[player1Key]?.kills,
},
playerTwo: {
pkh: Object.values(players).find(p => p.playerNumber === 1)?.ephemeralKey,
kills: hydra.clients[1]?.kills,
pkh: player2?.ephemeralKey,
kills: hydra.clients[player2Key]?.kills,
}
});
}
Expand Down

0 comments on commit 4a7eaf3

Please sign in to comment.