2023-09-17 00:54:33 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Thu, 3 Mar 2016 01:17:12 -0600
|
|
|
|
Subject: [PATCH] Improve Player chat API handling
|
|
|
|
|
|
|
|
Properly split up the chat and command handling to reflect the server now
|
|
|
|
having separate packets for both, and the client always using the correct packet. Text
|
|
|
|
from a chat packet should never be parsed into a command, even if it starts with the `/`
|
|
|
|
character.
|
|
|
|
|
|
|
|
Add a missing async catcher and improve Spigot's async catcher error message.
|
|
|
|
|
|
|
|
== AT ==
|
|
|
|
public net.minecraft.server.network.ServerGamePacketListenerImpl isChatMessageIllegal(Ljava/lang/String;)Z
|
|
|
|
|
|
|
|
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
Co-authored-by: SoSeDiK <mrsosedik@gmail.com>
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2024-10-21 00:06:54 +02:00
|
|
|
index 3a67b2b6a6d3204b2a7bbe8adbf2b0ecf7898551..02b9e1ed57f5d65698c461387ff7d48450e6a70f 100644
|
2023-09-17 00:54:33 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2024-06-13 19:12:48 +02:00
|
|
|
@@ -2013,7 +2013,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
2023-09-17 00:54:33 +02:00
|
|
|
}
|
|
|
|
OutgoingChatMessage outgoing = OutgoingChatMessage.create(original);
|
|
|
|
|
|
|
|
- if (!async && s.startsWith("/")) {
|
|
|
|
+ if (false && !async && s.startsWith("/")) { // Paper - Don't handle commands in chat logic
|
|
|
|
this.handleCommand(s);
|
|
|
|
} else if (this.player.getChatVisibility() == ChatVisiblity.SYSTEM) {
|
|
|
|
// Do nothing, this is coming from a plugin
|
2024-06-13 19:12:48 +02:00
|
|
|
@@ -2100,7 +2100,8 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
2023-09-17 00:54:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- private void handleCommand(String s) {
|
|
|
|
+ public void handleCommand(String s) { // Paper - private -> public
|
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp("Command Dispatched Async: " + s); // Paper - Add async catcher
|
|
|
|
co.aikar.timings.MinecraftTimings.playerCommandTimer.startTiming(); // Paper
|
|
|
|
if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot
|
|
|
|
this.LOGGER.info(this.player.getScoreboardName() + " issued server command: " + s);
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2024-10-21 00:06:54 +02:00
|
|
|
index 8f79d7611c3ee1c817d5671152e459ec4f413418..441a8d3355e0db773a5da330bf9361234da1ca89 100644
|
2023-09-17 00:54:33 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2024-10-21 00:06:54 +02:00
|
|
|
@@ -934,7 +934,7 @@ public final class CraftServer implements Server {
|
2023-09-17 00:54:33 +02:00
|
|
|
public boolean dispatchCommand(CommandSender sender, String commandLine) {
|
|
|
|
Preconditions.checkArgument(sender != null, "sender cannot be null");
|
|
|
|
Preconditions.checkArgument(commandLine != null, "commandLine cannot be null");
|
|
|
|
- org.spigotmc.AsyncCatcher.catchOp("command dispatch"); // Spigot
|
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp("Command Dispatched Async: " + commandLine); // Spigot // Paper - Include command in error message
|
|
|
|
|
|
|
|
if (this.commandMap.dispatch(sender, commandLine)) {
|
|
|
|
return true;
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2024-10-21 00:06:54 +02:00
|
|
|
index 545da59af2436b9a4363ec459456c8f15650b79f..9751cace64d9ad2b8b55080b13834e8ccb056b42 100644
|
2023-09-17 00:54:33 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2024-06-13 19:12:48 +02:00
|
|
|
@@ -546,7 +546,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2023-09-17 00:54:33 +02:00
|
|
|
|
|
|
|
if (this.getHandle().connection == null) return;
|
|
|
|
|
|
|
|
- this.getHandle().connection.chat(msg, PlayerChatMessage.system(msg), false);
|
|
|
|
+ // Paper start - Improve chat handling
|
|
|
|
+ if (ServerGamePacketListenerImpl.isChatMessageIllegal(msg)) {
|
|
|
|
+ this.getHandle().connection.disconnect(Component.translatable("multiplayer.disconnect.illegal_characters"));
|
|
|
|
+ } else {
|
|
|
|
+ if (msg.startsWith("/")) {
|
|
|
|
+ this.getHandle().connection.handleCommand(msg);
|
|
|
|
+ } else {
|
2024-04-19 21:47:24 +02:00
|
|
|
+ final PlayerChatMessage playerChatMessage = PlayerChatMessage.system(msg).withUnsignedContent(Component.literal(msg));
|
2023-09-17 00:54:33 +02:00
|
|
|
+ // TODO chat decorating
|
|
|
|
+ // TODO text filtering
|
|
|
|
+ this.getHandle().connection.chat(msg, playerChatMessage, false);
|
|
|
|
+ }
|
|
|
|
+ }
|
2024-01-23 14:34:17 +01:00
|
|
|
+ // Paper end - Improve chat handling
|
2023-09-17 00:54:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|