From ac8c27784634ead7d7ddd6cb1eb0efc99bfd3d60 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 19 Jan 2024 21:55:21 +0100 Subject: [PATCH] Potential Fix for hidden Bauserver. --- src/de/steamwar/bungeecore/Bauserver.java | 10 +++---- src/de/steamwar/bungeecore/Builderserver.java | 10 +++---- src/de/steamwar/bungeecore/Subserver.java | 28 +++++++++++-------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/de/steamwar/bungeecore/Bauserver.java b/src/de/steamwar/bungeecore/Bauserver.java index 9fff3d9..c5876f0 100644 --- a/src/de/steamwar/bungeecore/Bauserver.java +++ b/src/de/steamwar/bungeecore/Bauserver.java @@ -38,21 +38,21 @@ public class Bauserver extends Subserver { private final UUID owner; public Bauserver(String serverName, UUID owner, int port, ProcessBuilder processBuilder, Runnable shutdownCallback){ - super(Servertype.BAUSERVER, serverName, port, processBuilder, shutdownCallback, null); - this.owner = owner; + this(serverName, owner, port, processBuilder, shutdownCallback, null); } public Bauserver(String serverName, UUID owner, int port, ProcessBuilder processBuilder, Runnable shutdownCallback, Consumer failureCallback){ super(Servertype.BAUSERVER, serverName, port, processBuilder, shutdownCallback, failureCallback); this.owner = owner; + + synchronized (servers) { + servers.put(owner, this); + } } @Override protected void register() { super.register(); - synchronized (servers) { - servers.put(owner, this); - } } @Override diff --git a/src/de/steamwar/bungeecore/Builderserver.java b/src/de/steamwar/bungeecore/Builderserver.java index fd3e8f7..c085bb9 100644 --- a/src/de/steamwar/bungeecore/Builderserver.java +++ b/src/de/steamwar/bungeecore/Builderserver.java @@ -37,21 +37,21 @@ public class Builderserver extends Subserver { private final String map; public Builderserver(String serverName, String map, int port, ProcessBuilder processBuilder, Runnable shutdownCallback){ - super(Servertype.BUILDER, serverName, port, processBuilder, shutdownCallback, null); - this.map = map; + this(serverName, map, port, processBuilder, shutdownCallback, null); } public Builderserver(String serverName, String map, int port, ProcessBuilder processBuilder, Runnable shutdownCallback, Consumer failureCallback){ super(Servertype.BUILDER, serverName, port, processBuilder, shutdownCallback, failureCallback); this.map = map; + + synchronized (servers) { + servers.put(map, this); + } } @Override protected void register() { super.register(); - synchronized (servers) { - servers.put(map, this); - } } @Override diff --git a/src/de/steamwar/bungeecore/Subserver.java b/src/de/steamwar/bungeecore/Subserver.java index 37ef123..586524f 100644 --- a/src/de/steamwar/bungeecore/Subserver.java +++ b/src/de/steamwar/bungeecore/Subserver.java @@ -40,14 +40,11 @@ import java.util.logging.Level; import java.util.logging.Logger; public class Subserver { - - @SuppressWarnings("deprecation") - private static final Map servers = ProxyServer.getInstance().getServers(); private static final Logger logger = ProxyServer.getInstance().getLogger(); @Getter private static final List serverList = new LinkedList<>(); - private static final Map infoToServer = new HashMap<>(); + private static final Map infoToServer = new HashMap<>(); public static Subserver getSubserver(ProxiedPlayer p) { synchronized (serverList) { @@ -61,7 +58,7 @@ public class Subserver { public static Subserver getSubserver(ServerInfo server) { synchronized (serverList) { - return infoToServer.get(server.getName()); + return infoToServer.get(server); } } @@ -181,24 +178,29 @@ public class Subserver { } protected void register() { - servers.put(serverName, server); synchronized (serverList) { + if(ProxyServer.getInstance().getServers().containsKey(serverName)) { + throw new SecurityException("Server already registered: " + serverName); + } + + ProxyServer.getInstance().getServers().put(serverName, server); serverList.add(this); - infoToServer.put(serverName, this); + infoToServer.put(server, this); } } protected void unregister() { synchronized (serverList){ - infoToServer.remove(serverName); + infoToServer.remove(server); serverList.remove(this); + ProxyServer.getInstance().getServers().remove(serverName); } - servers.remove(serverName); } private void run() { register(); + Exception ex = null; try { if(checkpoint) { start(process.getErrorStream(), line -> line.contains("Restore finished successfully.")); @@ -229,13 +231,15 @@ public class Subserver { process.waitFor(); } catch(IOException e) { - failureCallback.accept(e); + ex = e; } catch(InterruptedException e) { - failureCallback.accept(e); + ex = e; Thread.currentThread().interrupt(); } finally { - shutdownCallback.run(); unregister(); + shutdownCallback.run(); + if(ex != null) + failureCallback.accept(ex); } }