Jump to content

[SOLVED][1.7.10] Packet handling client error


pingoleon60

Recommended Posts

Hello everyone.

I've been working on a server to client packet recently. So I've done this:

 

public class SendBipedCostumes implements IMessage {

public Quintet<Float,String,String,Float,Float>[] modelsDeclaration;

public SendBipedCostumes() { }

    public SendBipedCostumes(Quintet<Float,String,String,Float,Float>[] modelsDeclaration) {
    	this.modelsDeclaration = modelsDeclaration;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
    	System.out.println("Reading...");
        int size = Integer.parseInt(ByteBufUtils.readUTF8String(buf));
        ArrayList<Quintet<Float,String,String,Float,Float>> models = new ArrayList<Quintet<Float,String,String,Float,Float>>(); // new Object[size];
        for (int i = 0; i < size; i++) 
        	models.add(Quintet.with(buf.readFloat(), ByteBufUtils.readUTF8String(buf), ByteBufUtils.readUTF8String(buf), buf.readFloat(), buf.readFloat()));
        this.modelsDeclaration = models.toArray(new Quintet[models.size()]);
    	System.out.println("Read.");
    }

    @Override
    public void toBytes(ByteBuf buf) {
    	System.out.println("Writing...");
    	ByteBufUtils.writeUTF8String(buf, String.valueOf(this.modelsDeclaration.length));
        for (Quintet<Float,String,String,Float,Float> v : this.modelsDeclaration) {
        	System.out.println(String.valueOf(v.getValue0()).length());
            //ByteBufUtils.writeUTF8String(buf, String.valueOf(v.getValue0()));
            buf.writeFloat(v.getValue0());
        	System.out.println(v.getValue1().length());
            ByteBufUtils.writeUTF8String(buf, v.getValue1());
        	System.out.println(v.getValue2().length());
            ByteBufUtils.writeUTF8String(buf, v.getValue2());
        	System.out.println(String.valueOf(v.getValue3()).length());
            //ByteBufUtils.writeUTF8String(buf, String.valueOf(v.getValue3()));
        	buf.writeFloat(v.getValue3());
        	System.out.println(String.valueOf(v.getValue4()).length());
            //ByteBufUtils.writeUTF8String(buf, String.valueOf(v.getValue4()));
        	buf.writeFloat(v.getValue4());
        }
      	System.out.println("Written.");
    }
    
    
    public static class Handler implements IMessageHandler<SendBipedCostumes, IMessage> {
        
        @Override
        public IMessage onMessage(SendBipedCostumes m, MessageContext ctx) {
        	LyokoCraftMod.proxy.sendBipedCostumeHandler(m, ctx);
        	return null;
        }
        
}

 

It works perfectly in single player, the handler is executed with all the data it needs.

However, when I try to do it on a server, when the packet is sent, the client gets an error :

 

Internal Exception: io.netty.handler.codec.DecoderException:

java.IOException: The received string length is longer than maximum allowed (25 > 20)

 

The server however just doesn't say anything.

The problem is that no parameter is 25 bytes long. Actually they all are pretty small. The longest one is 19 simple characters long.

I don't know anything about netty, but I figured out that the problem occurs when the client tries to understand the raw packet, but it keeps failing because 20 is an hardcoded maximal value.

 

Do you know how I could find a way out of that problem?

Thanks in advance!

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.

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.