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 4b52c8b1..7f0b6105 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,6 +5,7 @@ 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; @@ -104,6 +105,10 @@ public abstract class AbstractPacketHandler { } + public void handle(ClientCommandSigned command) throws Exception + { + } + public void handle(Respawn respawn) 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 88ffac74..cb5c30d5 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,6 +14,7 @@ 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; @@ -513,7 +514,7 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_4, 0x12 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x14 ), map( ProtocolConstants.MINECRAFT_1_20_3, 0x15 ), - map( ProtocolConstants.MINECRAFT_1_20_5, 0x17 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x18 ) ); TO_SERVER.registerPacket( Chat.class, Chat::new, @@ -530,11 +531,17 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19, 0x03 ), map( ProtocolConstants.MINECRAFT_1_19_1, 0x04 ) ); + TO_SERVER.registerPacket( + ClientCommandSigned.class, + ClientCommandSigned::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x05 ) + ); TO_SERVER.registerPacket( ClientChat.class, ClientChat::new, map( ProtocolConstants.MINECRAFT_1_19, 0x04 ), - map( ProtocolConstants.MINECRAFT_1_19_1, 0x05 ) + map( ProtocolConstants.MINECRAFT_1_19_1, 0x05 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x06 ) ); TO_SERVER.registerPacket( TabCompleteRequest.class, @@ -549,7 +556,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x09 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x08 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x09 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x0A ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x0A ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x0B ) ); TO_SERVER.registerPacket( ClientSettings.class, @@ -563,7 +571,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x08 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x07 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x08 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x09 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x09 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x0A ) ); TO_SERVER.registerPacket( PluginMessage.class, @@ -581,17 +590,18 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_4, 0x0D ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x0F ), map( ProtocolConstants.MINECRAFT_1_20_3, 0x10 ), - map( ProtocolConstants.MINECRAFT_1_20_5, 0x11 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x12 ) ); TO_SERVER.registerPacket( StartConfiguration.class, StartConfiguration::new, - map( ProtocolConstants.MINECRAFT_1_20_2, 0x0B ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x0B ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x0C ) ); TO_SERVER.registerPacket( CookieResponse.class, CookieResponse::new, - map( ProtocolConstants.MINECRAFT_1_20_5, 0x10 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x11 ) ); } }, @@ -724,12 +734,12 @@ public enum Protocol TO_CLIENT.registerPacket( StoreCookie.class, StoreCookie::new, - map( ProtocolConstants.MINECRAFT_1_20_5, 0x09 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x0A ) ); TO_CLIENT.registerPacket( Transfer.class, Transfer::new, - map( ProtocolConstants.MINECRAFT_1_20_5, 0x0A ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x0B ) ); TO_SERVER.registerPacket( diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java b/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java index 1cff0fcc..af68f0c6 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java @@ -45,7 +45,7 @@ public class ProtocolConstants public static final int MINECRAFT_1_20 = 763; public static final int MINECRAFT_1_20_2 = 764; public static final int MINECRAFT_1_20_3 = 765; - public static final int MINECRAFT_1_20_5 = 1073742005; + public static final int MINECRAFT_1_20_5 = 1073742006; public static final List SUPPORTED_VERSIONS; public static final List SUPPORTED_VERSION_IDS; 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 887ff29f..fb53ba74 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,6 +33,11 @@ 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(); @@ -74,6 +79,11 @@ 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 new file mode 100644 index 00000000..30f102c1 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientCommandSigned.java @@ -0,0 +1,111 @@ +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/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 219e94b4..f80515d4 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,6 +31,7 @@ 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; @@ -196,6 +197,12 @@ public class UpstreamBridge extends PacketHandler handleChat( "/" + command.getCommand() ); } + @Override + public void handle(ClientCommandSigned command) throws Exception + { + handleChat( "/" + command.getCommand() ); + } + private String handleChat(String message) { for ( int index = 0, length = message.length(); index < length; index++ ) diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_16_2.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_16_2.java index 23324ce3..6e0cae63 100644 --- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_16_2.java +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_16_2.java @@ -22,7 +22,7 @@ class EntityMap_1_16_2 extends EntityMap static final EntityMap_1_16_2 INSTANCE_1_19_4 = new EntityMap_1_16_2( 0x03, 0x30 ); static final EntityMap_1_16_2 INSTANCE_1_20_2 = new EntityMap_1_16_2( -1, 0x33 ); static final EntityMap_1_16_2 INSTANCE_1_20_3 = new EntityMap_1_16_2( -1, 0x34 ); - static final EntityMap_1_16_2 INSTANCE_1_20_5 = new EntityMap_1_16_2( -1, 0x36 ); + static final EntityMap_1_16_2 INSTANCE_1_20_5 = new EntityMap_1_16_2( -1, 0x37 ); // private final int spawnPlayerId; private final int spectateId;