From 46323b6eba5ff741c5ea8ecd9e1b50336cb7f3d0 Mon Sep 17 00:00:00 2001 From: Alpha Date: Thu, 23 Mar 2023 20:53:41 +0900 Subject: [PATCH] Tweak console logs (#16) --- .../0010-Console-Log-Configuration.patch | 21 ++++ patches/server/0011-Console-log-tweaks.patch | 101 ++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 patches/server/0010-Console-Log-Configuration.patch create mode 100644 patches/server/0011-Console-log-tweaks.patch diff --git a/patches/server/0010-Console-Log-Configuration.patch b/patches/server/0010-Console-Log-Configuration.patch new file mode 100644 index 0000000..115e2e7 --- /dev/null +++ b/patches/server/0010-Console-Log-Configuration.patch @@ -0,0 +1,21 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: AlphaKR93 +Date: Fri, 10 Mar 2023 20:35:27 +0900 +Subject: [PATCH] Console Log Configuration + + +diff --git a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java +index f1d4e242cbf3e7eb2fc7a3dd40ba7865e26b12b1..bb64e51eb20dc72661a6d84545361530dbd0fc3e 100644 +--- a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java ++++ b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java +@@ -19,4 +19,10 @@ public class GlobalConfiguration extends ConfigurationPart { + + @Setting(Configuration.VERSION_FIELD) + public int version = CURRENT_VERSION; ++ ++ public ConsoleLogs consoleLogs; ++ public class ConsoleLogs extends ConfigurationPart { ++ ++ ++ } + } diff --git a/patches/server/0011-Console-log-tweaks.patch b/patches/server/0011-Console-log-tweaks.patch new file mode 100644 index 0000000..16e333a --- /dev/null +++ b/patches/server/0011-Console-log-tweaks.patch @@ -0,0 +1,101 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: AlphaKR93 +Date: Fri, 10 Mar 2023 21:45:37 +0900 +Subject: [PATCH] Console log tweaks + +[Offine Warning Configuration Patch] +Original by Irochi +Licensed under the GPL 3.0 + +diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java +index 4d9bc4a62ebae0f3707900503576c64733de639f..20265e7c71c125bc5b77039f4901e230738e849f 100644 +--- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java ++++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java +@@ -353,7 +353,7 @@ public final class ChatProcessor { + + private void sendToServer(final ChatType.Bound chatType, final @Nullable Function msgFunction) { + final PlayerChatMessage toConsoleMessage = msgFunction == null ? ChatProcessor.this.message : ChatProcessor.this.message.withUnsignedContent(msgFunction.apply(ChatProcessor.this.server.console)); +- ChatProcessor.this.server.logChatMessage(toConsoleMessage.decoratedContent(), chatType, ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage) ? null : "Not Secure"); ++ ChatProcessor.this.server.logChatMessage(toConsoleMessage.decoratedContent(), chatType, ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage) || !org.plazmamc.plazma.configurations.GlobalConfiguration.get().consoleLogs.enableSecureChatMarker ? null : "Not Secure"); + } + } + +diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java +index 429ccd583ecd136a63862e94b8eb36b371e28d0f..efcee39cd7154493de04ca903edbd32b5901b191 100644 +--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java ++++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java +@@ -179,16 +179,6 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface + DedicatedServer.LOGGER.warn("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\""); + } + +- // Paper start - detect running as root +- if (io.papermc.paper.util.ServerEnvironment.userIsRootOrAdmin()) { +- 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."); +- DedicatedServer.LOGGER.warn("FOR MORE INFORMATION, SEE https://madelinemiller.dev/blog/root-minecraft-server/"); +- DedicatedServer.LOGGER.warn("****************************"); +- } +- // Paper end +- + DedicatedServer.LOGGER.info("Loading properties"); + DedicatedServerProperties dedicatedserverproperties = this.settings.getProperties(); + +@@ -320,7 +310,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface + String proxyFlavor = (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) ? "Velocity" : "BungeeCord"; + String proxyLink = (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) ? "https://docs.papermc.io/velocity/security" : "http://www.spigotmc.org/wiki/firewall-guide/"; + // Paper end +- if (!this.usesAuthentication()) { ++ if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().consoleLogs.enableOfflineWarnings && !this.usesAuthentication()) { // Plazma + DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!"); + DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware."); + // Spigot start +@@ -333,9 +323,20 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface + DedicatedServer.LOGGER.warn("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose."); + } + // Spigot end +- DedicatedServer.LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file."); ++ DedicatedServer.LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the \"server.properties\" file or set \"console-logs.offline-warning\" to \"false\" in the \"plazma.yml\" file."); // Plazma + } + ++ // Plazma start - Moved down ++ // Paper start - detect running as root ++ if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().consoleLogs.enableRootUserWarnings && io.papermc.paper.util.ServerEnvironment.userIsRootOrAdmin()) { ++ 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."); ++ DedicatedServer.LOGGER.warn("FOR MORE INFORMATION, SEE https://madelinemiller.dev/blog/root-minecraft-server/"); ++ DedicatedServer.LOGGER.warn("****************************"); ++ } ++ // Paper end ++ // Plazma end + + if (!OldUsersConverter.serverReadyAfterUserconversion(this)) { + return false; +diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java +index 1a288ebcaade0cc44c7d09478f4f2f8eee7a4269..916b42ffaf5d60aebc0cc3f3c0ee37bdb7b5ca2d 100644 +--- a/src/main/java/net/minecraft/server/players/PlayerList.java ++++ b/src/main/java/net/minecraft/server/players/PlayerList.java +@@ -1426,7 +1426,7 @@ public abstract class PlayerList { + } + public void broadcastChatMessage(PlayerChatMessage message, Predicate shouldSendFiltered, @Nullable ServerPlayer sender, ChatType.Bound params, @Nullable Function unsignedFunction) { + // Paper end +- boolean flag = this.verifyChatTrusted(message); ++ boolean flag = this.verifyChatTrusted(message) || !org.plazmamc.plazma.configurations.GlobalConfiguration.get().consoleLogs.enableSecureChatMarker; + + this.server.logChatMessage((unsignedFunction == null ? message.decoratedContent() : unsignedFunction.apply(this.server.console)), params, flag ? null : "Not Secure"); // Paper + OutgoingChatMessage outgoingchatmessage = OutgoingChatMessage.create(message); +diff --git a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java +index bb64e51eb20dc72661a6d84545361530dbd0fc3e..c408e9ccee77022c5d2172252e62c5c75c853610 100644 +--- a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java ++++ b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java +@@ -23,6 +23,9 @@ public class GlobalConfiguration extends ConfigurationPart { + public ConsoleLogs consoleLogs; + public class ConsoleLogs extends ConfigurationPart { + ++ public boolean enableOfflineWarnings = true; ++ public boolean enableRootUserWarnings = true; ++ public boolean enableSecureChatMarker = Boolean.getBoolean("plazma.disableAutoOptimizeConfigurations"); + + } + }