/** * 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; }
private static String getNameFromDiscriminator(String channel, PluginMessage message) byte discrim = message.getData()[0]; if ( channel.equals( ForgeConstants.FML_HANDSHAKE_TAG ) )
/** * Sends the server mod list to the client, or stores it for sending later. * * @param modList The {@link PluginMessage} to send to the client containing * the mod list. * @throws IllegalArgumentException Thrown if the {@link PluginMessage} was * not as expected. */ public void setServerModList(PluginMessage modList) throws IllegalArgumentException { if ( !modList.getTag().equalsIgnoreCase( ForgeConstants.FML_HANDSHAKE_TAG ) || modList.getData()[0] != 2 ) { throw new IllegalArgumentException( "modList" ); } this.serverModList = modList; }
/** * 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 boolean apply(PluginMessage input) { return ( input.getTag().equals( "REGISTER" ) || input.getTag().equals( "minecraft:register" ) || input.getTag().equals( "MC|Brand" ) || input.getTag().equals( "minecraft:brand" ) ) && input.getData().length < Byte.MAX_VALUE; } };
@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 ForgeServerHandshakeState send(PluginMessage message, UserConnection con) { if ( message.getData()[0] == 3 && message.getTag().equals( ForgeConstants.FML_HANDSHAKE_TAG ) ) { con.getForgeClientHandler().setServerIdList( message ); return this; } if ( message.getData()[0] == -1 && message.getTag().equals( ForgeConstants.FML_HANDSHAKE_TAG ) ) // transition to COMPLETE after sending ACK { return this; } if ( message.getTag().equals( ForgeConstants.FORGE_REGISTER ) ) // wait for Forge channel registration { return COMPLETE; } return this; } },
/** * Gets the modlist from the packet. * * @param pluginMessage The packet representing FMLProxyPacket. * @return The modlist. */ public static Map<String, String> readModList(PluginMessage pluginMessage) { Map<String, String> modTags = new HashMap<>(); ByteBuf payload = Unpooled.wrappedBuffer( pluginMessage.getData() ); byte discriminator = payload.readByte(); if ( discriminator == 2 ) // ModList { ByteBuf buffer = payload.slice(); int modCount = DefinedPacket.readVarInt( buffer, 2 ); for ( int i = 0; i < modCount; i++ ) { modTags.put( DefinedPacket.readString( buffer ), DefinedPacket.readString( buffer ) ); } } return modTags; }
@Override public ForgeClientHandshakeState send(PluginMessage message, UserConnection con) { // Client Hello. if ( message.getData()[0] == 1 ) { return this; } // Mod list. if ( message.getData()[0] == 2 ) { if ( con.getForgeClientHandler().getClientModList() == null ) { // This is the first Forge connection - so get the mods now. // Once we've done it, no point doing it again. Map<String, String> clientModList = ForgeUtils.readModList( message ); con.getForgeClientHandler().setClientModList( clientModList ); } return WAITINGSERVERDATA; } return this; }
@Override public ForgeClientHandshakeState handle(PluginMessage message, UserConnection con) { ForgeLogger.logClient( ForgeLogger.LogDirection.RECEIVED, this.name(), message ); // Mod list. if ( message.getData()[0] == 2 ) { con.unsafe().sendPacket( message ); } return this; }
@Override public ForgeClientHandshakeState handle(PluginMessage message, UserConnection con) { // Ack. if ( message.getData()[0] == -1 ) { ForgeLogger.logClient( ForgeLogger.LogDirection.RECEIVED, this.name(), message ); con.unsafe().sendPacket( message ); } return this; }
@Override public ForgeClientHandshakeState handle(PluginMessage message, UserConnection con) { ForgeLogger.logClient( ForgeLogger.LogDirection.RECEIVED, this.name(), message ); // Server Hello. if ( message.getData()[0] == 0 ) { con.unsafe().sendPacket( message ); } return this; }
@Override public ForgeClientHandshakeState handle(PluginMessage message, UserConnection con) { // Ack. if ( message.getData()[0] == -1 ) { ForgeLogger.logClient( ForgeLogger.LogDirection.RECEIVED, this.name(), message ); con.unsafe().sendPacket( message ); } return this; }
@Override public ForgeClientHandshakeState handle(PluginMessage message, UserConnection con) { ForgeLogger.logClient( ForgeLogger.LogDirection.RECEIVED, this.name(), message ); // Mod ID's. if ( message.getData()[0] == 3 ) { con.unsafe().sendPacket( message ); return this; } con.unsafe().sendPacket( message ); // pass everything else return this; }
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() )
/** * 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; }
@Override public ForgeClientHandshakeState handle(PluginMessage message, UserConnection con) { ForgeLogger.logClient( LogDirection.RECEIVED, this.name(), message ); // Server Hello. if ( message.getData()[0] == 0 ) { con.unsafe().sendPacket( message ); } return this; }
@Override public ForgeClientHandshakeState handle(PluginMessage message, UserConnection con) { // Ack. if ( message.getData()[0] == -1 ) { ForgeLogger.logClient( ForgeLogger.LogDirection.RECEIVED, this.name(), message ); con.unsafe().sendPacket( message ); } return this; }
@Override public ForgeClientHandshakeState handle(PluginMessage message, UserConnection con) { // Ack. if ( message.getData()[0] == -1 ) { ForgeLogger.logClient( ForgeLogger.LogDirection.RECEIVED, this.name(), message ); con.unsafe().sendPacket( message ); } return this; }