@SubscribeEvent public void onConnectionCreated(FMLNetworkEvent.ServerConnectionFromClientEvent event) { JustEnoughDimensions.logInfo("FMLNetworkEvent.ServerConnectionFromClientEvent: Syncing dimension data to client"); DimensionSyncPacket packet = new DimensionSyncPacket(); packet.addDimensionData(DimensionConfig.instance().getRegisteredDimensions()); FMLEmbeddedChannel channel = JustEnoughDimensions.channels.get(Side.SERVER); channel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DISPATCHER); channel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(event.getManager().channel().attr(NetworkDispatcher.FML_DISPATCHER).get()); channel.writeOutbound(packet); }
/** * Register a message and it's associated handler. The message will have the supplied discriminator byte. The message handler will * be registered on the supplied side (this is the side where you want the message to be processed and acted upon). * * @param messageHandler the message handler instance * @param requestMessageType the message type * @param discriminator a discriminator byte * @param side the side for the handler */ public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(IMessageHandler<? super REQ, ? extends REPLY> messageHandler, Class<REQ> requestMessageType, int discriminator, Side side) { packetCodec.addDiscriminator(discriminator, requestMessageType); FMLEmbeddedChannel channel = channels.get(side); String type = channel.findChannelHandlerNameForType(SimpleIndexedCodec.class); if (side == Side.SERVER) { addServerHandlerAfter(channel, type, messageHandler, requestMessageType); } else { addClientHandlerAfter(channel, type, messageHandler, requestMessageType); } }
public static void registerChannel(ForgeModContainer forgeModContainer, Side side) { channelPair = NetworkRegistry.INSTANCE.newChannel(forgeModContainer, "FORGE", new ForgeRuntimeCodec()); if (side == Side.CLIENT) { addClientHandlers(); } FMLEmbeddedChannel serverChannel = channelPair.get(Side.SERVER); serverChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.NOWHERE); String handlerName = serverChannel.findChannelHandlerNameForType(ForgeRuntimeCodec.class); serverChannel.pipeline().addAfter(handlerName, "ServerToClientConnection", new ServerToClientConnectionEstablishedHandler()); }
@SideOnly(Side.CLIENT) private static void addClientHandlers() { FMLEmbeddedChannel clientChannel = channelPair.get(Side.CLIENT); String handlerName = clientChannel.findChannelHandlerNameForType(ForgeRuntimeCodec.class); clientChannel.pipeline().addAfter(handlerName, "DimensionHandler", new DimensionMessageHandler()); clientChannel.pipeline().addAfter(handlerName, "FluidIdRegistryHandler", new FluidIdRegistryMessageHandler()); }
public static FMLEmbeddedChannel getOrCreateChannel(String channelName, Side side) { if (!NetworkRegistry.INSTANCE.hasChannel(channelName, side)) { NetworkRegistry.INSTANCE.newChannel(channelName, new CustomInboundHandler()); } return NetworkRegistry.INSTANCE.getChannel(channelName, side); }
public static void assignHandler(Object channelKey, ICustomPacketHandler handler) { String channelName = channelName(channelKey); Side side = handler instanceof IServerPacketHandler ? Side.SERVER : Side.CLIENT; FMLEmbeddedChannel channel = getOrCreateChannel(channelName, side); channel.attr(cclHandler).get().handlers.put(side, side == Side.SERVER ? new ServerInboundHandler(handler) : new ClientInboundHandler(handler)); }
private SyncChannelHolder() { final EnumMap<Side, FMLEmbeddedChannel> channels = NetworkRegistry.INSTANCE.newChannel(CHANNEL_NAME, new InboundSyncHandler()); for (Map.Entry<Side, FMLEmbeddedChannel> e : channels.entrySet()) { final FMLEmbeddedChannel channel = e.getValue(); ExtendedOutboundHandler.install(channel); senders.put(e.getKey(), ExtPacketSenderFactory.createMultiplePlayersSender(channel)); } }
public void registerPacket(String modId, int i, Class<? extends AbstractPacket> packetClass) { packetCodec.addDiscriminator(i, packetClass); try { Side side = packetClass.newInstance().receivingSide(); if(side == null) { FMLEmbeddedChannel channelServer = channels.get(Side.SERVER); String typeServer = channelServer.findChannelHandlerNameForType(AbstractPacketCodec.class); PacketHandlerWrapper handlerServer = new PacketHandlerWrapper(Side.SERVER, packetClass); channelServer.pipeline().addAfter(typeServer, generateName(channelServer.pipeline(), handlerServer), handlerServer); FMLEmbeddedChannel channelClient = channels.get(Side.CLIENT); String typeClient = channelClient.findChannelHandlerNameForType(AbstractPacketCodec.class); PacketHandlerWrapper handlerClient = new PacketHandlerWrapper(Side.CLIENT, packetClass); channelClient.pipeline().addAfter(typeClient, generateName(channelClient.pipeline(), handlerClient), handlerClient); } else { FMLEmbeddedChannel channel = channels.get(side); String type = channel.findChannelHandlerNameForType(AbstractPacketCodec.class); PacketHandlerWrapper handler = new PacketHandlerWrapper(side, packetClass); channel.pipeline().addAfter(type, generateName(channel.pipeline(), handler), handler); } } catch(Exception e) { iChunUtil.LOGGER.warn("Could not create packet for class " + packetClass.getName() + " for channel " + modId + ". Is there a default constructor in that class?"); throw Throwables.propagate(e); } }
@SuppressWarnings("unchecked") public void preInit(FMLPreInitializationEvent event) { Util.logger.info("Injecting FML packet filter..."); try { EnumMap<Side, FMLEmbeddedChannel> channelPair = InjectionHandler.readStaticFieldOfType(FMLNetworkHandler.class, EnumMap.class); String targetName = channelPair.get(Side.SERVER).findChannelHandlerNameForType(FMLRuntimeCodec.class); ChannelPipeline pipeline = channelPair.get(Side.SERVER).pipeline(); pipeline.addAfter(targetName, "universalremote_OpenGuiFilter", m_openGuiFilter); } catch (Exception e) { Util.logger.logException("Unable to inject into FMLNetworkHandler!", e); } }
private <REQ extends IMessage, REPLY extends IMessage, NH extends INetHandler> void addServerHandlerAfter(FMLEmbeddedChannel channel, String type, IMessageHandler<? super REQ, ? extends REPLY> messageHandler, Class<REQ> requestType) { SimpleChannelHandlerWrapper<REQ, REPLY> handler = getHandlerWrapper(messageHandler, Side.SERVER, requestType); channel.pipeline().addAfter(type, generateName(channel.pipeline(), handler), handler); }
private <REQ extends IMessage, REPLY extends IMessage, NH extends INetHandler> void addClientHandlerAfter(FMLEmbeddedChannel channel, String type, IMessageHandler<? super REQ, ? extends REPLY> messageHandler, Class<REQ> requestType) { SimpleChannelHandlerWrapper<REQ, REPLY> handler = getHandlerWrapper(messageHandler, Side.CLIENT, requestType); channel.pipeline().addAfter(type, generateName(channel.pipeline(), handler), handler); }
public static void sendPacketToPlayer(FFSPacket packet, EntityPlayer player) { FMLEmbeddedChannel channel = channels.get(Side.SERVER); channel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); channel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); channel.writeOutbound(packet); }
public static void sendPacketToAllPlayers(FFSPacket packet) { FMLEmbeddedChannel channel = channels.get(Side.SERVER); channel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL); channel.writeOutbound(packet); }
public static void sendPacketToServer(FFSPacket packet) { FMLEmbeddedChannel channel = channels.get(Side.CLIENT); channel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); channel.writeOutbound(packet); }
public static void assignHandshakeHandler(Object channelKey, IHandshakeHandler handler) { FMLEmbeddedChannel channel = getOrCreateChannel(channelName(channelKey), Side.SERVER); channel.pipeline().addLast(new HandshakeInboundHandler(handler)); }
public static EnumMap<Side, FMLEmbeddedChannel> getChannels() { return channels; }
public static void setChannels(EnumMap<Side, FMLEmbeddedChannel> _channels) { channels = _channels; }
public Packet toMCPacket(SasaPacketBase packet) { return ((FMLEmbeddedChannel)channels.get(FMLCommonHandler.instance().getEffectiveSide())).generatePacketFrom(packet); }
@Override protected FMLEmbeddedChannel getChannel(Side side) { return channels.get(side); }
public static void install(Map<Side, FMLEmbeddedChannel> channels) { for (Side side : Side.values()) install(channels.get(side)); }
public static void install(FMLEmbeddedChannel fmlEmbeddedChannel) { fmlEmbeddedChannel.pipeline().addAfter("fml:outbound", "om:outbound", new ExtendedOutboundHandler()); }