From ab658d7e350112631ca2c28baffbce7c223e4843 Mon Sep 17 00:00:00 2001 From: allinkdev <44676012+allinkdev@users.noreply.github.com> Date: Wed, 21 Jun 2023 04:41:08 +0100 Subject: [PATCH] Improve chat signature disabling patch (#104) * Do not log expired chat message if signatures are disabled * Do not kick when chat signatures are disabled --- ...-Scissors-configuration-file-command.patch | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/patches/server/0035-Add-Scissors-configuration-file-command.patch b/patches/server/0035-Add-Scissors-configuration-file-command.patch index c84f1e8..717a950 100644 --- a/patches/server/0035-Add-Scissors-configuration-file-command.patch +++ b/patches/server/0035-Add-Scissors-configuration-file-command.patch @@ -452,6 +452,29 @@ index 74cf1c043beef03cfd5adf481414a5ee78bef2a6..182f68359a7a8c0b331acd103ed3952e } } } +diff --git a/src/main/java/net/minecraft/network/chat/SignedMessageChain.java b/src/main/java/net/minecraft/network/chat/SignedMessageChain.java +index c0a80824a0307ea673805015119cc834b268f0dc..cc67d0e351333731d953d5732215b19d1c36d4bc 100644 +--- a/src/main/java/net/minecraft/network/chat/SignedMessageChain.java ++++ b/src/main/java/net/minecraft/network/chat/SignedMessageChain.java +@@ -4,6 +4,8 @@ import com.mojang.logging.LogUtils; + import java.time.Instant; + import java.util.UUID; + import javax.annotation.Nullable; ++ ++import me.totalfreedom.scissors.ScissorsConfig; + import net.minecraft.util.SignatureUpdater; + import net.minecraft.util.SignatureValidator; + import net.minecraft.util.Signer; +@@ -41,7 +43,8 @@ public class SignedMessageChain { + if (!playerChatMessage.verify(signatureValidator)) { + throw new SignedMessageChain.DecodeException(Component.translatable("multiplayer.disconnect.unsigned_chat"), true, org.bukkit.event.player.PlayerKickEvent.Cause.UNSIGNED_CHAT); // Paper - kick event causes + } else { +- if (playerChatMessage.hasExpiredServer(Instant.now())) { ++ // Scissors - Do not log this message if chat signatures are disabled ++ if (playerChatMessage.hasExpiredServer(Instant.now()) && ScissorsConfig.chatSignaturesEnabled) { + LOGGER.warn("Received expired chat: '{}'. Is the client/server system time unsynchronized?", (Object)body.content()); + } + diff --git a/src/main/java/net/minecraft/server/Main.java b/src/main/java/net/minecraft/server/Main.java index dae36c6452ccd57a436dd918547b64d59957ab0a..d450cf3cf8ab5cbb5d32a28ee2e4a6717941adef 100644 --- a/src/main/java/net/minecraft/server/Main.java @@ -486,7 +509,7 @@ index 9f422cbeaa52b3e6a0a27af4f8ad4ddb7808483f..bbfb536ddec7f44d2a75d35ab495be26 this.setFlightAllowed(dedicatedserverproperties.allowFlight); this.setMotd(dedicatedserverproperties.motd); diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 7e473ebbc8d89b01e1ee09047d43d075906d0d7c..2ec716cdfec40106d72552b24b741c4219a6e196 100644 +index 7e473ebbc8d89b01e1ee09047d43d075906d0d7c..0f7311755c5718a96d8a295a44fd85290d5d4425 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -1,5 +1,6 @@ @@ -496,6 +519,15 @@ index 7e473ebbc8d89b01e1ee09047d43d075906d0d7c..2ec716cdfec40106d72552b24b741c42 import me.totalfreedom.scissors.event.player.SpectatorTeleportEvent; import com.google.common.collect.Lists; import com.google.common.primitives.Floats; +@@ -2323,7 +2324,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic + } + + private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) { +- if (exception.shouldDisconnect()) { ++ if (exception.shouldDisconnect() && ScissorsConfig.chatSignaturesEnabled) { // Scissors - Do not kick when chat signatures are disabled + this.disconnect(exception.getComponent(), exception.kickCause); // Paper - kick event causes + } else { + this.player.sendSystemMessage(exception.getComponent().copy().withStyle(ChatFormatting.RED)); @@ -2379,6 +2380,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic Optional optional = this.lastSeenMessages.applyUpdate(acknowledgment);