diff --git a/assets/js/app.js b/assets/js/app.js index d5446ce..7c2afe0 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -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 diff --git a/assets/js/servers.js b/assets/js/servers.js index 3b4bd62..bffe350 100644 --- a/assets/js/servers.js +++ b/assets/js/servers.js @@ -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 diff --git a/assets/js/socket.js b/assets/js/socket.js index 2bb3600..4fb764a 100644 --- a/assets/js/socket.js +++ b/assets/js/socket.js @@ -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) diff --git a/lib/servers.js b/lib/servers.js index 064903b..3fd5c6f 100644 --- a/lib/servers.js +++ b/lib/servers.js @@ -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