mirror of
https://github.com/kuroppoi/entralinked.git
synced 2026-03-21 17:24:40 -05:00
Abort as soon as one server fails to start
This commit is contained in:
parent
87a06a4c08
commit
724e30bfcc
|
|
@ -45,6 +45,8 @@ public class Entralinked {
|
|||
private MainView mainView;
|
||||
|
||||
public Entralinked(String[] args) {
|
||||
long beginTime = System.currentTimeMillis();
|
||||
|
||||
// Read command line arguments
|
||||
CommandLineArguments arguments = new CommandLineArguments(args);
|
||||
|
||||
|
|
@ -92,16 +94,11 @@ public class Entralinked {
|
|||
userManager = new UserManager();
|
||||
playerManager = new PlayerManager();
|
||||
|
||||
// Start servers
|
||||
boolean started = true;
|
||||
|
||||
// Create DNS server
|
||||
dnsServer = new DnsServer(hostAddress);
|
||||
started &= dnsServer.start();
|
||||
|
||||
// Create GameSpy server
|
||||
gameSpyServer = new GameSpyServer(this);
|
||||
started &= gameSpyServer.start();
|
||||
|
||||
// Create HTTP server
|
||||
httpServer = new HttpServer(this);
|
||||
|
|
@ -109,25 +106,41 @@ public class Entralinked {
|
|||
httpServer.addHandler(new PglHandler(this));
|
||||
httpServer.addHandler(new DlsHandler(this));
|
||||
httpServer.addHandler(new DashboardHandler(this));
|
||||
started &= httpServer.start();
|
||||
|
||||
// Handle post-startup GUI stuff
|
||||
if(mainView != null) {
|
||||
if(!started) {
|
||||
SwingUtilities.invokeLater(() -> mainView.setStatusLabelText(
|
||||
"ERROR: One or more servers failed to start! Please check the logs for info."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Start servers
|
||||
boolean started = startServers();
|
||||
|
||||
// Post-startup
|
||||
if(started) {
|
||||
logger.info("Startup complete! Took a total of {} milliseconds", System.currentTimeMillis() - beginTime);
|
||||
String hostIpAddress = hostAddress.getHostAddress();
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
mainView.setDashboardButtonEnabled(true);
|
||||
mainView.setStatusLabelText("Configure your DS to use the following DNS server: %s".formatted(hostIpAddress));
|
||||
});
|
||||
|
||||
if(mainView == null) {
|
||||
logger.info("Configure your DS to use the following DNS server: {}", hostIpAddress);
|
||||
} else {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
mainView.setDashboardButtonEnabled(true);
|
||||
mainView.setStatusLabelText("Configure your DS to use the following DNS server: %s".formatted(hostIpAddress));
|
||||
});
|
||||
}
|
||||
} else {
|
||||
stopServers();
|
||||
|
||||
if(mainView != null) {
|
||||
SwingUtilities.invokeLater(() -> mainView.setStatusLabelText(
|
||||
"ERROR: Entralinked failed to start. Please check the logs for info."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean startServers() {
|
||||
logger.info("Starting servers ...");
|
||||
return httpServer.start() && gameSpyServer.start() && dnsServer.start();
|
||||
}
|
||||
|
||||
public void stopServers() {
|
||||
logger.info("Stopping servers ...");
|
||||
|
||||
if(httpServer != null) {
|
||||
httpServer.stop();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ public abstract class NettyServerBase {
|
|||
|
||||
public boolean start() {
|
||||
if(started) {
|
||||
logger.warn("start() was called while {} server was already running!", name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +58,6 @@ public abstract class NettyServerBase {
|
|||
|
||||
public boolean stop() {
|
||||
if(!started) {
|
||||
logger.warn("stop() was called while {} server wasn't running!", name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@ package entralinked.network.dns;
|
|||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import entralinked.network.NettyServerBase;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
|
|
@ -17,13 +14,11 @@ import io.netty.handler.codec.dns.DatagramDnsResponseEncoder;
|
|||
|
||||
public class DnsServer extends NettyServerBase {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
private InetAddress hostAddress;
|
||||
|
||||
public DnsServer(InetAddress hostAddress) {
|
||||
super("DNS", 53);
|
||||
this.hostAddress = hostAddress;
|
||||
logger.info("DNS queries will be resolved to {}", hostAddress.getHostAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ public class HttpServer {
|
|||
|
||||
public boolean start() {
|
||||
if(started) {
|
||||
logger.warn("start() was called while HTTP server was already running!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +93,6 @@ public class HttpServer {
|
|||
|
||||
public boolean stop() {
|
||||
if(!started) {
|
||||
logger.warn("stop() was called while HTTP server wasn't running!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user