From de60af0d7b086382734fdaea949fbe22814d40d7 Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:45:46 -0700 Subject: [PATCH] #3659: Cleanup command packets for 1.20.5 --- .../protocol/AbstractPacketHandler.java | 4 +- .../net/md_5/bungee/protocol/Protocol.java | 11 +- .../bungee/protocol/packet/ClientCommand.java | 10 -- .../protocol/packet/ClientCommandSigned.java | 111 ------------------ .../packet/UnsignedClientCommand.java | 38 ++++++ .../bungee/connection/UpstreamBridge.java | 4 +- 6 files changed, 48 insertions(+), 130 deletions(-) delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommandSigned.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/UnsignedClientCommand.java diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index 7f0b6105..422cba54 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -5,7 +5,6 @@ import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.ClearTitles; import net.md_5.bungee.protocol.packet.ClientChat; import net.md_5.bungee.protocol.packet.ClientCommand; -import net.md_5.bungee.protocol.packet.ClientCommandSigned; import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.ClientStatus; import net.md_5.bungee.protocol.packet.Commands; @@ -52,6 +51,7 @@ import net.md_5.bungee.protocol.packet.Team; import net.md_5.bungee.protocol.packet.Title; import net.md_5.bungee.protocol.packet.TitleTimes; import net.md_5.bungee.protocol.packet.Transfer; +import net.md_5.bungee.protocol.packet.UnsignedClientCommand; import net.md_5.bungee.protocol.packet.ViewDistance; public abstract class AbstractPacketHandler @@ -105,7 +105,7 @@ public abstract class AbstractPacketHandler { } - public void handle(ClientCommandSigned command) throws Exception + public void handle(UnsignedClientCommand command) throws Exception { } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index bad7eb1e..2271a2e5 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -14,7 +14,6 @@ import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.ClearTitles; import net.md_5.bungee.protocol.packet.ClientChat; import net.md_5.bungee.protocol.packet.ClientCommand; -import net.md_5.bungee.protocol.packet.ClientCommandSigned; import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.Commands; import net.md_5.bungee.protocol.packet.CookieRequest; @@ -58,6 +57,7 @@ import net.md_5.bungee.protocol.packet.Team; import net.md_5.bungee.protocol.packet.Title; import net.md_5.bungee.protocol.packet.TitleTimes; import net.md_5.bungee.protocol.packet.Transfer; +import net.md_5.bungee.protocol.packet.UnsignedClientCommand; import net.md_5.bungee.protocol.packet.ViewDistance; public enum Protocol @@ -529,12 +529,13 @@ public enum Protocol ClientCommand.class, ClientCommand::new, map( ProtocolConstants.MINECRAFT_1_19, 0x03 ), - map( ProtocolConstants.MINECRAFT_1_19_1, 0x04 ) + map( ProtocolConstants.MINECRAFT_1_19_1, 0x04 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x05 ) ); TO_SERVER.registerPacket( - ClientCommandSigned.class, - ClientCommandSigned::new, - map( ProtocolConstants.MINECRAFT_1_20_5, 0x05 ) + UnsignedClientCommand.class, + UnsignedClientCommand::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x04 ) ); TO_SERVER.registerPacket( ClientChat.class, diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommand.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommand.java index fb53ba74..887ff29f 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommand.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommand.java @@ -33,11 +33,6 @@ public class ClientCommand extends DefinedPacket public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { command = readString( buf, 256 ); - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 ) - { - return; - } - timestamp = buf.readLong(); salt = buf.readLong(); @@ -79,11 +74,6 @@ public class ClientCommand extends DefinedPacket public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( command, buf ); - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 ) - { - return; - } - buf.writeLong( timestamp ); buf.writeLong( salt ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommandSigned.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommandSigned.java deleted file mode 100644 index 30f102c1..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommandSigned.java +++ /dev/null @@ -1,111 +0,0 @@ -package net.md_5.bungee.protocol.packet; - -import com.google.common.base.Preconditions; -import io.netty.buffer.ByteBuf; -import java.util.HashMap; -import java.util.Map; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import net.md_5.bungee.protocol.AbstractPacketHandler; -import net.md_5.bungee.protocol.ChatChain; -import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.ProtocolConstants; -import net.md_5.bungee.protocol.SeenMessages; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@EqualsAndHashCode(callSuper = false) -public class ClientCommandSigned extends DefinedPacket -{ - - private String command; - private long timestamp; - private long salt; - private Map signatures; - private boolean signedPreview; - private ChatChain chain; - private SeenMessages seenMessages; - - @Override - public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) - { - command = readString( buf, 256 ); - timestamp = buf.readLong(); - salt = buf.readLong(); - - int cnt = readVarInt( buf ); - Preconditions.checkArgument( cnt <= 8, "Too many signatures" ); - signatures = new HashMap<>( cnt ); - for ( int i = 0; i < cnt; i++ ) - { - String name = readString( buf, 16 ); - byte[] signature; - - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_3 ) - { - signature = new byte[ 256 ]; - buf.readBytes( signature ); - } else - { - signature = readArray( buf ); - } - signatures.put( name, signature ); - } - - if ( protocolVersion < ProtocolConstants.MINECRAFT_1_19_3 ) - { - signedPreview = buf.readBoolean(); - } - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_3 ) - { - seenMessages = new SeenMessages(); - seenMessages.read( buf, direction, protocolVersion ); - } else if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) - { - chain = new ChatChain(); - chain.read( buf, direction, protocolVersion ); - } - } - - @Override - public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) - { - writeString( command, buf ); - buf.writeLong( timestamp ); - buf.writeLong( salt ); - - writeVarInt( signatures.size(), buf ); - for ( Map.Entry entry : signatures.entrySet() ) - { - writeString( entry.getKey(), buf ); - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_3 ) - { - buf.writeBytes( entry.getValue() ); - } else - { - writeArray( entry.getValue(), buf ); - } - } - - if ( protocolVersion < ProtocolConstants.MINECRAFT_1_19_3 ) - { - buf.writeBoolean( signedPreview ); - } - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_3 ) - { - seenMessages.write( buf, direction, protocolVersion ); - } else if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) - { - chain.write( buf, direction, protocolVersion ); - } - } - - @Override - public void handle(AbstractPacketHandler handler) throws Exception - { - handler.handle( this ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/UnsignedClientCommand.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/UnsignedClientCommand.java new file mode 100644 index 00000000..97a2bb70 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/UnsignedClientCommand.java @@ -0,0 +1,38 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.ProtocolConstants; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class UnsignedClientCommand extends DefinedPacket +{ + + private String command; + + @Override + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + command = readString( buf, 256 ); + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + writeString( command, buf ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 4dc0315f..5c1cf858 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -31,7 +31,6 @@ import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.ClientChat; import net.md_5.bungee.protocol.packet.ClientCommand; -import net.md_5.bungee.protocol.packet.ClientCommandSigned; import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.CookieResponse; import net.md_5.bungee.protocol.packet.FinishConfiguration; @@ -43,6 +42,7 @@ import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.StartConfiguration; import net.md_5.bungee.protocol.packet.TabCompleteRequest; import net.md_5.bungee.protocol.packet.TabCompleteResponse; +import net.md_5.bungee.protocol.packet.UnsignedClientCommand; import net.md_5.bungee.util.AllowedCharacters; public class UpstreamBridge extends PacketHandler @@ -198,7 +198,7 @@ public class UpstreamBridge extends PacketHandler } @Override - public void handle(ClientCommandSigned command) throws Exception + public void handle(UnsignedClientCommand command) throws Exception { handleChat( "/" + command.getCommand() ); }