fix/issue #6
This commit is contained in:
4 files changed
+52
-18
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dayzr-bot",
|
||||
"version": "9.7.3",
|
||||
"version": "10.0.0",
|
||||
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
||||
"main": "index.js",
|
||||
"nodemonConfig": {
|
||||
|
||||
+37
-3
@@ -10,6 +10,7 @@ const { DownloadNitradoFile, CheckServerStatus } = require('../util/NitradoAPI')
|
||||
const { HandlePlayerLogs, HandleActivePlayersList } = require('../util/LogsHandler');
|
||||
const { HandleKillfeed } = require('../util/KillfeedHandler');
|
||||
const { HandleExpiredUAVs, HandleEvents } = require('../util/AlarmsHandler');
|
||||
const { SendConnectionLogs } = require('../util/AdminLogsHandler');
|
||||
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
@@ -140,7 +141,10 @@ class DayzRBot extends Client {
|
||||
if (!this.exists(guild.playerstats)) guild.playerstats = [];
|
||||
let s = guild.playerstats;
|
||||
|
||||
s.map(p => p.connected = false) // assume all players not connected
|
||||
|
||||
for (let i = logIndex + 1; i < lines.length; i++) {
|
||||
if (line.includes('| ####')) continue;
|
||||
if (lines[i].includes("(id=Unknown") || lines[i].includes("Player \"Unknown Entity\"")) continue;
|
||||
if ((i - 1) >= 0 && lines[i] == lines[i-1]) continue; // continue if this line is a duplicate of the last line
|
||||
if (lines[i].includes('connected') || lines[i].includes('pos=<') || lines[1].includes('hit by Player')) s = await HandlePlayerLogs(this, guildId, s, lines[i]);
|
||||
@@ -151,7 +155,9 @@ class DayzRBot extends Client {
|
||||
}
|
||||
|
||||
const playerTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g;
|
||||
s.map(p => p.connected = false) // make all connections false
|
||||
let previouslyConnected = s.filter(p => p.connected); // All players with connection log captured above and no disconnect log
|
||||
let detectedAsConnected = [];
|
||||
let lastDetectedTime;
|
||||
|
||||
for (let i = lines.length - 1; i > 0; i--) {
|
||||
if (lines[i].includes('PlayerList log:')) {
|
||||
@@ -168,22 +174,50 @@ class DayzRBot extends Client {
|
||||
playerID: data[3],
|
||||
};
|
||||
|
||||
lastDetectedTime = info.time;
|
||||
|
||||
if (!this.exists(info.player) || !this.exists(info.playerID)) continue;
|
||||
|
||||
let playerStat = s.find(stat => stat.playerID == info.playerID)
|
||||
let playerStat = s.find(stat => stat.playerID == info.playerID);
|
||||
let playerStatIndex = s.indexOf(playerStat);
|
||||
if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID);
|
||||
if (!previouslyConnected.includes(playerStat)) {
|
||||
|
||||
// This player was not connected before, i.e missing connection log?
|
||||
playerStat.connected = true;
|
||||
playerStat.lastConnectionDate = this.getDateEST(info.time); // Assume connected now
|
||||
detectedAsConnected.push()
|
||||
}
|
||||
|
||||
if (playerStatIndex == -1) s.push(playerStat);
|
||||
else s[playerStatIndex] = playerStat;
|
||||
|
||||
detectedAsConnected.push(playerStat);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < previouslyConnected.length; i++) {
|
||||
if (!detectedAsConnected.includes(previouslyConnected[i])) {
|
||||
|
||||
// This player disconnected without a disconnect log appearing.
|
||||
client.log('Players disconnected withouth disconnect log: this can happen!!!') // debug proof
|
||||
|
||||
let playerStat = spreviouslyConnected[i];
|
||||
let playerStatIndex = s.indexOf(playerStat);
|
||||
|
||||
playerStat.connected = false;
|
||||
s[playerStatIndex] = playerStat;
|
||||
|
||||
SendConnectionLogs(client, guildId, {
|
||||
time: lastDetectedTime,
|
||||
player: playerStat.gamertag,
|
||||
connected: false,
|
||||
lastConnectionDate: playerStat.lastConnectionDate,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, {
|
||||
$set: {
|
||||
"server.playerstats": s
|
||||
|
||||
@@ -31,12 +31,12 @@ module.exports = {
|
||||
|
||||
let newDt = await client.getDateEST(data.time);
|
||||
|
||||
let diff = Math.round((newDt.getTime() - data.lastDamageDate.getTime()) / 1000 / 60); // diff minutes
|
||||
let diffSeconds = Math.round((newDt.getTime() - data.lastDamageDate.getTime()) / 1000);
|
||||
|
||||
// If diff is greater than 5 minutes, not a combat log
|
||||
// or if death after last combat and death was before logout event
|
||||
if (data.lastDamageDate <= data.lastDeathDate && data.lastDeathDate < newDt) return;
|
||||
if (diff > 5) return;
|
||||
// or if death after last combat
|
||||
if (data.lastDamageDate <= data.lastDeathDate) return;
|
||||
if (diffSeconds > (5 * 60)) return;
|
||||
|
||||
let guild = await client.GetGuild(guildId);
|
||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||
|
||||
+10
-10
@@ -20,7 +20,6 @@ module.exports = {
|
||||
time: data[1],
|
||||
player: data[2],
|
||||
playerID: data[3],
|
||||
connected: true,
|
||||
};
|
||||
|
||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return stats;
|
||||
@@ -32,6 +31,7 @@ module.exports = {
|
||||
let newDt = await client.getDateEST(info.time);
|
||||
|
||||
playerStat.lastConnectionDate = newDt;
|
||||
playerStat.connected = true;
|
||||
|
||||
if (playerStatIndex == -1) stats.push(playerStat);
|
||||
else stats[playerStatIndex] = playerStat;
|
||||
@@ -39,7 +39,7 @@ module.exports = {
|
||||
SendConnectionLogs(client, guildId, {
|
||||
time: info.time,
|
||||
player: info.player,
|
||||
connected: info.connected,
|
||||
connected: true,
|
||||
lastConnectionDate: null,
|
||||
});
|
||||
}
|
||||
@@ -52,7 +52,6 @@ module.exports = {
|
||||
time: data[1],
|
||||
player: data[2],
|
||||
playerID: data[3],
|
||||
connected: false
|
||||
}
|
||||
|
||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return stats;
|
||||
@@ -62,14 +61,15 @@ module.exports = {
|
||||
if (playerStat == undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
||||
|
||||
let newDt = await client.getDateEST(info.time);
|
||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
||||
let oldUnixTime = Math.floor(playerStat.lastConnectionDate.getTime()/1000);
|
||||
let seconds = unixTime - oldUnixTime;
|
||||
let unixTime = Math.round(newDt.getTime()/1000); // Seconds
|
||||
let oldUnixTime = Math.round(playerStat.lastConnectionDate.getTime()/1000); // Seconds
|
||||
let sessionTimeSeconds = unixTime - oldUnixTime;
|
||||
if (!client.exists(playerStat.longestSessionTime)) playerStat.longestSessionTime = 0;
|
||||
|
||||
playerStat.totalSessionTime = playerStat.totalSessionTime + seconds;
|
||||
playerStat.lastSessionTime = seconds;
|
||||
playerStat.longestSessionTime = seconds > playerStat.longestSessionTime ? seconds : playerStat.longestSessionTime;
|
||||
playerStat.totalSessionTime = playerStat.totalSessionTime + sessionTimeSeconds;
|
||||
playerStat.lastSessionTime = sessionTimeSeconds;
|
||||
playerStat.longestSessionTime = sessionTimeSeconds > playerStat.longestSessionTime ? sessionTimeSeconds : playerStat.longestSessionTime;
|
||||
playerStat.connected = false;
|
||||
|
||||
if (playerStatIndex == -1) stats.push(playerStat);
|
||||
else stats[playerStatIndex] = playerStat;
|
||||
@@ -77,7 +77,7 @@ module.exports = {
|
||||
SendConnectionLogs(client, guildId, {
|
||||
time: info.time,
|
||||
player: info.player,
|
||||
connected: info.connected,
|
||||
connected: false,
|
||||
lastConnectionDate: playerStat.lastConnectionDate,
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user