Error while cloning clientbound player chat packets in 1.19.1
LOOHP opened this issue ยท 14 comments
- 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:
- Have code that intercepts and deepClones clientbound player chat packets
- Join the game
- Do
/say Hello
with your player, this one should work fine - Do
/say Hello
again, this one should fail, see console for error
Expected behavior
Cloning works
Version Info
https://pastebin.com/h266ciKW
Ja wat is dat denn ๐ ... Can you provide a small code example how I can reproduce that (agane)?
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();
}
});
Looking at the issue it doesn't seem to be related with ProtocolLib, just like the other chat serialization issue.
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...
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)
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?
I can change the unsigned content part of the packet right? Just not the other signed stuff.
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?
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 :)
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 ๐ค
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?