From 78ca16dfe3bf9a21d5c054a1884d4f5f198a62bc Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 28 Jul 2022 04:00:00 +1000 Subject: [PATCH] Minecraft 1.19.1 support --- .../protocol/AbstractPacketHandler.java | 5 -- .../net/md_5/bungee/protocol/ChatChain.java | 82 ++++++++++++++++++ .../net/md_5/bungee/protocol/Protocol.java | 78 ++++++++++------- .../bungee/protocol/ProtocolConstants.java | 4 +- .../bungee/protocol/packet/ClientChat.java | 11 +++ .../bungee/protocol/packet/ClientCommand.java | 11 +++ .../bungee/protocol/packet/LoginRequest.java | 20 +++++ .../bungee/protocol/packet/PlayerChat.java | 84 ------------------- .../bungee/protocol/packet/SystemChat.java | 11 ++- .../java/net/md_5/bungee/EncryptionUtil.java | 18 +++- .../java/net/md_5/bungee/ServerConnector.java | 2 +- .../bungee/connection/InitialHandler.java | 42 ++++++++-- .../net/md_5/bungee/entitymap/EntityMap.java | 2 + .../bungee/entitymap/EntityMap_1_16_2.java | 2 +- 14 files changed, 237 insertions(+), 135 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/ChatChain.java delete mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerChat.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 35236382..2658e144 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 @@ -23,7 +23,6 @@ import net.md_5.bungee.protocol.packet.LoginPayloadResponse; import net.md_5.bungee.protocol.packet.LoginRequest; import net.md_5.bungee.protocol.packet.LoginSuccess; import net.md_5.bungee.protocol.packet.PingPacket; -import net.md_5.bungee.protocol.packet.PlayerChat; import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter; import net.md_5.bungee.protocol.packet.PlayerListItem; import net.md_5.bungee.protocol.packet.PluginMessage; @@ -86,10 +85,6 @@ public abstract class AbstractPacketHandler { } - public void handle(PlayerChat chat) throws Exception - { - } - public void handle(SystemChat chat) throws Exception { } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/ChatChain.java b/protocol/src/main/java/net/md_5/bungee/protocol/ChatChain.java new file mode 100644 index 00000000..7cc79e4f --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/ChatChain.java @@ -0,0 +1,82 @@ +package net.md_5.bungee.protocol; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class ChatChain extends DefinedPacket +{ + + private List seen; + private List received; + + @Override + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + seen = readLinks( buf ); + if ( buf.readBoolean() ) + { + received = readLinks( buf ); + } + } + + private static List readLinks(ByteBuf buf) + { + int cnt = readVarInt( buf ); + Preconditions.checkArgument( cnt <= 5, "Too many entries" ); + List chain = new LinkedList<>(); + for ( int i = 0; i < cnt; i++ ) + { + chain.add( new ChainLink( readUUID( buf ), readArray( buf ) ) ); + } + return chain; + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + writeLinks( seen, buf ); + if ( received != null ) + { + buf.writeBoolean( true ); + writeLinks( received, buf ); + } else + { + buf.writeBoolean( false ); + } + } + + private static void writeLinks(List links, ByteBuf buf) + { + writeVarInt( links.size(), buf ); + for ( ChainLink link : links ) + { + writeUUID( link.sender, buf ); + writeArray( link.signature, buf ); + } + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + throw new UnsupportedOperationException( "Not supported." ); + } + + @Data + public static class ChainLink + { + + private final UUID sender; + private final byte[] signature; + } +} 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 694a474c..04dc178d 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 @@ -29,7 +29,6 @@ import net.md_5.bungee.protocol.packet.LoginPayloadResponse; import net.md_5.bungee.protocol.packet.LoginRequest; import net.md_5.bungee.protocol.packet.LoginSuccess; import net.md_5.bungee.protocol.packet.PingPacket; -import net.md_5.bungee.protocol.packet.PlayerChat; import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter; import net.md_5.bungee.protocol.packet.PlayerListItem; import net.md_5.bungee.protocol.packet.PluginMessage; @@ -80,7 +79,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_16, 0x20 ), map( ProtocolConstants.MINECRAFT_1_16_2, 0x1F ), map( ProtocolConstants.MINECRAFT_1_17, 0x21 ), - map( ProtocolConstants.MINECRAFT_1_19, 0x1E ) + map( ProtocolConstants.MINECRAFT_1_19, 0x1E ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x20 ) ); TO_CLIENT.registerPacket( Login.class, @@ -92,7 +92,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_16, 0x25 ), map( ProtocolConstants.MINECRAFT_1_16_2, 0x24 ), map( ProtocolConstants.MINECRAFT_1_17, 0x26 ), - map( ProtocolConstants.MINECRAFT_1_19, 0x23 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x23 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x25 ) ); TO_CLIENT.registerPacket( Chat.class, Chat::new, @@ -117,7 +118,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_16, 0x3A ), map( ProtocolConstants.MINECRAFT_1_16_2, 0x39 ), map( ProtocolConstants.MINECRAFT_1_17, 0x3D ), - map( ProtocolConstants.MINECRAFT_1_19, 0x3B ) + map( ProtocolConstants.MINECRAFT_1_19, 0x3B ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x3E ) ); TO_CLIENT.registerPacket( BossBar.class, @@ -128,11 +130,6 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_17, 0x0D ), map( ProtocolConstants.MINECRAFT_1_19, 0x0A ) ); - TO_CLIENT.registerPacket( - PlayerChat.class, - PlayerChat::new, - map( ProtocolConstants.MINECRAFT_1_19, 0x30 ) - ); TO_CLIENT.registerPacket( PlayerListItem.class, // PlayerInfo PlayerListItem::new, @@ -145,7 +142,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_16, 0x33 ), map( ProtocolConstants.MINECRAFT_1_16_2, 0x32 ), map( ProtocolConstants.MINECRAFT_1_17, 0x36 ), - map( ProtocolConstants.MINECRAFT_1_19, 0x34 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x34 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x37 ) ); TO_CLIENT.registerPacket( TabCompleteResponse.class, @@ -169,7 +167,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_13, 0x45 ), map( ProtocolConstants.MINECRAFT_1_14, 0x49 ), map( ProtocolConstants.MINECRAFT_1_15, 0x4A ), - map( ProtocolConstants.MINECRAFT_1_17, 0x53 ) + map( ProtocolConstants.MINECRAFT_1_17, 0x53 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x56 ) ); TO_CLIENT.registerPacket( ScoreboardScore.class, @@ -181,7 +180,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_13, 0x48 ), map( ProtocolConstants.MINECRAFT_1_14, 0x4C ), map( ProtocolConstants.MINECRAFT_1_15, 0x4D ), - map( ProtocolConstants.MINECRAFT_1_17, 0x56 ) + map( ProtocolConstants.MINECRAFT_1_17, 0x56 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x59 ) ); TO_CLIENT.registerPacket( ScoreboardDisplay.class, @@ -193,7 +193,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_13, 0x3E ), map( ProtocolConstants.MINECRAFT_1_14, 0x42 ), map( ProtocolConstants.MINECRAFT_1_15, 0x43 ), - map( ProtocolConstants.MINECRAFT_1_17, 0x4C ) + map( ProtocolConstants.MINECRAFT_1_17, 0x4C ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x4F ) ); TO_CLIENT.registerPacket( Team.class, @@ -205,7 +206,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_13, 0x47 ), map( ProtocolConstants.MINECRAFT_1_14, 0x4B ), map( ProtocolConstants.MINECRAFT_1_15, 0x4C ), - map( ProtocolConstants.MINECRAFT_1_17, 0x55 ) + map( ProtocolConstants.MINECRAFT_1_17, 0x55 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x58 ) ); TO_CLIENT.registerPacket( PluginMessage.class, @@ -218,7 +220,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_16, 0x18 ), map( ProtocolConstants.MINECRAFT_1_16_2, 0x17 ), map( ProtocolConstants.MINECRAFT_1_17, 0x18 ), - map( ProtocolConstants.MINECRAFT_1_19, 0x15 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x15 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x16 ) ); TO_CLIENT.registerPacket( Kick.class, @@ -231,7 +234,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_16, 0x1A ), map( ProtocolConstants.MINECRAFT_1_16_2, 0x19 ), map( ProtocolConstants.MINECRAFT_1_17, 0x1A ), - map( ProtocolConstants.MINECRAFT_1_19, 0x17 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x17 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x19 ) ); TO_CLIENT.registerPacket( Title.class, @@ -244,7 +248,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_15, 0x50 ), map( ProtocolConstants.MINECRAFT_1_16, 0x4F ), map( ProtocolConstants.MINECRAFT_1_17, 0x59 ), - map( ProtocolConstants.MINECRAFT_1_18, 0x5A ) + map( ProtocolConstants.MINECRAFT_1_18, 0x5A ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x5D ) ); TO_CLIENT.registerPacket( ClearTitles.class, @@ -256,18 +261,21 @@ public enum Protocol Subtitle.class, Subtitle::new, map( ProtocolConstants.MINECRAFT_1_17, 0x57 ), - map( ProtocolConstants.MINECRAFT_1_18, 0x58 ) + map( ProtocolConstants.MINECRAFT_1_18, 0x58 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x5B ) ); TO_CLIENT.registerPacket( TitleTimes.class, TitleTimes::new, map( ProtocolConstants.MINECRAFT_1_17, 0x5A ), - map( ProtocolConstants.MINECRAFT_1_18, 0x5B ) + map( ProtocolConstants.MINECRAFT_1_18, 0x5B ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x5E ) ); TO_CLIENT.registerPacket( SystemChat.class, SystemChat::new, - map( ProtocolConstants.MINECRAFT_1_19, 0x5F ) + map( ProtocolConstants.MINECRAFT_1_19, 0x5F ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x62 ) ); TO_CLIENT.registerPacket( PlayerListHeaderFooter.class, @@ -283,7 +291,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_16, 0x53 ), map( ProtocolConstants.MINECRAFT_1_17, 0x5E ), map( ProtocolConstants.MINECRAFT_1_18, 0x5F ), - map( ProtocolConstants.MINECRAFT_1_19, 0x60 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x60 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x63 ) ); TO_CLIENT.registerPacket( EntityStatus.class, @@ -296,7 +305,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_16, 0x1B ), map( ProtocolConstants.MINECRAFT_1_16_2, 0x1A ), map( ProtocolConstants.MINECRAFT_1_17, 0x1B ), - map( ProtocolConstants.MINECRAFT_1_19, 0x18 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x18 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x1A ) ); TO_CLIENT.registerPacket( Commands.class, @@ -315,7 +325,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_16, 0x1E ), map( ProtocolConstants.MINECRAFT_1_16_2, 0x1D ), map( ProtocolConstants.MINECRAFT_1_17, 0x1E ), - map( ProtocolConstants.MINECRAFT_1_19, 0x1B ) + map( ProtocolConstants.MINECRAFT_1_19, 0x1B ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x1D ) ); TO_CLIENT.registerPacket( ViewDistance.class, @@ -324,7 +335,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_15, 0x42 ), map( ProtocolConstants.MINECRAFT_1_16, 0x41 ), map( ProtocolConstants.MINECRAFT_1_17, 0x4A ), - map( ProtocolConstants.MINECRAFT_1_19, 0x49 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x49 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x4C ) ); TO_SERVER.registerPacket( @@ -338,7 +350,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_14, 0x0F ), map( ProtocolConstants.MINECRAFT_1_16, 0x10 ), map( ProtocolConstants.MINECRAFT_1_17, 0x0F ), - map( ProtocolConstants.MINECRAFT_1_19, 0x11 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x11 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x12 ) ); TO_SERVER.registerPacket( Chat.class, Chat::new, @@ -352,12 +365,14 @@ public enum Protocol TO_SERVER.registerPacket( ClientCommand.class, ClientCommand::new, - map( ProtocolConstants.MINECRAFT_1_19, 0x03 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x03 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x04 ) ); TO_SERVER.registerPacket( ClientChat.class, ClientChat::new, - map( ProtocolConstants.MINECRAFT_1_19, 0x04 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x04 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x05 ) ); TO_SERVER.registerPacket( TabCompleteRequest.class, @@ -368,7 +383,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_12_1, 0x01 ), map( ProtocolConstants.MINECRAFT_1_13, 0x05 ), map( ProtocolConstants.MINECRAFT_1_14, 0x06 ), - map( ProtocolConstants.MINECRAFT_1_19, 0x08 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x08 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x09 ) ); TO_SERVER.registerPacket( ClientSettings.class, @@ -378,7 +394,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_12, 0x05 ), map( ProtocolConstants.MINECRAFT_1_12_1, 0x04 ), map( ProtocolConstants.MINECRAFT_1_14, 0x05 ), - map( ProtocolConstants.MINECRAFT_1_19, 0x07 ) + map( ProtocolConstants.MINECRAFT_1_19, 0x07 ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x08 ) ); TO_SERVER.registerPacket( PluginMessage.class, @@ -390,7 +407,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_13, 0x0A ), map( ProtocolConstants.MINECRAFT_1_14, 0x0B ), map( ProtocolConstants.MINECRAFT_1_17, 0x0A ), - map( ProtocolConstants.MINECRAFT_1_19, 0x0C ) + map( ProtocolConstants.MINECRAFT_1_19, 0x0C ), + map( ProtocolConstants.MINECRAFT_1_19_1, 0x0D ) ); } }, 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 180a5759..0471b9a5 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 @@ -39,6 +39,7 @@ public class ProtocolConstants public static final int MINECRAFT_1_18 = 757; public static final int MINECRAFT_1_18_2 = 758; public static final int MINECRAFT_1_19 = 759; + public static final int MINECRAFT_1_19_1 = 760; public static final List SUPPORTED_VERSIONS; public static final List SUPPORTED_VERSION_IDS; @@ -90,7 +91,8 @@ public class ProtocolConstants ProtocolConstants.MINECRAFT_1_17_1, ProtocolConstants.MINECRAFT_1_18, ProtocolConstants.MINECRAFT_1_18_2, - ProtocolConstants.MINECRAFT_1_19 + ProtocolConstants.MINECRAFT_1_19, + ProtocolConstants.MINECRAFT_1_19_1 ); if ( SNAPSHOT_SUPPORT ) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientChat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientChat.java index 0569170f..aabc549a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientChat.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientChat.java @@ -6,6 +6,7 @@ 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; @@ -21,6 +22,7 @@ public class ClientChat extends DefinedPacket private long salt; private byte[] signature; private boolean signedPreview; + private ChatChain chain; @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) @@ -30,6 +32,11 @@ public class ClientChat extends DefinedPacket salt = buf.readLong(); signature = readArray( buf ); signedPreview = buf.readBoolean(); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) + { + chain = new ChatChain(); + chain.read( buf, direction, protocolVersion ); + } } @Override @@ -40,6 +47,10 @@ public class ClientChat extends DefinedPacket buf.writeLong( salt ); writeArray( signature, buf ); buf.writeBoolean( signedPreview ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) + { + chain.write( buf ); + } } @Override 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 53c4144f..2b106a2f 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 @@ -9,6 +9,7 @@ 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; @@ -24,6 +25,7 @@ public class ClientCommand extends DefinedPacket private long salt; private Map signatures; private boolean signedPreview; + private ChatChain chain; @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) @@ -41,6 +43,11 @@ public class ClientCommand extends DefinedPacket } signedPreview = buf.readBoolean(); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) + { + chain = new ChatChain(); + chain.read( buf, direction, protocolVersion ); + } } @Override @@ -58,6 +65,10 @@ public class ClientCommand extends DefinedPacket } buf.writeBoolean( signedPreview ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) + { + chain.write( buf ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java index 8b148625..d9839973 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java @@ -1,6 +1,7 @@ package net.md_5.bungee.protocol.packet; import io.netty.buffer.ByteBuf; +import java.util.UUID; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -19,6 +20,7 @@ public class LoginRequest extends DefinedPacket private String data; private PlayerPublicKey publicKey; + private UUID uuid; @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) @@ -28,6 +30,13 @@ public class LoginRequest extends DefinedPacket { publicKey = readPublicKey( buf ); } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) + { + if ( buf.readBoolean() ) + { + uuid = readUUID( buf ); + } + } } @Override @@ -38,6 +47,17 @@ public class LoginRequest extends DefinedPacket { writePublicKey( publicKey, buf ); } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) + { + if ( uuid != null ) + { + buf.writeBoolean( true ); + writeUUID( uuid, buf ); + } else + { + buf.writeBoolean( false ); + } + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerChat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerChat.java deleted file mode 100644 index ca0e5964..00000000 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PlayerChat.java +++ /dev/null @@ -1,84 +0,0 @@ -package net.md_5.bungee.protocol.packet; - -import io.netty.buffer.ByteBuf; -import java.util.UUID; -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 PlayerChat extends DefinedPacket -{ - - private static final UUID EMPTY_UUID = new UUID( 0L, 0L ); - private String signedContent; - private String unsignedContent; // nullable - private UUID sender; - private int typeId; - private String displayName; - private String teamName; // nullable - private long timestamp; - private long salt; - private byte[] signature; - - @Override - public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) - { - signedContent = readString( buf, 262144 ); - if ( buf.readBoolean() ) - { - unsignedContent = readString( buf, 262144 ); - } - typeId = readVarInt( buf ); - sender = readUUID( buf ); - displayName = readString( buf, 262144 ); - if ( buf.readBoolean() ) - { - teamName = readString( buf, 262144 ); - } - timestamp = buf.readLong(); - salt = buf.readLong(); - signature = readArray( buf ); - } - - @Override - public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) - { - writeString( signedContent, buf ); - if ( unsignedContent != null ) - { - buf.writeBoolean( true ); - writeString( unsignedContent, buf ); - } else - { - buf.writeBoolean( false ); - } - writeVarInt( typeId, buf ); - writeUUID( sender, buf ); - writeString( displayName, buf ); - if ( teamName != null ) - { - buf.writeBoolean( true ); - writeString( teamName, buf ); - } else - { - buf.writeBoolean( false ); - } - buf.writeLong( timestamp ); - buf.writeLong( salt ); - writeArray( signature, buf ); - } - - @Override - public void handle(AbstractPacketHandler handler) throws Exception - { - handler.handle( this ); - } -} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/SystemChat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/SystemChat.java index f353e61f..2614f86e 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/SystemChat.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/SystemChat.java @@ -5,6 +5,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.protocol.AbstractPacketHandler; import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.ProtocolConstants; @@ -23,14 +24,20 @@ public class SystemChat extends DefinedPacket public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { message = readString( buf, 262144 ); - position = readVarInt( buf ); + position = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) ? ( ( buf.readBoolean() ) ? ChatMessageType.ACTION_BAR.ordinal() : 0 ) : readVarInt( buf ); } @Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( message, buf ); - writeVarInt( position, buf ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) + { + buf.writeBoolean( position == ChatMessageType.ACTION_BAR.ordinal() ); + } else + { + writeVarInt( position, buf ); + } } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java index ad7ea6a2..de12a565 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -3,6 +3,8 @@ package net.md_5.bungee; import com.google.common.io.ByteStreams; import com.google.common.primitives.Longs; import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.security.Key; @@ -17,6 +19,7 @@ import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; import java.util.Base64; import java.util.Random; +import java.util.UUID; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; @@ -73,12 +76,23 @@ public class EncryptionUtil return new EncryptionRequest( hash, pubKey, verify ); } - public static boolean check(PlayerPublicKey publicKey) throws GeneralSecurityException + public static boolean check(PlayerPublicKey publicKey, UUID uuid) throws GeneralSecurityException { Signature signature = Signature.getInstance( "SHA1withRSA" ); signature.initVerify( MOJANG_KEY ); - signature.update( ( publicKey.getExpiry() + "-----BEGIN RSA PUBLIC KEY-----\n" + MIME_ENCODER.encodeToString( getPubkey( publicKey.getKey() ).getEncoded() ) + "\n-----END RSA PUBLIC KEY-----\n" ).getBytes( StandardCharsets.US_ASCII ) ); + byte[] check; + if ( uuid != null ) + { + byte[] encoded = getPubkey( publicKey.getKey() ).getEncoded(); + check = new byte[ 24 + encoded.length ]; + + ByteBuffer.wrap( check ).order( ByteOrder.BIG_ENDIAN ).putLong( uuid.getMostSignificantBits() ).putLong( uuid.getLeastSignificantBits() ).putLong( publicKey.getExpiry() ).put( encoded ); + } else + { + check = ( publicKey.getExpiry() + "-----BEGIN RSA PUBLIC KEY-----\n" + MIME_ENCODER.encodeToString( getPubkey( publicKey.getKey() ).getEncoded() ) + "\n-----END RSA PUBLIC KEY-----\n" ).getBytes( StandardCharsets.US_ASCII ); + } + signature.update( check ); return signature.verify( publicKey.getSignature() ); } diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 380d0aea..3be014b2 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -123,7 +123,7 @@ public class ServerConnector extends PacketHandler channel.write( copiedHandshake ); channel.setProtocol( Protocol.LOGIN ); - channel.write( new LoginRequest( user.getName(), null ) ); + channel.write( new LoginRequest( user.getName(), null, user.getUniqueId() ) ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index 15de64c5..74362ef9 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -8,6 +8,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.security.GeneralSecurityException; import java.security.MessageDigest; import java.time.Instant; import java.util.HashSet; @@ -396,10 +397,13 @@ public class InitialHandler extends PacketHandler implements PendingConnection return; } - if ( !EncryptionUtil.check( publicKey ) ) + if ( getVersion() < ProtocolConstants.MINECRAFT_1_19_1 ) { - disconnect( bungee.getTranslation( "secure_profile_invalid" ) ); - return; + if ( !EncryptionUtil.check( publicKey, null ) ) + { + disconnect( bungee.getTranslation( "secure_profile_invalid" ) ); + return; + } } } @@ -509,6 +513,32 @@ public class InitialHandler extends PacketHandler implements PendingConnection private void finish() { + offlineId = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + getName() ).getBytes( Charsets.UTF_8 ) ); + if ( uniqueId == null ) + { + uniqueId = offlineId; + } + + if ( BungeeCord.getInstance().config.isEnforceSecureProfile() ) + { + if ( getVersion() >= ProtocolConstants.MINECRAFT_1_19_1 ) + { + boolean secure = false; + try + { + secure = EncryptionUtil.check( loginRequest.getPublicKey(), uniqueId ); + } catch ( GeneralSecurityException ex ) + { + } + + if ( !secure ) + { + disconnect( bungee.getTranslation( "secure_profile_invalid" ) ); + return; + } + } + } + if ( isOnlineMode() ) { // Check for multiple connections @@ -539,12 +569,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection } - offlineId = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + getName() ).getBytes( Charsets.UTF_8 ) ); - if ( uniqueId == null ) - { - uniqueId = offlineId; - } - Callback complete = new Callback() { @Override diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java index 81a1cfc3..dc949c66 100644 --- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java @@ -76,6 +76,8 @@ public abstract class EntityMap return EntityMap_1_16_2.INSTANCE_1_18; case ProtocolConstants.MINECRAFT_1_19: return EntityMap_1_16_2.INSTANCE_1_19; + case ProtocolConstants.MINECRAFT_1_19_1: + return EntityMap_1_16_2.INSTANCE_1_19_1; } throw new RuntimeException( "Version " + version + " has no entity map" ); } 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 b9d0b651..7241dc56 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 @@ -18,7 +18,7 @@ class EntityMap_1_16_2 extends EntityMap static final EntityMap_1_16_2 INSTANCE_1_17 = new EntityMap_1_16_2( 0x04, 0x2D ); static final EntityMap_1_16_2 INSTANCE_1_18 = new EntityMap_1_16_2( 0x04, 0x2D ); static final EntityMap_1_16_2 INSTANCE_1_19 = new EntityMap_1_16_2( 0x02, 0x2F ); - + static final EntityMap_1_16_2 INSTANCE_1_19_1 = new EntityMap_1_16_2( 0x02, 0x30 ); // private final int spawnPlayerId; private final int spectateId;