send playerCount in payload directly instead of nesting into legacy data structure

This commit is contained in:
Nick Krecklow 2020-05-08 16:13:24 -05:00
parent 04d94a9461
commit 320dc3c2fb
No known key found for this signature in database
GPG Key ID: 5F149FDE156FFA94
4 changed files with 8 additions and 14 deletions

@ -119,7 +119,7 @@ export class App {
// Set initial playerCount to the payload's value
// This will always exist since it is explicitly generated by the backend
// This is used for any post-add rendering of things like the percentageBar
serverRegistration.playerCount = payload.result.players.online
serverRegistration.playerCount = payload.playerCount
}
// Create the plot instance internally with the restructured and cleaned data

@ -105,8 +105,8 @@ export class ServerRegistration {
}
handlePing (payload, timestamp) {
if (payload.result) {
this.playerCount = payload.result.players.online
if (typeof payload.playerCount !== 'undefined') {
this.playerCount = payload.playerCount
// Only update graph for successful pings
// This intentionally pauses the server graph when pings begin to fail
@ -200,12 +200,12 @@ export class ServerRegistration {
errorElement.style.display = 'block'
errorElement.innerText = ping.error.message
} else if (ping.result) {
} else if (typeof ping.playerCount !== 'undefined') {
// Ensure the player-count element is visible and hide the error element
playerCountLabelElement.style.display = 'block'
errorElement.style.display = 'none'
document.getElementById('player-count-value_' + this.serverId).innerText = formatNumber(ping.result.players.online)
document.getElementById('player-count-value_' + this.serverId).innerText = formatNumber(ping.playerCount)
}
// An updated favicon has been sent, update the src

@ -101,7 +101,7 @@ export class SocketManager {
// Skip any incoming updates if the graph is disabled
if (serverUpdate.updateHistoryGraph && this._app.graphDisplayManager.isVisible) {
// Update may not be successful, safely append 0 points
const playerCount = serverUpdate.result ? serverUpdate.result.players.online : 0
const playerCount = serverUpdate.playerCount || 0
this._app.graphDisplayManager.addGraphPoint(serverRegistration.serverId, payload.timestamp, playerCount)

@ -70,9 +70,7 @@ class ServerRegistration {
// Append a result object
// This filters out unwanted data from resp
update.result = {
players: resp.players
}
update.playerCount = resp.players.online
if (config.logToDatabase) {
// Update calculated graph peak regardless if the graph is being updated
@ -115,11 +113,7 @@ class ServerRegistration {
// Assume the ping was a success and define result
// pingHistory does not keep error references, so its impossible to detect if this is an error
// It is also pointless to store that data since it will be short lived
payload.result = {
players: {
online: this._pingHistory[this._pingHistory.length - 1]
}
}
payload.playerCount = this._pingHistory[this._pingHistory.length - 1]
// Send a copy of pingHistory
// Include the last value even though it is contained within payload