mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-09 04:09:54 +01:00
81 lines
4.6 KiB
Diff
81 lines
4.6 KiB
Diff
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
|
|
index e85268e4c20371d4264effb70ae9fa8e435f8766..98266c0349d21fc1ebf0d34a3d898825d477d6e5 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -1918,7 +1918,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
}
|
|
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
|
|
@@ -2002,7 +2002,8 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
}
|
|
}
|
|
|
|
- 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
|
|
index c2289c8ef49c73d662a67eab7a2b8c0cf9bb31a9..3e3c3db4a9a4474af79d2470da2ab133eef7cf4c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -889,7 +889,7 @@ public final class CraftServer implements Server {
|
|
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
|
|
index 5ded753f030cad268f8aaeaf242985c67da2ca8d..965f40d5acb8cfe401e22c4c15efa84b36ac3ace 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -452,7 +452,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
|
|
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 {
|
|
+ final PlayerChatMessage playerChatMessage = PlayerChatMessage.system(msg).withResult(new net.minecraft.network.chat.ChatDecorator.ModernResult(Component.literal(msg), true, false));
|
|
+ // TODO chat decorating
|
|
+ // TODO text filtering
|
|
+ this.getHandle().connection.chat(msg, playerChatMessage, false);
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
@Override
|