From 0c68f7cceb8a86dba2b54ccb0181e3817d0d1d02 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:01:15 +0100 Subject: [PATCH] Reuse chat packet --- .../ChatSignaturePacketHandler.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/raphimc/viaproxy/proxy/packethandler/ChatSignaturePacketHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/packethandler/ChatSignaturePacketHandler.java index 5af24e95..63ba10f2 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/packethandler/ChatSignaturePacketHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/packethandler/ChatSignaturePacketHandler.java @@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3; import com.viaversion.viaversion.api.type.Types; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import net.raphimc.netminecraft.constants.ConnectionState; @@ -68,17 +69,14 @@ public boolean handleC2P(Packet packet, List listeners) t final MessageMetadata metadata = new MessageMetadata(null, timestamp, salt); final byte[] signature = chatSession.signChatMessage(metadata, message, new PlayerMessageSignature[0]); - final ByteBuf newChatMessage = Unpooled.buffer(); - PacketTypes.writeVarInt(newChatMessage, this.chatMessageId); - PacketTypes.writeString(newChatMessage, message); // message - newChatMessage.writeLong(timestamp); // timestamp - newChatMessage.writeLong(salt); // salt - Types.OPTIONAL_SIGNATURE_BYTES.write(newChatMessage, signature); // signature - PacketTypes.writeVarInt(newChatMessage, 0); // offset - Types.ACKNOWLEDGED_BIT_SET.write(newChatMessage, new BitSet(20)); // acknowledged - this.proxyConnection.getChannel().writeAndFlush(newChatMessage).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); - - return false; + final ByteBuf newChatMessageData = Unpooled.buffer(); + PacketTypes.writeString(newChatMessageData, message); // message + newChatMessageData.writeLong(timestamp); // timestamp + newChatMessageData.writeLong(salt); // salt + Types.OPTIONAL_SIGNATURE_BYTES.write(newChatMessageData, signature); // signature + PacketTypes.writeVarInt(newChatMessageData, 0); // offset + Types.ACKNOWLEDGED_BIT_SET.write(newChatMessageData, new BitSet(20)); // acknowledged + unknownPacket.data = ByteBufUtil.getBytes(newChatMessageData); } }