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 {
@Override
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()];
buf.readBytes(bytes);
buf.readerIndex(0);
//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,
Pixel