Java 类net.minecraftforge.fml.common.network.handshake.NetworkDispatcher 实例源码

项目:CustomWorldGen    文件:FMLOutboundHandler.java   
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    int dimension = (Integer)args;
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.builder();
    for (EntityPlayerMP player : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerList())
    {
        if (dimension == player.dimension)
        {
            NetworkDispatcher dispatcher = player.connection.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();
}
项目:CustomWorldGen    文件:FMLOutboundHandler.java   
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    TargetPoint tp = (TargetPoint)args;
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.builder();
    for (EntityPlayerMP player : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerList())
    {
        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.connection.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
                if (dispatcher != null) builder.add(dispatcher);
            }
        }
    }
    return builder.build();
}
项目:justenoughdimensions    文件:JEDEventHandler.java   
@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);
}
项目:CustomWorldGen    文件:FMLNetworkHandler.java   
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;
}
项目:CustomWorldGen    文件:FMLOutboundHandler.java   
@Override
public void validateArgs(Object args)
{
    if (!(args instanceof NetworkDispatcher))
    {
        throw new RuntimeException("DISPATCHER expects a NetworkDispatcher");
    }
}
项目:CustomWorldGen    文件:FMLOutboundHandler.java   
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    EntityPlayerMP player = (EntityPlayerMP) args;
    NetworkDispatcher dispatcher = (player == null || player instanceof FakePlayer) ? null : player.connection.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
    return dispatcher == null ? ImmutableList.<NetworkDispatcher>of() : ImmutableList.of(dispatcher);
}
项目:CustomWorldGen    文件:FMLOutboundHandler.java   
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.builder();
    for (EntityPlayerMP player : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerList())
    {
        NetworkDispatcher dispatcher = player.connection.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
        if (dispatcher != null) builder.add(dispatcher);
    }
    return builder.build();
}
项目:CustomWorldGen    文件:NetworkRegistry.java   
/**
 * 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);
    }
}
项目:CodeChickenLib    文件:PacketCustom.java   
@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.handshakeReceived((NetHandlerPlayServer) netHandler);
        }
    } else {
        ctx.fireUserEventTriggered(evt);
    }
}
项目:Factorization    文件:InteractionLiason.java   
private void initLiason() {
    // We're fairly similar to PacketProxyingPlayer.initWrapping()
    networkManager = new CustomChannelNetworkManager(proxiedChannel, EnumPacketDirection.SERVERBOUND);
    this.playerNetServerHandler = new NetHandlerPlayServer(MinecraftServer.getServer(), networkManager, this);
    playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).set(new NetworkDispatcher(networkManager));
    //Compare net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget.PLAYER.{...}.selectNetworks(Object, ChannelHandlerContext, FMLProxyPacket)
    playerNetServerHandler.netManager.setConnectionState(EnumConnectionState.PLAY);
}
项目:Factorization    文件:PacketProxyingPlayer.java   
void preinitWrapping() {
    playerNetServerHandler = new NetHandlerPlayServer(mcServer, networkManager, this);
    playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).set(new NetworkDispatcher(this.networkManager));
    //Compare net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget.PLAYER.{...}.selectNetworks(Object, ChannelHandlerContext, FMLProxyPacket)
    playerNetServerHandler.netManager.setConnectionState(EnumConnectionState.PLAY);
    /* (misc notes here)
     * We don't need to touch NetworkDispatcher; we need a NetworkManager.
     *
     * NetworkManager.scheduleOutboundPacket is too early I think?
     * What we really want is its channel.
     */
}
项目:Factorization    文件:HammerProxy.java   
public boolean queueUnwrappedPacket(EntityPlayer player, Object packetObj) {
    if (packetObj == null) return true;
    if (player == null) {
        if (packetObj instanceof C00PacketKeepAlive || packetObj instanceof S00PacketKeepAlive) {
            NORELEASE.fixme("Shouldn't this, like, not happen?");
            return true;
        }
        NORELEASE.println("No player to handle: " + packetObj + " " + packetObj.getClass().getSimpleName());
        return true;
    }
    if (player.worldObj.isRemote) return false;
    Packet packet = (Packet) packetObj;
    // May possibly need to inject the liason into things up higher, during reading. Somehow. Hopefulloy won't be needed.
    InteractionLiason liason = InteractionLiason.activeLiasons.get(player);
    if (liason == null) {
        if (!(packet instanceof C00PacketKeepAlive)) {
            // Seems our system isn't perfect. :/
            // Keepalives are generated from a different thread I guess.
            Hammer.logWarning("Liasonless wrapped packet: " + packet.getClass().getSimpleName() + " " + packet.toString());
        }
        return true;
    }
    NetHandlerPlayServer handler = liason.playerNetServerHandler;
    if (packet instanceof FMLProxyPacket) {
        FMLProxyPacket fml = (FMLProxyPacket) packet;
        NetworkDispatcher dispatcher = handler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
        fml.setTarget(Side.CLIENT);
        fml.setDispatcher(dispatcher);
        if (fml.payload().readerIndex() != 0) {
            Core.logSevere("Packet double-processing detected! Channel: " + fml.channel());
            return true;
        }
    }
    packet.processPacket(handler);
    return true;
}
项目:OpenModsLib    文件:SelectMultiplePlayers.java   
@Override
public void listDispatchers(Collection<EntityPlayerMP> players, Collection<NetworkDispatcher> result) {
    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);
    }
}
项目:OpenModsLib    文件:SelectChunkWatchers.java   
@Override
public void listDispatchers(DimCoord coord, Collection<NetworkDispatcher> result) {
    WorldServer server = DimensionManager.getWorld(coord.dimension);

    Set<EntityPlayerMP> players = NetUtils.getPlayersWatchingBlock(server, coord.blockPos.getX(), coord.blockPos.getZ());

    for (EntityPlayerMP player : players) {
        NetworkDispatcher dispatcher = NetUtils.getPlayerDispatcher(player);
        result.add(dispatcher);
    }
}
项目:OpenModsLib    文件:SelectEntityWatchers.java   
@Override
public void listDispatchers(Entity entity, Collection<NetworkDispatcher> result) {
    Preconditions.checkArgument(entity.world instanceof WorldServer, "Invalid side");
    WorldServer server = (WorldServer)entity.world;
    Set<EntityPlayerMP> players = NetUtils.getPlayersWatchingEntity(server, entity);

    for (EntityPlayerMP player : players) {
        NetworkDispatcher dispatcher = NetUtils.getPlayerDispatcher(player);
        result.add(dispatcher);
    }
}
项目:OpenModsLib    文件:ExtendedOutboundHandler.java   
@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 {
        final Collection<NetworkDispatcher> dispatchers = getDispatchers(target, arg);
        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);
    }

}
项目:CustomWorldGen    文件:NetworkHandshakeEstablished.java   
public NetworkHandshakeEstablished(NetworkDispatcher dispatcher, INetHandler netHandler, Side origin)
{
    this.netHandler = netHandler;
    this.dispatcher = dispatcher;
    this.side = origin;
}
项目:CustomWorldGen    文件:FMLProxyPacket.java   
public void setDispatcher(NetworkDispatcher networkDispatcher)
{
    this.dispatcher = networkDispatcher;
}
项目:CustomWorldGen    文件:FMLProxyPacket.java   
public NetworkDispatcher getDispatcher()
{
    return this.dispatcher;
}
项目:CustomWorldGen    文件:HandshakeCompletionHandler.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, CompleteHandshake msg) throws Exception
{
    NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).getAndRemove();
    dispatcher.completeHandshake(msg.target);
}
项目:CustomWorldGen    文件:FMLNetworkHandler.java   
public static void fmlServerHandshake(PlayerList scm, NetworkManager manager, EntityPlayerMP player)
{
    NetworkDispatcher dispatcher = NetworkDispatcher.allocAndSet(manager, scm);
    dispatcher.serverToClientHandshake(player);
}
项目:CustomWorldGen    文件:FMLNetworkHandler.java   
public static void fmlClientHandshake(NetworkManager networkManager)
{
    NetworkDispatcher dispatcher = NetworkDispatcher.allocAndSet(networkManager);
    dispatcher.clientToServerHandshake();
}
项目:CustomWorldGen    文件:FMLOutboundHandler.java   
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    return null;
}
项目:CustomWorldGen    文件:FMLOutboundHandler.java   
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    return ImmutableList.of((NetworkDispatcher)args);
}
项目:CustomWorldGen    文件:FMLOutboundHandler.java   
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    return ImmutableList.of(packet.getDispatcher());
}
项目:CustomWorldGen    文件:FMLOutboundHandler.java   
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    NetworkManager clientConnection = FMLCommonHandler.instance().getClientToServerNetworkManager();
    return clientConnection == null || clientConnection.channel().attr(NetworkDispatcher.FML_DISPATCHER).get() == null ? ImmutableList.<NetworkDispatcher>of() : ImmutableList.of(clientConnection.channel().attr(NetworkDispatcher.FML_DISPATCHER).get());
}
项目:CustomWorldGen    文件:FMLOutboundHandler.java   
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
{
    if (!(msg instanceof FMLProxyPacket))
    {
        return;
    }
    FMLProxyPacket pkt = (FMLProxyPacket) msg;
    OutboundTarget outboundTarget;
    Object args = null;
    NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
    // INTERNAL message callback - let it pass out
    if (dispatcher != null)
    {
        ctx.write(msg, promise);
        return;
    }

    outboundTarget = ctx.channel().attr(FML_MESSAGETARGET).get();
    Side channelSide = ctx.channel().attr(NetworkRegistry.CHANNEL_SOURCE).get();
    if (outboundTarget != null && outboundTarget.allowed.contains(channelSide))
    {
        args = ctx.channel().attr(FML_MESSAGETARGETARGS).get();
        outboundTarget.validateArgs(args);
    }
    else if (channelSide == Side.CLIENT)
    {
        outboundTarget = OutboundTarget.TOSERVER;
    }
    else
    {
        throw new FMLNetworkException("Packet arrived at the outbound handler without a valid target!");
    }

    List<NetworkDispatcher> dispatchers = outboundTarget.selectNetworks(args, ctx, pkt);

    // This will drop the messages into the output queue at the embedded channel
    if (dispatchers == null)
    {
        ctx.write(msg, promise);
        return;
    }
    for (NetworkDispatcher targetDispatcher : dispatchers)
    {
        targetDispatcher.sendProxy((FMLProxyPacket) msg);
    }
}
项目:OpenModsLib    文件:ExtendedOutboundHandler.java   
private static <T> Collection<NetworkDispatcher> getDispatchers(IPacketTargetSelector<T> target, Object arg) {
    final Collection<NetworkDispatcher> output = Lists.newArrayList();
    target.listDispatchers(target.castArg(arg), output);
    return output;
}
项目:OpenModsLib    文件:NetUtils.java   
public static NetworkDispatcher getPlayerDispatcher(EntityPlayerMP player) {
    NetworkDispatcher dispatcher = player.connection.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
    return dispatcher;
}
项目:CustomWorldGen    文件:FMLOutboundHandler.java   
public abstract List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet);
项目:OpenModsLib    文件:IPacketTargetSelector.java   
public void listDispatchers(T arg, Collection<NetworkDispatcher> result);