private EnumMap<Side, FMLEmbeddedChannel> getNewChannelHandler() { EnumMap<Side, FMLEmbeddedChannel> handlers = NetworkRegistry.INSTANCE.newChannel(ID, handler); ChannelHandler.PacketExecuter executer = new ChannelHandler.PacketExecuter(); for(Map.Entry<Side, FMLEmbeddedChannel> e : handlers.entrySet()) { FMLEmbeddedChannel channel = e.getValue(); String codec = channel.findChannelHandlerNameForType(ChannelHandler.class); channel.pipeline().addAfter(codec, "PacketExecuter", executer); } return handlers; }
/** * 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()); }
/** * 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 type * @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(Class<? extends IMessageHandler<REQ, 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 SendPacketToPlayerListExcept(AbstractPacket packet, EnumMap<Side, FMLEmbeddedChannel> channels, ArrayList<EntityPlayer> list, EntityPlayer pla){ for(EntityPlayer pl : list) { if(pl.getCommandSenderName().equalsIgnoreCase(pla.getCommandSenderName())) continue; channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(pl); channels.get(Side.SERVER).writeAndFlush(packet); } }
public static void SendPacketToPlayerList(AbstractPacket packet, EnumMap<Side, FMLEmbeddedChannel> channels, ArrayList<EntityPlayer> list){ for(EntityPlayer pl : list) { channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(pl); channels.get(Side.SERVER).writeAndFlush(packet); } }
public static void sendToAllExcept(AbstractPacket packet, EntityPlayer player, EnumMap<Side, FMLEmbeddedChannel> channels) { if(FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList != null && FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList.size() > 0) for(int i = 0; i < FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList.size(); i++) { EntityPlayer player1 = (EntityPlayer)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList.get(i); if(player.getCommandSenderName().equalsIgnoreCase(player1.getCommandSenderName())) { continue; } PacketHandler.sendToPlayer(packet, player1, channels); } }
@SideOnly(Side.CLIENT) public void setClientHandler(SimpleChannelInboundHandler<T> handler) { FMLEmbeddedChannel channel = channels.get(Side.CLIENT); String codecName = channel.findChannelHandlerNameForType(codec.getClass()); if(handlers.get(Side.CLIENT) != null) { channel.pipeline().remove("ClientHandler"); } channel.pipeline().addAfter(codecName, "ClientHandler", handler); handlers.put(Side.CLIENT, handler); }
public void setServerHandler(SimpleChannelInboundHandler<T> handler) { FMLEmbeddedChannel channel = channels.get(Side.SERVER); String codecName = channel.findChannelHandlerNameForType(codec.getClass()); if(handlers.get(Side.SERVER) != null) { channel.pipeline().remove("ServerHandler"); } channel.pipeline().addAfter(codecName, "ServerHandler", handler); handlers.put(Side.SERVER, handler); }
public static void register() { NetworkHandler.channels = (EnumMap<Side, FMLEmbeddedChannel>)NetworkRegistry.INSTANCE.newChannel("XU|Pkt", new ChannelHandler[] { new PacketCodec(), ExtraUtilsMod.proxy.getNewPacketHandler() }); }
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, messageHandler.getClass().getName(), 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, messageHandler.getClass().getName(), handler); }
public ImagineNetwork(final String channelName) { final Map<Side, FMLEmbeddedChannel> channels = (Map<Side, FMLEmbeddedChannel>)NetworkRegistry.INSTANCE.newChannel(channelName, new ChannelHandler[] { new ImaginePacketCodec(this), new ImaginePacketHandler() }); this.mServerChannel = channels.get(Side.SERVER); this.mClientChannel = channels.get(Side.CLIENT); }
public static void transferPlayerToDimension(EntityPlayerMP player, int dim, ServerConfigurationManager manager, Environment environ) { int oldDim = player.dimension; WorldServer worldserver = manager.getServerInstance().worldServerForDimension(player.dimension); player.dimension = dim; WorldServer worldserver1 = manager.getServerInstance().worldServerForDimension(player.dimension); // Cauldron dont crash the client, let 'em know there's a new dimension in town if (DimensionManager.isBukkitDimension(dim)) { FMLEmbeddedChannel serverChannel = ForgeNetworkHandler.getServerChannel(); serverChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); serverChannel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); serverChannel.writeOutbound(new ForgeMessage.DimensionRegisterMessage(dim, environ.getId())); } // Cauldron end player.playerNetServerHandler.sendPacket(new S07PacketRespawn(dim, worldserver1.difficultySetting, worldserver1.getWorldInfo() .getTerrainType(), player.theItemInWorldManager.getGameType())); player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel)); worldserver.removePlayerEntityDangerously(player); if (player.riddenByEntity != null) { player.riddenByEntity.mountEntity(null); } if (player.ridingEntity != null) { player.mountEntity(null); } player.isDead = false; transferEntityToWorld(player, worldserver, worldserver1); manager.func_72375_a(player, worldserver); player.playerNetServerHandler.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch); player.theItemInWorldManager.setWorld(worldserver1); manager.updateTimeAndWeatherForPlayer(player, worldserver1); manager.syncPlayerInventory(player); Iterator<PotionEffect> iterator = player.getActivePotionEffects().iterator(); while (iterator.hasNext()) { PotionEffect potioneffect = iterator.next(); player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), potioneffect)); } FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldDim, dim); }
private <REQ extends IMessage, REPLY extends IMessage, NH extends INetHandler> void addServerHandlerAfter(FMLEmbeddedChannel channel, String type, Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestType) { SimpleChannelHandlerWrapper<REQ, REPLY> handler = getHandlerWrapper(messageHandler, Side.SERVER, requestType); channel.pipeline().addAfter(type, messageHandler.getName(), handler); }
private <REQ extends IMessage, REPLY extends IMessage, NH extends INetHandler> void addClientHandlerAfter(FMLEmbeddedChannel channel, String type, Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestType) { SimpleChannelHandlerWrapper<REQ, REPLY> handler = getHandlerWrapper(messageHandler, Side.CLIENT, requestType); channel.pipeline().addAfter(type, messageHandler.getName(), handler); }
public void sendTo(IBarrelMessage message, EntityPlayerMP player) { ((FMLEmbeddedChannel)this.channels.get(Side.SERVER)).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); ((FMLEmbeddedChannel)this.channels.get(Side.SERVER)).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); ((FMLEmbeddedChannel)this.channels.get(Side.SERVER)).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); }
public void sendToDimension(IBarrelMessage message, int dimensionId) { ((FMLEmbeddedChannel)this.channels.get(Side.SERVER)).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION); ((FMLEmbeddedChannel)this.channels.get(Side.SERVER)).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(Integer.valueOf(dimensionId)); ((FMLEmbeddedChannel)this.channels.get(Side.SERVER)).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); }
public void sendToAllAround(IBarrelMessage message, NetworkRegistry.TargetPoint point) { ((FMLEmbeddedChannel)this.channels.get(Side.SERVER)).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); ((FMLEmbeddedChannel)this.channels.get(Side.SERVER)).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point); ((FMLEmbeddedChannel)this.channels.get(Side.SERVER)).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); }
public Packet func_145844_m() { return ((FMLEmbeddedChannel)BarrelPacketHandler.INSTANCE.channels.get(Side.SERVER)).generatePacketFrom(new Message0x00FulleTileEntityNBT(this)); }
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()); }
public void sendPayloadToPlayers(ByteBuf payload, Collection<EntityPlayerMP> players) { FMLProxyPacket packet = new FMLProxyPacket(payload, CHANNEL_NAME); FMLEmbeddedChannel channel = channels.get(Side.SERVER); ExtendedOutboundHandler.selectTargets(channel, SelectMultiplePlayers.INSTANCE, players); channel.writeAndFlush(packet).addListener(NetUtils.LOGGING_LISTENER); }
public static Packet GetPacket(AbstractPacket packet, EnumMap<Side, FMLEmbeddedChannel> channels){ return channels.get(Side.SERVER).generatePacketFrom(packet); }
public static void sendToAll(AbstractPacket packet, EnumMap<Side, FMLEmbeddedChannel> channels) { channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL); channels.get(Side.SERVER).writeAndFlush(packet); }
public static void sendToPlayer(AbstractPacket packet, EntityPlayer player, EnumMap<Side, FMLEmbeddedChannel> channels) { channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); channels.get(Side.SERVER).writeAndFlush(packet); }
public static void sendToAllAround(AbstractPacket packet, NetworkRegistry.TargetPoint point, EnumMap<Side, FMLEmbeddedChannel> channels) { channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point); channels.get(Side.SERVER).writeAndFlush(packet); }
public static void sendToDimension(AbstractPacket packet, int dimension, EnumMap<Side, FMLEmbeddedChannel> channels) { channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION); channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimension); channels.get(Side.SERVER).writeAndFlush(packet); }