From d4fa6514270fdc1c3e4198e982bdb8db9b0e5f5c Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 6 Apr 2020 14:33:36 +0100 Subject: [PATCH 1/5] Made the server kick all players before we shutdown and close the window when we finish on standalone. --- .../geysermc/connector/GeyserConnector.java | 38 +++++++++++++++++++ .../command/defaults/StopCommand.java | 5 +++ 2 files changed, 43 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index fb93a27de..5ed177b08 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -49,6 +49,7 @@ import java.net.InetSocketAddress; import java.text.DecimalFormat; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -141,6 +142,41 @@ public class GeyserConnector { bootstrap.getGeyserLogger().info("Shutting down Geyser."); shuttingDown = true; + if (players.size() >= 1) { + bootstrap.getGeyserLogger().info("Kicking " + players.size() + " players"); + + for (GeyserSession playerSession : players.values()) { + playerSession.disconnect("Geyser Proxy shutting down."); + } + + CompletableFuture future = CompletableFuture.runAsync(new Runnable() { + @Override + public void run() { + // Simulate a long-running Job + try { + while (true) { + bootstrap.getGeyserLogger().info("Current entries: " + players.size()); + if (players.size() == 0) { + return; + } + + TimeUnit.MILLISECONDS.sleep(100); + } + } catch (InterruptedException e) { + throw new IllegalStateException(e); + } + } + }); + + // Block and wait for the future to complete + try { + future.get(); + bootstrap.getGeyserLogger().info("Kicked all players"); + } catch (Exception e) { + // Quietly fail + } + } + generalThreadPool.shutdown(); bedrockServer.close(); players.clear(); @@ -148,6 +184,8 @@ public class GeyserConnector { authType = null; commandMap.getCommands().clear(); commandMap = null; + + bootstrap.getGeyserLogger().info("Geyser shutdown successfully."); } public void addPlayer(GeyserSession player) { diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java index 4694d0fd0..2222cdef5 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java @@ -48,6 +48,11 @@ public class StopCommand extends GeyserCommand { if (!sender.isConsole() && connector.getPlatformType() == PlatformType.STANDALONE) { return; } + connector.shutdown(); + + if (connector.getPlatformType() == PlatformType.STANDALONE) { + System.exit(0); + } } } From c114f49e848fe446781e30a04ec9ee77e59a1b7e Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 6 Apr 2020 14:34:45 +0100 Subject: [PATCH 2/5] Fixed player count and removed debug code --- .../src/main/java/org/geysermc/connector/GeyserConnector.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 5ed177b08..90b107a5a 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -143,7 +143,7 @@ public class GeyserConnector { shuttingDown = true; if (players.size() >= 1) { - bootstrap.getGeyserLogger().info("Kicking " + players.size() + " players"); + bootstrap.getGeyserLogger().info("Kicking " + (players.size() / 3) + " players"); for (GeyserSession playerSession : players.values()) { playerSession.disconnect("Geyser Proxy shutting down."); @@ -155,7 +155,6 @@ public class GeyserConnector { // Simulate a long-running Job try { while (true) { - bootstrap.getGeyserLogger().info("Current entries: " + players.size()); if (players.size() == 0) { return; } From 41e0de44849e1d1ae6e696a5108a0aece6c8d484 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 6 Apr 2020 14:35:18 +0100 Subject: [PATCH 3/5] Cleaned up language --- .../src/main/java/org/geysermc/connector/GeyserConnector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 90b107a5a..3342fecd9 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -143,7 +143,7 @@ public class GeyserConnector { shuttingDown = true; if (players.size() >= 1) { - bootstrap.getGeyserLogger().info("Kicking " + (players.size() / 3) + " players"); + bootstrap.getGeyserLogger().info("Kicking " + (players.size() / 3) + " player(s)"); for (GeyserSession playerSession : players.values()) { playerSession.disconnect("Geyser Proxy shutting down."); From 90dc33e394938a1e72d091143a7202ec894a77eb Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 6 Apr 2020 14:47:07 +0100 Subject: [PATCH 4/5] Fixed support for ctrl+c shutdown --- .../org/geysermc/platform/standalone/console/GeyserLogger.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java index 7df8a4efb..ac21215cb 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java @@ -52,7 +52,7 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger @Override protected void shutdown() { - GeyserConnector.getInstance().shutdown(); + GeyserConnector.getInstance().getBootstrap().onDisable(); } @Override From 70975a1d3679a8ec19bc4cb343940889bfd57bb4 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Wed, 8 Apr 2020 01:03:25 +0100 Subject: [PATCH 5/5] Updated player count for ade40d5 --- .../src/main/java/org/geysermc/connector/GeyserConnector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 3342fecd9..7c518abc2 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -143,7 +143,7 @@ public class GeyserConnector { shuttingDown = true; if (players.size() >= 1) { - bootstrap.getGeyserLogger().info("Kicking " + (players.size() / 3) + " player(s)"); + bootstrap.getGeyserLogger().info("Kicking " + players.size() + " player(s)"); for (GeyserSession playerSession : players.values()) { playerSession.disconnect("Geyser Proxy shutting down.");