From 58487a150522509a75ffee00666959301553b2db Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Sun, 8 Oct 2023 09:48:57 -0700 Subject: [PATCH] update/filter out false positives in combat log detection --- package.json | 2 +- structures/DayzRBot.js | 3 ++- util/AdminLogsHandler.js | 4 ++-- util/KillfeedHandler.js | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e11a1d2..cdcc61c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "10.3.5", + "version": "10.3.6", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": { diff --git a/structures/DayzRBot.js b/structures/DayzRBot.js index ca6e5f2..6f8a071 100644 --- a/structures/DayzRBot.js +++ b/structures/DayzRBot.js @@ -8,7 +8,7 @@ const mongoose = require('mongoose'); // custom util imports const { DownloadNitradoFile, CheckServerStatus } = require('../util/NitradoAPI'); const { HandlePlayerLogs, HandleActivePlayersList } = require('../util/LogsHandler'); -const { HandleKillfeed } = require('../util/KillfeedHandler'); +const { HandleKillfeed, UpdateLastDeathDate } = require('../util/KillfeedHandler'); const { HandleExpiredUAVs, HandleEvents } = require('../util/AlarmsHandler'); const path = require("path"); @@ -155,6 +155,7 @@ class DayzRBot extends Client { if (!(i + 1 >= lines.length) && lines[i + 1].includes('killed by') && lines[i].includes('TransportHit')) s = await HandleKillfeed(this, guildId, s, lines[i]) // Handles vehicle deaths if (!(i + 1 >= lines.length) && lines[i + 1].includes('killed by Player') && lines[i].includes('hit by Player')) s = await HandleKillfeed(this, guildId, s, lines[i]); // Handles regular deaths if (lines[i].includes('killed by Player') && !lines[i - 1].includes('hit by Player')) s = await HandleKillfeed(this, guildId, s, lines[i]); // Handles deaths missing hit by log + if (lines[i].includes('killed by Zmb') || lines[i].includes('>) died.')) s = await UpdateLastDeathDate(this, s, lines[i]); // Updates users last death date for non PVP deaths. } for (const [channel_id, data] of Object.entries(this.alarmPingQueue)) { diff --git a/util/AdminLogsHandler.js b/util/AdminLogsHandler.js index efcd9ae..c04f06e 100644 --- a/util/AdminLogsHandler.js +++ b/util/AdminLogsHandler.js @@ -41,8 +41,8 @@ module.exports = { if (diffSeconds > (data.combatLogTimer * 60)) return; if (data.lastDamageDate <= data.lastDeathDate) return; - // If lastHitBy (attacker) died to this player or another, - // then it does not count as combat logging, (the combat ended) + // If lastHitBy (attacker) died after shooting this player + // then it does not count as combat logging, (the combat ended due to death) let attacker = guild.playerstats.find(stat => stat.gamertag = data.lastHitBy); if (attacker.lastDeathDate > data.lastDamageDate) return; diff --git a/util/KillfeedHandler.js b/util/KillfeedHandler.js index 10b2a36..32de368 100644 --- a/util/KillfeedHandler.js +++ b/util/KillfeedHandler.js @@ -40,6 +40,33 @@ const Vehicles = { module.exports = { + // Update last death date for non PVP deaths + UpdateLastDeathDate: async (client, stats, line) => { + let killedByZmb = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>) killed by (.*)/g; + let diedTemplate = /(.*) \| Player \"(.*)\" \(DEAD\) \(id=(.*) pos=<(.*)>) died. Stats> Water: (.*) Energy: (.*) Bleed sources: (.*)/g; + + let data = line.includes('>) died.') ? [...line.matchAll(diedTemplate)][0] : [...line.matchAll(killedByZmb)][0]; + if (!data) return stats; + + let info = { + time: data[1], + victim: data[2], + victimID: data[3], + victimPOS: data[4].split(', ').map(v => parseFloat(v)), + }; + + const newDt = await client.getDateEST(info.time); + + let victimStat = stats.find(stat => stat.playerID == info.victimID); + let victimStatIndex = stats.indexOf(victimStat); + if (victimStat == undefined) victimStat = client.getDefaultPlayerStats(info.victim, info.victimID); + victimStat.lastDeathDate = newDt; + if (victimStatIndex == -1) stats.push(victimStat); + else stats[victimStatIndex] = victimStat; + + return stats; + }, + HandleKillfeed: async (client, guildId, stats, line) => { let guild = await client.GetGuild(guildId); @@ -117,6 +144,13 @@ module.exports = { const destination = lastDist > 500 ? `${destination_dir} of ${tempDest}` : `Near ${tempDest}`; if (killedBy == Templates.LandMine || killedBy == Templates.Explosion || killedBy == Templates.Vehicle) { + let victimStat = stats.find(stat => stat.playerID == info.victimID) + let victimStatIndex = stats.indexOf(victimStat); + if (victimStat == undefined) victimStat = client.getDefaultPlayerStats(info.victim, info.victimID); + victimStat.lastDeathDate = newDt; + if (victimStatIndex == -1) stats.push(victimStat); + else stats[victimStatIndex] = victimStat; + const cod = killedBy == Templates.LandMine ? `Land Mine Trap` : killedBy == Templates.Vehicle ? Vehicles[info.causeOfDeath] : info.causeOfDeath; const coord = showCoords ? `\n***Location [${info.victimPOS[0]}, ${info.victimPOS[1]}](https://www.izurvive.com/chernarusplussatmap/#location=${info.victimPOS[0]};${info.victimPOS[1]})***\n${destination}` : '';