Correctly send the MC|Brand packet

This commit is contained in:
Thinkofdeath 2014-09-02 13:54:52 +01:00
parent 73d7e0cf99
commit 65ae8b4c6a
2 changed files with 43 additions and 5 deletions

View File

@ -3,6 +3,9 @@ package net.md_5.bungee;
import com.google.common.base.Preconditions;
import java.util.Objects;
import java.util.Queue;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
@ -23,6 +26,7 @@ import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.MinecraftOutput;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.Protocol;
import net.md_5.bungee.protocol.ProtocolConstants;
import net.md_5.bungee.protocol.packet.EncryptionRequest;
import net.md_5.bungee.protocol.packet.Handshake;
import net.md_5.bungee.protocol.packet.Login;
@ -151,10 +155,19 @@ public class ServerConnector extends PacketHandler
user.unsafe().sendPacket( modLogin );
if ( user.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_SNAPSHOT )
{
MinecraftOutput out = new MinecraftOutput();
out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" );
user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray() ) );
} else
{
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand );
user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand.array().clone() ) );
brand.release();
}
} else
{
user.getTabListHandler().onServerChange();

View File

@ -4,6 +4,10 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import java.io.DataInput;
import java.util.Objects;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.ServerConnection;
import net.md_5.bungee.api.chat.TextComponent;
@ -23,7 +27,9 @@ import net.md_5.bungee.api.score.Team;
import net.md_5.bungee.chat.ComponentSerializer;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.PacketWrapper;
import net.md_5.bungee.protocol.ProtocolConstants;
import net.md_5.bungee.protocol.packet.KeepAlive;
import net.md_5.bungee.protocol.packet.PlayerListItem;
import net.md_5.bungee.protocol.packet.ScoreboardObjective;
@ -218,9 +224,28 @@ public class DownstreamBridge extends PacketHandler
}
if ( pluginMessage.getTag().equals( "MC|Brand" ) )
{
if ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_SNAPSHOT )
{
try
{
ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() );
String serverBrand = DefinedPacket.readString( brand );
brand.release();
brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand );
pluginMessage.setData( brand.array().clone() );
brand.release();
} catch ( Exception ignored ) {
// TODO: Remove this
// Older spigot protocol builds sent the brand incorrectly
return;
}
} else
{
String serverBrand = new String( pluginMessage.getData(), "UTF-8" );
pluginMessage.setData( ( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand ).getBytes( "UTF-8" ) );
}
// changes in the packet are ignored so we need to send it manually
con.unsafe().sendPacket( pluginMessage );
throw CancelSendSignal.INSTANCE;