Jump to content

Recommended Posts

Posted

I'm getting this in my console:

[09:55:14] [server thread/ERROR] [FML]: Detected ongoing potential memory leak. 100 packets have leaked. Top offenders
[09:55:14] [server thread/ERROR] [FML]: 	 ttm : 100

 

I'm partially worried, because this packet is from the client to the server, and is gonna be sent a lot.

 

Packet:

package ttm.network;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.ForgeHooks;
import ttm.Reference;

public class PacketMessage extends AbstractPacket {
public int msgID;

public PacketMessage(int msgID) {
	super();
	this.msgID = msgID;
}

public PacketMessage() {
	this(0);
}

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	buffer.writeInt(msgID);
}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	msgID = buffer.readInt();
}

@Override
public void handleClientSide(EntityPlayer player) {
}

@Override
public void handleServerSide(EntityPlayer player) {
	switch(msgID) {
	case Reference.PacketMessages.JUMP: {
		ForgeHooks.onLivingJump(player);
		break;
	}
	}
}
}

 

Should I be worried about this?

Kain

Posted

I've run into a problem.

 

Whenever I send the message to the server, it never arrives. It only writes to the byte buffer.

 

Message:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraftforge.common.ForgeHooks;
import ttm.Reference;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class SimpleServerMessage extends AbstractMessage {
public int msgID;

public SimpleServerMessage(int msgID) {
	super();
	this.msgID = msgID;
}

public SimpleServerMessage() {
	this(0);
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(msgID);
}

@Override
public void fromBytes(ByteBuf buf) {
	msgID = buf.readInt();
}

public static class Handler implements IMessageHandler<SimpleServerMessage, IMessage> {
	public IMessage onMessage(SimpleServerMessage message, MessageContext ctx) {
		switch(message.msgID) {
		case Reference.PacketMessages.JUMP: {
			ForgeHooks.onLivingJump(ctx.getServerHandler().playerEntity);
			break;
		}
		}

		return null;
	}
}
}

 

Basic Message:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import ttm.TtM;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public abstract class BasicMessage implements IMessage {
@Override
public abstract void fromBytes(ByteBuf buf);

@Override
public abstract void toBytes(ByteBuf buf);

public void sendToAll() {
	TtM.networkChannel.sendToAll(this);
}

public void sendTo(EntityPlayerMP player) {
	TtM.networkChannel.sendTo(this, player);
}

public void sendToServer() {
	TtM.networkChannel.sendToServer(this);
	System.err.println("TO THE SERVER!");
}
}

Kain

Posted

Ok, I only had the IDs because that message class was only for short messages.

 

None of my other messages are being received either.

 

Mod:

package ttm;

import static ttm.Reference.ID;
import static ttm.Reference.NAME;
import static ttm.Reference.VERSION;
import ttm.handler.GuiHandler;
import ttm.network.MessageJump;
import ttm.network.MessageOpenGui;
import ttm.network.MessageQuickStack;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;

@Mod(name = NAME, modid = ID, version = VERSION)
public class TtM {
@Instance(ID)
public static TtM instance;
@SidedProxy(serverSide = ID + ".ServerProxy", clientSide = ID + ".ClientProxy")
public static ServerProxy proxy;

public static GuiHandler guiHandler = new GuiHandler();
public static SimpleNetworkWrapper networkChannel;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	NetworkRegistry.INSTANCE.registerGuiHandler(this, guiHandler);
	networkChannel = NetworkRegistry.INSTANCE.newSimpleChannel("TtM");
	loadPackets();

	proxy.loadServer();
	proxy.loadClient();
}

public void loadPackets() {
	networkChannel.registerMessage(MessageJump.Handler.class, MessageJump.class, 0, Side.SERVER);
	networkChannel.registerMessage(MessageOpenGui.Handler.class, MessageOpenGui.class, 0, Side.SERVER);
	networkChannel.registerMessage(MessageQuickStack.Handler.class, MessageQuickStack.class, 0, Side.SERVER);
}
}

 

Message:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import ttm.TtM;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class MessageOpenGui extends BasicMessage {
public int guiID;

public MessageOpenGui(int guiID) {
	super();
	this.guiID = guiID;
}

public MessageOpenGui() {
	this(0);
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(guiID);

	System.err.println("HI2");
}

@Override
public void fromBytes(ByteBuf buf) {
	guiID = buf.readInt();

	System.err.println("HI");
}

public static class Handler implements IMessageHandler<MessageOpenGui, IMessage> {
	public IMessage onMessage(MessageOpenGui message, MessageContext ctx) {
		EntityPlayer player = ctx.getServerHandler().playerEntity;

		player.openGui(TtM.instance, message.guiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);

		return null;
	}
}
}

 

BasicMessage:

package ttm.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import ttm.TtM;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public abstract class BasicMessage implements IMessage {
@Override
public abstract void fromBytes(ByteBuf buf);

@Override
public abstract void toBytes(ByteBuf buf);

public void sendToAll() {
	TtM.networkChannel.sendToAll(this);
}

public void sendTo(EntityPlayerMP player) {
	TtM.networkChannel.sendTo(this, player);
}

public void sendToServer() {
	TtM.networkChannel.sendToServer(this);
	System.err.println("TO THE SERVER!");
}
}

Kain

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.

Guest
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.

Announcements



×
×
  • Create New...

Important Information

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