2023-03-14 20:02:26 +01:00
|
|
|
From ffc7cfe376ea12c3232492bcaad76e04c6b138db Mon Sep 17 00:00:00 2001
|
2016-09-15 22:43:27 +02:00
|
|
|
From: Aaron Hill <aa1ronham@gmail.com>
|
2017-05-15 17:54:56 +02:00
|
|
|
Date: Thu, 15 Sep 2016 22:38:37 +0200
|
2016-09-15 22:43:27 +02:00
|
|
|
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
|
2022-12-07 17:30:18 +01:00
|
|
|
index 88865b85..0c334afc 100644
|
2016-09-15 22:43:27 +02:00
|
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java
|
|
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java
|
2022-06-07 19:12:20 +02:00
|
|
|
@@ -10,6 +10,8 @@ import net.md_5.bungee.protocol.packet.ClientStatus;
|
2019-04-23 10:09:26 +02:00
|
|
|
import net.md_5.bungee.protocol.packet.Commands;
|
|
|
|
import net.md_5.bungee.protocol.packet.EncryptionRequest;
|
|
|
|
import net.md_5.bungee.protocol.packet.EncryptionResponse;
|
|
|
|
+import net.md_5.bungee.protocol.packet.EntityEffect; // Waterfall
|
|
|
|
+import net.md_5.bungee.protocol.packet.EntityRemoveEffect; // Waterfall
|
|
|
|
import net.md_5.bungee.protocol.packet.EntityStatus;
|
2020-03-07 23:50:46 +01:00
|
|
|
import net.md_5.bungee.protocol.packet.GameState;
|
2019-04-23 10:09:26 +02:00
|
|
|
import net.md_5.bungee.protocol.packet.Handshake;
|
2022-12-07 17:30:18 +01:00
|
|
|
@@ -223,4 +225,14 @@ public abstract class AbstractPacketHandler
|
2022-08-14 19:48:43 +02:00
|
|
|
public void handle(ServerData serverData) throws Exception
|
2016-09-15 22:43:27 +02:00
|
|
|
{
|
|
|
|
}
|
2018-12-21 16:24:26 +01:00
|
|
|
+
|
2016-09-15 22:43:27 +02:00
|
|
|
+ // Waterfall start
|
|
|
|
+ public void handle(EntityEffect entityEffect) throws Exception
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void handle(EntityRemoveEffect removeEffect) throws Exception
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+ // 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
|
2023-03-14 20:02:26 +01:00
|
|
|
index dabfa4db..7e0c4f7a 100644
|
2016-09-15 22:43:27 +02:00
|
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
|
|
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java
|
2022-06-07 19:12:20 +02:00
|
|
|
@@ -20,6 +20,8 @@ import net.md_5.bungee.protocol.packet.EncryptionRequest;
|
2016-09-15 22:43:27 +02:00
|
|
|
import net.md_5.bungee.protocol.packet.EncryptionResponse;
|
2018-12-21 16:24:26 +01:00
|
|
|
import net.md_5.bungee.protocol.packet.EntityStatus;
|
2020-03-07 23:50:46 +01:00
|
|
|
import net.md_5.bungee.protocol.packet.GameState;
|
2016-09-15 22:43:27 +02:00
|
|
|
+import net.md_5.bungee.protocol.packet.EntityEffect;
|
|
|
|
+import net.md_5.bungee.protocol.packet.EntityRemoveEffect;
|
|
|
|
import net.md_5.bungee.protocol.packet.Handshake;
|
|
|
|
import net.md_5.bungee.protocol.packet.KeepAlive;
|
|
|
|
import net.md_5.bungee.protocol.packet.Kick;
|
2023-03-14 20:02:26 +01:00
|
|
|
@@ -140,6 +142,20 @@ public enum Protocol
|
|
|
|
map( ProtocolConstants.MINECRAFT_1_19, 0x0A ),
|
|
|
|
map( ProtocolConstants.MINECRAFT_1_19_4, 0xB )
|
2016-09-15 22:43:27 +02:00
|
|
|
);
|
|
|
|
+ // Waterfall start
|
|
|
|
+ TO_CLIENT.registerPacket(
|
|
|
|
+ EntityEffect.class,
|
2021-06-11 22:13:31 +02:00
|
|
|
+ EntityEffect::new,
|
2016-09-15 22:43:27 +02:00
|
|
|
+ map(ProtocolConstants.MINECRAFT_1_8, 0x1D),
|
2022-06-12 07:52:49 +02:00
|
|
|
+ map(ProtocolConstants.MINECRAFT_1_9, -1)
|
2016-09-15 22:43:27 +02:00
|
|
|
+ );
|
|
|
|
+ TO_CLIENT.registerPacket(
|
|
|
|
+ EntityRemoveEffect.class,
|
2021-06-11 22:13:31 +02:00
|
|
|
+ EntityRemoveEffect::new,
|
2016-09-15 22:43:27 +02:00
|
|
|
+ map(ProtocolConstants.MINECRAFT_1_8, 0x1E),
|
2022-06-12 07:52:49 +02:00
|
|
|
+ map(ProtocolConstants.MINECRAFT_1_9, -1)
|
2016-09-15 22:43:27 +02:00
|
|
|
+ );
|
|
|
|
+ // Waterfall end
|
|
|
|
TO_CLIENT.registerPacket(
|
|
|
|
PlayerListItem.class, // PlayerInfo
|
2021-06-11 22:13:31 +02:00
|
|
|
PlayerListItem::new,
|
2016-09-15 22:43:27 +02:00
|
|
|
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
|
2017-05-14 16:07:38 +02:00
|
|
|
index 00000000..d11a9ea9
|
2016-09-15 22:43:27 +02:00
|
|
|
--- /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
|
2017-05-14 16:07:38 +02:00
|
|
|
index 00000000..7ed2dc3a
|
2016-09-15 22:43:27 +02:00
|
|
|
--- /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
|
2022-06-12 07:52:49 +02:00
|
|
|
index 846f8338..7fe08ecd 100644
|
2016-09-15 22:43:27 +02:00
|
|
|
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
|
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
2018-11-04 21:27:05 +01:00
|
|
|
@@ -1,7 +1,9 @@
|
|
|
|
package net.md_5.bungee;
|
2016-09-15 22:43:27 +02:00
|
|
|
|
|
|
|
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;
|
2022-06-07 19:12:20 +02:00
|
|
|
@@ -125,6 +127,10 @@ public final class UserConnection implements ProxiedPlayer
|
2016-09-15 22:43:27 +02:00
|
|
|
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
|
|
|
|
private String displayName;
|
|
|
|
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
|
2023-03-14 20:02:26 +01:00
|
|
|
index e8ef17a1..c7180803 100644
|
2016-09-15 22:43:27 +02:00
|
|
|
--- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
|
|
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
|
2022-02-06 06:54:54 +01:00
|
|
|
@@ -51,6 +51,8 @@ import net.md_5.bungee.protocol.PacketWrapper;
|
2018-07-15 12:58:44 +02:00
|
|
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
2016-09-15 22:43:27 +02:00
|
|
|
import net.md_5.bungee.protocol.packet.BossBar;
|
2018-12-21 16:24:26 +01:00
|
|
|
import net.md_5.bungee.protocol.packet.Commands;
|
2016-09-15 22:43:27 +02:00
|
|
|
+import net.md_5.bungee.protocol.packet.EntityEffect;
|
|
|
|
+import net.md_5.bungee.protocol.packet.EntityRemoveEffect;
|
|
|
|
import net.md_5.bungee.protocol.packet.KeepAlive;
|
2019-04-23 10:09:26 +02:00
|
|
|
import net.md_5.bungee.protocol.packet.Kick;
|
2016-09-15 22:43:27 +02:00
|
|
|
import net.md_5.bungee.protocol.packet.PlayerListItem;
|
2022-12-07 17:30:18 +01:00
|
|
|
@@ -682,6 +684,32 @@ public class DownstreamBridge extends PacketHandler
|
2016-09-15 22:43:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Waterfall start
|
|
|
|
+ @Override
|
|
|
|
+ public void handle(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(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
|
2016-10-30 15:46:05 +01:00
|
|
|
public void handle(Respawn respawn)
|
2016-09-15 22:43:27 +02:00
|
|
|
{
|
|
|
|
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
|
2020-01-06 20:43:23 +01:00
|
|
|
index d15044f4..bea2bbff 100644
|
2016-09-15 22:43:27 +02:00
|
|
|
--- a/proxy/src/main/java/net/md_5/bungee/forge/ForgeClientHandler.java
|
|
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/forge/ForgeClientHandler.java
|
2018-05-28 23:00:27 +02:00
|
|
|
@@ -9,6 +9,8 @@ import lombok.NonNull;
|
2016-10-25 18:57:11 +02:00
|
|
|
import lombok.RequiredArgsConstructor;
|
2016-09-15 22:43:27 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2020-01-06 20:43:23 +01:00
|
|
|
@@ -94,9 +96,23 @@ public class ForgeClientHandler
|
2016-09-15 22:43:27 +02:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
--
|
2023-03-14 20:02:26 +01:00
|
|
|
2.37.3.windows.1
|
2016-09-15 22:43:27 +02:00
|
|
|
|