Search in sources :

Example 6 with FMLProxyPacket

use of net.minecraftforge.fml.common.network.internal.FMLProxyPacket in project Railcraft by Railcraft.

the class RailcraftPacket method getPacket.

public FMLProxyPacket getPacket() {
    ByteBuf byteBuf = Unpooled.buffer();
    try (ByteBufOutputStream out = new ByteBufOutputStream(byteBuf);
        RailcraftOutputStream data = new RailcraftOutputStream(out)) {
        data.writeByte(getID());
        writeData(data);
        return new FMLProxyPacket(new PacketBuffer(byteBuf), CHANNEL_NAME);
    } catch (IOException e) {
        Game.logThrowable("Error constructing packet: {0}", e, getClass());
        if (Game.DEVELOPMENT_ENVIRONMENT)
            throw new RuntimeException(e);
    }
    PacketBuffer buffer = new PacketBuffer(byteBuf);
    buffer.writeByte(-1);
    return new FMLProxyPacket(buffer, CHANNEL_NAME);
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 7 with FMLProxyPacket

use of net.minecraftforge.fml.common.network.internal.FMLProxyPacket in project MinecraftForge by MinecraftForge.

the class FMLHandshakeMessage method makeCustomChannelRegistration.

public static FMLProxyPacket makeCustomChannelRegistration(Set<String> channels) {
    String salutation = Joiner.on('\0').join(Iterables.concat(Arrays.asList("FML|HS", "FML", "FML|MP"), channels));
    FMLProxyPacket proxy = new FMLProxyPacket(new PacketBuffer(Unpooled.wrappedBuffer(salutation.getBytes(Charsets.UTF_8))), "REGISTER");
    return proxy;
}
Also used : FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 8 with FMLProxyPacket

use of net.minecraftforge.fml.common.network.internal.FMLProxyPacket in project MinecraftForge by MinecraftForge.

the class NetworkDispatcher method handleClientSideCustomPacket.

private boolean handleClientSideCustomPacket(SPacketCustomPayload msg, ChannelHandlerContext context) {
    String channelName = msg.getChannelName();
    if ("FML|MP".equals(channelName)) {
        try {
            if (multipart == null) {
                multipart = new MultiPartCustomPayload(msg.getBufferData());
            } else {
                multipart.processPart(msg.getBufferData());
            }
        } catch (IOException e) {
            this.kickWithMessage(e.getMessage());
            multipart = null;
            return true;
        }
        if (multipart.isComplete()) {
            msg = multipart;
            channelName = msg.getChannelName();
            multipart = null;
        } else {
            // Haven't received all so return till we have.
            return true;
        }
    }
    if ("FML|HS".equals(channelName) || "REGISTER".equals(channelName) || "UNREGISTER".equals(channelName)) {
        FMLProxyPacket proxy = new FMLProxyPacket(msg);
        proxy.setDispatcher(this);
        handshakeChannel.writeInbound(proxy);
        // forward any messages into the regular channel
        for (Object push : handshakeChannel.inboundMessages()) {
            List<FMLProxyPacket> messageResult = FMLNetworkHandler.forwardHandshake((FMLMessage.CompleteHandshake) push, this, Side.CLIENT);
            for (FMLProxyPacket result : messageResult) {
                result.setTarget(Side.CLIENT);
                result.payload().resetReaderIndex();
                context.fireChannelRead(result);
            }
        }
        handshakeChannel.inboundMessages().clear();
        return true;
    } else if (NetworkRegistry.INSTANCE.hasChannel(channelName, Side.CLIENT)) {
        FMLProxyPacket proxy = new FMLProxyPacket(msg);
        proxy.setDispatcher(this);
        context.fireChannelRead(proxy);
        return true;
    }
    return false;
}
Also used : FMLMessage(net.minecraftforge.fml.common.network.internal.FMLMessage) FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) TextComponentString(net.minecraft.util.text.TextComponentString) IOException(java.io.IOException)

Example 9 with FMLProxyPacket

use of net.minecraftforge.fml.common.network.internal.FMLProxyPacket in project MinecraftForge by MinecraftForge.

the class ForgeNetworkTestMod method onPlayerLogin.

@SubscribeEvent
public void onPlayerLogin(PlayerLoggedInEvent e) {
    if (channel == null)
        return;
    PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
    buffer.writeByte(0);
    // disconnects vanilla clients in 1.11
    channel.sendTo(new FMLProxyPacket(buffer, MOD_ID), (EntityPlayerMP) e.player);
}
Also used : FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) PacketBuffer(net.minecraft.network.PacketBuffer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

FMLProxyPacket (net.minecraftforge.fml.common.network.internal.FMLProxyPacket)9 PacketBuffer (net.minecraft.network.PacketBuffer)4 ByteBuf (io.netty.buffer.ByteBuf)2 IOException (java.io.IOException)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 FMLMessage (net.minecraftforge.fml.common.network.internal.FMLMessage)2 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)1 Packet (net.minecraft.network.Packet)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 OutboundTarget (net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget)1 NetworkDispatcher (net.minecraftforge.fml.common.network.handshake.NetworkDispatcher)1 Side (net.minecraftforge.fml.relauncher.Side)1