Files
KeYiMC/patches/server/0007-Options-of-warnings.patch
2022-11-19 11:02:48 +08:00

72 lines
4.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: nostalgic853 <yuu8583@proton.me>
Date: Sat, 22 Oct 2022 17:23:09 +0800
Subject: [PATCH] Options of warnings
Let users decide if we should warn while running in a root user
Let users decide if we should warn while running in offline mode
Let users decide if we should warn while running in proxy mode
diff --git a/src/main/java/cc/keyimc/keyi/KeyiConfig.java b/src/main/java/cc/keyimc/keyi/KeyiConfig.java
index bc9403d002ef24e71be67a962d099f5d73db9540..5582c15a37fbbf74d2039ba15d67684f5294a46d 100644
--- a/src/main/java/cc/keyimc/keyi/KeyiConfig.java
+++ b/src/main/java/cc/keyimc/keyi/KeyiConfig.java
@@ -132,4 +132,14 @@ public final class KeyiConfig {
public static void reload() {
KeyiConfig.init((File) MinecraftServer.getServer().options.valueOf("keyi-settings"));
}
+
+ public static boolean enableRootUserWarning = true;
+ public static boolean enableOfflineModeWarning = true;
+ public static boolean enableProxyUnsafeWarning = true;
+
+ private static void misc() {
+ enableRootUserWarning = getBoolean("misc.enable-root-user-warning", enableRootUserWarning);
+ enableOfflineModeWarning = getBoolean("misc.enable-offline-mode-warning", enableOfflineModeWarning);
+ enableProxyUnsafeWarning = getBoolean("misc.enable-proxy-unsafe-warning", enableProxyUnsafeWarning);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index a9c4f1192f53fea55b2f5edc8a91b6911489e2d3..5420915b21bbd17eeaba2ba45e08399a3abe6952 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -185,7 +185,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
}
// Paper start - detect running as root
- if (io.papermc.paper.util.ServerEnvironment.userIsRootOrAdmin()) {
+ if (io.papermc.paper.util.ServerEnvironment.userIsRootOrAdmin() && cc.keyimc.keyi.KeyiConfig.enableRootUserWarning) { // KeYi start - let user decide if we should warn
DedicatedServer.LOGGER.warn("****************************");
DedicatedServer.LOGGER.warn("YOU ARE RUNNING THIS SERVER AS AN ADMINISTRATIVE OR ROOT USER. THIS IS NOT ADVISED.");
DedicatedServer.LOGGER.warn("YOU ARE OPENING YOURSELF UP TO POTENTIAL RISKS WHEN DOING THIS.");
@@ -326,10 +326,15 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
// CraftBukkit end
if (!this.usesAuthentication()) {
- DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
- DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
+ // KeYi start - let users choose if we should warn while running in offline mode
+ if (cc.keyimc.keyi.KeyiConfig.enableOfflineModeWarning) {
+ DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
+ DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
+ DedicatedServer.LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file."); // KeYi - move up
+ }
+ // KeYi end
// Spigot start
- if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()) { // Purpur
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() && cc.keyimc.keyi.KeyiConfig.enableProxyUnsafeWarning) { // Purpur // KeYi - Let users decide if we should warn while running in proxy mode
DedicatedServer.LOGGER.warn("Whilst this makes it possible to use BungeeCord or Velocity, unless access to your server is properly restricted, it also opens up the ability for hackers to connect with any username they choose."); // Purpur
DedicatedServer.LOGGER.warn("Please see http://www.spigotmc.org/wiki/firewall-guide/ for further information.");
} else {
@@ -337,7 +342,6 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
DedicatedServer.LOGGER.warn("You will not be offered any support as long as the server allows offline-mode players to join."); // Purpur
}
// Spigot end
- DedicatedServer.LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
}