Waterfall/BungeeCord-Patches/0030-Fix-potion-race-condition-on-Forge-1.8.9.patch

221 lines
7.8 KiB
Diff
Raw Normal View History

From 8eea3ccfded59af6e76549d279cf0def408a10ba Mon Sep 17 00:00:00 2001
From: Aaron Hill <aa1ronham@gmail.com>
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
2023-09-21 12:33:23 +02:00
index 0f8f5885..b3c8c6e2 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
2023-09-21 12:33:23 +02:00
@@ -238,4 +238,14 @@ public abstract class AbstractPacketHandler
public void handle(FinishConfiguration finishConfiguration) throws Exception
{
}
2018-12-21 16:24:26 +01:00
+
+ // Waterfall start
2023-09-21 12:33:23 +02:00
+ public void handle(net.md_5.bungee.protocol.packet.EntityEffect entityEffect) throws Exception
+ {
+ }
+
2023-09-21 12:33:23 +02:00
+ 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 7a62088d..cff35a06 100644
--- 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;
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;
@@ -126,6 +128,10 @@ public final class UserConnection implements ProxiedPlayer
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: 5a1e342e Minecraft 1.20.2 support d9bbdc32 Add Java 21 compilation support cfe00fa4 #3490: Add ComponentBuilder#build() and ComponentSerializer#deserialize() d68ebd1e Minecraft 1.20.2-rc1 support a7cd79eb #3516: Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.5.0 to 3.6.0 9e83ee6f #3508: Use same compression threshold checks as Vanilla 7c81d917 #3513: Bump org.apache.maven.plugins:maven-enforcer-plugin from 3.4.0 to 3.4.1 5b126b7f Fix javadoc plugin version in non-dist builds 9fe7d21f #3510: Bump actions/checkout from 3 to 4 94ea0271 #3505: Bump io.netty:netty-bom from 4.1.96.Final to 4.1.97.Final 3af672d2 #3504: Bump org.apache.maven.plugins:maven-enforcer-plugin from 3.3.0 to 3.4.0 0dd7b984 Bump version to 1.20-R0.2-SNAPSHOT a793692a Release 1.20-R0.1 23fb8382 #3493: Bump io.netty:netty-bom from 4.1.95.Final to 4.1.96.Final 2d6d89d6 #3492: Bump io.netty:netty-bom from 4.1.94.Final to 4.1.95.Final 0199cb90 #3489: Add command string length limit when decoding ClientCommand 958cef50 #3488: Bump scriptus from 0.4.1 to 0.5.0 9f5ace90 #3418: Add tab completion for bungee command names in pre-1.13 versions 3a6e2631 #3479: Bump netty-bom from 4.1.93.Final to 4.1.94.Final c7adcf9f Disable maven enforcer for now da3616e6 SPIGOT-7400: Downgrade maven-resolver due to issues resolving certain depends b371fe67 #3478: Bump maven-shade-plugin from 3.4.1 to 3.5.0 6324c7d5 #3401: Only synchronize necessary parts of the BungeeServerInfo#sendData method 6263fe28 #3426: Made find command output hover and clickable 9a7617f9 #3475: Add KickPlayerRaw channel 9a71358d #3439: Add GetPlayerServer bungee plugin message subchannel a96a2e80 #3437: Remove unused enum in ServerConnector and add color to exception message
2023-09-21 18:59:49 +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
@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 f461c096..80275a15 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
@@ -740,6 +740,32 @@ public class DownstreamBridge extends PacketHandler
}
}
+ // Waterfall start
+ @Override
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: 5a1e342e Minecraft 1.20.2 support d9bbdc32 Add Java 21 compilation support cfe00fa4 #3490: Add ComponentBuilder#build() and ComponentSerializer#deserialize() d68ebd1e Minecraft 1.20.2-rc1 support a7cd79eb #3516: Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.5.0 to 3.6.0 9e83ee6f #3508: Use same compression threshold checks as Vanilla 7c81d917 #3513: Bump org.apache.maven.plugins:maven-enforcer-plugin from 3.4.0 to 3.4.1 5b126b7f Fix javadoc plugin version in non-dist builds 9fe7d21f #3510: Bump actions/checkout from 3 to 4 94ea0271 #3505: Bump io.netty:netty-bom from 4.1.96.Final to 4.1.97.Final 3af672d2 #3504: Bump org.apache.maven.plugins:maven-enforcer-plugin from 3.3.0 to 3.4.0 0dd7b984 Bump version to 1.20-R0.2-SNAPSHOT a793692a Release 1.20-R0.1 23fb8382 #3493: Bump io.netty:netty-bom from 4.1.95.Final to 4.1.96.Final 2d6d89d6 #3492: Bump io.netty:netty-bom from 4.1.94.Final to 4.1.95.Final 0199cb90 #3489: Add command string length limit when decoding ClientCommand 958cef50 #3488: Bump scriptus from 0.4.1 to 0.5.0 9f5ace90 #3418: Add tab completion for bungee command names in pre-1.13 versions 3a6e2631 #3479: Bump netty-bom from 4.1.93.Final to 4.1.94.Final c7adcf9f Disable maven enforcer for now da3616e6 SPIGOT-7400: Downgrade maven-resolver due to issues resolving certain depends b371fe67 #3478: Bump maven-shade-plugin from 3.4.1 to 3.5.0 6324c7d5 #3401: Only synchronize necessary parts of the BungeeServerInfo#sendData method 6263fe28 #3426: Made find command output hover and clickable 9a7617f9 #3475: Add KickPlayerRaw channel 9a71358d #3439: Add GetPlayerServer bungee plugin message subchannel a96a2e80 #3437: Remove unused enum in ServerConnector and add color to exception message
2023-09-21 18:59:49 +02:00
+ 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
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: 5a1e342e Minecraft 1.20.2 support d9bbdc32 Add Java 21 compilation support cfe00fa4 #3490: Add ComponentBuilder#build() and ComponentSerializer#deserialize() d68ebd1e Minecraft 1.20.2-rc1 support a7cd79eb #3516: Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.5.0 to 3.6.0 9e83ee6f #3508: Use same compression threshold checks as Vanilla 7c81d917 #3513: Bump org.apache.maven.plugins:maven-enforcer-plugin from 3.4.0 to 3.4.1 5b126b7f Fix javadoc plugin version in non-dist builds 9fe7d21f #3510: Bump actions/checkout from 3 to 4 94ea0271 #3505: Bump io.netty:netty-bom from 4.1.96.Final to 4.1.97.Final 3af672d2 #3504: Bump org.apache.maven.plugins:maven-enforcer-plugin from 3.3.0 to 3.4.0 0dd7b984 Bump version to 1.20-R0.2-SNAPSHOT a793692a Release 1.20-R0.1 23fb8382 #3493: Bump io.netty:netty-bom from 4.1.95.Final to 4.1.96.Final 2d6d89d6 #3492: Bump io.netty:netty-bom from 4.1.94.Final to 4.1.95.Final 0199cb90 #3489: Add command string length limit when decoding ClientCommand 958cef50 #3488: Bump scriptus from 0.4.1 to 0.5.0 9f5ace90 #3418: Add tab completion for bungee command names in pre-1.13 versions 3a6e2631 #3479: Bump netty-bom from 4.1.93.Final to 4.1.94.Final c7adcf9f Disable maven enforcer for now da3616e6 SPIGOT-7400: Downgrade maven-resolver due to issues resolving certain depends b371fe67 #3478: Bump maven-shade-plugin from 3.4.1 to 3.5.0 6324c7d5 #3401: Only synchronize necessary parts of the BungeeServerInfo#sendData method 6263fe28 #3426: Made find command output hover and clickable 9a7617f9 #3475: Add KickPlayerRaw channel 9a71358d #3439: Add GetPlayerServer bungee plugin message subchannel a96a2e80 #3437: Remove unused enum in ServerConnector and add color to exception message
2023-09-21 18:59:49 +02:00
+ 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
2016-10-30 15:46:05 +01:00
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
2018-05-28 23:00:27 +02:00
@@ -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.
*
--
2023-09-21 12:33:23 +02:00
2.42.0