diff --git a/src/main/java/net/rptools/maptool/server/MapToolServer.java b/src/main/java/net/rptools/maptool/server/MapToolServer.java index b93657fbeb..584f13ca1c 100644 --- a/src/main/java/net/rptools/maptool/server/MapToolServer.java +++ b/src/main/java/net/rptools/maptool/server/MapToolServer.java @@ -21,6 +21,7 @@ import java.util.Map.Entry; import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.swing.SwingUtilities; import net.rptools.clientserver.ConnectionFactory; @@ -67,6 +68,7 @@ public enum State { Stopped } + @Nonnull private final String serviceIdentifier; private final Server server; private final MessageHandler messageHandler; private final Router router; @@ -81,7 +83,7 @@ public enum State { private final AssetProducerThread assetProducerThread; private final boolean useUPnP; - private final ServiceAnnouncer announcer; + @Nullable private ServiceAnnouncer announcer; private Campaign campaign; private ServerPolicy policy; private HeartbeatThread heartbeatThread; @@ -97,16 +99,12 @@ public MapToolServer( boolean useUPnP, ServerPolicy policy, ServerSidePlayerDatabase playerDb) { + this.serviceIdentifier = id; this.config = config; this.useUPnP = useUPnP; this.policy = new ServerPolicy(policy); this.playerDatabase = playerDb; - this.announcer = - config == null || id == null - ? null - : new ServiceAnnouncer(id, config.getPort(), AppConstants.SERVICE_GROUP); - server = ConnectionFactory.getInstance().createServer(this.config); messageHandler = new ServerMessageHandler(this); this.router = new Router(); @@ -354,6 +352,7 @@ public void stop() { if (announcer != null) { announcer.stop(); + announcer = null; } // Unregister ourselves @@ -418,7 +417,8 @@ public void start() throws IOException { } } - if (announcer != null) { + if (serviceIdentifier != null && config != null) { + announcer = new ServiceAnnouncer(serviceIdentifier, config.getPort(), AppConstants.SERVICE_GROUP); announcer.start(); }