3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-16 11:30:06 +01:00
Paper/patches/server/0906-Untrash-chat-handling.patch

101 Zeilen
5.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nassim Jahnke <jahnke.nassim@gmail.com>
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 3825aa2c381a3ee77e05bea520ff5fb828733857..4e9832d5753b98621e68246ffc5d80c86a3b5ed3 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java
@@ -40,24 +40,16 @@ 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 a9193fcd719e403e4b821a2a0cf22fe2a8490943..03507b5ac5908962e9ebc4b98f53f23110573baa 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2104,11 +2104,6 @@ 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
@@ -2118,8 +2113,15 @@ 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
}
@@ -2133,8 +2135,9 @@ 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()));
@@ -2147,6 +2150,8 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}
this.detectRateSpam(true, "/" + packet.command()); // Spigot
// CraftBukkit end
+ });
+ // Paper end - untrash chat handling
}
}