1
0

Potential Fix for hidden Bauserver.

Dieser Commit ist enthalten in:
Lixfel 2024-01-19 21:55:21 +01:00
Ursprung cd8706b67f
Commit ac8c277846
3 geänderte Dateien mit 26 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -38,21 +38,21 @@ public class Bauserver extends Subserver {
private final UUID owner; private final UUID owner;
public Bauserver(String serverName, UUID owner, int port, ProcessBuilder processBuilder, Runnable shutdownCallback){ public Bauserver(String serverName, UUID owner, int port, ProcessBuilder processBuilder, Runnable shutdownCallback){
super(Servertype.BAUSERVER, serverName, port, processBuilder, shutdownCallback, null); this(serverName, owner, port, processBuilder, shutdownCallback, null);
this.owner = owner;
} }
public Bauserver(String serverName, UUID owner, int port, ProcessBuilder processBuilder, Runnable shutdownCallback, Consumer<Exception> failureCallback){ public Bauserver(String serverName, UUID owner, int port, ProcessBuilder processBuilder, Runnable shutdownCallback, Consumer<Exception> failureCallback){
super(Servertype.BAUSERVER, serverName, port, processBuilder, shutdownCallback, failureCallback); super(Servertype.BAUSERVER, serverName, port, processBuilder, shutdownCallback, failureCallback);
this.owner = owner; this.owner = owner;
synchronized (servers) {
servers.put(owner, this);
}
} }
@Override @Override
protected void register() { protected void register() {
super.register(); super.register();
synchronized (servers) {
servers.put(owner, this);
}
} }
@Override @Override

Datei anzeigen

@ -37,21 +37,21 @@ public class Builderserver extends Subserver {
private final String map; private final String map;
public Builderserver(String serverName, String map, int port, ProcessBuilder processBuilder, Runnable shutdownCallback){ public Builderserver(String serverName, String map, int port, ProcessBuilder processBuilder, Runnable shutdownCallback){
super(Servertype.BUILDER, serverName, port, processBuilder, shutdownCallback, null); this(serverName, map, port, processBuilder, shutdownCallback, null);
this.map = map;
} }
public Builderserver(String serverName, String map, int port, ProcessBuilder processBuilder, Runnable shutdownCallback, Consumer<Exception> failureCallback){ public Builderserver(String serverName, String map, int port, ProcessBuilder processBuilder, Runnable shutdownCallback, Consumer<Exception> failureCallback){
super(Servertype.BUILDER, serverName, port, processBuilder, shutdownCallback, failureCallback); super(Servertype.BUILDER, serverName, port, processBuilder, shutdownCallback, failureCallback);
this.map = map; this.map = map;
synchronized (servers) {
servers.put(map, this);
}
} }
@Override @Override
protected void register() { protected void register() {
super.register(); super.register();
synchronized (servers) {
servers.put(map, this);
}
} }
@Override @Override

Datei anzeigen

@ -40,14 +40,11 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
public class Subserver { public class Subserver {
@SuppressWarnings("deprecation")
private static final Map<String, ServerInfo> servers = ProxyServer.getInstance().getServers();
private static final Logger logger = ProxyServer.getInstance().getLogger(); private static final Logger logger = ProxyServer.getInstance().getLogger();
@Getter @Getter
private static final List<Subserver> serverList = new LinkedList<>(); private static final List<Subserver> serverList = new LinkedList<>();
private static final Map<String, Subserver> infoToServer = new HashMap<>(); private static final Map<ServerInfo, Subserver> infoToServer = new HashMap<>();
public static Subserver getSubserver(ProxiedPlayer p) { public static Subserver getSubserver(ProxiedPlayer p) {
synchronized (serverList) { synchronized (serverList) {
@ -61,7 +58,7 @@ public class Subserver {
public static Subserver getSubserver(ServerInfo server) { public static Subserver getSubserver(ServerInfo server) {
synchronized (serverList) { synchronized (serverList) {
return infoToServer.get(server.getName()); return infoToServer.get(server);
} }
} }
@ -181,24 +178,29 @@ public class Subserver {
} }
protected void register() { protected void register() {
servers.put(serverName, server);
synchronized (serverList) { synchronized (serverList) {
if(ProxyServer.getInstance().getServers().containsKey(serverName)) {
throw new SecurityException("Server already registered: " + serverName);
}
ProxyServer.getInstance().getServers().put(serverName, server);
serverList.add(this); serverList.add(this);
infoToServer.put(serverName, this); infoToServer.put(server, this);
} }
} }
protected void unregister() { protected void unregister() {
synchronized (serverList){ synchronized (serverList){
infoToServer.remove(serverName); infoToServer.remove(server);
serverList.remove(this); serverList.remove(this);
ProxyServer.getInstance().getServers().remove(serverName);
} }
servers.remove(serverName);
} }
private void run() { private void run() {
register(); register();
Exception ex = null;
try { try {
if(checkpoint) { if(checkpoint) {
start(process.getErrorStream(), line -> line.contains("Restore finished successfully.")); start(process.getErrorStream(), line -> line.contains("Restore finished successfully."));
@ -229,13 +231,15 @@ public class Subserver {
process.waitFor(); process.waitFor();
} catch(IOException e) { } catch(IOException e) {
failureCallback.accept(e); ex = e;
} catch(InterruptedException e) { } catch(InterruptedException e) {
failureCallback.accept(e); ex = e;
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} finally { } finally {
shutdownCallback.run();
unregister(); unregister();
shutdownCallback.run();
if(ex != null)
failureCallback.accept(ex);
} }
} }