public PluginMessage registerChannels(int protocolVersion) { if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) { return new PluginMessage( "minecraft:register", Util.format( Iterables.transform( pluginChannels, PluginMessage.MODERNISE ), "\00" ).getBytes( Charsets.UTF_8 ), false ); } return new PluginMessage( "REGISTER", Util.format( pluginChannels, "\00" ).getBytes( Charsets.UTF_8 ), false ); }
@Override public void handle(PluginMessage pluginMessage) throws Exception if ( pluginMessage.getTag().equals( "BungeeCord" ) ) if ( pluginMessage.getTag().equals( "FML" ) && pluginMessage.getStream().readUnsignedByte() == 1 ) if ( pluginMessage.getTag().equals( ForgeConstants.FML_HANDSHAKE_TAG ) ) if ( con.getServer() != null && !con.getServer().isForgeServer() && pluginMessage.getData().length > Short.MAX_VALUE ) PluginMessageEvent event = new PluginMessageEvent( con, con.getServer(), pluginMessage.getTag(), pluginMessage.getData().clone() ); if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
/** * Handles any {@link PluginMessage} that contains a FML Handshake or Forge * Register. * * @param message The message to handle. * @throws IllegalArgumentException If the wrong packet is sent down. */ public void handle(PluginMessage message) throws IllegalArgumentException { if ( !message.getTag().equalsIgnoreCase( ForgeConstants.FML_HANDSHAKE_TAG ) && !message.getTag().equalsIgnoreCase( ForgeConstants.FORGE_REGISTER ) ) { throw new IllegalArgumentException( "Expecting a Forge REGISTER or FML Handshake packet." ); } message.setAllowExtendedPacket( true ); // FML allows extended packets so this must be enabled ForgeServerHandshakeState prevState = state; packetQueue.add( message ); state = state.send( message, con ); if ( state != prevState ) // send packets { synchronized ( packetQueue ) { while ( !packetQueue.isEmpty() ) { ForgeLogger.logServer( LogDirection.SENDING, prevState.name(), packetQueue.getFirst() ); con.getForgeClientHandler().receive( packetQueue.removeFirst() ); } } } }
@Override public void handle(PluginMessage pluginMessage) throws Exception DataInput in = pluginMessage.getStream(); PluginMessageEvent event = new PluginMessageEvent( server, con, pluginMessage.getTag(), pluginMessage.getData().clone() ); if ( pluginMessage.getTag().equals( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand" ) ) ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() ); String serverBrand = DefinedPacket.readString( brand ); brand.release(); pluginMessage.setData( DefinedPacket.toArray( brand ) ); brand.release(); if ( pluginMessage.getTag().equals( "BungeeCord" ) )
/** * Gets the registered FML channels from the packet. * * @param pluginMessage The packet representing FMLProxyPacket. * @return The registered channels. */ public static Set<String> readRegisteredChannels(PluginMessage pluginMessage) { String channels = new String( pluginMessage.getData(), Charsets.UTF_8 ); String[] split = channels.split( "\0" ); Set<String> channelSet = ImmutableSet.copyOf( split ); return channelSet; }
for (Object message : (List) relayMessages) { PluginMessage plMsg = (PluginMessage) message; String channel = plMsg.getTag(); int id1_13 = ProtocolVersion.v1_13.getId(); if (previousServerProtocol != -1) { channel = InventoryPackets.getNewPluginChannelId(channel); if (channel.equals("minecraft:register")) { String[] channels = new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0"); for (int i = 0; i < channels.length; i++) { channels[i] = InventoryPackets.getNewPluginChannelId(channels[i]); plMsg.setData(Joiner.on('\0').join(channels).getBytes(StandardCharsets.UTF_8)); String[] channels = new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0"); for (int i = 0; i < channels.length; i++) { channels[i] = InventoryPackets.getOldPluginChannelId(channels[i]); plMsg.setData(Joiner.on('\0').join(channels).getBytes(StandardCharsets.UTF_8)); plMsg.setTag(channel);
static void logServer(LogDirection direction, String stateName, PluginMessage message) { String dir = direction == LogDirection.SENDING ? "Server -> Bungee" : "Server <- Bungee"; String log = "[" + stateName + " " + dir + "][" + direction.name() + ": " + getNameFromDiscriminator( message.getTag(), message ) + "]"; BungeeCord.getInstance().getLogger().log( Level.FINE, log ); }
public void setData(ByteBuf buf) { Preconditions.checkNotNull(buf, "Null buffer"); setData(ByteBufUtil.getBytes(buf)); }
@Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( tag, buf ); if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) { writeArrayLegacy( data, buf, allowExtendedPacket ); } else { buf.writeBytes( data ); } }
@Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { tag = readString( buf ); if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) { data = readArrayLegacy( buf ); } else { int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000; Preconditions.checkArgument( buf.readableBytes() < maxSize ); data = new byte[ buf.readableBytes() ]; buf.readBytes( data ); } }
@Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? MODERNISE.apply( tag ) : tag, buf ); buf.writeBytes( data ); }
@Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { tag = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? MODERNISE.apply( readString( buf ) ) : readString( buf ); int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000; Preconditions.checkArgument( buf.readableBytes() < maxSize ); data = new byte[ buf.readableBytes() ]; buf.readBytes( data ); }
@Override public void handle(PluginMessage pluginMessage) throws Exception PluginMessageEvent event = new PluginMessageEvent( con.getServer(), con, pluginMessage.getTag(), pluginMessage.getData().clone() ); if ( pluginMessage.getTag().equals( "MC|Brand" ) ) 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 ); brand.release(); } catch ( Exception ignored ) String serverBrand = new String( pluginMessage.getData(), "UTF-8" ); pluginMessage.setData( ( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand ).getBytes( "UTF-8" ) ); if ( pluginMessage.getTag().equals( "BungeeCord" ) ) DataInput in = pluginMessage.getStream();
private static String getNameFromDiscriminator(String channel, PluginMessage message) byte discrim = message.getData()[0]; if ( channel.equals( ForgeConstants.FML_HANDSHAKE_TAG ) )
/** * Handles the Forge packet. * * @param message The Forge Handshake packet to handle. */ public void handle(PluginMessage message) throws IllegalArgumentException { if ( !message.getTag().equalsIgnoreCase( ForgeConstants.FML_HANDSHAKE_TAG ) ) { throw new IllegalArgumentException( "Expecting a Forge Handshake packet." ); } message.setAllowExtendedPacket( true ); // FML allows extended packets so this must be enabled ForgeClientHandshakeState prevState = state; Preconditions.checkState( packetQueue.size() < 128, "Forge packet queue too big!" ); packetQueue.add( message ); state = state.send( message, con ); if ( state != prevState ) // state finished, send packets { synchronized ( packetQueue ) { while ( !packetQueue.isEmpty() ) { ForgeLogger.logClient( ForgeLogger.LogDirection.SENDING, prevState.name(), packetQueue.getFirst() ); con.getForgeServerHandler().receive( packetQueue.removeFirst() ); } } } }
static void logClient(LogDirection direction, String stateName, PluginMessage message) { String dir = direction == LogDirection.SENDING ? "Client -> Bungee" : "Client <- Bungee"; String log = "[" + stateName + " " + dir + "][" + direction.name() + ": " + getNameFromDiscriminator( message.getTag(), message ) + "]"; BungeeCord.getInstance().getLogger().log( Level.FINE, log ); }
/** * Sends the server ID list to the client, or stores it for sending later. * * @param idList The {@link PluginMessage} to send to the client containing * the ID list. * @throws IllegalArgumentException Thrown if the {@link PluginMessage} was * not as expected. */ public void setServerIdList(PluginMessage idList) throws IllegalArgumentException { if ( !idList.getTag().equalsIgnoreCase( ForgeConstants.FML_HANDSHAKE_TAG ) || idList.getData()[0] != 3 ) { throw new IllegalArgumentException( "idList" ); } this.serverIdList = idList; }
@Override public ForgeServerHandshakeState handle(PluginMessage message, ChannelWrapper ch) { ForgeLogger.logServer( LogDirection.RECEIVED, this.name(), message ); if ( message.getData()[0] == 1 ) // Client Hello { ch.write( message ); } if ( message.getData()[0] == 2 ) // Client ModList { ch.write( message ); } return this; }
@Override public void handle(PluginMessage pluginMessage) throws Exception if ( pluginMessage.getTag().equals( "BungeeCord" ) ) if ( pluginMessage.getTag().equals( "FML" ) && pluginMessage.getStream().readUnsignedByte() == 1 ) if ( pluginMessage.getTag().equals( ForgeConstants.FML_HANDSHAKE_TAG ) ) if ( con.getServer() != null && !con.getServer().isForgeServer() && pluginMessage.getData().length > Short.MAX_VALUE ) PluginMessageEvent event = new PluginMessageEvent( con, con.getServer(), pluginMessage.getTag(), pluginMessage.getData().clone() ); if ( bungee.getPluginManager().callEvent( event ).isCancelled() ) if ( pluginMessage.getTag().equals( "REGISTER" ) )