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

108 lines
6.7 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2023-12-11 01:20:31 +00:00
From: Telesphoreo <me@telesphoreo.me>
Date: Sun, 10 Dec 2023 18:48:55 -0600
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
2023-12-11 01:20:31 +00:00
index 74cf1c043beef03cfd5adf481414a5ee78bef2a6..939f4a0639c847b94cfc9acf1409a7a3fc5ae58f 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;
2023-12-11 01:20:31 +00:00
+import me.totalfreedom.scissors.ScissorsConfig;
import net.minecraft.server.level.ServerPlayer;
public interface OutgoingChatMessage {
2023-12-11 01:20:31 +00:00
@@ -44,10 +45,22 @@ public interface OutgoingChatMessage {
// Paper end
PlayerChatMessage playerChatMessage = this.message.filter(filterMaskEnabled);
playerChatMessage = unsigned != null ? playerChatMessage.withUnsignedContent(unsigned) : playerChatMessage; // Paper
- if (!playerChatMessage.isFullyFiltered()) {
2023-12-11 01:20:31 +00:00
+ // Sccissors start
+ if (!playerChatMessage.isFullyFiltered() && ScissorsConfig.chatSignaturesEnabled) {
sender.connection.sendPlayerChatMessage(playerChatMessage, params);
+ return;
}
+ sender.connection.sendPlayerChatMessage(new PlayerChatMessage(
+ SignedMessageLink.unsigned(playerChatMessage.sender()),
+ null,
+ SignedMessageBody.unsigned(playerChatMessage.signedContent()),
+ unsigned,
+ playerChatMessage.filterMask(),
+ playerChatMessage.result()
+ ), params);
+ // Scissors end
2023-12-11 01:20:31 +00:00
+
}
}
}
diff --git a/src/main/java/net/minecraft/network/chat/SignedMessageChain.java b/src/main/java/net/minecraft/network/chat/SignedMessageChain.java
2024-01-18 23:05:55 +00:00
index 22ead092ae984d1eaa052fe97981ce3c49b521d8..77be2549c1c836fd21f510ed1082cbd22ec60f09 100644
--- a/src/main/java/net/minecraft/network/chat/SignedMessageChain.java
+++ b/src/main/java/net/minecraft/network/chat/SignedMessageChain.java
2023-12-11 01:20:31 +00:00
@@ -5,6 +5,8 @@ import java.time.Instant;
import java.util.UUID;
2023-12-11 01:20:31 +00:00
import java.util.function.BooleanSupplier;
import javax.annotation.Nullable;
2023-12-11 01:20:31 +00:00
+
+import me.totalfreedom.scissors.ScissorsConfig;
import net.minecraft.util.SignatureUpdater;
import net.minecraft.util.SignatureValidator;
import net.minecraft.util.Signer;
2023-12-11 01:20:31 +00:00
@@ -46,7 +48,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
2024-01-18 23:05:55 +00:00
index 24bd79c80b1b8fadce647febcf461f564e1eae88..e94f9879bfd06e9f45373389bbdce67ee05a9773 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-10-15 22:45:13 +00:00
@@ -1,5 +1,6 @@
package net.minecraft.server.network;
2023-12-11 01:20:31 +00:00
+import me.totalfreedom.scissors.ScissorsConfig;
2023-10-15 22:45:13 +00:00
import me.totalfreedom.scissors.event.player.SpectatorTeleportEvent; // Scissors
import com.google.common.collect.Lists;
import com.google.common.primitives.Floats;
2024-01-18 23:06:06 +00:00
@@ -2249,7 +2250,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) {
2023-12-11 01:20:31 +00:00
ServerGamePacketListenerImpl.LOGGER.warn("Failed to update secure chat state for {}: '{}'", this.player.getGameProfile().getName(), exception.getComponent().getString());
- 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));
2024-01-18 23:05:55 +00:00
@@ -2297,6 +2298,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
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
}
2024-01-18 23:05:55 +00:00
@@ -2495,6 +2497,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
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
}
2024-01-18 23:05:55 +00:00
@@ -3473,6 +3476,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@Override
public void handleChatSessionUpdate(ServerboundChatSessionUpdatePacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
+ if (!ScissorsConfig.chatSignaturesEnabled) return; // Scissors
RemoteChatSession.Data remotechatsession_a = packet.chatSession();
ProfilePublicKey.Data profilepublickey_a = this.chatSession != null ? this.chatSession.profilePublicKey().data() : null;
ProfilePublicKey.Data profilepublickey_a1 = remotechatsession_a.profilePublicKey();