mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-01 15:36:45 +00:00
add id for servers hash of jvm name & version, processor info, memory size and plugins
This commit is contained in:
parent
851ac18f0d
commit
7b7118fe0d
@ -67,6 +67,7 @@ import com.volmit.iris.util.scheduling.Queue;
|
||||
import com.volmit.iris.util.scheduling.ShurikenQueue;
|
||||
import com.volmit.iris.util.sentry.Attachments;
|
||||
import com.volmit.iris.util.sentry.IrisLogger;
|
||||
import com.volmit.iris.util.sentry.ServerID;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import io.sentry.Sentry;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
@ -956,6 +957,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
var settings = IrisSettings.get().getSentry();
|
||||
if (settings.disableAutoReporting || Sentry.isEnabled()) return;
|
||||
Iris.info("Enabling Sentry for anonymous error reporting. You can disable this in the settings.");
|
||||
Iris.info("Your server ID is: " + ServerID.ID);
|
||||
Sentry.init(options -> {
|
||||
options.setDsn("https://b16ecc222e9c1e0c48faecacb906fd89@o4509451052646400.ingest.de.sentry.io/4509452722765904");
|
||||
if (settings.debug) {
|
||||
@ -976,6 +978,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
});
|
||||
});
|
||||
Sentry.configureScope(scope -> {
|
||||
if (settings.includeServerId) scope.setUser(ServerID.asUser());
|
||||
scope.addAttachment(Attachments.PLUGINS);
|
||||
scope.setTag("server", Bukkit.getVersion());
|
||||
scope.setTag("server.type", Bukkit.getName());
|
||||
|
@ -225,6 +225,7 @@ public class IrisSettings {
|
||||
|
||||
@Data
|
||||
public static class IrisSettingsSentry {
|
||||
public boolean includeServerId = true;
|
||||
public boolean disableAutoReporting = false;
|
||||
public boolean debug = false;
|
||||
}
|
||||
|
59
core/src/main/java/com/volmit/iris/util/sentry/ServerID.java
Normal file
59
core/src/main/java/com/volmit/iris/util/sentry/ServerID.java
Normal file
@ -0,0 +1,59 @@
|
||||
package com.volmit.iris.util.sentry;
|
||||
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import io.sentry.protocol.User;
|
||||
import lombok.SneakyThrows;
|
||||
import org.bukkit.Bukkit;
|
||||
import oshi.SystemInfo;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class ServerID {
|
||||
public static final String ID = calculate();
|
||||
|
||||
public static User asUser() {
|
||||
User u = new User();
|
||||
u.setId(ID);
|
||||
return u;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static String calculate() {
|
||||
Digest md = new Digest();
|
||||
md.update(System.getProperty("java.vm.name"));
|
||||
md.update(System.getProperty("java.vm.version"));
|
||||
md.update(new SystemInfo().getHardware().getProcessor().toString());
|
||||
md.update(Runtime.getRuntime().maxMemory());
|
||||
for (var p : Bukkit.getPluginManager().getPlugins()) {
|
||||
md.update(p.getName());
|
||||
}
|
||||
|
||||
return IO.bytesToHex(md.digest());
|
||||
}
|
||||
|
||||
private static final class Digest {
|
||||
private final MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
private final byte[] buffer = new byte[8];
|
||||
private final ByteBuffer wrapped = ByteBuffer.wrap(buffer);
|
||||
|
||||
private Digest() throws NoSuchAlgorithmException {
|
||||
}
|
||||
|
||||
public void update(String string) {
|
||||
if (string == null) return;
|
||||
md.update(string.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public void update(long Long) {
|
||||
wrapped.putLong(0, Long);
|
||||
md.update(buffer, 0, 8);
|
||||
}
|
||||
|
||||
public byte[] digest() {
|
||||
return md.digest();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user