mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-28 21:26:01 +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
|
@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 {
|
||||||
|
@ -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) {
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user