Correctly send the MC|Brand packet
This commit is contained in:
parent
73d7e0cf99
commit
65ae8b4c6a
@ -3,6 +3,9 @@ package net.md_5.bungee;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
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.MinecraftOutput;
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
import net.md_5.bungee.protocol.Protocol;
|
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.EncryptionRequest;
|
||||||
import net.md_5.bungee.protocol.packet.Handshake;
|
import net.md_5.bungee.protocol.packet.Handshake;
|
||||||
import net.md_5.bungee.protocol.packet.Login;
|
import net.md_5.bungee.protocol.packet.Login;
|
||||||
@ -151,10 +155,19 @@ public class ServerConnector extends PacketHandler
|
|||||||
|
|
||||||
user.unsafe().sendPacket( modLogin );
|
user.unsafe().sendPacket( modLogin );
|
||||||
|
|
||||||
|
if ( user.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||||
|
{
|
||||||
MinecraftOutput out = new MinecraftOutput();
|
MinecraftOutput out = new MinecraftOutput();
|
||||||
out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" );
|
out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" );
|
||||||
user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray() ) );
|
user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray() ) );
|
||||||
} else
|
} 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();
|
user.getTabListHandler().onServerChange();
|
||||||
|
|
||||||
|
@ -4,6 +4,10 @@ import com.google.common.io.ByteArrayDataOutput;
|
|||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.md_5.bungee.ServerConnection;
|
import net.md_5.bungee.ServerConnection;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
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.chat.ComponentSerializer;
|
||||||
import net.md_5.bungee.netty.ChannelWrapper;
|
import net.md_5.bungee.netty.ChannelWrapper;
|
||||||
import net.md_5.bungee.netty.PacketHandler;
|
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.PacketWrapper;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
import net.md_5.bungee.protocol.packet.KeepAlive;
|
import net.md_5.bungee.protocol.packet.KeepAlive;
|
||||||
import net.md_5.bungee.protocol.packet.PlayerListItem;
|
import net.md_5.bungee.protocol.packet.PlayerListItem;
|
||||||
import net.md_5.bungee.protocol.packet.ScoreboardObjective;
|
import net.md_5.bungee.protocol.packet.ScoreboardObjective;
|
||||||
@ -218,9 +224,28 @@ public class DownstreamBridge extends PacketHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( pluginMessage.getTag().equals( "MC|Brand" ) )
|
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" );
|
String serverBrand = new String( pluginMessage.getData(), "UTF-8" );
|
||||||
pluginMessage.setData( ( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand ).getBytes( "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
|
// changes in the packet are ignored so we need to send it manually
|
||||||
con.unsafe().sendPacket( pluginMessage );
|
con.unsafe().sendPacket( pluginMessage );
|
||||||
throw CancelSendSignal.INSTANCE;
|
throw CancelSendSignal.INSTANCE;
|
||||||
|
Loading…
Reference in New Issue
Block a user