-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mirai: Configurable chat message signatures
- Loading branch information
1 parent
a1a283d
commit 43ca79a
Showing
1 changed file
with
183 additions
and
0 deletions.
There are no files selected for viewing
183 changes: 183 additions & 0 deletions
183
patches/server/0079-Mirai-Configurable-chat-message-signatures.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: etil2jz <81570777+etil2jz@users.noreply.github.com> | ||
Date: Tue, 2 Aug 2022 14:48:12 +0200 | ||
Subject: [PATCH] Mirai: Configurable chat message signatures | ||
|
||
Fixed & Updated by Dreeam-qwq | ||
Original license: GPLv3 | ||
Original project: https://github.com/Dreeam-qwq/Mirai | ||
|
||
Original license: GPLv3 | ||
Original project: https://github.com/etil2jz/Mirai | ||
|
||
diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java | ||
index 397f985756c5bc6c11a32c844d536000dd922ed1..4a6a94c471d317dd8ea2ad83c5b97826208effb9 100644 | ||
--- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java | ||
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java | ||
@@ -356,7 +356,7 @@ public final class ChatProcessor { | ||
|
||
private void sendToServer(final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> 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, !GaleGlobalConfiguration.get().logToConsole.chat.notSecureMarker || ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage) ? null : "Not Secure"); // Gale - do not log Not Secure marker | ||
+ ChatProcessor.this.server.logChatMessage(toConsoleMessage.decoratedContent(), chatType, !org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled || !GaleGlobalConfiguration.get().logToConsole.chat.notSecureMarker || ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage) ? null : "Not Secure"); // Gale - do not log Not Secure marker // Leaf - Mirai - Configurable chat message signatures | ||
} | ||
} | ||
|
||
diff --git a/src/main/java/net/minecraft/network/protocol/game/ServerboundChatCommandPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundChatCommandPacket.java | ||
index b8c1f3b9afddc87d56541c8af63cffecfcdd2653..65594c88f660b9d535cd2c6960496fae031446ac 100644 | ||
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundChatCommandPacket.java | ||
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundChatCommandPacket.java | ||
@@ -16,7 +16,7 @@ public record ServerboundChatCommandPacket(String command, Instant timeStamp, lo | ||
buf.writeUtf(this.command, 256); | ||
buf.writeInstant(this.timeStamp); | ||
buf.writeLong(this.salt); | ||
- this.argumentSignatures.write(buf); | ||
+ if (org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) this.argumentSignatures.write(buf); // Leaf - Mirai - Configurable chat message signatures | ||
this.lastSeenMessages.write(buf); | ||
} | ||
|
||
diff --git a/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java | ||
index d1d2fc0c57523c1abf1e8bfec913c78927c3dafc..a39b0b643ee08ad3360ad5163af79c1d8b5887e4 100644 | ||
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java | ||
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java | ||
@@ -17,7 +17,7 @@ public record ServerboundChatPacket(String message, Instant timeStamp, long salt | ||
buf.writeUtf(this.message, 256); | ||
buf.writeInstant(this.timeStamp); | ||
buf.writeLong(this.salt); | ||
- buf.writeNullable(this.signature, MessageSignature::write); | ||
+ if (org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) buf.writeNullable(this.signature, MessageSignature::write); // Leaf - Mirai - Configurable chat message signatures | ||
this.lastSeenMessages.write(buf); | ||
} | ||
|
||
diff --git a/src/main/java/net/minecraft/network/protocol/status/ServerStatus.java b/src/main/java/net/minecraft/network/protocol/status/ServerStatus.java | ||
index c40979e2fa37acb2f3df493395f3ab6e185345d7..8f1ea047b76f083603e7c86d73c7eeab1c3f3f76 100644 | ||
--- a/src/main/java/net/minecraft/network/protocol/status/ServerStatus.java | ||
+++ b/src/main/java/net/minecraft/network/protocol/status/ServerStatus.java | ||
@@ -17,7 +17,7 @@ import net.minecraft.network.chat.ComponentSerialization; | ||
|
||
public record ServerStatus(Component description, Optional<ServerStatus.Players> players, Optional<ServerStatus.Version> version, Optional<ServerStatus.Favicon> favicon, boolean enforcesSecureChat) { | ||
public static final Codec<ServerStatus> CODEC = RecordCodecBuilder.create((instance) -> { | ||
- return instance.group(ComponentSerialization.CODEC.optionalFieldOf("description", CommonComponents.EMPTY).forGetter(ServerStatus::description), ServerStatus.Players.CODEC.optionalFieldOf("players").forGetter(ServerStatus::players), ServerStatus.Version.CODEC.optionalFieldOf("version").forGetter(ServerStatus::version), ServerStatus.Favicon.CODEC.optionalFieldOf("favicon").forGetter(ServerStatus::favicon), Codec.BOOL.optionalFieldOf("enforcesSecureChat", Boolean.valueOf(false)).forGetter(ServerStatus::enforcesSecureChat)).apply(instance, ServerStatus::new); | ||
+ return !org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled ? instance.group(ComponentSerialization.CODEC.optionalFieldOf("description", CommonComponents.EMPTY).forGetter(ServerStatus::description), ServerStatus.Players.CODEC.optionalFieldOf("players").forGetter(ServerStatus::players), ServerStatus.Version.CODEC.optionalFieldOf("version").forGetter(ServerStatus::version), ServerStatus.Favicon.CODEC.optionalFieldOf("favicon").forGetter(ServerStatus::favicon), Codec.BOOL.optionalFieldOf("enforcesSecureChat", Boolean.FALSE).forGetter(x -> true)).apply(instance, ServerStatus::new) : instance.group(ComponentSerialization.CODEC.optionalFieldOf("description", CommonComponents.EMPTY).forGetter(ServerStatus::description), ServerStatus.Players.CODEC.optionalFieldOf("players").forGetter(ServerStatus::players), ServerStatus.Version.CODEC.optionalFieldOf("version").forGetter(ServerStatus::version), ServerStatus.Favicon.CODEC.optionalFieldOf("favicon").forGetter(ServerStatus::favicon), Codec.BOOL.optionalFieldOf("enforcesSecureChat", Boolean.FALSE).forGetter(ServerStatus::enforcesSecureChat)).apply(instance, ServerStatus::new); // Leaf - Mirai - Configurable chat message signatures | ||
}); | ||
|
||
public static record Favicon(byte[] iconBytes) { | ||
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java | ||
index a83fb872a1d186a3547c12f518e1bb0067fffaf7..fbe299dc0e2d0903075f64f199a498c3e57f07ab 100644 | ||
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java | ||
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java | ||
@@ -681,6 +681,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface | ||
|
||
@Override | ||
public boolean enforceSecureProfile() { | ||
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) return false; // Leaf - Mirai - Configurable chat message signatures | ||
DedicatedServerProperties dedicatedserverproperties = this.getProperties(); | ||
|
||
// Paper start - Add setting for proxy online mode status | ||
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java | ||
index 9b87e62426f8805247b86eef0fe2939cf76aa1d8..8221cb9a4cc0cc382ed1dbc8e7c743d65ab91be5 100644 | ||
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java | ||
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java | ||
@@ -2262,7 +2262,7 @@ public class ServerPlayer extends Player { | ||
} | ||
|
||
public void sendServerStatus(ServerStatus metadata) { | ||
- this.connection.send(new ClientboundServerDataPacket(metadata.description(), metadata.favicon().map(ServerStatus.Favicon::iconBytes), metadata.enforcesSecureChat())); | ||
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) this.connection.send(new ClientboundServerDataPacket(metadata.description(), metadata.favicon().map(ServerStatus.Favicon::iconBytes), true)); else this.connection.send(new ClientboundServerDataPacket(metadata.description(), metadata.favicon().map(ServerStatus.Favicon::iconBytes), metadata.enforcesSecureChat())); // Leaf - Mirai - Configurable chat message signatures | ||
} | ||
|
||
@Override | ||
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java | ||
index 4a6bb425902b780ddfcc505e71d4ff70ff0babb9..843127487b5b7e3441bc76203590ec212e0edb9e 100644 | ||
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java | ||
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java | ||
@@ -279,10 +279,30 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack | ||
} | ||
|
||
public void send(Packet<?> packet) { | ||
+ // Leaf start - Mirai - Configurable chat message signatures | ||
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) { | ||
+ if (packet instanceof net.minecraft.network.protocol.game.ClientboundPlayerChatPacket chat) { | ||
+ packet = new net.minecraft.network.protocol.game.ClientboundSystemChatPacket(io.papermc.paper.adventure.PaperAdventure.asAdventure(chat.chatType().resolve(this.player.level().registryAccess()) | ||
+ .get().decorate(chat.unsignedContent() != null ? chat.unsignedContent() | ||
+ : Component.literal(chat.body().content()))), false); | ||
+ | ||
+ this.send(packet); | ||
+ return; | ||
+ } | ||
+ } | ||
+ // Leaf end - Mirai | ||
this.send(packet, (PacketSendListener) null); | ||
} | ||
|
||
public void send(Packet<?> packet, @Nullable PacketSendListener callbacks) { | ||
+ // Leaf start - Mirai - Configurable chat message signatures | ||
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) { | ||
+ if (packet instanceof net.minecraft.network.protocol.game.ClientboundPlayerChatPacket chat && callbacks != null) { | ||
+ this.send(chat); | ||
+ return; | ||
+ } | ||
+ } | ||
+ // Leaf end - Mirai | ||
// CraftBukkit start | ||
if (packet == null || this.processedDisconnect) { // Spigot | ||
return; | ||
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java | ||
index 25c7f47382f8a9949e2785c36f67dcf455d33f5a..b79c9c983dc960732927bbc13017e7eb028e485b 100644 | ||
--- a/src/main/java/net/minecraft/server/players/PlayerList.java | ||
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java | ||
@@ -1533,7 +1533,7 @@ public abstract class PlayerList { | ||
// Paper end | ||
boolean flag = this.verifyChatTrusted(message); | ||
|
||
- this.server.logChatMessage((unsignedFunction == null ? message.decoratedContent() : unsignedFunction.apply(this.server.console)), params, flag || !GaleGlobalConfiguration.get().logToConsole.chat.notSecureMarker ? null : "Not Secure"); // Paper // Gale - do not log Not Secure marker | ||
+ this.server.logChatMessage((unsignedFunction == null ? message.decoratedContent() : unsignedFunction.apply(this.server.console)), params, !org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled || flag || !GaleGlobalConfiguration.get().logToConsole.chat.notSecureMarker ? null : "Not Secure"); // Paper // Gale - do not log Not Secure marker // Leaf - Mirai - Configurable chat message signatures | ||
OutgoingChatMessage outgoingchatmessage = OutgoingChatMessage.create(message); | ||
boolean flag1 = false; | ||
|
||
@@ -1562,6 +1562,7 @@ public abstract class PlayerList { | ||
} | ||
|
||
public boolean verifyChatTrusted(PlayerChatMessage message) { // Paper - private -> public | ||
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) return true; // Leaf - Mirai - Configurable chat message signatures | ||
return message.hasSignature() && !message.hasExpiredServer(Instant.now()); | ||
} | ||
|
||
diff --git a/src/main/java/org/dreeam/leaf/config/modules/network/ChatMessageSignature.java b/src/main/java/org/dreeam/leaf/config/modules/network/ChatMessageSignature.java | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..81172f9b01d91dedb8830cf3623f541b51ca3c0f | ||
--- /dev/null | ||
+++ b/src/main/java/org/dreeam/leaf/config/modules/network/ChatMessageSignature.java | ||
@@ -0,0 +1,32 @@ | ||
+package org.dreeam.leaf.config.modules.network; | ||
+ | ||
+import com.electronwill.nightconfig.core.file.CommentedFileConfig; | ||
+import org.dreeam.leaf.config.ConfigInfo; | ||
+import org.dreeam.leaf.config.EnumConfigCategory; | ||
+import org.dreeam.leaf.config.IConfigModule; | ||
+ | ||
+public class ChatMessageSignature implements IConfigModule { | ||
+ | ||
+ @Override | ||
+ public EnumConfigCategory getCategory() { | ||
+ return EnumConfigCategory.NETWORK; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public String getBaseName() { | ||
+ return "chat_message_signature"; | ||
+ } | ||
+ | ||
+ @ConfigInfo(baseName = "enabled") | ||
+ public static boolean enabled = true; | ||
+ | ||
+ @Override | ||
+ public void onLoaded(CommentedFileConfig config) { | ||
+ config.setComment("network.chat_message_signature", """ | ||
+ Whether or not enable chat message signature, | ||
+ disable will prevent players to report chat messages. | ||
+ And also disables the popup when joining a server without | ||
+ 'secure chat', such as offline-mode servers. | ||
+ """); | ||
+ } | ||
+} |