-
-
Notifications
You must be signed in to change notification settings - Fork 304
/
Copy path0065-Prevent-proxy-commands-from-breaking-the-chat-chain-.patch
137 lines (132 loc) · 5.88 KB
/
0065-Prevent-proxy-commands-from-breaking-the-chat-chain-.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
From 66fd24d779f736f3bf164336db6f434bc3d6e5f9 Mon Sep 17 00:00:00 2001
From: Shane Freeder <[email protected]>
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 e2221010..4dde7257 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
@@ -287,5 +287,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 b4b6f25e..dce064d7 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
@@ -614,6 +614,13 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_20_5, 0x06 ),
map( ProtocolConstants.MINECRAFT_1_21_2, 0x07 )
);
+ // 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 33c838f9..f259ee91 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
@@ -108,4 +108,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 ba0ef69d..3aa97849 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
@@ -198,16 +198,22 @@ public class UpstreamBridge extends PacketHandler
@Override
public void handle(ClientCommand command) throws Exception
{
- handleChat( "/" + command.getCommand() );
+ handleChat( "/" + command.getCommand(), command );
}
@Override
public void handle(UnsignedClientCommand command) throws Exception
{
- handleChat( "/" + command.getCommand() );
+ handleChat( "/" + command.getCommand(), null); // Waterfall
}
private String handleChat(String message)
+ {
+ // Waterfall start
+ return handleChat(message, null);
+ }
+ private String handleChat(String message, @javax.annotation.Nullable ClientCommand clientCommand)
+ // Waterfall end
{
for ( int index = 0, length = message.length(); index < length; index++ )
{
@@ -226,7 +232,13 @@ 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()));
+ }
}
+ // Waterfall end
}
throw CancelSendSignal.INSTANCE;
}
--
2.47.1.windows.2