Jump to content

Storing and loading FMLProxyPackets


Recommended Posts

Hello fellow Modders,


for my current Project I need to store all IMessages the Client sends to the Server (and the other way around) in a File and load them later. Therefore, I'm hooking into the FML Channel using the following code:


            NetworkManager nm = event.manager;
            Channel channel = nm.channel();

            for(String channelName : NetworkRegistry.INSTANCE.channelNamesFor(Side.CLIENT)) {
                FMLEmbeddedChannel embeddedChannel = NetworkRegistry.INSTANCE.getChannel(channelName, Side.CLIENT);
                embeddedChannel.pipeline().addFirst(new IMessageInboundListener());

            for(String channelName : NetworkRegistry.INSTANCE.channelNamesFor(Side.SERVER)) {
                FMLEmbeddedChannel embeddedChannel = NetworkRegistry.INSTANCE.getChannel(channelName, Side.SERVER);
                embeddedChannel.pipeline().addFirst(new IMessageOutboundListener());


The IMessageInboundListener looks the following way:


public class IMessageInboundListener extends ChannelInboundHandlerAdapter {

    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        int somehting = 0;
        if(msg instanceof FMLProxyPacket) {
            FMLProxyPacket proxyPacket = (FMLProxyPacket)msg;

            String channelName = proxyPacket.channel();
            Side target = proxyPacket.getTarget();

            ByteBuf buf = proxyPacket.payload();
            byte[] bytes = new byte[buf.readableBytes()];

            //some code to store the Packet is here
        super.channelRead(ctx, msg);


Now, my question is - how do I re-send these Packets to the Server? How can I reconstruct the Packet from the byte array, channel name and target Side and where do I need to inject it?


Thanks in advance,


Link to comment
Share on other sites

The FMLProxyPacket has a constructor that takes the ByteBuf payload and a string for channel name. Before the SimpleNetworkWrapper was working, I actually made a packet system using FMLProxyPackets. I had a tutorial here: https://www.blogger.com/blogger.g?blogID=8871285205929815684#editor/target=page;pageID=4638645929701985216;onPublishedMenu=pages;onClosedMenu=pages;postNum=23;src=pagename


That tutorial should show how to send and receive FMLProxyPackets.


What are you trying to achieve? You realize that it might be a LOT of data to store...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.