PaperMC/patches/server/Untrash-chat-handling.patch
Nassim Jahnke 7b0c67ff2e Slightly untrash Spigot chat handling
Vanilla technically allows chat messages with starting slashes now,
Spigot still accepts them as commands, most likely due to being too
lazy to properly differentiate between chat and command intent in
their implementation. This disallows modified clients to send chat
messages with slashes and makes sure chat validation always happens
on the netty event loop, rather than there and possibly being moved
to the main thread, thus having the delayed handling cause a bad
process order of message ids.
2022-06-08 21:42:49 +02:00

100 lines
5.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nassim Jahnke <nassim@njahnke.dev>
Date: Wed, 8 Jun 2022 21:30:34 +0200
Subject: [PATCH] Untrash chat handling
Vanilla technically allows chat messages with starting slashes now,
Spigot still accepts them as commands, most likely due to being too
lazy to properly differentiate between chat and command intent in
their implementation. This disallows modified clients to send chat
messages with slashes and makes sure chat validation always happens
on the netty event loop, rather than there and possibly being moved
to the main thread, thus having the delayed handling cause a bad
process order of message ids.
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java
@@ -0,0 +0,0 @@ public class ServerboundChatPacket implements Packet<ServerGamePacketListener> {
}
// Spigot Start
- private static final java.util.concurrent.ExecutorService executors = java.util.concurrent.Executors.newCachedThreadPool(
+ // Paper start - untrash chat event handling
+ public static final java.util.concurrent.ExecutorService executors = java.util.concurrent.Executors.newCachedThreadPool(
new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon( true ).setNameFormat( "Async Chat Thread - #%d" ).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build() ); // Paper
public void handle(final ServerGamePacketListener listener) {
- if ( !this.message.startsWith("/") )
- {
- ServerboundChatPacket.executors.execute( new Runnable() // Paper - Use #execute to propagate exceptions up instead of swallowing them
- {
-
- @Override
- public void run()
- {
- listener.handleChat( ServerboundChatPacket.this );
- }
- } );
+ if (this.message.startsWith("/")) {
+ // Just don't allow this instead of creating gigantic diff when untrashing more Spigot code
return;
}
- // Spigot End
listener.handleChat(this);
+ // Paper end - untrash chat event handling
}
public String getMessage() {
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@Override
public void handleChat(ServerboundChatPacket packet) {
- // CraftBukkit start - async chat
- // SPIGOT-3638
- if (this.server.isStopped()) {
- return;
- }
// CraftBukkit end
if (ServerGamePacketListenerImpl.isChatMessageIllegal(packet.getMessage())) {
this.server.scheduleOnMain(() -> { // Paper - push to main for event firing
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
if (this.tryHandleChat(packet.getMessage(), packet.getTimeStamp())) {
// CraftBukkit start
// this.filterTextPacket(packetplayinchat.getMessage(), (filteredtext) -> {
+ // Paper start - untrash chat handling
+ ServerboundChatPacket.executors.execute(() -> {
+ if (this.server.isStopped()) {
+ return;
+ }
this.handleChat(packet, FilteredText.passThrough(packet.getMessage())); // CraftBukkit - filter NYI
// });
+ });
+ // Paper end - untrash chat handling
// CraftBukkit end
}
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
this.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"));
}); // Paper - push to main for event firing
} else {
- PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
+ // Paper start - untrash chat handling
if (this.tryHandleChat(packet.command(), packet.timeStamp())) {
+ this.server.scheduleOnMain(() -> {
// CraftBukkit start
// CommandListenerWrapper commandlistenerwrapper = this.player.createCommandSourceStack().withSigningContext(serverboundchatcommandpacket.signingContext(this.player.getUUID()));
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}
this.detectRateSpam(true, "/" + packet.command()); // Spigot
// CraftBukkit end
+ });
+ // Paper end - untrash chat handling
}
}