mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-25 03:35:26 +01:00
Disallow starting unregistered servers
This commit is contained in:
parent
b2b80036d7
commit
ee59429e1d
@ -173,13 +173,14 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
@Override
|
||||
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 (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);
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
queue(new PacketExAddServer(((ExternalSubServer) server), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> {
|
||||
if (data.contains(0x0002)) ((ExternalSubServer) server).started(data.getUUID(0x0002));
|
||||
}));
|
||||
((ExternalSubServer) server).register();
|
||||
servers.put(server.getName().toLowerCase(), server);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -97,6 +97,10 @@ public class ExternalSubServer extends SubServerImpl {
|
||||
this.lock = false;
|
||||
}
|
||||
|
||||
void register() {
|
||||
registered = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start(UUID player) {
|
||||
if (!lock && isAvailable() && isEnabled() && !running && getCurrentIncompatibilities().size() == 0) {
|
||||
|
@ -106,10 +106,11 @@ public class InternalHost extends Host {
|
||||
@Override
|
||||
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 (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);
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
((InternalSubServer) server).register();
|
||||
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());
|
||||
return true;
|
||||
|
@ -136,6 +136,10 @@ public class InternalSubServer extends SubServerImpl {
|
||||
this.lock = false;
|
||||
}
|
||||
|
||||
void register() {
|
||||
registered = true;
|
||||
}
|
||||
|
||||
private void run() {
|
||||
boolean locked = lock;
|
||||
allowrestart = true;
|
||||
|
@ -100,7 +100,7 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !updating && getHost().isAvailable();
|
||||
return registered && !updating && getHost().isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user