-
-
Notifications
You must be signed in to change notification settings - Fork 303
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
BoomEaro
wants to merge
1
commit into
PaperMC:master
Choose a base branch
from
BoomEaro:feature/decoder-slice
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
BungeeCord-Patches/0067-Always-slice-until-entity-rewrite-is-being-used-in-M.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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