Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ByteBuf#copy only when entity rewrite is actually used #799

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
From fa7dcf4b0fa0b5aaf20c9071b547699ae43ab530 Mon Sep 17 00:00:00 2001
From: BoomEaro <[email protected]>
Date: Mon, 3 Apr 2023 13:03:53 +0300
Subject: [PATCH] Always slice until entity rewrite is being used in
MinecraftDecoder


diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
index ac83e325..b6950ff1 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
@@ -20,6 +20,8 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
private int protocolVersion;
@Setter
private boolean supportsForge = false;
+ @Setter
+ private boolean slice = true; // Waterfall
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we default to the safe side, copy instead of slice?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we default to the safe side, copy instead of slice?

As far as I remember, the only situation where the proxy actually changes the buffer is when an entity map instance appears in the UserConnection.
Before the proxy creates the UserConnection, the proxy decodes the Handshake, Login, and a couple of other packets. (when the state is not yet FINISHING in InitialHandler)
It doesn't seem to make sense at this stage specifically to copy the buffer for these packets.

Copy link
Contributor

@Janmm14 Janmm14 Apr 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw why you don't set this directly at initialization of minecraftdecoder to the config value of rewriting disabled?

if we don't want to clone packets given the game phase, this should somewhere be explicitely mentioned - either in code or a simple comment


public MinecraftDecoder(Protocol protocol, boolean server, int protocolVersion) {
this.protocol = protocol;
@@ -38,7 +40,7 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
}

Protocol.DirectionData prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT;
- ByteBuf slice = in.copy(); // Can't slice this one due to EntityMap :(
+ ByteBuf slice = ( this.slice ? in.retainedSlice() : in.copy() ); // Waterfall

Object packetTypeInfo = null;
try
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
index 8181d76b..1e05104e 100644
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
@@ -385,6 +385,7 @@ public class ServerConnector extends PacketHandler
ServerInfo from = ( user.getServer() == null ) ? null : user.getServer().getInfo();
user.setServer( server );
ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user, server ) );
+ ch.getHandle().pipeline().get( MinecraftDecoder.class ).setSlice( user.isDisableEntityMetadataRewrite() ); // Waterfall: Change decoder mode for downstream connection

bungee.getPluginManager().callEvent( new ServerSwitchEvent( user, from ) );

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 cf82c182..e3df5c82 100644
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
@@ -158,6 +158,8 @@ public final class UserConnection implements ProxiedPlayer
{
this.entityRewrite = EntityMap.getEntityMap( getPendingConnection().getVersion() );

+ ch.getHandle().pipeline().get( MinecraftDecoder.class ).setSlice( isDisableEntityMetadataRewrite() ); // Waterfall: Change decoder mode for upstream connection
+
this.displayName = name;

tabListHandler = new ServerUnique( this );
--
2.33.0.windows.2