@SuppressWarnings("unchecked") @Override public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet) { int dimension = (Integer)args; ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder(); for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b) { if (dimension == player.field_71093_bK) { NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); // Null dispatchers may exist for fake players - skip them if (dispatcher != null) builder.add(dispatcher); } } return builder.build(); }
@SuppressWarnings("unchecked") @Override public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet) { TargetPoint tp = (TargetPoint)args; ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder(); for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b) { if (player.field_71093_bK == tp.dimension) { double d4 = tp.x - player.field_70165_t; double d5 = tp.y - player.field_70163_u; double d6 = tp.z - player.field_70161_v; if (d4 * d4 + d5 * d5 + d6 * d6 < tp.range * tp.range) { NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); if (dispatcher != null) builder.add(dispatcher); } } } return builder.build(); }
@SuppressWarnings("unchecked") @Override public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet) { int dimension = (Integer)args; ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder(); for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList) { if (dimension == player.dimension) { NetworkDispatcher dispatcher = player.playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); // Null dispatchers may exist for fake players - skip them if (dispatcher != null) builder.add(dispatcher); } } return builder.build(); }
@SuppressWarnings("unchecked") @Override public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet) { TargetPoint tp = (TargetPoint)args; ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder(); for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList) { if (player.dimension == tp.dimension) { double d4 = tp.x - player.posX; double d5 = tp.y - player.posY; double d6 = tp.z - player.posZ; if (d4 * d4 + d5 * d5 + d6 * d6 < tp.range * tp.range) { NetworkDispatcher dispatcher = player.playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); if (dispatcher != null) builder.add(dispatcher); } } } return builder.build(); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof NetworkHandshakeEstablished) { INetHandler netHandler = ((NetworkDispatcher) ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).get()).getNetHandler(); if (netHandler instanceof NetHandlerPlayServer) handler.handshakeRecieved((NetHandlerPlayServer) netHandler); } else ctx.fireUserEventTriggered(evt); }
public static List<FMLProxyPacket> forwardHandshake(CompleteHandshake push, NetworkDispatcher target, Side side) { channelPair.get(side).attr(NetworkDispatcher.FML_DISPATCHER).set(target); channelPair.get(side).writeOutbound(push); ArrayList<FMLProxyPacket> list = new ArrayList<FMLProxyPacket>(); for (Object o: channelPair.get(side).outboundMessages()) { list.add((FMLProxyPacket)o); } channelPair.get(side).outboundMessages().clear(); return list; }
@Override public void validateArgs(Object args) { if (!(args instanceof NetworkDispatcher)) { throw new RuntimeException("DISPATCHER expects a NetworkDispatcher"); } }
@Override public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet) { EntityPlayerMP player = (EntityPlayerMP) args; NetworkDispatcher dispatcher = player == null ? null : player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); return dispatcher == null ? ImmutableList.<NetworkDispatcher>of() : ImmutableList.of(dispatcher); }
@SuppressWarnings("unchecked") @Override public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet) { ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder(); for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b) { NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); if (dispatcher != null) builder.add(dispatcher); } return builder.build(); }
/** * INTERNAL fire a handshake to all channels * @param networkDispatcher The dispatcher firing * @param origin which side the dispatcher is on */ public void fireNetworkHandshake(NetworkDispatcher networkDispatcher, Side origin) { NetworkHandshakeEstablished handshake = new NetworkHandshakeEstablished(networkDispatcher, networkDispatcher.getNetHandler(), origin); for (Entry<String, FMLEmbeddedChannel> channel : channels.get(origin).entrySet()) { channel.getValue().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.DISPATCHER); channel.getValue().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(networkDispatcher); channel.getValue().pipeline().fireUserEventTriggered(handshake); } }
@Override public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet) { EntityPlayerMP player = (EntityPlayerMP) args; NetworkDispatcher dispatcher = player == null ? null : player.playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); return dispatcher == null ? ImmutableList.<NetworkDispatcher>of() : ImmutableList.of(dispatcher); }
@SuppressWarnings("unchecked") @Override public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet) { ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder(); for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList) { NetworkDispatcher dispatcher = player.playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); if (dispatcher != null) builder.add(dispatcher); } return builder.build(); }
@Override public void listDispatchers(Object arg, Collection<NetworkDispatcher> result) { try { Collection<EntityPlayerMP> players = (Collection<EntityPlayerMP>) arg; for (EntityPlayerMP player : players) { NetworkDispatcher dispatcher = NetUtils.getPlayerDispatcher(player); if (dispatcher != null) result.add(dispatcher); else Log.info("Trying to send message to disconnected player %s", player); } } catch (ClassCastException e) { throw new IllegalArgumentException("Argument must be collection of EntityPlayerMP"); } }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (!(msg instanceof FMLProxyPacket)) { ctx.write(msg); return; } final Channel channel = ctx.channel(); final IPacketTargetSelector target = channel.attr(MESSAGETARGET).get(); if (target == null) { ctx.write(msg); return; } final FMLProxyPacket pkt = (FMLProxyPacket)msg; final Side channelSide = channel.attr(NetworkRegistry.CHANNEL_SOURCE).get(); Preconditions.checkState(target.isAllowedOnSide(channelSide), "Packet not allowed on side"); final String channelName = channel.attr(NetworkRegistry.FML_CHANNEL).get(); Object arg = channel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).get(); try { Collection<NetworkDispatcher> dispatchers = Lists.newArrayList(); target.listDispatchers(arg, dispatchers); for (NetworkDispatcher dispatcher : dispatchers) dispatcher.sendProxy(pkt); } catch (Throwable t) { throw new IllegalStateException(String.format( "Failed to select and send message (selector %s, arg: %s, channel: %s, side: %s)", target, arg, channelName, channelSide), t); } }
@Override protected void channelRead0(ChannelHandlerContext ctx, CompleteHandshake msg) throws Exception { // Cauldron start - attempt to fix race condition with attr being null Object attr = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER); if (attr != null) { NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).getAndRemove(); dispatcher.completeHandshake(msg.target); } // Cauldron end }
public NetworkHandshakeEstablished(NetworkDispatcher dispatcher, INetHandler netHandler, Side origin) { this.netHandler = netHandler; this.dispatcher = dispatcher; this.side = origin; }