Skip to content

Commit

Permalink
fix: Avoid a couple cases where no NUIManager would cause trouble. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Cervator committed Oct 3, 2021
1 parent 3f2e51f commit 221c2fe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package org.terasology.engine.core.modes.loadProcesses;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.config.Config;
import org.terasology.engine.context.Context;
import org.terasology.engine.core.modes.SingleStepLoadProcess;
Expand All @@ -12,6 +14,7 @@
import org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup;

public class StartServer extends SingleStepLoadProcess {
private static final Logger logger = LoggerFactory.getLogger(StartServer.class);

private final Context context;
private final boolean dedicated;
Expand All @@ -36,8 +39,14 @@ public boolean step() {
int port = config.getNetwork().getServerPort();
context.get(NetworkSystem.class).host(port, dedicated);
} catch (HostingFailedException e) {
context.get(NUIManager.class).pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Failed to Host",
e.getMessage() + " - Reverting to single player");
NUIManager nui = context.get(NUIManager.class);
if (nui != null) {
nui.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Failed to Host",
e.getMessage() + " - Reverting to single player");
} else {
logger.error("Failed to Host. NUI was also unavailable for warning popup (headless?)", e);
throw new RuntimeException("Cannot host game successfully from likely headless start, terminating");
}
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,20 @@ public void host(int port, boolean dedicatedServer) throws HostingFailedExceptio

// enumerate all network interfaces that listen
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();

while (interfaces.hasMoreElements()) {
NetworkInterface ifc = interfaces.nextElement();
if (!ifc.isLoopback()) {
for (InterfaceAddress ifadr : ifc.getInterfaceAddresses()) {
InetAddress adr = ifadr.getAddress();
logger.info("Listening on network interface \"{}\", hostname \"{}\" ({})",
ifc.getDisplayName(), adr.getCanonicalHostName(), adr.getHostAddress());
// Exclude interfaces with the following key words to avoid common virtual and otherwise unlikely useful nics
// TODO: Make this configurable via config.cfg?
if (ifc.getDisplayName().contains("VirtualBox") || ifc.getDisplayName().contains("ISATAP")) {
logger.info("Skipping filtered interface name {}", ifc.getDisplayName());
} else {
InetAddress adr = ifadr.getAddress();
logger.info("Listening on network interface \"{}\", hostname \"{}\" ({})",
ifc.getDisplayName(), adr.getCanonicalHostName(), adr.getHostAddress());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ private static class FamilyInfo extends StyleInfo {

public void apply(UISkinBuilder builder) {
super.apply(builder);

// Check if we actually have the NUI Manager available, this would for instance not be the case if starting a headless game server
NUIManager nui = CoreRegistry.get(NUIManager.class);
if (nui == null) {
logger.warn("NUIManager was unavailable, skipping UISkinFormat as not needed. This may or may not be a problem");
return;
}

if (elements != null) {
for (Map.Entry<String, ElementInfo> entry : elements.entrySet()) {
WidgetLibrary library = CoreRegistry.get(NUIManager.class).getWidgetMetadataLibrary();
Expand Down

0 comments on commit 221c2fe

Please sign in to comment.