Allow dumps to be created even if GeyserServer failed to start (#4930)

This commit is contained in:
Konicai 2024-08-03 10:23:06 -05:00 committed by GitHub
parent 3d7e62a408
commit 61ae5debd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 33 deletions

View file

@ -63,31 +63,31 @@ public class DumpCommand extends GeyserCommand {
this.geyser = geyser;
}
@Override
public void register(CommandManager<GeyserCommandSource> manager) {
manager.command(baseBuilder(manager)
.optional(ARGUMENTS, stringArrayParser(), SuggestionProvider.blockingStrings((ctx, input) -> {
// parse suggestions here
List<String> inputs = new ArrayList<>();
while (input.hasRemainingInput()) {
inputs.add(input.readStringSkipWhitespace());
}
@Override
public void register(CommandManager<GeyserCommandSource> manager) {
manager.command(baseBuilder(manager)
.optional(ARGUMENTS, stringArrayParser(), SuggestionProvider.blockingStrings((ctx, input) -> {
// parse suggestions here
List<String> inputs = new ArrayList<>();
while (input.hasRemainingInput()) {
inputs.add(input.readStringSkipWhitespace());
}
if (inputs.size() <= 2) {
return SUGGESTIONS; // only `geyser dump` was typed (2 literals)
}
if (inputs.size() <= 2) {
return SUGGESTIONS; // only `geyser dump` was typed (2 literals)
}
// the rest of the input after `geyser dump` is for this argument
inputs = inputs.subList(2, inputs.size());
// the rest of the input after `geyser dump` is for this argument
inputs = inputs.subList(2, inputs.size());
// don't suggest any words they have already typed
List<String> suggestions = new ArrayList<>();
SUGGESTIONS.forEach(suggestions::add);
suggestions.removeAll(inputs);
return suggestions;
}))
.handler(this::execute));
}
// don't suggest any words they have already typed
List<String> suggestions = new ArrayList<>();
SUGGESTIONS.forEach(suggestions::add);
suggestions.removeAll(inputs);
return suggestions;
}))
.handler(this::execute));
}
@Override
public void execute(CommandContext<GeyserCommandSource> context) {
@ -113,13 +113,15 @@ public class DumpCommand extends GeyserCommand {
source.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.collecting", source.locale()));
String dumpData;
try {
DumpInfo dump = new DumpInfo(geyser, addLog);
if (offlineDump) {
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
// Make arrays easier to read
prettyPrinter.indentArraysWith(new DefaultIndenter(" ", "\n"));
dumpData = MAPPER.writer(prettyPrinter).writeValueAsString(new DumpInfo(addLog));
dumpData = MAPPER.writer(prettyPrinter).writeValueAsString(dump);
} else {
dumpData = MAPPER.writeValueAsString(new DumpInfo(addLog));
dumpData = MAPPER.writeValueAsString(dump);
}
} catch (IOException e) {
source.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.collect_error", source.locale()));

View file

@ -81,7 +81,7 @@ public class DumpInfo {
private final FlagsInfo flagsInfo;
private final List<ExtensionInfo> extensionInfo;
public DumpInfo(boolean addLog) {
public DumpInfo(GeyserImpl geyser, boolean addLog) {
this.versionInfo = new VersionInfo();
this.cpuCount = Runtime.getRuntime().availableProcessors();
@ -91,7 +91,7 @@ public class DumpInfo {
this.gitInfo = new GitInfo(GeyserImpl.BUILD_NUMBER, GeyserImpl.COMMIT.substring(0, 7), GeyserImpl.COMMIT, GeyserImpl.BRANCH, GeyserImpl.REPOSITORY);
this.config = GeyserImpl.getInstance().getConfig();
this.config = geyser.getConfig();
this.floodgate = new Floodgate();
String md5Hash = "unknown";
@ -107,7 +107,7 @@ public class DumpInfo {
//noinspection UnstableApiUsage
sha256Hash = byteSource.hash(Hashing.sha256()).toString();
} catch (Exception e) {
if (GeyserImpl.getInstance().getConfig().isDebugMode()) {
if (this.config.isDebugMode()) {
e.printStackTrace();
}
}
@ -116,18 +116,22 @@ public class DumpInfo {
this.ramInfo = new RamInfo();
if (addLog) {
this.logsInfo = new LogsInfo();
this.logsInfo = new LogsInfo(geyser);
}
this.userPlatforms = new Object2IntOpenHashMap<>();
for (GeyserSession session : GeyserImpl.getInstance().getSessionManager().getAllSessions()) {
for (GeyserSession session : geyser.getSessionManager().getAllSessions()) {
DeviceOs device = session.getClientData().getDeviceOs();
userPlatforms.put(device, userPlatforms.getOrDefault(device, 0) + 1);
}
this.connectionAttempts = GeyserImpl.getInstance().getGeyserServer().getConnectionAttempts();
if (geyser.getGeyserServer() != null) {
this.connectionAttempts = geyser.getGeyserServer().getConnectionAttempts();
} else {
this.connectionAttempts = 0; // Fallback if Geyser failed to fully startup
}
this.bootstrapInfo = GeyserImpl.getInstance().getBootstrap().getDumpInfo();
this.bootstrapInfo = geyser.getBootstrap().getDumpInfo();
this.flagsInfo = new FlagsInfo();
@ -244,10 +248,10 @@ public class DumpInfo {
public static class LogsInfo {
private String link;
public LogsInfo() {
public LogsInfo(GeyserImpl geyser) {
try {
Map<String, String> fields = new HashMap<>();
fields.put("content", FileUtils.readAllLines(GeyserImpl.getInstance().getBootstrap().getLogsPath()).collect(Collectors.joining("\n")));
fields.put("content", FileUtils.readAllLines(geyser.getBootstrap().getLogsPath()).collect(Collectors.joining("\n")));
JsonNode logData = GeyserImpl.JSON_MAPPER.readTree(WebUtils.postForm("https://api.mclo.gs/1/log", fields));