Add session tracking to connected
This commit is contained in:
2 files changed
+18
-4
No files matched your search
@@ -41,6 +41,7 @@ class DayzRBot extends Client {
|
|||||||
this.databaseConnected = false;
|
this.databaseConnected = false;
|
||||||
this.arInterval = arInterval;
|
this.arInterval = arInterval;
|
||||||
this.arIntervalId; // Interval for auto-restart functions
|
this.arIntervalId; // Interval for auto-restart functions
|
||||||
|
this.playerSessions = new Map();
|
||||||
this.autoRestartInit();
|
this.autoRestartInit();
|
||||||
this.LoadCommandsAndInteractionHandlers();
|
this.LoadCommandsAndInteractionHandlers();
|
||||||
this.LoadEvents();
|
this.LoadEvents();
|
||||||
@@ -154,7 +155,6 @@ class DayzRBot extends Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const playerTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g;
|
const playerTemplate = /(.*) \| Player \"(.*)\" \(id=(.*) pos=<(.*)>\)/g;
|
||||||
const playerSessions = new Map();
|
|
||||||
let previouslyConnected = s.filter(p => p.connected); // All players with connection log captured above and no disconnect log
|
let previouslyConnected = s.filter(p => p.connected); // All players with connection log captured above and no disconnect log
|
||||||
let lastDetectedTime;
|
let lastDetectedTime;
|
||||||
|
|
||||||
@@ -182,9 +182,9 @@ class DayzRBot extends Client {
|
|||||||
if (!previouslyConnected.includes(playerStat) && this.exists(playerStat.lastDisconnectionDate) && playerStat.lastDisconnectionDate !== null && playerStat.lastDisconnectionDate.getTime() > lastDetectedTime.getTime()) continue; // Skip this player if the lastDisconnectionDate time is later than the player log entry.
|
if (!previouslyConnected.includes(playerStat) && this.exists(playerStat.lastDisconnectionDate) && playerStat.lastDisconnectionDate !== null && playerStat.lastDisconnectionDate.getTime() > lastDetectedTime.getTime()) continue; // Skip this player if the lastDisconnectionDate time is later than the player log entry.
|
||||||
|
|
||||||
// Track adjusted sessions this instance has handled (e.g. no bot crashes or restarts).
|
// Track adjusted sessions this instance has handled (e.g. no bot crashes or restarts).
|
||||||
if (playerSessions.has(info.playerID)) {
|
if (this.playerSessions.has(info.playerID)) {
|
||||||
// Player is already in a session, update the session's end time.
|
// Player is already in a session, update the session's end time.
|
||||||
const session = playerSessions.get(info.playerID);
|
const session = this.playerSessions.get(info.playerID);
|
||||||
session.endTime = lastDetectedTime; // Update end time.
|
session.endTime = lastDetectedTime; // Update end time.
|
||||||
} else {
|
} else {
|
||||||
// Player is not in a session, create a new session.
|
// Player is not in a session, create a new session.
|
||||||
@@ -192,7 +192,7 @@ class DayzRBot extends Client {
|
|||||||
startTime: lastDetectedTime,
|
startTime: lastDetectedTime,
|
||||||
endTime: null, // Initialize end time as null.
|
endTime: null, // Initialize end time as null.
|
||||||
};
|
};
|
||||||
playerSessions.set(info.playerID, newSession);
|
this.playerSessions.set(info.playerID, newSession);
|
||||||
|
|
||||||
// Check if the player has been marked as connected before, but only if a session doesn't exist
|
// Check if the player has been marked as connected before, but only if a session doesn't exist
|
||||||
// in the map, indicating the connection was discovered in the logs during this session.
|
// in the map, indicating the connection was discovered in the logs during this session.
|
||||||
|
|||||||
@@ -38,6 +38,20 @@ module.exports = {
|
|||||||
playerStat.lastConnectionDate = newDt;
|
playerStat.lastConnectionDate = newDt;
|
||||||
playerStat.connected = true;
|
playerStat.connected = true;
|
||||||
|
|
||||||
|
// Track adjusted sessions this instance has handled (e.g. no bot crashes or restarts).
|
||||||
|
if (client.playerSessions.has(info.playerID)) {
|
||||||
|
// Player is already in a session, update the session's end time.
|
||||||
|
const session = client.playerSessions.get(info.playerID);
|
||||||
|
session.endTime = newDt; // Update end time.
|
||||||
|
} else {
|
||||||
|
// Player is not in a session, create a new session.
|
||||||
|
const newSession = {
|
||||||
|
startTime: newDt,
|
||||||
|
endTime: null, // Initialize end time as null.
|
||||||
|
};
|
||||||
|
client.playerSessions.set(info.playerID, newSession);
|
||||||
|
}
|
||||||
|
|
||||||
if (playerStatIndex === -1) stats.push(playerStat);
|
if (playerStatIndex === -1) stats.push(playerStat);
|
||||||
else stats[playerStatIndex] = playerStat;
|
else stats[playerStatIndex] = playerStat;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user