Skip to content

Commit 46c4e0c

Browse files
committed
feat: auto-run host doctor when hosting fails to start at boot
Prints the full diagnosis checklist to the server log via HostDoctor.logReport, so admins get the exact config fix without having to know the doctor command exists.
1 parent b2f13b0 commit 46c4e0c

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

core/src/main/java/pl/skidam/automodpack_core/protocol/HostDoctor.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ public enum Status { OK, INFO, WARN, FAIL }
2727

2828
public record CheckResult(Status status, String name, String detail) {}
2929

30+
// Logs the checklist - used when hosting fails at boot, where no command source exists.
31+
// Pass minecraftPort -1 when unknown.
32+
public static void logReport(int minecraftPort) {
33+
for (CheckResult result : run(minecraftPort)) {
34+
String line = "[" + result.status() + "] " + result.name() + (result.detail().isEmpty() ? "" : " - " + result.detail());
35+
switch (result.status()) {
36+
case FAIL -> LOGGER.error(line);
37+
case WARN -> LOGGER.warn(line);
38+
default -> LOGGER.info(line);
39+
}
40+
}
41+
}
42+
3043
public static List<CheckResult> run(int minecraftPort) {
3144
List<CheckResult> results = new ArrayList<>();
3245

@@ -101,8 +114,9 @@ private static void checkTls(List<CheckResult> results) {
101114

102115
private static void checkPorts(List<CheckResult> results, int minecraftPort) {
103116
if (serverConfig.bindPort == -1) {
117+
String mcPort = minecraftPort > 0 ? String.valueOf(minecraftPort) : "?";
104118
results.add(new CheckResult(Status.INFO, "Port setup",
105-
"sharing the Minecraft port (" + minecraftPort + ") using magic packets - proxies and DDoS protection (Velocity, BungeeCord, TCPShield...) usually break this; if clients get connection errors, set bindPort to a free port and portToSend to how it is reachable from outside"));
119+
"sharing the Minecraft port (" + mcPort + ") using magic packets - proxies and DDoS protection (Velocity, BungeeCord, TCPShield...) usually break this; if clients get connection errors, set bindPort to a free port and portToSend to how it is reachable from outside"));
106120
} else if (serverConfig.portToSend == -1) {
107121
results.add(new CheckResult(Status.FAIL, "Port setup",
108122
"bindPort is " + serverConfig.bindPort + " but portToSend is -1, so clients will try the Minecraft port and fail - set portToSend to " + serverConfig.bindPort + " (or to the externally forwarded port)"));

src/main/java/pl/skidam/automodpack/init/Common.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pl.skidam.automodpack.networking.ModPackets;
77
import pl.skidam.automodpack_core.modpack.ModpackExecutor;
88
import pl.skidam.automodpack_core.loader.LoaderManagerService;
9+
import pl.skidam.automodpack_core.protocol.HostDoctor;
910
import pl.skidam.automodpack_core.protocol.netty.NettyServer;
1011

1112
import java.util.HashMap;
@@ -52,6 +53,11 @@ public static void afterSetupServer() {
5253
}
5354

5455
hostServer.start();
56+
57+
if (serverConfig.modpackHost && !hostServer.isRunning()) {
58+
LOGGER.error("Modpack host failed to start - running diagnosis:");
59+
HostDoctor.logReport(-1);
60+
}
5561
}
5662

5763
public static void beforeShutdownServer() {

0 commit comments

Comments
 (0)