Provide the Geyser file's MD5 and hash in Geyser dumps
@@ -27,8 +27,12 @@ package org.geysermc.connector.dump;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.github.steveice10.mc.protocol.MinecraftConstants;
+import com.google.common.hash.Hashing;
+import com.google.common.io.ByteSource;
+import com.google.common.io.Files;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
+import lombok.AllArgsConstructor;
import lombok.Getter;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.common.serializer.AsteriskSerializer;
@@ -39,6 +43,7 @@ import org.geysermc.connector.utils.DockerCheck;
import org.geysermc.connector.utils.FileUtils;
import org.geysermc.floodgate.util.DeviceOS;
+import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@@ -55,8 +60,9 @@ public class DumpInfo {
private final DumpInfo.VersionInfo versionInfo;
private Properties gitInfo;
private final GeyserConfiguration config;
- private Object2IntMap<DeviceOS> userPlatforms;
- private RamInfo ramInfo;
+ private final HashInfo hashInfo;
+ private final Object2IntMap<DeviceOS> userPlatforms;
+ private final RamInfo ramInfo;
private final BootstrapDumpInfo bootstrapInfo;
public DumpInfo() {
@@ -69,9 +75,29 @@ public class DumpInfo {
this.config = GeyserConnector.getInstance().getConfig();
+ String md5Hash = "unknown";
+ String sha256Hash = "unknown";
+ try {
+ // https://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file
+ // https://stackoverflow.com/questions/304268/getting-a-files-md5-checksum-in-java
+ File file = new File(DumpInfo.class.getProtectionDomain().getCodeSource().getLocation().toURI());
+ ByteSource byteSource = Files.asByteSource(file);
+ // Jenkins uses MD5 for its hash
+ //noinspection UnstableApiUsage
+ md5Hash = byteSource.hash(Hashing.md5()).toString();
+ //noinspection UnstableApiUsage
+ sha256Hash = byteSource.hash(Hashing.sha256()).toString();
+ } catch (Exception e) {
+ if (GeyserConnector.getInstance().getConfig().isDebugMode()) {
+ e.printStackTrace();
+ }
+ }
+
+ this.hashInfo = new HashInfo(md5Hash, sha256Hash);
+
this.ramInfo = new DumpInfo.RamInfo();
- this.userPlatforms = new Object2IntOpenHashMap();
+ this.userPlatforms = new Object2IntOpenHashMap<>();
for (GeyserSession session : GeyserConnector.getInstance().getPlayers()) {
DeviceOS device = session.getClientData().getDeviceOS();
userPlatforms.put(device, userPlatforms.getOrDefault(device, 0) + 1);
@@ -106,6 +132,13 @@ public class DumpInfo {
}
}
+ @AllArgsConstructor
+ @Getter
+ public static class HashInfo {
+ private final String md5Hash;
+ private final String sha256Hash;
+ }
+
@Getter
public static class NetworkInfo {
