diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e9b9f6..64387f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 3.0.8 +* Fixes player array corruption on some protocols which only report player counts without names (Thanks to a-sync) +* Fixes minecraft protocol not using player list from bedrock protocol in some cases + ### 3.0.7 * Fixes corrupted dayzMods when packet overflow is present diff --git a/lib/Results.js b/lib/Results.js index fafa54a..b2a9ae3 100644 --- a/lib/Results.js +++ b/lib/Results.js @@ -39,21 +39,6 @@ class Results { maxplayers = 0; players = new Players(); bots = new Players(); - - set players(val) { - if (typeof val === 'number') { - this.players.setNum(val); - } else if (Array.isArray(val)) { - this.players = val; - } - } - set bots(val) { - if (typeof val === 'number') { - this.bots.setNum(val); - } else if (Array.isArray(val)) { - this.bots = val; - } - } } module.exports = Results; diff --git a/package.json b/package.json index fa901e8..74ed642 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ], "main": "lib/index.js", "author": "GameDig Contributors", - "version": "3.0.7", + "version": "3.0.8", "repository": { "type": "git", "url": "https://github.com/gamedig/node-gamedig.git" diff --git a/protocols/geneshift.js b/protocols/geneshift.js index ce0946f..3c9c45c 100644 --- a/protocols/geneshift.js +++ b/protocols/geneshift.js @@ -28,7 +28,7 @@ class GeneShift extends Core { state.raw.country = found[1]; state.name = found[4]; state.map = found[5]; - state.players = parseInt(found[6]); + state.players.setNum(parseInt(found[6])); state.maxplayers = parseInt(found[7]); // fields[8] is unknown? state.raw.rules = found[9]; diff --git a/protocols/jc2mp.js b/protocols/jc2mp.js index 996809c..05f060f 100644 --- a/protocols/jc2mp.js +++ b/protocols/jc2mp.js @@ -12,7 +12,7 @@ class Jc2mp extends Gamespy3 { async run(state) { await super.run(state); if(!state.players.length && parseInt(state.raw.numplayers)) { - state.players = parseInt(state.raw.numplayers); + state.players.setNum(parseInt(state.raw.numplayers)); } } } diff --git a/protocols/minecraft.js b/protocols/minecraft.js index 785f39e..0ea1c1d 100644 --- a/protocols/minecraft.js +++ b/protocols/minecraft.js @@ -1,7 +1,8 @@ -const Core = require('./core'), - MinecraftVanilla = require('./minecraftvanilla'), - MinecraftBedrock = require('./minecraftbedrock'), - Gamespy3 = require('./gamespy3'); +const Core = require('./core'); +const MinecraftVanilla = require('./minecraftvanilla'); +const MinecraftBedrock = require('./minecraftbedrock'); +const Gamespy3 = require('./gamespy3'); +const Results = require('../lib/Results'); /* Vanilla servers respond to minecraftvanilla only @@ -17,6 +18,7 @@ class Minecraft extends Core { this.srvRecord = "_minecraft._tcp"; } async run(state) { + /** @type {Promise[]} */ const promises = []; const vanillaResolver = new MinecraftVanilla(); @@ -57,7 +59,7 @@ class Minecraft extends Core { if (bedrockState) { if (bedrockState.name) state.name = bedrockState.name; if (bedrockState.maxplayers) state.maxplayers = bedrockState.maxplayers; - if (bedrockState.players) state.players = bedrockState.players; + if (bedrockState.players.length) state.players = bedrockState.players; if (bedrockState.map) state.map = bedrockState.map; } if (vanillaState) { @@ -76,13 +78,13 @@ class Minecraft extends Core { state.name = name; } catch(e) {} if (vanillaState.maxplayers) state.maxplayers = vanillaState.maxplayers; - if (vanillaState.players) state.players = vanillaState.players; + if (vanillaState.players.length) state.players = vanillaState.players; } if (gamespyState) { if (gamespyState.name) state.name = gamespyState.name; if (gamespyState.maxplayers) state.maxplayers = gamespyState.maxplayers; if (gamespyState.players.length) state.players = gamespyState.players; - else if (gamespyState.raw.numplayers) state.players = parseInt(gamespyState.raw.numplayers); + else if (gamespyState.raw.numplayers) state.players.setNum(parseInt(gamespyState.raw.numplayers)); } // remove dupe spaces from name state.name = state.name.replace(/\s+/g, ' '); diff --git a/protocols/minecraftbedrock.js b/protocols/minecraftbedrock.js index 4c166fc..3aa658e 100644 --- a/protocols/minecraftbedrock.js +++ b/protocols/minecraftbedrock.js @@ -57,7 +57,7 @@ class MinecraftBedrock extends Core { state.name = split.shift(); state.raw.protocolVersion = split.shift(); state.raw.mcVersion = split.shift(); - state.players = parseInt(split.shift()); + state.players.setNum(parseInt(split.shift())); state.maxplayers = parseInt(split.shift()); if (split.length) state.raw.serverId = split.shift(); if (split.length) state.map = split.shift(); diff --git a/protocols/mumbleping.js b/protocols/mumbleping.js index eca4a4c..b666178 100644 --- a/protocols/mumbleping.js +++ b/protocols/mumbleping.js @@ -17,7 +17,7 @@ class MumblePing extends Core { state.raw.versionMinor = reader.uint(1); state.raw.versionPatch = reader.uint(1); reader.skip(8); - state.players = reader.uint(4); + state.players.setNum(reader.uint(4)); state.maxplayers = reader.uint(4); state.raw.allowedbandwidth = reader.uint(4); } diff --git a/protocols/openttd.js b/protocols/openttd.js index 5fc2e11..0da2d0d 100644 --- a/protocols/openttd.js +++ b/protocols/openttd.js @@ -35,7 +35,7 @@ class OpenTtd extends Core { state.password = !!reader.uint(1); state.maxplayers = reader.uint(1); - state.players = reader.uint(1); + state.players.setNum(reader.uint(1)); state.raw.numspectators = reader.uint(1); state.map = reader.string(); state.raw.map_width = reader.uint(2); diff --git a/protocols/rfactor.js b/protocols/rfactor.js index 1716a12..d48a559 100644 --- a/protocols/rfactor.js +++ b/protocols/rfactor.js @@ -27,7 +27,7 @@ class Rfactor extends Core { state.raw.ping = reader.uint(2); state.raw.packedFlags = reader.uint(1); state.raw.rate = reader.uint(1); - state.players = reader.uint(1); + state.players.setNum(reader.uint(1)); state.maxplayers = reader.uint(1); state.raw.bots = reader.uint(1); state.raw.packedSpecial = reader.uint(1); diff --git a/protocols/samp.js b/protocols/samp.js index bc452aa..28ad970 100644 --- a/protocols/samp.js +++ b/protocols/samp.js @@ -69,7 +69,7 @@ class Samp extends Core { } } if (!gotPlayerData) { - state.players = state.raw.numplayers; + state.players.setNum(state.raw.numplayers); } } async sendPacket(type,allowTimeout) { diff --git a/protocols/savage2.js b/protocols/savage2.js index 8dae2eb..dfa7a5e 100644 --- a/protocols/savage2.js +++ b/protocols/savage2.js @@ -11,7 +11,7 @@ class Savage2 extends Core { reader.skip(12); state.name = this.stripColorCodes(reader.string()); - state.players = reader.uint(1); + state.players.setNum(reader.uint(1)); state.maxplayers = reader.uint(1); state.raw.time = reader.string(); state.map = reader.string(); diff --git a/protocols/starmade.js b/protocols/starmade.js index d9e4f10..86567d3 100644 --- a/protocols/starmade.js +++ b/protocols/starmade.js @@ -61,7 +61,7 @@ class Starmade extends Core { if(typeof data[2] === 'string') state.name = data[2]; if(typeof data[3] === 'string') state.raw.description = data[3]; if(typeof data[4] === 'number') state.raw.startTime = data[4]; - if(typeof data[5] === 'number') state.players = data[5]; + if(typeof data[5] === 'number') state.players.setNum(data[5]); if(typeof data[6] === 'number') state.maxplayers = data[6]; } }