Scissors/patches/server/0035-Add-configuration-option-to-disable-chat-signatures.patch

102 lines
6.1 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Tue, 31 Jan 2023 23:16:52 +0000
Subject: [PATCH] Add configuration option to disable chat signatures
diff --git a/src/main/java/net/minecraft/network/chat/OutgoingChatMessage.java b/src/main/java/net/minecraft/network/chat/OutgoingChatMessage.java
index 74cf1c043beef03cfd5adf481414a5ee78bef2a6..1a44bad14ce764d6c09f38065ee8e5f0da4975aa 100644
--- a/src/main/java/net/minecraft/network/chat/OutgoingChatMessage.java
+++ b/src/main/java/net/minecraft/network/chat/OutgoingChatMessage.java
@@ -1,5 +1,6 @@
package net.minecraft.network.chat;
+import me.totalfreedom.scissors.ScissorsConfig; // Scissors
import net.minecraft.server.level.ServerPlayer;
public interface OutgoingChatMessage {
@@ -44,10 +45,25 @@ public interface OutgoingChatMessage {
// Paper end
PlayerChatMessage playerChatMessage = this.message.filter(filterMaskEnabled);
playerChatMessage = unsigned != null ? playerChatMessage.withUnsignedContent(unsigned) : playerChatMessage; // Paper
- if (!playerChatMessage.isFullyFiltered()) {
+ // Scissors start
+ if (!playerChatMessage.isFullyFiltered() && ScissorsConfig.chatSignaturesEnabled) {
sender.connection.sendPlayerChatMessage(playerChatMessage, params);
+ return;
}
+ if (sender.getServer().server.getOnlineMode()) {
+ sender.connection.sendDisguisedChatMessage(playerChatMessage.decoratedContent(), params);
+ } else {
+ sender.connection.sendPlayerChatMessage(new PlayerChatMessage(
+ SignedMessageLink.unsigned(playerChatMessage.sender()),
+ null,
+ SignedMessageBody.unsigned(playerChatMessage.signedContent()),
+ unsigned,
+ playerChatMessage.filterMask(),
+ playerChatMessage.result()
+ ), params);
+ }
+ // Scissors end
}
}
}
diff --git a/src/main/java/net/minecraft/network/chat/SignedMessageChain.java b/src/main/java/net/minecraft/network/chat/SignedMessageChain.java
index c0a80824a0307ea673805015119cc834b268f0dc..9f28f86b1b56ea55ab39f6ac988c1f47c5312c6c 100644
--- a/src/main/java/net/minecraft/network/chat/SignedMessageChain.java
+++ b/src/main/java/net/minecraft/network/chat/SignedMessageChain.java
@@ -4,6 +4,7 @@ import com.mojang.logging.LogUtils;
import java.time.Instant;
import java.util.UUID;
import javax.annotation.Nullable;
+import me.totalfreedom.scissors.ScissorsConfig; // Scissors
import net.minecraft.util.SignatureUpdater;
import net.minecraft.util.SignatureValidator;
import net.minecraft.util.Signer;
@@ -41,7 +42,7 @@ 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())) {
+ if (playerChatMessage.hasExpiredServer(Instant.now()) && ScissorsConfig.chatSignaturesEnabled) { // Scissors
LOGGER.warn("Received expired chat: '{}'. Is the client/server system time unsynchronized?", (Object)body.content());
}
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index d428490171bb1c0209ca9a279c2b1e1e1dfcf914..8274514733caf0fb3c3db5836a3ab9bd204c4378 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 @@
package net.minecraft.server.network;
+import me.totalfreedom.scissors.ScissorsConfig; // Scissors
import me.totalfreedom.scissors.event.player.SpectatorTeleportEvent; // Scissors
import com.google.common.collect.Lists;
import com.google.common.primitives.Floats;
@@ -2311,7 +2312,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));
@@ -2367,6 +2368,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
Optional<LastSeenMessages> optional = this.lastSeenMessages.applyUpdate(acknowledgment);
if (optional.isEmpty()) {
+ if (!ScissorsConfig.chatSignaturesEnabled) return optional; // Scissors
ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString());
this.disconnect(ServerGamePacketListenerImpl.CHAT_VALIDATION_FAILED, org.bukkit.event.player.PlayerKickEvent.Cause.CHAT_VALIDATION_FAILED); // Paper - kick event causes
}
@@ -2602,6 +2604,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
synchronized (this.lastSeenMessages) {
if (!this.lastSeenMessages.applyOffset(packet.offset())) {
+ if (!ScissorsConfig.chatSignaturesEnabled) return; // Scissors
ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString());
this.disconnect(ServerGamePacketListenerImpl.CHAT_VALIDATION_FAILED, org.bukkit.event.player.PlayerKickEvent.Cause.CHAT_VALIDATION_FAILED); // Paper - kick event causes
}