Fix missing call to release() in the event channel handler (#4513)

This commit is contained in:
Ben Staddon 2017-12-17 02:00:35 +00:00 committed by LexManos
parent 7438ef466e
commit cd99957627
2 changed files with 33 additions and 10 deletions

View file

@ -22,8 +22,6 @@ package net.minecraftforge.fml.common.network;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
import org.apache.logging.log4j.Level;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
@ -49,6 +47,7 @@ public class NetworkEventFiringHandler extends SimpleChannelInboundHandler<FMLPr
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception
{
eventChannel.fireRead(msg,ctx);
msg.payload().release();
}
@Override
@ -56,6 +55,7 @@ public class NetworkEventFiringHandler extends SimpleChannelInboundHandler<FMLPr
{
eventChannel.fireUserEvent(evt,ctx);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
{

View file

@ -10,37 +10,60 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.fml.common.network.FMLEventChannel;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
import net.minecraftforge.fml.relauncher.Side;
import org.apache.logging.log4j.Logger;
@Mod(modid = ForgeNetworkTestMod.MOD_ID, name = ForgeNetworkTestMod.MOD_ID, version = "1.0", acceptableRemoteVersions = "*")
public class ForgeNetworkTestMod
{
private static final boolean ENABLED = false;
public static final String MOD_ID = "forgenetworktest";
public static final String MOD_ID = "forge_network_test";
private FMLEventChannel channel;
private Logger logger;
@EventHandler
public void onPreInit(FMLPreInitializationEvent e)
{
if (ENABLED && e.getSide() == Side.SERVER)
if (ENABLED)
{
MinecraftForge.EVENT_BUS.register(this);
channel = NetworkRegistry.INSTANCE.newEventDrivenChannel(MOD_ID);
channel.register(this);
logger = e.getModLog();
}
}
@SubscribeEvent
public void onPlayerLogin(PlayerLoggedInEvent e)
{
if (channel == null)
if (ENABLED)
{
return;
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
buffer.writeString("Welcome to the server!");
channel.sendTo(new FMLProxyPacket(buffer, MOD_ID), (EntityPlayerMP) e.player); // disconnects vanilla clients in 1.11
logger.info("Welcomed player to the server");
}
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
buffer.writeByte(0);
channel.sendTo(new FMLProxyPacket(buffer, MOD_ID), (EntityPlayerMP) e.player); // disconnects vanilla clients in 1.11
}
@SubscribeEvent
public void onPacketReceived(FMLNetworkEvent.ClientCustomPacketEvent e)
{
PacketBuffer payload = new PacketBuffer(e.getPacket().payload());
logger.info("Received message from server: {}", payload.readString(64));
PacketBuffer reply = new PacketBuffer(Unpooled.buffer());
reply.writeString("Thanks!");
e.setReply(new FMLProxyPacket(reply, MOD_ID));
logger.info("Sent a reply");
}
@SubscribeEvent
public void onPacketReceived(FMLNetworkEvent.ServerCustomPacketEvent e)
{
PacketBuffer payload = new PacketBuffer(e.getPacket().payload());
logger.info("Received reply from client: {}", payload.readString(64));
}
}