unify TimeTracker code, explicitly mark nullable playerCounts as unsafe
This commit is contained in:
@ -4,6 +4,8 @@ const dns = require('dns')
|
||||
const TimeTracker = require('./time')
|
||||
const Server = require('./server')
|
||||
|
||||
const { getPlayerCountOrNull } = require('./util')
|
||||
|
||||
const config = require('../config')
|
||||
const minecraftVersions = require('../minecraft_versions')
|
||||
|
||||
@ -23,16 +25,16 @@ class ServerRegistration {
|
||||
|
||||
handlePing (timestamp, resp, err, version, updateHistoryGraph) {
|
||||
// Use null to represent a failed ping
|
||||
const playerCount = resp ? resp.players.online : null
|
||||
const unsafePlayerCount = getPlayerCountOrNull(resp)
|
||||
|
||||
// Store into in-memory ping data
|
||||
TimeTracker.pushAndShift(this._pingHistory, playerCount, TimeTracker.getMaxServerGraphDataLength())
|
||||
TimeTracker.pushAndShift(this._pingHistory, unsafePlayerCount, TimeTracker.getMaxServerGraphDataLength())
|
||||
|
||||
// Only notify the frontend to append to the historical graph
|
||||
// if both the graphing behavior is enabled and the backend agrees
|
||||
// that the ping is eligible for addition
|
||||
if (updateHistoryGraph) {
|
||||
TimeTracker.pushAndShift(this.graphData, playerCount, TimeTracker.getMaxGraphDataLength())
|
||||
TimeTracker.pushAndShift(this.graphData, unsafePlayerCount, TimeTracker.getMaxGraphDataLength())
|
||||
}
|
||||
|
||||
// Delegate out update payload generation
|
||||
@ -51,7 +53,7 @@ class ServerRegistration {
|
||||
if (config.logToDatabase && (!this.recordData || resp.players.online > this.recordData.playerCount)) {
|
||||
this.recordData = {
|
||||
playerCount: resp.players.online,
|
||||
timestamp: Math.floor(timestamp / 1000)
|
||||
timestamp: TimeTracker.toSeconds(timestamp)
|
||||
}
|
||||
|
||||
// Append an updated recordData
|
||||
@ -160,7 +162,7 @@ class ServerRegistration {
|
||||
}
|
||||
return {
|
||||
playerCount: this.graphData[this._graphPeakIndex],
|
||||
timestamp: this._app.timeTracker.getHistoricalPointSeconds(this._graphPeakIndex)
|
||||
timestamp: this._app.timeTracker.getGraphPointAt(this._graphPeakIndex)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user