Skip to content

Commit 221c2fe

Browse files
authored
fix: Avoid a couple cases where no NUIManager would cause trouble. (#4919)
1 parent 3f2e51f commit 221c2fe

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/StartServer.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

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

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

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

1619
private final Context context;
1720
private final boolean dedicated;
@@ -36,8 +39,14 @@ public boolean step() {
3639
int port = config.getNetwork().getServerPort();
3740
context.get(NetworkSystem.class).host(port, dedicated);
3841
} catch (HostingFailedException e) {
39-
context.get(NUIManager.class).pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Failed to Host",
40-
e.getMessage() + " - Reverting to single player");
42+
NUIManager nui = context.get(NUIManager.class);
43+
if (nui != null) {
44+
nui.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Failed to Host",
45+
e.getMessage() + " - Reverting to single player");
46+
} else {
47+
logger.error("Failed to Host. NUI was also unavailable for warning popup (headless?)", e);
48+
throw new RuntimeException("Cannot host game successfully from likely headless start, terminating");
49+
}
4150
}
4251
return true;
4352
}

engine/src/main/java/org/terasology/engine/network/internal/NetworkSystemImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,20 @@ public void host(int port, boolean dedicatedServer) throws HostingFailedExceptio
179179

180180
// enumerate all network interfaces that listen
181181
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
182+
182183
while (interfaces.hasMoreElements()) {
183184
NetworkInterface ifc = interfaces.nextElement();
184185
if (!ifc.isLoopback()) {
185186
for (InterfaceAddress ifadr : ifc.getInterfaceAddresses()) {
186-
InetAddress adr = ifadr.getAddress();
187-
logger.info("Listening on network interface \"{}\", hostname \"{}\" ({})",
188-
ifc.getDisplayName(), adr.getCanonicalHostName(), adr.getHostAddress());
187+
// Exclude interfaces with the following key words to avoid common virtual and otherwise unlikely useful nics
188+
// TODO: Make this configurable via config.cfg?
189+
if (ifc.getDisplayName().contains("VirtualBox") || ifc.getDisplayName().contains("ISATAP")) {
190+
logger.info("Skipping filtered interface name {}", ifc.getDisplayName());
191+
} else {
192+
InetAddress adr = ifadr.getAddress();
193+
logger.info("Listening on network interface \"{}\", hostname \"{}\" ({})",
194+
ifc.getDisplayName(), adr.getCanonicalHostName(), adr.getHostAddress());
195+
}
189196
}
190197
}
191198
}

engine/src/main/java/org/terasology/engine/rendering/nui/skin/UISkinFormat.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ private static class FamilyInfo extends StyleInfo {
129129

130130
public void apply(UISkinBuilder builder) {
131131
super.apply(builder);
132+
133+
// Check if we actually have the NUI Manager available, this would for instance not be the case if starting a headless game server
134+
NUIManager nui = CoreRegistry.get(NUIManager.class);
135+
if (nui == null) {
136+
logger.warn("NUIManager was unavailable, skipping UISkinFormat as not needed. This may or may not be a problem");
137+
return;
138+
}
139+
132140
if (elements != null) {
133141
for (Map.Entry<String, ElementInfo> entry : elements.entrySet()) {
134142
WidgetLibrary library = CoreRegistry.get(NUIManager.class).getWidgetMetadataLibrary();

0 commit comments

Comments
 (0)