Disallow starting unregistered servers

This commit is contained in:
ME1312 2021-06-06 02:02:27 -04:00
parent b2b80036d7
commit ee59429e1d
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
5 changed files with 13 additions and 3 deletions

View File

@ -173,13 +173,14 @@ public class ExternalHost extends Host implements ClientHandler {
@Override @Override
public boolean addSubServer(UUID player, SubServer server) throws InvalidServerException { public boolean addSubServer(UUID player, SubServer server) throws InvalidServerException {
if (server.getHost() != this) throw new IllegalArgumentException("That Server does not belong to this Host!"); if (server.getHost() != this) throw new IllegalArgumentException("That Server does not belong to this Host!");
if (plugin.api.getServers().keySet().contains(server.getName().toLowerCase())) throw new InvalidServerException("A Server already exists with this name!"); if (plugin.api.getServers().containsKey(server.getName().toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
SubAddServerEvent event = new SubAddServerEvent(player, this, server); SubAddServerEvent event = new SubAddServerEvent(player, this, server);
plugin.getPluginManager().callEvent(event); plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
queue(new PacketExAddServer(((ExternalSubServer) server), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> { queue(new PacketExAddServer(((ExternalSubServer) server), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> {
if (data.contains(0x0002)) ((ExternalSubServer) server).started(data.getUUID(0x0002)); if (data.contains(0x0002)) ((ExternalSubServer) server).started(data.getUUID(0x0002));
})); }));
((ExternalSubServer) server).register();
servers.put(server.getName().toLowerCase(), server); servers.put(server.getName().toLowerCase(), server);
return true; return true;
} else { } else {

View File

@ -97,6 +97,10 @@ public class ExternalSubServer extends SubServerImpl {
this.lock = false; this.lock = false;
} }
void register() {
registered = true;
}
@Override @Override
public boolean start(UUID player) { public boolean start(UUID player) {
if (!lock && isAvailable() && isEnabled() && !running && getCurrentIncompatibilities().size() == 0) { if (!lock && isAvailable() && isEnabled() && !running && getCurrentIncompatibilities().size() == 0) {

View File

@ -106,10 +106,11 @@ public class InternalHost extends Host {
@Override @Override
public boolean addSubServer(UUID player, SubServer server) throws InvalidServerException { public boolean addSubServer(UUID player, SubServer server) throws InvalidServerException {
if (server.getHost() != this) throw new IllegalArgumentException("That Server does not belong to this Host!"); if (server.getHost() != this) throw new IllegalArgumentException("That Server does not belong to this Host!");
if (plugin.api.getServers().keySet().contains(server.getName().toLowerCase())) throw new InvalidServerException("A Server already exists with this name!"); if (plugin.api.getServers().containsKey(server.getName().toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
SubAddServerEvent event = new SubAddServerEvent(player, this, server); SubAddServerEvent event = new SubAddServerEvent(player, this, server);
plugin.getPluginManager().callEvent(event); plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
((InternalSubServer) server).register();
servers.put(server.getName().toLowerCase(), server); servers.put(server.getName().toLowerCase(), server);
if (UPnP.isUPnPAvailable() && plugin.config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getAddress().getPort()); if (UPnP.isUPnPAvailable() && plugin.config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getAddress().getPort());
return true; return true;

View File

@ -136,6 +136,10 @@ public class InternalSubServer extends SubServerImpl {
this.lock = false; this.lock = false;
} }
void register() {
registered = true;
}
private void run() { private void run() {
boolean locked = lock; boolean locked = lock;
allowrestart = true; allowrestart = true;

View File

@ -100,7 +100,7 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
@Override @Override
public boolean isAvailable() { public boolean isAvailable() {
return !updating && getHost().isAvailable(); return registered && !updating && getHost().isAvailable();
} }
@Override @Override