Merge pull request #14 from SowinskiBraeden/test/issue-#6-solution
Test/issue #6 solution
This commit is contained in:
4 files changed
+49
-18
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dayzr-bot",
|
"name": "dayzr-bot",
|
||||||
"version": "9.7.3",
|
"version": "9.8.0",
|
||||||
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"nodemonConfig": {
|
"nodemonConfig": {
|
||||||
|
|||||||
+34
-3
@@ -10,6 +10,7 @@ const { DownloadNitradoFile, CheckServerStatus } = require('../util/NitradoAPI')
|
|||||||
const { HandlePlayerLogs, HandleActivePlayersList } = require('../util/LogsHandler');
|
const { HandlePlayerLogs, HandleActivePlayersList } = require('../util/LogsHandler');
|
||||||
const { HandleKillfeed } = require('../util/KillfeedHandler');
|
const { HandleKillfeed } = require('../util/KillfeedHandler');
|
||||||
const { HandleExpiredUAVs, HandleEvents } = require('../util/AlarmsHandler');
|
const { HandleExpiredUAVs, HandleEvents } = require('../util/AlarmsHandler');
|
||||||
|
const { SendConnectionLogs } = require('../util/AdminLogsHandler');
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@@ -140,7 +141,10 @@ class DayzRBot extends Client {
|
|||||||
if (!this.exists(guild.playerstats)) guild.playerstats = [];
|
if (!this.exists(guild.playerstats)) guild.playerstats = [];
|
||||||
let s = 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++) {
|
for (let i = logIndex + 1; i < lines.length; i++) {
|
||||||
|
if (lines[i].includes('| ####')) continue;
|
||||||
if (lines[i].includes("(id=Unknown") || lines[i].includes("Player \"Unknown Entity\"")) 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 ((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]);
|
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;
|
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--) {
|
for (let i = lines.length - 1; i > 0; i--) {
|
||||||
if (lines[i].includes('PlayerList log:')) {
|
if (lines[i].includes('PlayerList log:')) {
|
||||||
@@ -168,22 +174,47 @@ class DayzRBot extends Client {
|
|||||||
playerID: data[3],
|
playerID: data[3],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lastDetectedTime = info.time;
|
||||||
|
|
||||||
if (!this.exists(info.player) || !this.exists(info.playerID)) continue;
|
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);
|
let playerStatIndex = s.indexOf(playerStat);
|
||||||
if (playerStat == undefined) playerStat = this.getDefaultPlayerStats(info.player, info.playerID);
|
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.connected = true;
|
||||||
|
playerStat.lastConnectionDate = this.getDateEST(info.time); // Assume connected now
|
||||||
|
detectedAsConnected.push()
|
||||||
|
}
|
||||||
|
|
||||||
if (playerStatIndex == -1) s.push(playerStat);
|
if (playerStatIndex == -1) s.push(playerStat);
|
||||||
else s[playerStatIndex] = playerStat;
|
else s[playerStatIndex] = playerStat;
|
||||||
|
detectedAsConnected.push(playerStat);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < previouslyConnected.length; i++) {
|
||||||
|
if (!detectedAsConnected.includes(previouslyConnected[i])) {
|
||||||
|
|
||||||
|
let playerStat = previouslyConnected[i];
|
||||||
|
let playerStatIndex = s.indexOf(playerStat);
|
||||||
|
|
||||||
|
playerStat.connected = false;
|
||||||
|
s[playerStatIndex] = playerStat;
|
||||||
|
|
||||||
|
SendConnectionLogs(this, guildId, {
|
||||||
|
time: lastDetectedTime,
|
||||||
|
player: playerStat.gamertag,
|
||||||
|
connected: false,
|
||||||
|
lastConnectionDate: playerStat.lastConnectionDate,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, {
|
await this.dbo.collection("guilds").updateOne({ "server.serverID": guildId }, {
|
||||||
$set: {
|
$set: {
|
||||||
"server.playerstats": s
|
"server.playerstats": s
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ module.exports = {
|
|||||||
|
|
||||||
let newDt = await client.getDateEST(data.time);
|
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
|
// If diff is greater than 5 minutes, not a combat log
|
||||||
// or if death after last combat and death was before logout event
|
// or if death after last combat
|
||||||
if (data.lastDamageDate <= data.lastDeathDate && data.lastDeathDate < newDt) return;
|
if (data.lastDamageDate <= data.lastDeathDate) return;
|
||||||
if (diff > 5) return;
|
if (diffSeconds > (5 * 60)) return;
|
||||||
|
|
||||||
let guild = await client.GetGuild(guildId);
|
let guild = await client.GetGuild(guildId);
|
||||||
if (!client.exists(guild.connectionLogsChannel)) return;
|
if (!client.exists(guild.connectionLogsChannel)) return;
|
||||||
|
|||||||
+10
-10
@@ -20,7 +20,6 @@ module.exports = {
|
|||||||
time: data[1],
|
time: data[1],
|
||||||
player: data[2],
|
player: data[2],
|
||||||
playerID: data[3],
|
playerID: data[3],
|
||||||
connected: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return stats;
|
if (!client.exists(info.player) || !client.exists(info.playerID)) return stats;
|
||||||
@@ -32,6 +31,7 @@ module.exports = {
|
|||||||
let newDt = await client.getDateEST(info.time);
|
let newDt = await client.getDateEST(info.time);
|
||||||
|
|
||||||
playerStat.lastConnectionDate = newDt;
|
playerStat.lastConnectionDate = newDt;
|
||||||
|
playerStat.connected = true;
|
||||||
|
|
||||||
if (playerStatIndex == -1) stats.push(playerStat);
|
if (playerStatIndex == -1) stats.push(playerStat);
|
||||||
else stats[playerStatIndex] = playerStat;
|
else stats[playerStatIndex] = playerStat;
|
||||||
@@ -39,7 +39,7 @@ module.exports = {
|
|||||||
SendConnectionLogs(client, guildId, {
|
SendConnectionLogs(client, guildId, {
|
||||||
time: info.time,
|
time: info.time,
|
||||||
player: info.player,
|
player: info.player,
|
||||||
connected: info.connected,
|
connected: true,
|
||||||
lastConnectionDate: null,
|
lastConnectionDate: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,6 @@ module.exports = {
|
|||||||
time: data[1],
|
time: data[1],
|
||||||
player: data[2],
|
player: data[2],
|
||||||
playerID: data[3],
|
playerID: data[3],
|
||||||
connected: false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!client.exists(info.player) || !client.exists(info.playerID)) return stats;
|
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);
|
if (playerStat == undefined) playerStat = client.getDefaultPlayerStats(info.player, info.playerID);
|
||||||
|
|
||||||
let newDt = await client.getDateEST(info.time);
|
let newDt = await client.getDateEST(info.time);
|
||||||
let unixTime = Math.floor(newDt.getTime()/1000);
|
let unixTime = Math.round(newDt.getTime()/1000); // Seconds
|
||||||
let oldUnixTime = Math.floor(playerStat.lastConnectionDate.getTime()/1000);
|
let oldUnixTime = Math.round(playerStat.lastConnectionDate.getTime()/1000); // Seconds
|
||||||
let seconds = unixTime - oldUnixTime;
|
let sessionTimeSeconds = unixTime - oldUnixTime;
|
||||||
if (!client.exists(playerStat.longestSessionTime)) playerStat.longestSessionTime = 0;
|
if (!client.exists(playerStat.longestSessionTime)) playerStat.longestSessionTime = 0;
|
||||||
|
|
||||||
playerStat.totalSessionTime = playerStat.totalSessionTime + seconds;
|
playerStat.totalSessionTime = playerStat.totalSessionTime + sessionTimeSeconds;
|
||||||
playerStat.lastSessionTime = seconds;
|
playerStat.lastSessionTime = sessionTimeSeconds;
|
||||||
playerStat.longestSessionTime = seconds > playerStat.longestSessionTime ? seconds : playerStat.longestSessionTime;
|
playerStat.longestSessionTime = sessionTimeSeconds > playerStat.longestSessionTime ? sessionTimeSeconds : playerStat.longestSessionTime;
|
||||||
|
playerStat.connected = false;
|
||||||
|
|
||||||
if (playerStatIndex == -1) stats.push(playerStat);
|
if (playerStatIndex == -1) stats.push(playerStat);
|
||||||
else stats[playerStatIndex] = playerStat;
|
else stats[playerStatIndex] = playerStat;
|
||||||
@@ -77,7 +77,7 @@ module.exports = {
|
|||||||
SendConnectionLogs(client, guildId, {
|
SendConnectionLogs(client, guildId, {
|
||||||
time: info.time,
|
time: info.time,
|
||||||
player: info.player,
|
player: info.player,
|
||||||
connected: info.connected,
|
connected: false,
|
||||||
lastConnectionDate: playerStat.lastConnectionDate,
|
lastConnectionDate: playerStat.lastConnectionDate,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user