diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java index 9c086869..10e16d79 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java @@ -48,6 +48,14 @@ public abstract class DefinedPacket buf.writeBytes( b ); } + public static byte[] toArray(ByteBuf buf) + { + byte[] ret = new byte[ buf.readableBytes() ]; + buf.readBytes( ret ); + + return ret; + } + public static byte[] readArray(ByteBuf buf) { return readArray( buf, buf.readableBytes() ); 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 977b3def..976636ac 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -199,7 +199,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", DefinedPacket.readArray( brand ), handshakeHandler.isServerForge() ) ); + user.unsafe().sendPacket( new PluginMessage( "MC|Brand", DefinedPacket.toArray( 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 3daab361..288d6024 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 @@ -1,6 +1,7 @@ package net.md_5.bungee.connection; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import java.io.DataInput; @@ -233,9 +234,12 @@ public class DownstreamBridge extends PacketHandler ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() ); String serverBrand = DefinedPacket.readString( brand ); brand.release(); + + Preconditions.checkState( !serverBrand.contains( bungee.getName() ), "Cannot connect proxy to itself!" ); + brand = ByteBufAllocator.DEFAULT.heapBuffer(); DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand ); - pluginMessage.setData( DefinedPacket.readArray( brand ) ); + pluginMessage.setData( DefinedPacket.toArray( brand ) ); brand.release(); // changes in the packet are ignored so we need to send it manually con.unsafe().sendPacket( pluginMessage );