Waterfall/BungeeCord-Patches/0032-Upgrade-to-netty-4.1.p...

121 lines
5.5 KiB
Diff

From da4c0a77fa856feae15b346aa2428714270afccf Mon Sep 17 00:00:00 2001
From: Techcable <Techcable@techcable.net>
Date: Tue, 3 May 2016 20:31:52 -0700
Subject: [PATCH] Upgrade to netty 4.1
Don't access a ByteBuf's underlying array with ByteBuf.array()
- ByteBuf.array() returns the underlying array storage, and does *not* return a view of the buffer as an array
diff --git a/pom.xml b/pom.xml
index fda3278..d2f458a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,7 +76,7 @@
<properties>
<build.number>unknown</build.number>
- <netty.version>4.0.33.Final</netty.version>
+ <netty.version>4.1.0.CR7</netty.version>
<!-- Require Java 8 -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
diff --git a/protocol/pom.xml b/protocol/pom.xml
index 8b462f5..ccee47e 100644
--- a/protocol/pom.xml
+++ b/protocol/pom.xml
@@ -32,6 +32,12 @@
<scope>compile</scope>
</dependency>
<dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-handler</artifactId>
+ <version>${netty.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>3.0.3</version>
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java
index bbaef39..e094932 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java
@@ -9,6 +9,8 @@ import java.io.DataInputStream;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import io.netty.buffer.ByteBufInputStream;
+import io.netty.buffer.ByteBufUtil;
import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.ProtocolConstants;
@@ -20,9 +22,22 @@ import net.md_5.bungee.protocol.ProtocolConstants;
public class PluginMessage extends DefinedPacket
{
+ public PluginMessage(String tag, ByteBuf data, boolean allowExtendedPacket) {
+ this(tag, ByteBufUtil.getBytes(data), allowExtendedPacket);
+ }
+
private String tag;
private byte[] data;
+ public void setData(byte[] data) {
+ this.data = Preconditions.checkNotNull(data, "Null data");
+ }
+
+ public void setData(ByteBuf buf) {
+ Preconditions.checkNotNull(buf, "Null buffer");
+ setData(ByteBufUtil.getBytes(buf));
+ }
+
/**
* Allow this packet to be sent as an "extended" packet.
*/
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 44f0b61..e327325 100644
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
@@ -232,7 +232,7 @@ public class ServerConnector extends PacketHandler
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand );
- user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand.array().clone(), handshakeHandler.isServerForge() ) );
+ user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand, handshakeHandler.isServerForge() ) );
brand.release();
} else
{
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 7ba0bcb..fa57f28 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
@@ -235,7 +235,7 @@ public class DownstreamBridge extends PacketHandler
brand.release();
brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand );
- pluginMessage.setData( brand.array().clone() );
+ pluginMessage.setData( brand );
brand.release();
// changes in the packet are ignored so we need to send it manually
con.unsafe().sendPacket( pluginMessage );
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
index f0d0189..aec8251 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
@@ -41,9 +41,9 @@ import net.md_5.bungee.protocol.Varint21LengthFieldPrepender;
public class PipelineUtils
{
- public static final AttributeKey<ListenerInfo> LISTENER = new AttributeKey<>( "ListerInfo" );
- public static final AttributeKey<UserConnection> USER = new AttributeKey<>( "User" );
- public static final AttributeKey<BungeeServerInfo> TARGET = new AttributeKey<>( "Target" );
+ public static final AttributeKey<ListenerInfo> LISTENER = AttributeKey.newInstance("ListerInfo");
+ public static final AttributeKey<UserConnection> USER = AttributeKey.newInstance("User");
+ public static final AttributeKey<BungeeServerInfo> TARGET = AttributeKey.newInstance("Target");
public static final ChannelInitializer<Channel> SERVER_CHILD = new ChannelInitializer<Channel>()
{
@Override
--
2.8.3