ProtocolLib

3M Downloads

Error while cloning clientbound player chat packets in 1.19.1

LOOHP opened this issue ยท 14 comments

commented
  • This issue is not solved in a development build

Describe the bug
An error occurs when cloning clientbound player chat packets in 1.19.1
The cloning works fine for the first packet cloned every time the player rejoins the game.
The error: https://pastebin.com/dumnuW2L

To Reproduce
Steps to reproduce the behavior:

  1. Have code that intercepts and deepClones clientbound player chat packets
  2. Join the game
  3. Do /say Hello with your player, this one should work fine
  4. Do /say Hello again, this one should fail, see console for error

Expected behavior
Cloning works

Version Info
https://pastebin.com/h266ciKW

commented

Ja wat is dat denn ๐Ÿ˜  ... Can you provide a small code example how I can reproduce that (agane)?

commented

Ja wat is dat denn ๐Ÿ˜  ... Can you provide a small code example how I can reproduce that (agane)?

This is all you need xd

ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ListenerPriority.MONITOR, PacketType.Play.Server.CHAT) {
	@Override
	public void onPacketSending(PacketEvent event) {
		event.getPacket().deepClone();
	}
});
commented

The last message part is where the cloning failed?

commented

Looking at the issue it doesn't seem to be related with ProtocolLib, just like the other chat serialization issue.

commented

However weirdly the error does not appear on the first call after a rejoin.

commented

Yea when the first message is send the packet changes (the last message signature is present + the last messages are written). I took a quick look over that, but I had no nerves to debug the remapped server...

commented

Seems to be working!

commented

Looking at the server code it seems like the server is always sending an empty optional as the unsigned content when a "normal" chat message is sent by the client (See SignedMessageChain#unpack L36)

commented

I will take another look today, but I was wondering why you're even cloning the packet? You (iirc) cannot just edit the messages in that packet without causing the signature of the message to be invalid anyway?

commented

I can change the unsigned content part of the packet right? Just not the other signed stuff.

commented

But since it's unsigned, I should be able to modify that in the packet without breaking the signed stuff. The client would still accept it right?

commented

I have no idea what the client does when a chat message comes in, I would have to take a look into the client code to tell you :)

commented

Okay now I'm confused. I can confirm that something within ProtocolLib is causing the issue, cloning the packet like this:

protocolManager.addPacketListener(new PacketAdapter(this, Play.Server.CHAT) {
  @Override
  public void onPacketSending(PacketEvent event) {
    ClientboundPlayerChatPacket packet = (ClientboundPlayerChatPacket) event.getPacket().getHandle();

    ByteBuf byteBuf = Unpooled.buffer();
    PacketDataSerializer serializer = new PacketDataSerializer(byteBuf);

    packet.a(serializer);

    ClientboundPlayerChatPacket clone = new ClientboundPlayerChatPacket(serializer);
    event.getPlayer().sendMessage("CLONED " + packet + " as " + clone);
  }
});

doesn't throw any exceptions ๐Ÿค”

commented

Took a bit to replace the old cloning method cleanly, but it should work now. Can you try https://github.com/derklaro/ProtocolLib/suites/7590899434/artifacts/314394256 and give feedback if it works for you now too?