#1945: Relay MC|Brand messages

This commit is contained in:
md_5 2016-08-26 16:11:38 +10:00
parent 98e3c70460
commit 5c809c2499
4 changed files with 16 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package net.md_5.bungee.protocol.packet;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import net.md_5.bungee.protocol.DefinedPacket;
import io.netty.buffer.ByteBuf;
import java.io.ByteArrayInputStream;
@ -20,6 +21,15 @@ import net.md_5.bungee.protocol.ProtocolConstants;
public class PluginMessage extends DefinedPacket
{
public static final Predicate<PluginMessage> SHOULD_RELAY = new Predicate<PluginMessage>()
{
@Override
public boolean apply(PluginMessage input)
{
return input.getTag().equals( "REGISTER" ) || input.getTag().equals( "MC|Brand" );
}
};
//
private String tag;
private byte[] data;

View File

@ -30,7 +30,6 @@ import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.Protocol;
import net.md_5.bungee.protocol.packet.BossBar;
import net.md_5.bungee.protocol.packet.EncryptionRequest;
import net.md_5.bungee.protocol.packet.Handshake;
import net.md_5.bungee.protocol.packet.Kick;
@ -170,7 +169,7 @@ public class ServerConnector extends PacketHandler
}
}
for ( PluginMessage message : user.getPendingConnection().getRegisterMessages() )
for ( PluginMessage message : user.getPendingConnection().getRelayMessages() )
{
ch.write( message );
}

View File

@ -72,7 +72,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
private LoginRequest loginRequest;
private EncryptionRequest request;
@Getter
private final List<PluginMessage> registerMessages = new BoundedArrayList<>( 128 );
private final List<PluginMessage> relayMessages = new BoundedArrayList<>( 128 );
private State thisState = State.HANDSHAKE;
private final Unsafe unsafe = new Unsafe()
{
@ -126,9 +126,9 @@ public class InitialHandler extends PacketHandler implements PendingConnection
public void handle(PluginMessage pluginMessage) throws Exception
{
// TODO: Unregister?
if ( pluginMessage.getTag().equals( "REGISTER" ) )
if ( PluginMessage.SHOULD_RELAY.apply( pluginMessage ) )
{
registerMessages.add( pluginMessage );
relayMessages.add( pluginMessage );
}
}

View File

@ -13,7 +13,6 @@ import net.md_5.bungee.api.event.TabCompleteEvent;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.PacketHandler;
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.Chat;
import net.md_5.bungee.protocol.packet.PlayerListItem;
@ -191,9 +190,9 @@ public class UpstreamBridge extends PacketHandler
}
// TODO: Unregister as well?
if ( pluginMessage.getTag().equals( "REGISTER" ) )
if ( PluginMessage.SHOULD_RELAY.apply( pluginMessage ) )
{
con.getPendingConnection().getRegisterMessages().add( pluginMessage );
con.getPendingConnection().getRelayMessages().add( pluginMessage );
}
}