From f6440bde07e9549a44a15680e10ca65b36e9e46e Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Fri, 22 Dec 2023 15:33:22 +0100 Subject: [PATCH 1/3] - Added Sufficient Permission check --- .../iris/core/safeguard/ServerBootSFG.java | 24 +++++++++++++++++++ .../volmit/iris/core/safeguard/UtilsSFG.java | 4 ++++ .../iris/util/mantle/TectonicPlate.java | 4 ++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/safeguard/ServerBootSFG.java b/core/src/main/java/com/volmit/iris/core/safeguard/ServerBootSFG.java index 4cf20c30f..0fe8169ce 100644 --- a/core/src/main/java/com/volmit/iris/core/safeguard/ServerBootSFG.java +++ b/core/src/main/java/com/volmit/iris/core/safeguard/ServerBootSFG.java @@ -19,6 +19,7 @@ public class ServerBootSFG { public static final Map incompatibilities = new HashMap<>(); public static boolean isJDK17 = true; public static boolean isJRE = false; + public static boolean hasPrivileges = false; public static boolean unsuportedversion = false; protected static boolean safeguardPassed; public static boolean passedserversoftware = true; @@ -82,6 +83,11 @@ public class ServerBootSFG { joiner.add("Unsupported JDK"); severityMedium++; } + if (!hasPrivileges()){ + hasPrivileges = true; + joiner.add("Has insufficient Privileges"); + severityHigh++; + } allIncompatibilities = joiner.toString(); @@ -122,6 +128,24 @@ public class ServerBootSFG { return path != null && checkJavac(path + File.separator + "bin"); } + public static boolean hasPrivileges() { + File pv = new File(Bukkit.getWorldContainer() + "iristest.json"); + if (pv.exists()){ + pv.delete(); + } + try { + if (pv.createNewFile()){ + if (pv.canWrite() && pv.canRead()){ + pv.delete(); + return true; + } + } + } catch (Exception e){ + return false; + } + return false; + } + private static boolean checkJavac(String path) { return !path.isEmpty() && (new File(path, "javac").exists() || new File(path, "javac.exe").exists()); } diff --git a/core/src/main/java/com/volmit/iris/core/safeguard/UtilsSFG.java b/core/src/main/java/com/volmit/iris/core/safeguard/UtilsSFG.java index b0cd659d6..49f1d9476 100644 --- a/core/src/main/java/com/volmit/iris/core/safeguard/UtilsSFG.java +++ b/core/src/main/java/com/volmit/iris/core/safeguard/UtilsSFG.java @@ -43,6 +43,10 @@ public class UtilsSFG { Iris.safeguard(C.RED + "Unsupported Server Software"); Iris.safeguard(C.RED + "- Please consider using Paper or Purpur instead."); } + if (!ServerBootSFG.hasPrivileges) { + Iris.safeguard(C.RED + "Insufficient Privileges"); + Iris.safeguard(C.RED + "- The server has insufficient Privileges to run iris. Please contact support."); + } if (!ServerBootSFG.isJDK17) { Iris.safeguard(C.YELLOW + "Unsupported java version"); Iris.safeguard(C.YELLOW + "- Please consider using JDK 17 Instead of JDK " + Iris.getJavaVersion()); diff --git a/core/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java b/core/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java index a93cb9c4d..a916ea1d8 100644 --- a/core/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java +++ b/core/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java @@ -83,7 +83,7 @@ public class TectonicPlate { public static TectonicPlate read(int worldHeight, File file) throws IOException, ClassNotFoundException { FileInputStream fin = new FileInputStream(file); DataInputStream din; - if (file.getName().endsWith("ttp")) { + if (file.getName().endsWith("ttp.lz4")) { GZIPInputStream gzi = new GZIPInputStream(fin); din = new DataInputStream(gzi); } else { @@ -174,7 +174,7 @@ public class TectonicPlate { PrecisionStopwatch p = PrecisionStopwatch.start(); FileOutputStream fos = new FileOutputStream(file); DataOutputStream dos; - if (file.getName().endsWith("ttp")) { + if (file.getName().endsWith("ttp.lz4")) { GZIPOutputStream gzo = new GZIPOutputStream(fos); dos = new DataOutputStream(gzo); } else { From 55ed9d7132baf19cb144e3829f0150ca8677804a Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Fri, 22 Dec 2023 15:59:05 +0100 Subject: [PATCH 2/3] - Added DiskSpace check --- .../iris/core/safeguard/ServerBootSFG.java | 19 ++++++++++++++++++- .../volmit/iris/core/safeguard/UtilsSFG.java | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/volmit/iris/core/safeguard/ServerBootSFG.java b/core/src/main/java/com/volmit/iris/core/safeguard/ServerBootSFG.java index 0fe8169ce..0a8b2983c 100644 --- a/core/src/main/java/com/volmit/iris/core/safeguard/ServerBootSFG.java +++ b/core/src/main/java/com/volmit/iris/core/safeguard/ServerBootSFG.java @@ -6,6 +6,7 @@ import com.volmit.iris.core.nms.v1X.NMSBinding1X; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; +import javax.print.attribute.standard.Severity; import java.io.File; import java.util.HashMap; import java.util.Map; @@ -18,6 +19,7 @@ import static com.volmit.iris.core.safeguard.IrisSafeguard.*; public class ServerBootSFG { public static final Map incompatibilities = new HashMap<>(); public static boolean isJDK17 = true; + public static boolean hasEnoughDiskSpace = false; public static boolean isJRE = false; public static boolean hasPrivileges = false; public static boolean unsuportedversion = false; @@ -85,7 +87,12 @@ public class ServerBootSFG { } if (!hasPrivileges()){ hasPrivileges = true; - joiner.add("Has insufficient Privileges"); + joiner.add("Insufficient Privileges"); + severityHigh++; + } + if (!enoughDiskSpace()){ + hasEnoughDiskSpace = false; + joiner.add("Insufficient Disk Space"); severityHigh++; } @@ -146,6 +153,16 @@ public class ServerBootSFG { return false; } + public static boolean enoughDiskSpace() { + File freeSpace = new File(Bukkit.getWorldContainer() + "."); + double gigabytes = freeSpace.getFreeSpace() / (1024.0 * 1024.0 * 1024.0); + if (gigabytes > 3){ + return true; + } else { + return false; + } + } + private static boolean checkJavac(String path) { return !path.isEmpty() && (new File(path, "javac").exists() || new File(path, "javac.exe").exists()); } diff --git a/core/src/main/java/com/volmit/iris/core/safeguard/UtilsSFG.java b/core/src/main/java/com/volmit/iris/core/safeguard/UtilsSFG.java index 49f1d9476..b4dac8a9d 100644 --- a/core/src/main/java/com/volmit/iris/core/safeguard/UtilsSFG.java +++ b/core/src/main/java/com/volmit/iris/core/safeguard/UtilsSFG.java @@ -47,6 +47,10 @@ public class UtilsSFG { Iris.safeguard(C.RED + "Insufficient Privileges"); Iris.safeguard(C.RED + "- The server has insufficient Privileges to run iris. Please contact support."); } + if (!ServerBootSFG.hasEnoughDiskSpace) { + Iris.safeguard(C.RED + "Insufficient Disk Space"); + Iris.safeguard(C.RED + "- The server has insufficient Free DiskSpace to run iris required 3GB+."); + } if (!ServerBootSFG.isJDK17) { Iris.safeguard(C.YELLOW + "Unsupported java version"); Iris.safeguard(C.YELLOW + "- Please consider using JDK 17 Instead of JDK " + Iris.getJavaVersion()); From 5127b7c95933a40993b9332854456107db42a761 Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Fri, 22 Dec 2023 16:16:48 +0100 Subject: [PATCH 3/3] - Added DiskSpace to Splash - Changed form ofSize to contain a space --- core/src/main/java/com/volmit/iris/Iris.java | 2 ++ .../main/java/com/volmit/iris/util/format/Form.java | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/Iris.java b/core/src/main/java/com/volmit/iris/Iris.java index 020756d42..535c01120 100644 --- a/core/src/main/java/com/volmit/iris/Iris.java +++ b/core/src/main/java/com/volmit/iris/Iris.java @@ -788,6 +788,7 @@ public class Iris extends VolmitPlugin implements Listener { padd + C.GRAY + " " + C.DARK_GRAY + "@@@" + C.GRAY + "@@@@@@@@@@@@@@" }; String[] splash; + File freeSpace = new File(Bukkit.getWorldContainer() + "."); if (unstablemode) { splash = splashunstable; } else if (warningmode) { @@ -835,6 +836,7 @@ public class Iris extends VolmitPlugin implements Listener { Iris.info("Process Threads: " + getCPUThreads()); Iris.info("Process Memory: " + getHardware.getProcessMemory() + " MB"); + Iris.info("Free DiskSpace: " + Form.ofSize(freeSpace.getFreeSpace(), 1024)); if (getHardware.getProcessMemory() < 5999) { Iris.warn("6GB+ Ram is recommended"); } diff --git a/core/src/main/java/com/volmit/iris/util/format/Form.java b/core/src/main/java/com/volmit/iris/util/format/Form.java index a38867767..bb2e7ec27 100644 --- a/core/src/main/java/com/volmit/iris/util/format/Form.java +++ b/core/src/main/java/com/volmit/iris/util/format/Form.java @@ -683,23 +683,23 @@ public class Form { */ public static String ofSize(long s, int div) { double d = (double) s; - String sub = "Bytes"; + String sub = " Bytes"; if (d > div - 1) { d /= div; - sub = "KB"; + sub = " KB"; if (d > div - 1) { d /= div; - sub = "MB"; + sub = " MB"; if (d > div - 1) { d /= div; - sub = "GB"; + sub = " GB"; if (d > div - 1) { d /= div; - sub = "TB"; + sub = " TB"; } } }