-
-
Notifications
You must be signed in to change notification settings - Fork 303
/
0029-Fix-potion-race-condition-on-Forge-1.8.9.patch
220 lines (213 loc) · 7.78 KB
/
0029-Fix-potion-race-condition-on-Forge-1.8.9.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
From f5c341bf2e3a268299c88c9fe9726111194e498d Mon Sep 17 00:00:00 2001
From: Aaron Hill <[email protected]>
Date: Thu, 15 Sep 2016 22:38:37 +0200
Subject: [PATCH] Fix potion race condition on Forge 1.8.9
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 8d91211b..e2221010 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
@@ -278,4 +278,14 @@ public abstract class AbstractPacketHandler
public void handle(ServerLinks serverLinks) throws Exception
{
}
+
+ // Waterfall start
+ public void handle(net.md_5.bungee.protocol.packet.EntityEffect entityEffect) throws Exception
+ {
+ }
+
+ public void handle(net.md_5.bungee.protocol.packet.EntityRemoveEffect removeEffect) throws Exception
+ {
+ }
+ // Waterfall end
}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/EntityEffect.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EntityEffect.java
new file mode 100644
index 00000000..d11a9ea9
--- /dev/null
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EntityEffect.java
@@ -0,0 +1,45 @@
+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;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode(callSuper = false)
+public class EntityEffect extends DefinedPacket {
+
+ private int entityId;
+ private int effectId;
+ private int amplifier;
+ private int duration;
+ private boolean hideParticles;
+
+ @Override
+ public void read(ByteBuf buf) {
+ this.entityId = readVarInt(buf);
+ this.effectId = buf.readUnsignedByte();
+ this.amplifier = buf.readUnsignedByte();
+ this.duration = readVarInt(buf);
+ this.hideParticles = buf.readBoolean();
+ }
+
+ @Override
+ public void write(ByteBuf buf) {
+ writeVarInt(this.entityId, buf);
+ buf.writeByte(this.effectId);
+ buf.writeByte(this.amplifier);
+ writeVarInt(this.duration, buf);
+ buf.writeBoolean(this.hideParticles);
+ }
+
+ @Override
+ public void handle(AbstractPacketHandler handler) throws Exception {
+ handler.handle(this);
+ }
+}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/EntityRemoveEffect.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EntityRemoveEffect.java
new file mode 100644
index 00000000..7ed2dc3a
--- /dev/null
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EntityRemoveEffect.java
@@ -0,0 +1,36 @@
+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;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode(callSuper = false)
+public class EntityRemoveEffect extends DefinedPacket {
+
+ private int entityId;
+ private int effectId;
+
+ @Override
+ public void read(ByteBuf buf) {
+ this.entityId = readVarInt(buf);
+ this.effectId = buf.readUnsignedByte();
+ }
+
+ @Override
+ public void write(ByteBuf buf) {
+ writeVarInt(this.entityId, buf);
+ buf.writeByte(effectId);
+ }
+
+ @Override
+ public void handle(AbstractPacketHandler handler) throws Exception {
+ handler.handle(this);
+ }
+}
diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
index d8f7bc95..d15f2bcc 100644
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
@@ -1,7 +1,9 @@
package net.md_5.bungee;
import com.google.common.base.Preconditions;
+import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Multimap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
@@ -129,6 +131,10 @@ public final class UserConnection implements ProxiedPlayer
private final Scoreboard serverSentScoreboard = new Scoreboard();
@Getter
private final Collection<UUID> sentBossBars = new HashSet<>();
+ // Waterfall start
+ @Getter
+ private final Multimap<Integer, Integer> potions = HashMultimap.create();
+ // Waterfall end
@Getter
@Setter
private String lastCommandTabbed;
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
index d4036c5d..ad9fc042 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
@@ -753,6 +753,32 @@ public class DownstreamBridge extends PacketHandler
}
}
+ // Waterfall start
+ @Override
+ public void handle(net.md_5.bungee.protocol.packet.EntityEffect entityEffect) throws Exception
+ {
+ // Don't send any potions when switching between servers (which involves a handshake), which can trigger a race
+ // condition on the client.
+ if (this.con.getForgeClientHandler().isForgeUser() && !this.con.getForgeClientHandler().isHandshakeComplete()) {
+ throw CancelSendSignal.INSTANCE;
+ }
+ con.getPotions().put(rewriteEntityId(entityEffect.getEntityId()), entityEffect.getEffectId());
+ }
+
+ @Override
+ public void handle(net.md_5.bungee.protocol.packet.EntityRemoveEffect removeEffect) throws Exception
+ {
+ con.getPotions().remove(rewriteEntityId(removeEffect.getEntityId()), removeEffect.getEffectId());
+ }
+
+ private int rewriteEntityId(int entityId) {
+ if (entityId == con.getServerEntityId()) {
+ return con.getClientEntityId();
+ }
+ return entityId;
+ }
+ // Waterfall end
+
@Override
public void handle(Respawn respawn)
{
diff --git a/proxy/src/main/java/net/md_5/bungee/forge/ForgeClientHandler.java b/proxy/src/main/java/net/md_5/bungee/forge/ForgeClientHandler.java
index d15044f4..bea2bbff 100644
--- a/proxy/src/main/java/net/md_5/bungee/forge/ForgeClientHandler.java
+++ b/proxy/src/main/java/net/md_5/bungee/forge/ForgeClientHandler.java
@@ -9,6 +9,8 @@ import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.md_5.bungee.UserConnection;
+import net.md_5.bungee.protocol.ProtocolConstants;
+import net.md_5.bungee.protocol.packet.EntityRemoveEffect;
import net.md_5.bungee.protocol.packet.PluginMessage;
/**
@@ -94,9 +96,23 @@ public class ForgeClientHandler
public void resetHandshake()
{
state = ForgeClientHandshakeState.HELLO;
+
+ // This issue only exists in Forge 1.8.9
+ if (this.con.getPendingConnection().getVersion() == ProtocolConstants.MINECRAFT_1_8) {
+ this.resetAllThePotions(con);
+ }
+
con.unsafe().sendPacket( ForgeConstants.FML_RESET_HANDSHAKE );
}
+ private void resetAllThePotions(UserConnection con) {
+ // Just to be sure
+ for (Map.Entry<Integer, Integer> entry: con.getPotions().entries()) {
+ con.unsafe().sendPacket(new EntityRemoveEffect(entry.getKey(), entry.getValue()));
+ }
+ con.getPotions().clear();
+ }
+
/**
* Sends the server mod list to the client, or stores it for sending later.
*
--
2.45.1