unify TimeTracker code, explicitly mark nullable playerCounts as unsafe
This commit is contained in:
11
lib/ping.js
11
lib/ping.js
@ -3,6 +3,9 @@ const minecraftBedrockPing = require('mcpe-ping-fixed')
|
||||
|
||||
const logger = require('./logger')
|
||||
const MessageOf = require('./message')
|
||||
const TimeTracker = require('./time')
|
||||
|
||||
const { getPlayerCountOrNull } = require('./util')
|
||||
|
||||
const config = require('../config')
|
||||
|
||||
@ -83,7 +86,7 @@ class PingController {
|
||||
}
|
||||
|
||||
pingAll = () => {
|
||||
const { timestamp, updateHistoryGraph } = this._app.timeTracker.newPingTimestamp()
|
||||
const { timestamp, updateHistoryGraph } = this._app.timeTracker.newPointTimestamp()
|
||||
|
||||
this.startPingTasks(results => {
|
||||
const updates = []
|
||||
@ -94,9 +97,9 @@ class PingController {
|
||||
// Log to database if enabled
|
||||
// Use null to represent a failed ping
|
||||
if (config.logToDatabase) {
|
||||
const playerCount = result.resp ? result.resp.players.online : null
|
||||
const unsafePlayerCount = getPlayerCountOrNull(result.resp)
|
||||
|
||||
this._app.database.insertPing(serverRegistration.data.ip, timestamp, playerCount)
|
||||
this._app.database.insertPing(serverRegistration.data.ip, timestamp, unsafePlayerCount)
|
||||
}
|
||||
|
||||
// Generate a combined update payload
|
||||
@ -110,7 +113,7 @@ class PingController {
|
||||
// Send object since updates uses serverIds as keys
|
||||
// Send a single timestamp entry since it is shared
|
||||
this._app.server.broadcast(MessageOf('updateServers', {
|
||||
timestamp: Math.floor(timestamp / 1000),
|
||||
timestamp: TimeTracker.toSeconds(timestamp),
|
||||
updateHistoryGraph,
|
||||
updates
|
||||
}))
|
||||
|
Reference in New Issue
Block a user