Search in sources :

Example 1 with NetworkDispatcher

use of net.minecraftforge.fml.common.network.handshake.NetworkDispatcher in project MinecraftForge by MinecraftForge.

the class FMLNetworkHandler method fmlServerHandshake.

public static void fmlServerHandshake(PlayerList scm, NetworkManager manager, EntityPlayerMP player) {
    NetworkDispatcher dispatcher = NetworkDispatcher.allocAndSet(manager, scm);
    dispatcher.serverToClientHandshake(player);
}
Also used : NetworkDispatcher(net.minecraftforge.fml.common.network.handshake.NetworkDispatcher)

Example 2 with NetworkDispatcher

use of net.minecraftforge.fml.common.network.handshake.NetworkDispatcher in project MinecraftForge by MinecraftForge.

the class FMLNetworkHandler method fmlClientHandshake.

public static void fmlClientHandshake(NetworkManager networkManager) {
    NetworkDispatcher dispatcher = NetworkDispatcher.allocAndSet(networkManager);
    dispatcher.clientToServerHandshake();
}
Also used : NetworkDispatcher(net.minecraftforge.fml.common.network.handshake.NetworkDispatcher)

Example 3 with NetworkDispatcher

use of net.minecraftforge.fml.common.network.handshake.NetworkDispatcher in project MinecraftForge by MinecraftForge.

the class FMLOutboundHandler method write.

@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);
    }
}
Also used : Side(net.minecraftforge.fml.relauncher.Side) NetworkDispatcher(net.minecraftforge.fml.common.network.handshake.NetworkDispatcher) FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket)

Example 4 with NetworkDispatcher

use of net.minecraftforge.fml.common.network.handshake.NetworkDispatcher in project MinecraftForge by MinecraftForge.

the class HandshakeCompletionHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, CompleteHandshake msg) throws Exception {
    NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).getAndRemove();
    dispatcher.completeHandshake(msg.target);
}
Also used : NetworkDispatcher(net.minecraftforge.fml.common.network.handshake.NetworkDispatcher)

Aggregations

NetworkDispatcher (net.minecraftforge.fml.common.network.handshake.NetworkDispatcher)4 FMLProxyPacket (net.minecraftforge.fml.common.network.internal.FMLProxyPacket)1 Side (net.minecraftforge.fml.relauncher.Side)1