Waterfall/BungeeCord-Patches/0066-Prevent-proxy-commands-from-breaking-the-chat-chain-.patch
Shane Freeder c7448e5017
Updated Upstream (BungeeCord)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

BungeeCord Changes:
e642b9dd Minecraft 24w13a support
db623d10 #3640: Bump org.apache.maven.plugins:maven-gpg-plugin from 3.2.1 to 3.2.2
61bb9f5b #3637: Bump org.projectlombok:lombok from 1.18.30 to 1.18.32
9551b453 #3639: Bump io.netty:netty-bom from 4.1.107.Final to 4.1.108.Final
dc680b87 #3636: Bump org.apache.maven.plugins:maven-gpg-plugin from 3.1.0 to 3.2.1
156eda78 #3635: Bump org.apache.maven.plugins:maven-compiler-plugin
31be68af Minecraft 24w12a support
ffa011c7 #3622: Revert "#3256: Allow - and . in online mode as some accounts still have these…"
22536c11 #3618: Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.1 to 3.5.2
2394e204 #3629: Fix scoreboard team data reading
1b88a847 Minecraft 24w10a support
2024-03-29 18:03:46 +00:00

143 lines
6.4 KiB
Diff

From 89d615e5423ffd5ff38790c6cbea9eb93e53b307 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Sun, 15 Oct 2023 00:36:38 +0100
Subject: [PATCH] Prevent proxy commands from breaking the chat chain system
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java
index 14ad2e71..fe6c7339 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java
@@ -277,5 +277,9 @@ public abstract class AbstractPacketHandler
public void handle(net.md_5.bungee.protocol.packet.EntityRemoveEffect removeEffect) throws Exception
{
}
+
+ public void handle(net.md_5.bungee.protocol.packet.ClientChatAcknowledgement clientChatAcknowledgement)
+ {
+ }
// Waterfall end
}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
index 414d4578..3a69fced 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
@@ -545,6 +545,13 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_19_1, 0x05 ),
map( ProtocolConstants.MINECRAFT_1_20_5, 0x06 )
);
+ // Waterfall start
+ TO_SERVER.registerPacket(
+ net.md_5.bungee.protocol.packet.ClientChatAcknowledgement.class,
+ net.md_5.bungee.protocol.packet.ClientChatAcknowledgement::new,
+ map (ProtocolConstants.MINECRAFT_1_19_3, 0x3)
+ );
+ // Waterfall end
TO_SERVER.registerPacket(
TabCompleteRequest.class,
TabCompleteRequest::new,
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientChatAcknowledgement.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientChatAcknowledgement.java
new file mode 100644
index 00000000..08ecf2a3
--- /dev/null
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientChatAcknowledgement.java
@@ -0,0 +1,33 @@
+package net.md_5.bungee.protocol.packet;
+
+import io.netty.buffer.ByteBuf;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+import net.md_5.bungee.protocol.AbstractPacketHandler;
+import net.md_5.bungee.protocol.DefinedPacket;
+import net.md_5.bungee.protocol.ProtocolConstants;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode(callSuper = false)
+public class ClientChatAcknowledgement extends DefinedPacket {
+ private int offset;
+
+ @Override
+ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
+ this.offset = DefinedPacket.readVarInt(buf);
+ }
+
+ @Override
+ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
+ DefinedPacket.writeVarInt(this.offset, buf);
+ }
+
+ @Override
+ public void handle(AbstractPacketHandler handler) throws Exception {
+ handler.handle(this);
+ }
+}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommand.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommand.java
index fb53ba74..f8e2db8d 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommand.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommand.java
@@ -118,4 +118,9 @@ public class ClientCommand extends DefinedPacket
{
handler.handle( this );
}
+
+ public boolean isSigned() {
+ if (salt == 0) return false;
+ return this.seenMessages != null && !this.seenMessages.getAcknowledged().isEmpty();
+ }
}
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
index 3084e7e7..333db20f 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
@@ -196,16 +196,22 @@ public class UpstreamBridge extends PacketHandler
@Override
public void handle(ClientCommand command) throws Exception
{
- handleChat( "/" + command.getCommand() );
+ handleChat( "/" + command.getCommand(), command, null ); // Waterfall
}
@Override
public void handle(ClientCommandSigned command) throws Exception
{
- handleChat( "/" + command.getCommand() );
+ handleChat( "/" + command.getCommand(), null, command ); // Waterfall
}
private String handleChat(String message)
+ {
+ // Waterfall start
+ return handleChat(message, null, null);
+ }
+ private String handleChat(String message, @javax.annotation.Nullable ClientCommand clientCommand, @javax.annotation.Nullable ClientCommandSigned clientCommandSigned)
+ // Waterfall end
{
boolean empty = true;
for ( int index = 0, length = message.length(); index < length; index++ )
@@ -231,7 +237,18 @@ public class UpstreamBridge extends PacketHandler
if ( !chatEvent.isCommand() || !bungee.getPluginManager().dispatchCommand( con, message.substring( 1 ) ) )
{
return message;
+ // Waterfall start - We're going to cancel this packet, so, no matter what, we might as well try to send this
+ } else if (clientCommand != null && clientCommand.isSigned() && clientCommand.getSeenMessages() != null) {
+ if (con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_19_3) {
+ con.getServer().unsafe().sendPacket(new net.md_5.bungee.protocol.packet.ClientChatAcknowledgement(clientCommand.getSeenMessages().getOffset()));
+ }
+ // and then for the new one
+ } else if (clientCommandSigned != null) {
+ if (con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_20_5) {
+ con.getServer().unsafe().sendPacket(new net.md_5.bungee.protocol.packet.ClientChatAcknowledgement(clientCommandSigned.getSeenMessages().getOffset()));
+ }
}
+ // Waterfall end
}
throw CancelSendSignal.INSTANCE;
}
--
2.44.0