3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-09-28 06:01:10 +02:00

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

Dieser Commit ist enthalten in:
Konicai 2024-08-03 10:23:06 -05:00 committet von GitHub
Ursprung 3d7e62a408
Commit 61ae5debd4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 39 neuen und 33 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -81,7 +81,7 @@ public class DumpInfo {
private final FlagsInfo flagsInfo; private final FlagsInfo flagsInfo;
private final List<ExtensionInfo> extensionInfo; private final List<ExtensionInfo> extensionInfo;
public DumpInfo(boolean addLog) { public DumpInfo(GeyserImpl geyser, boolean addLog) {
this.versionInfo = new VersionInfo(); this.versionInfo = new VersionInfo();
this.cpuCount = Runtime.getRuntime().availableProcessors(); 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.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(); this.floodgate = new Floodgate();
String md5Hash = "unknown"; String md5Hash = "unknown";
@ -107,7 +107,7 @@ public class DumpInfo {
//noinspection UnstableApiUsage //noinspection UnstableApiUsage
sha256Hash = byteSource.hash(Hashing.sha256()).toString(); sha256Hash = byteSource.hash(Hashing.sha256()).toString();
} catch (Exception e) { } catch (Exception e) {
if (GeyserImpl.getInstance().getConfig().isDebugMode()) { if (this.config.isDebugMode()) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -116,18 +116,22 @@ public class DumpInfo {
this.ramInfo = new RamInfo(); this.ramInfo = new RamInfo();
if (addLog) { if (addLog) {
this.logsInfo = new LogsInfo(); this.logsInfo = new LogsInfo(geyser);
} }
this.userPlatforms = new Object2IntOpenHashMap<>(); this.userPlatforms = new Object2IntOpenHashMap<>();
for (GeyserSession session : GeyserImpl.getInstance().getSessionManager().getAllSessions()) { for (GeyserSession session : geyser.getSessionManager().getAllSessions()) {
DeviceOs device = session.getClientData().getDeviceOs(); DeviceOs device = session.getClientData().getDeviceOs();
userPlatforms.put(device, userPlatforms.getOrDefault(device, 0) + 1); 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(); this.flagsInfo = new FlagsInfo();
@ -244,10 +248,10 @@ public class DumpInfo {
public static class LogsInfo { public static class LogsInfo {
private String link; private String link;
public LogsInfo() { public LogsInfo(GeyserImpl geyser) {
try { try {
Map<String, String> fields = new HashMap<>(); 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)); JsonNode logData = GeyserImpl.JSON_MAPPER.readTree(WebUtils.postForm("https://api.mclo.gs/1/log", fields));