From f2177204beedbbacc71bd3bd52b87b4c7bd19ebc Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Sat, 15 Feb 2020 22:05:13 +0100 Subject: [PATCH 1/3] Fix wrong player count in minecraftvanilla protocol --- protocols/minecraftvanilla.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/protocols/minecraftvanilla.js b/protocols/minecraftvanilla.js index c55294e..7ea0a4b 100644 --- a/protocols/minecraftvanilla.js +++ b/protocols/minecraftvanilla.js @@ -54,9 +54,10 @@ class MinecraftVanilla extends Core { name: player.name }); } - } - for (let i = 0; i < Math.min(json.players.online, 10000); i++) { - state.players.push({}); + } else { + for (let i = 0; i < Math.min(json.players.online, 10000); i++) { + state.players.push({}); + } } } From f5238027c75515b5cc4cb87f06f67be39bbcda93 Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Tue, 18 Feb 2020 14:52:04 +0100 Subject: [PATCH 2/3] Handle situtation where sample exists, but does not contain all players --- protocols/minecraftvanilla.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/protocols/minecraftvanilla.js b/protocols/minecraftvanilla.js index 7ea0a4b..f8b051c 100644 --- a/protocols/minecraftvanilla.js +++ b/protocols/minecraftvanilla.js @@ -47,6 +47,7 @@ class MinecraftVanilla extends Core { state.raw = json; state.maxplayers = json.players.max; + if(json.players.sample) { for(const player of json.players.sample) { state.players.push({ @@ -54,10 +55,13 @@ class MinecraftVanilla extends Core { name: player.name }); } - } else { - for (let i = 0; i < Math.min(json.players.online, 10000); i++) { - state.players.push({}); - } + } + + // players.sample may not contain all players or no players at all, depending on how many players are only. + // Insert a dummy player object for every online player that is not listed in players.sample. + // Limit player amount to 10.000 players for performance reasons. + for (let i = state.players.length; i < Math.min(json.players.online, 10000); i++) { + state.players.push({}); } } From f3b04d52d55a7242fe1cbbb3b93f629b9bd32c54 Mon Sep 17 00:00:00 2001 From: Pascal Sthamer Date: Tue, 18 Feb 2020 14:53:39 +0100 Subject: [PATCH 3/3] Fix typo --- protocols/minecraftvanilla.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/minecraftvanilla.js b/protocols/minecraftvanilla.js index f8b051c..45dd6c5 100644 --- a/protocols/minecraftvanilla.js +++ b/protocols/minecraftvanilla.js @@ -57,7 +57,7 @@ class MinecraftVanilla extends Core { } } - // players.sample may not contain all players or no players at all, depending on how many players are only. + // players.sample may not contain all players or no players at all, depending on how many players are online. // Insert a dummy player object for every online player that is not listed in players.sample. // Limit player amount to 10.000 players for performance reasons. for (let i = state.players.length; i < Math.min(json.players.online, 10000); i++) {