From ec7e86716370cb757588a0545fdcec4db8226155 Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sat, 20 Jan 2024 02:40:25 +0100 Subject: [PATCH 01/14] support for snapshot 24w03a (1.20.5) --- .../protocol/AbstractPacketHandler.java | 10 ++ .../net/md_5/bungee/protocol/Protocol.java | 134 ++++++++++++++---- .../bungee/protocol/ProtocolConstants.java | 6 +- .../protocol/packet/EncryptionRequest.java | 9 ++ .../md_5/bungee/protocol/packet/Login.java | 19 ++- .../bungee/protocol/packet/ServerData.java | 8 +- .../bungee/protocol/packet/StoreCookie.java | 41 ++++++ .../md_5/bungee/protocol/packet/Transfer.java | 43 ++++++ .../java/net/md_5/bungee/EncryptionUtil.java | 3 +- .../java/net/md_5/bungee/ServerConnector.java | 2 +- .../bungee/connection/InitialHandler.java | 4 + .../net/md_5/bungee/entitymap/EntityMap.java | 2 + .../bungee/entitymap/EntityMap_1_16_2.java | 1 + 13 files changed, 241 insertions(+), 41 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/StoreCookie.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/Transfer.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 4383dbb53f..70a7c51dd8 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 @@ -40,6 +40,7 @@ import net.md_5.bungee.protocol.packet.StartConfiguration; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; +import net.md_5.bungee.protocol.packet.StoreCookie; import net.md_5.bungee.protocol.packet.Subtitle; import net.md_5.bungee.protocol.packet.SystemChat; import net.md_5.bungee.protocol.packet.TabCompleteRequest; @@ -47,6 +48,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.ViewDistance; public abstract class AbstractPacketHandler @@ -243,4 +245,12 @@ public void handle(StartConfiguration startConfiguration) throws Exception public void handle(FinishConfiguration finishConfiguration) throws Exception { } + + public void handle(Transfer transfer) throws Exception + { + } + + public void handle(StoreCookie storeCookie) 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 cc08447cbc..ae8d787a63 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 @@ -46,6 +46,7 @@ import net.md_5.bungee.protocol.packet.StartConfiguration; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; +import net.md_5.bungee.protocol.packet.StoreCookie; import net.md_5.bungee.protocol.packet.Subtitle; import net.md_5.bungee.protocol.packet.SystemChat; import net.md_5.bungee.protocol.packet.TabCompleteRequest; @@ -53,6 +54,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.ViewDistance; public enum Protocol @@ -90,7 +92,9 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x20 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x1F ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x23 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x24 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x24 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x25 ) + ); TO_CLIENT.registerPacket( Login.class, @@ -106,7 +110,9 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x25 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x24 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x28 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x29 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x29 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 42 ) + ); TO_CLIENT.registerPacket( Chat.class, Chat::new, @@ -136,7 +142,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x3D ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x41 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x43 ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x45 ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x45 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x46 ) ); TO_CLIENT.registerPacket( BossBar.class, @@ -195,7 +202,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x54 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x58 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x5A ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x5C ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x5C ), + map( ProtocolConstants.MINECRAFT_1_20_5, 93 ) ); TO_CLIENT.registerPacket( ScoreboardScore.class, @@ -212,12 +220,14 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x57 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x5B ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x5D ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x5F ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x5F ), + map( ProtocolConstants.MINECRAFT_1_20_5, 96 ) ); TO_CLIENT.registerPacket( ScoreboardScoreReset.class, ScoreboardScoreReset::new, - map( ProtocolConstants.MINECRAFT_1_20_3, 0x42 ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x42 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x43 ) ); TO_CLIENT.registerPacket( ScoreboardDisplay.class, @@ -234,7 +244,9 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x4D ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x51 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x53 ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x55 ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x55 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x56 ) + ); TO_CLIENT.registerPacket( Team.class, @@ -251,7 +263,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x56 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x5A ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x5C ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x5E ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x5E ), + map( ProtocolConstants.MINECRAFT_1_20_5, 95 ) ); TO_CLIENT.registerPacket( PluginMessage.class, @@ -268,7 +281,9 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x16 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x15 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x17 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x18 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x18 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 25 ) + ); TO_CLIENT.registerPacket( Kick.class, @@ -285,7 +300,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x19 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x17 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x1A ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x1B ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x1B ), + map( ProtocolConstants.MINECRAFT_1_20_5, 28 ) ); TO_CLIENT.registerPacket( Title.class, @@ -303,7 +319,10 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x5B ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x5F ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x61 ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x63 ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x63 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x64 ) + + ); TO_CLIENT.registerPacket( ClearTitles.class, @@ -323,7 +342,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x59 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x5D ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x5F ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x61 ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x61 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x62 ) ); TO_CLIENT.registerPacket( TitleTimes.class, @@ -334,7 +354,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x5C ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x60 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x62 ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x64 ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x64 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x65 ) ); TO_CLIENT.registerPacket( SystemChat.class, @@ -344,7 +365,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x60 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x64 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x67 ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x69 ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x69 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 107 ) ); TO_CLIENT.registerPacket( PlayerListHeaderFooter.class, @@ -365,7 +387,9 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x61 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x65 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x68 ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x6A ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x6A ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x6C ) + ); TO_CLIENT.registerPacket( EntityStatus.class, @@ -382,7 +406,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x1A ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x19 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x1C ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x1D ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x1D ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x1E ) ); TO_CLIENT.registerPacket( Commands.class, @@ -408,7 +433,9 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x1D ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x1C ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x1F ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x20 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x20 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 33 ) + ); TO_CLIENT.registerPacket( ViewDistance.class, @@ -422,7 +449,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x4B ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x4F ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x51 ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x53 ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x53 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x61 ) ); TO_CLIENT.registerPacket( ServerData.class, @@ -432,27 +460,42 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x41 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x45 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x47 ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x49 ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x49 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x4A ) ); TO_CLIENT.registerPacket( PlayerListItemRemove.class, PlayerListItemRemove::new, map( ProtocolConstants.MINECRAFT_1_19_3, 0x35 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x39 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x3B ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x3B ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x3C ) + ); TO_CLIENT.registerPacket( PlayerListItemUpdate.class, PlayerListItemUpdate::new, map( ProtocolConstants.MINECRAFT_1_19_3, 0x36 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x3A ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x3C ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x3C ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x3D ) ); TO_CLIENT.registerPacket( StartConfiguration.class, StartConfiguration::new, map( ProtocolConstants.MINECRAFT_1_20_2, 0x65 ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x67 ) + map( ProtocolConstants.MINECRAFT_1_20_3, 0x67 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x68 ) + ); + TO_CLIENT.registerPacket( + StoreCookie.class, + StoreCookie::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x6A ) + ); + TO_CLIENT.registerPacket( + Transfer.class, + Transfer::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x72 ) ); TO_SERVER.registerPacket( @@ -471,7 +514,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x11 ), 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_3, 0x15 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 22 ) ); TO_SERVER.registerPacket( Chat.class, Chat::new, @@ -538,7 +582,9 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x0C ), 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_3, 0x10 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x11 ) + ); TO_SERVER.registerPacket( StartConfiguration.class, @@ -633,25 +679,46 @@ public enum Protocol { { + + // 1.20.5 0 cookie request clientbount 1 serverbound increment other by 1 TO_CLIENT.registerPacket( PluginMessage.class, PluginMessage::new, - map( ProtocolConstants.MINECRAFT_1_20_2, 0x00 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x00 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x01 ) + ); TO_CLIENT.registerPacket( Kick.class, Kick::new, - map( ProtocolConstants.MINECRAFT_1_20_2, 0x01 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x01 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x02 ) + ); TO_CLIENT.registerPacket( FinishConfiguration.class, FinishConfiguration::new, - map( ProtocolConstants.MINECRAFT_1_20_2, 0x02 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x02 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x03 ) + + ); TO_CLIENT.registerPacket( KeepAlive.class, KeepAlive::new, - map( ProtocolConstants.MINECRAFT_1_20_2, 0x03 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x03 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x04 ) + + ); + TO_CLIENT.registerPacket( + StoreCookie.class, + StoreCookie::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x09 ) + ); + TO_CLIENT.registerPacket( + Transfer.class, + Transfer::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x0A ) ); TO_SERVER.registerPacket( @@ -662,17 +729,22 @@ public enum Protocol TO_SERVER.registerPacket( PluginMessage.class, PluginMessage::new, - map( ProtocolConstants.MINECRAFT_1_20_2, 0x01 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x01 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x02 ) ); TO_SERVER.registerPacket( FinishConfiguration.class, FinishConfiguration::new, - map( ProtocolConstants.MINECRAFT_1_20_2, 0x02 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x02 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x03 ) + ); TO_SERVER.registerPacket( KeepAlive.class, KeepAlive::new, - map( ProtocolConstants.MINECRAFT_1_20_2, 0x03 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x03 ), + map( ProtocolConstants.MINECRAFT_1_20_5, 0x04 ) + ); } }; 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 6cb4c798ec..a7cc34a980 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 @@ -6,7 +6,7 @@ public class ProtocolConstants { - private static final boolean SNAPSHOT_SUPPORT = Boolean.getBoolean( "net.md_5.bungee.protocol.snapshot" ); + private static final boolean SNAPSHOT_SUPPORT = true || Boolean.getBoolean( "net.md_5.bungee.protocol.snapshot" ); public static final int MINECRAFT_1_8 = 47; public static final int MINECRAFT_1_9 = 107; public static final int MINECRAFT_1_9_1 = 108; @@ -45,6 +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 = 1073741996; public static final List SUPPORTED_VERSIONS; public static final List SUPPORTED_VERSION_IDS; @@ -108,8 +109,7 @@ public class ProtocolConstants if ( SNAPSHOT_SUPPORT ) { - // supportedVersions.add( "1.20.x" ); - // supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_20_3 ); + supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_20_5 ); } SUPPORTED_VERSIONS = supportedVersions.build(); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java index a29524ca81..2c167475cc 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java @@ -19,6 +19,7 @@ public class EncryptionRequest extends DefinedPacket private String serverId; private byte[] publicKey; private byte[] verifyToken; + private boolean shouldAuthenticate; @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) @@ -26,6 +27,10 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco serverId = readString( buf ); publicKey = readArray( buf ); verifyToken = readArray( buf ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 ) + { + shouldAuthenticate = buf.readBoolean(); + } } @Override @@ -34,6 +39,10 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc writeString( serverId, buf ); writeArray( publicKey, buf ); writeArray( verifyToken, buf ); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 ) + { + buf.writeBoolean( shouldAuthenticate ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java index f110c65568..24f3b31afe 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java @@ -41,6 +41,7 @@ public class Login extends DefinedPacket private boolean flat; private Location deathLocation; private int portalCooldown; + private boolean secureProfile; @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) @@ -135,7 +136,13 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco dimension = readString( buf ); worldName = readString( buf ); seed = buf.readLong(); - gameMode = buf.readUnsignedByte(); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 ) + { + gameMode = buf.readByte(); + } else + { + gameMode = buf.readUnsignedByte(); + } previousGameMode = buf.readByte(); } if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 ) @@ -154,6 +161,11 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco { portalCooldown = readVarInt( buf ); } + + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 ) + { + secureProfile = buf.readBoolean(); + } } @Override @@ -275,6 +287,11 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc { writeVarInt( portalCooldown, buf ); } + + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 ) + { + buf.writeBoolean( secureProfile ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ServerData.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ServerData.java index d3427f38d8..f9f485e4ab 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ServerData.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ServerData.java @@ -33,7 +33,7 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco { if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_4 ) { - icon = DefinedPacket.readArray( buf ); + icon = readArray( buf ); } else { icon = readString( buf ); @@ -45,7 +45,7 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco preview = buf.readBoolean(); } - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 && protocolVersion < ProtocolConstants.MINECRAFT_1_20_5 ) { enforceSecure = buf.readBoolean(); } @@ -76,7 +76,7 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc buf.writeBoolean( true ); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_4 ) { - DefinedPacket.writeArray( (byte[]) icon, buf ); + writeArray( (byte[]) icon, buf ); } else { writeString( (String) icon, buf ); @@ -91,7 +91,7 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc buf.writeBoolean( preview ); } - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 && protocolVersion < ProtocolConstants.MINECRAFT_1_20_5 ) { buf.writeBoolean( enforceSecure ); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/StoreCookie.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/StoreCookie.java new file mode 100644 index 0000000000..7a728a04eb --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/StoreCookie.java @@ -0,0 +1,41 @@ +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 StoreCookie extends DefinedPacket +{ + + private String key; + private byte[] data; + + @Override + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + key = readString( buf ); + data = readArray( buf, 5120 ); + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + writeString( key, buf ); + writeArray( data, 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/Transfer.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Transfer.java new file mode 100644 index 0000000000..891eedfade --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Transfer.java @@ -0,0 +1,43 @@ +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 Transfer extends DefinedPacket +{ + + private String host; + private int port; + + @Override + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + host = readString( buf ); + port = readVarInt( buf ); + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + writeString( host, buf ); + writeVarInt( port, buf ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } + +} 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 de12a5651a..fb497ca0cd 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -73,7 +73,8 @@ public static EncryptionRequest encryptRequest() byte[] pubKey = keys.getPublic().getEncoded(); byte[] verify = new byte[ 4 ]; random.nextBytes( verify ); - return new EncryptionRequest( hash, pubKey, verify ); + // always auth for now + return new EncryptionRequest( hash, pubKey, verify, true ); } public static boolean check(PlayerPublicKey publicKey, UUID uuid) throws GeneralSecurityException 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 dc6a5a8fd9..193a20578a 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -243,7 +243,7 @@ public static void handleLogin(ProxyServer bungee, ChannelWrapper ch, UserConnec // Set tab list size, TODO: what shall we do about packet mutability Login modLogin = new Login( login.getEntityId(), login.isHardcore(), login.getGameMode(), login.getPreviousGameMode(), login.getWorldNames(), login.getDimensions(), login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(), (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.getViewDistance(), login.getSimulationDistance(), login.isReducedDebugInfo(), login.isNormalRespawn(), login.isLimitedCrafting(), login.isDebug(), login.isFlat(), login.getDeathLocation(), - login.getPortalCooldown() ); + login.getPortalCooldown(), login.isSecureProfile() ); user.unsafe().sendPacket( modLogin ); 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 b1b087aa16..80b69e7071 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 @@ -109,6 +109,8 @@ public void sendPacket(DefinedPacket packet) private boolean legacy; @Getter private String extraDataInHandshake = ""; + @Getter + private boolean transferred; private UserConnection userCon; @Override @@ -349,6 +351,8 @@ public void handle(Handshake handshake) throws Exception ch.setProtocol( Protocol.STATUS ); break; case 2: + case 3: // transferred + this.transferred = handshake.getRequestedProtocol() == 3; // Login bungee.getLogger().log( Level.INFO, "{0} has connected", this ); thisState = State.USERNAME; 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 9a47f2ec4c..2bf92a03a3 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 @@ -86,6 +86,8 @@ public static EntityMap getEntityMap(int version) return EntityMap_1_16_2.INSTANCE_1_20_2; case ProtocolConstants.MINECRAFT_1_20_3: return EntityMap_1_16_2.INSTANCE_1_20_3; + case ProtocolConstants.MINECRAFT_1_20_5: + return EntityMap_1_16_2.INSTANCE_1_20_5; } 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 007957a8c8..8a8063a279 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,6 +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, 111 ); // private final int spawnPlayerId; private final int spectateId; From d4c583b650eb1790e4a30266ea487a1239fd01c7 Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sat, 20 Jan 2024 02:47:21 +0100 Subject: [PATCH 02/14] packet ids are hex --- .../net/md_5/bungee/protocol/Protocol.java | 18 +++++++++--------- .../bungee/protocol/ProtocolConstants.java | 2 +- .../bungee/entitymap/EntityMap_1_16_2.java | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) 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 ae8d787a63..004d1aa156 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 @@ -111,7 +111,7 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x24 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x28 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x29 ), - map( ProtocolConstants.MINECRAFT_1_20_5, 42 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x2A ) ); TO_CLIENT.registerPacket( Chat.class, @@ -203,7 +203,7 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_4, 0x58 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x5A ), map( ProtocolConstants.MINECRAFT_1_20_3, 0x5C ), - map( ProtocolConstants.MINECRAFT_1_20_5, 93 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x5D ) ); TO_CLIENT.registerPacket( ScoreboardScore.class, @@ -221,7 +221,7 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_4, 0x5B ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x5D ), map( ProtocolConstants.MINECRAFT_1_20_3, 0x5F ), - map( ProtocolConstants.MINECRAFT_1_20_5, 96 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x60 ) ); TO_CLIENT.registerPacket( ScoreboardScoreReset.class, @@ -264,7 +264,7 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_4, 0x5A ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x5C ), map( ProtocolConstants.MINECRAFT_1_20_3, 0x5E ), - map( ProtocolConstants.MINECRAFT_1_20_5, 95 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x5F ) ); TO_CLIENT.registerPacket( PluginMessage.class, @@ -282,7 +282,7 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x15 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x17 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x18 ), - map( ProtocolConstants.MINECRAFT_1_20_5, 25 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x19 ) ); TO_CLIENT.registerPacket( @@ -301,7 +301,7 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x17 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x1A ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x1B ), - map( ProtocolConstants.MINECRAFT_1_20_5, 28 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x1C ) ); TO_CLIENT.registerPacket( Title.class, @@ -366,7 +366,7 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_4, 0x64 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x67 ), map( ProtocolConstants.MINECRAFT_1_20_3, 0x69 ), - map( ProtocolConstants.MINECRAFT_1_20_5, 107 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x6B ) ); TO_CLIENT.registerPacket( PlayerListHeaderFooter.class, @@ -434,7 +434,7 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x1C ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x1F ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x20 ), - map( ProtocolConstants.MINECRAFT_1_20_5, 33 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x21 ) ); TO_CLIENT.registerPacket( @@ -515,7 +515,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, 22 ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x16 ) ); TO_SERVER.registerPacket( Chat.class, Chat::new, 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 a7cc34a980..b9c82dd6aa 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 @@ -6,7 +6,7 @@ public class ProtocolConstants { - private static final boolean SNAPSHOT_SUPPORT = true || Boolean.getBoolean( "net.md_5.bungee.protocol.snapshot" ); + private static final boolean SNAPSHOT_SUPPORT = Boolean.getBoolean( "net.md_5.bungee.protocol.snapshot" ); public static final int MINECRAFT_1_8 = 47; public static final int MINECRAFT_1_9 = 107; public static final int MINECRAFT_1_9_1 = 108; 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 8a8063a279..b92f3f1f5d 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, 111 ); + static final EntityMap_1_16_2 INSTANCE_1_20_5 = new EntityMap_1_16_2( -1, 0x6F ); // private final int spawnPlayerId; private final int spectateId; From 5a17c111dfc3e714a1964616e7e5403decc65ffe Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sat, 20 Jan 2024 02:51:02 +0100 Subject: [PATCH 03/14] remove weird empty lines --- .../java/net/md_5/bungee/protocol/Protocol.java | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) 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 004d1aa156..560f2cdb3d 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 @@ -94,7 +94,6 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_4, 0x23 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x24 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x25 ) - ); TO_CLIENT.registerPacket( Login.class, @@ -246,7 +245,6 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_20_2, 0x53 ), map( ProtocolConstants.MINECRAFT_1_20_3, 0x55 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x56 ) - ); TO_CLIENT.registerPacket( Team.class, @@ -283,7 +281,6 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_4, 0x17 ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x18 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x19 ) - ); TO_CLIENT.registerPacket( Kick.class, @@ -321,8 +318,6 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_20_2, 0x61 ), map( ProtocolConstants.MINECRAFT_1_20_3, 0x63 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x64 ) - - ); TO_CLIENT.registerPacket( ClearTitles.class, @@ -389,7 +384,6 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_20_2, 0x68 ), map( ProtocolConstants.MINECRAFT_1_20_3, 0x6A ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x6C ) - ); TO_CLIENT.registerPacket( EntityStatus.class, @@ -435,7 +429,6 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_4, 0x1F ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x20 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x21 ) - ); TO_CLIENT.registerPacket( ViewDistance.class, @@ -584,7 +577,6 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_20_2, 0x0F ), map( ProtocolConstants.MINECRAFT_1_20_3, 0x10 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x11 ) - ); TO_SERVER.registerPacket( StartConfiguration.class, @@ -680,35 +672,30 @@ public enum Protocol { - // 1.20.5 0 cookie request clientbount 1 serverbound increment other by 1 + // 1.20.5 0 cookie request clientbound 1 serverbound increment other by 1 TO_CLIENT.registerPacket( PluginMessage.class, PluginMessage::new, map( ProtocolConstants.MINECRAFT_1_20_2, 0x00 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x01 ) - ); TO_CLIENT.registerPacket( Kick.class, Kick::new, map( ProtocolConstants.MINECRAFT_1_20_2, 0x01 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x02 ) - ); TO_CLIENT.registerPacket( FinishConfiguration.class, FinishConfiguration::new, map( ProtocolConstants.MINECRAFT_1_20_2, 0x02 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x03 ) - - ); TO_CLIENT.registerPacket( KeepAlive.class, KeepAlive::new, map( ProtocolConstants.MINECRAFT_1_20_2, 0x03 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x04 ) - ); TO_CLIENT.registerPacket( StoreCookie.class, @@ -737,14 +724,12 @@ public enum Protocol FinishConfiguration::new, map( ProtocolConstants.MINECRAFT_1_20_2, 0x02 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x03 ) - ); TO_SERVER.registerPacket( KeepAlive.class, KeepAlive::new, map( ProtocolConstants.MINECRAFT_1_20_2, 0x03 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x04 ) - ); } }; From f984c90af2ece3d15fe685180f047fd6e4454e0d Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sat, 20 Jan 2024 14:13:07 +0100 Subject: [PATCH 04/14] added CookieRequest and CookieResponse --- .../protocol/AbstractPacketHandler.java | 10 ++++ .../net/md_5/bungee/protocol/Protocol.java | 28 +++++++++- .../bungee/protocol/packet/CookieRequest.java | 38 ++++++++++++++ .../protocol/packet/CookieResponse.java | 51 +++++++++++++++++++ 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieRequest.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieResponse.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 70a7c51dd8..4b52c8b181 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 @@ -8,6 +8,8 @@ import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.ClientStatus; import net.md_5.bungee.protocol.packet.Commands; +import net.md_5.bungee.protocol.packet.CookieRequest; +import net.md_5.bungee.protocol.packet.CookieResponse; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.EntityStatus; @@ -253,4 +255,12 @@ public void handle(Transfer transfer) throws Exception public void handle(StoreCookie storeCookie) throws Exception { } + + public void handle(CookieRequest cookieRequest) throws Exception + { + } + + public void handle(CookieResponse cookieResponse) 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 560f2cdb3d..37b9a8ba31 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 @@ -16,6 +16,8 @@ import net.md_5.bungee.protocol.packet.ClientCommand; import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.Commands; +import net.md_5.bungee.protocol.packet.CookieRequest; +import net.md_5.bungee.protocol.packet.CookieResponse; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.EntityStatus; @@ -480,6 +482,11 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_20_3, 0x67 ), map( ProtocolConstants.MINECRAFT_1_20_5, 0x68 ) ); + TO_CLIENT.registerPacket( + CookieRequest.class, + CookieRequest::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x16 ) + ); TO_CLIENT.registerPacket( StoreCookie.class, StoreCookie::new, @@ -583,6 +590,11 @@ public enum Protocol StartConfiguration::new, map( ProtocolConstants.MINECRAFT_1_20_2, 0x0B ) ); + TO_SERVER.registerPacket( + CookieResponse.class, + CookieResponse::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x10 ) + ); } }, // 1 @@ -643,6 +655,11 @@ public enum Protocol LoginPayloadRequest::new, map( ProtocolConstants.MINECRAFT_1_13, 0x04 ) ); + TO_CLIENT.registerPacket( + CookieRequest.class, + CookieRequest::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x05 ) + ); TO_SERVER.registerPacket( LoginRequest.class, @@ -664,6 +681,11 @@ public enum Protocol LoginAcknowledged::new, map( ProtocolConstants.MINECRAFT_1_20_2, 0x03 ) ); + TO_SERVER.registerPacket( + CookieResponse.class, + CookieResponse::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x04 ) + ); } }, // 3 @@ -672,7 +694,11 @@ public enum Protocol { - // 1.20.5 0 cookie request clientbound 1 serverbound increment other by 1 + TO_CLIENT.registerPacket( + CookieRequest.class, + CookieRequest::new, + map( ProtocolConstants.MINECRAFT_1_20_5, 0x00 ) + ); TO_CLIENT.registerPacket( PluginMessage.class, PluginMessage::new, diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieRequest.java new file mode 100644 index 0000000000..cb29519aab --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieRequest.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 CookieRequest extends DefinedPacket +{ + + private String cookie; + + @Override + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + cookie = readString( buf ); + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + writeString( cookie, 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/CookieResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieResponse.java new file mode 100644 index 0000000000..a913693e21 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieResponse.java @@ -0,0 +1,51 @@ +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 CookieResponse extends DefinedPacket +{ + + private String cookie; + private byte[] data; + + @Override + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + cookie = readString( buf ); + if ( buf.readBoolean() ) + { + data = readArray( buf ); + } + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + writeString( cookie, buf ); + if ( data != null ) + { + buf.writeBoolean( true ); + writeArray( data, buf ); + } else + { + buf.writeBoolean( false ); + } + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} From 0e51f06a9ab4972bf45a1ca95555117da81291b3 Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sat, 20 Jan 2024 14:34:46 +0100 Subject: [PATCH 05/14] add option to disable transfers --- .../main/java/net/md_5/bungee/conf/Configuration.java | 3 +++ .../net/md_5/bungee/connection/InitialHandler.java | 10 ++++++++-- proxy/src/main/resources/messages.properties | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java index 54c3223c95..70a2635f3b 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java @@ -68,6 +68,8 @@ public class Configuration implements ProxyConfig private int compressionThreshold = 256; private boolean preventProxyConnections; private boolean forgeSupport; + private boolean rejectTransfers; + public void load() { @@ -103,6 +105,7 @@ public void load() compressionThreshold = adapter.getInt( "network_compression_threshold", compressionThreshold ); preventProxyConnections = adapter.getBoolean( "prevent_proxy_connections", preventProxyConnections ); forgeSupport = adapter.getBoolean( "forge_support", forgeSupport ); + rejectTransfers = adapter.getBoolean( "reject_transfers", rejectTransfers ); disabledCommands = new CaseInsensitiveSet( (Collection) adapter.getList( "disabled_commands", Arrays.asList( "disabledcommandhere" ) ) ); 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 80b69e7071..fc5abf837b 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 @@ -351,8 +351,8 @@ public void handle(Handshake handshake) throws Exception ch.setProtocol( Protocol.STATUS ); break; case 2: - case 3: // transferred - this.transferred = handshake.getRequestedProtocol() == 3; + case 3: + transferred = handshake.getRequestedProtocol() == 3; // Login bungee.getLogger().log( Level.INFO, "{0} has connected", this ); thisState = State.USERNAME; @@ -369,6 +369,12 @@ public void handle(Handshake handshake) throws Exception } return; } + + if ( transferred && bungee.config.isRejectTransfers() ) + { + disconnect( bungee.getTranslation( "reject_transfer" ) ); + return; + } break; default: throw new QuietException( "Cannot request protocol " + handshake.getRequestedProtocol() ); diff --git a/proxy/src/main/resources/messages.properties b/proxy/src/main/resources/messages.properties index e42b798bc3..f58fdc6cdb 100644 --- a/proxy/src/main/resources/messages.properties +++ b/proxy/src/main/resources/messages.properties @@ -40,3 +40,4 @@ command_perms_permission=\u00a79- {0} command_ip=\u00a79IP of {0} is {1} illegal_chat_characters=\u00a7cIllegal characters in chat ({0}) kick_message=\u00a7cYou have been kicked off the proxy. +reject_transfer=\u00a7cYour transfer was rejected. \ No newline at end of file From cc979abbe201cbf9419fd6f14a2f8090264281ce Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sat, 20 Jan 2024 16:14:35 +0100 Subject: [PATCH 06/14] added cookie store and retrieve API --- .../bungee/api/connection/ProxiedPlayer.java | 23 ++++++++ .../java/net/md_5/bungee/UserConnection.java | 13 +++++ .../bungee/connection/InitialHandler.java | 57 +++++++++++++++++++ .../bungee/connection/UpstreamBridge.java | 7 +++ 4 files changed, 100 insertions(+) diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java index ab879248b2..5a267f2b5d 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java @@ -3,6 +3,7 @@ import java.util.Locale; import java.util.Map; import java.util.UUID; +import java.util.concurrent.CompletableFuture; import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.CommandSender; @@ -339,4 +340,26 @@ public enum MainHand */ @Deprecated Scoreboard getScoreboard(); + + /** + * Retrieves a cookie from this player. + * + * @param cookie the resource location of the cookie, for example "bungeecord:my_cookie" + * + * @return a {@link CompletableFuture} that will be completed when the Cookie response is received + * @apiNote Only useable for 1.20.5 clients or newer, + * if the cookie is not set in the client, the {@link CompletableFuture} will complete with a null value + */ + CompletableFuture retrieveCookie(String cookie); + + + /** + * Stores a cookie in this player's client. + * + * @param cookie the resource location of the cookie, for example "bungeecord:my_cookie" + * @param data the data to store in the cookie + * + * @apiNote Only useable for 1.20.5 clients or newer + */ + void storeCookie(String cookie, byte[] data); } diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 04143a4689..0aa8517ad2 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -20,6 +20,7 @@ import java.util.Objects; import java.util.Queue; import java.util.UUID; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.logging.Level; import lombok.Getter; @@ -771,4 +772,16 @@ public Scoreboard getScoreboard() { return serverSentScoreboard; } + + @Override + public CompletableFuture retrieveCookie(String cookie) + { + return pendingConnection.retrieveCookie( cookie ); + } + + @Override + public void storeCookie(String cookie, byte[] data) + { + pendingConnection.storeCookie( cookie, data ); + } } 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 fc5abf837b..de6b91109e 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 @@ -11,12 +11,19 @@ import java.security.MessageDigest; import java.time.Instant; import java.util.HashSet; +import java.util.Queue; import java.util.Set; import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.logging.Level; import javax.crypto.SecretKey; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.ToString; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeServerInfo; import net.md_5.bungee.EncryptionUtil; @@ -51,6 +58,8 @@ import net.md_5.bungee.protocol.PlayerPublicKey; import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.ProtocolConstants; +import net.md_5.bungee.protocol.packet.CookieRequest; +import net.md_5.bungee.protocol.packet.CookieResponse; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.Handshake; @@ -64,6 +73,7 @@ import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; +import net.md_5.bungee.protocol.packet.StoreCookie; import net.md_5.bungee.util.AllowedCharacters; import net.md_5.bungee.util.BufUtil; import net.md_5.bungee.util.QuietException; @@ -86,6 +96,18 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Getter private final Set registeredChannels = new HashSet<>(); private State thisState = State.HANDSHAKE; + private final Queue requestedCookies = new ConcurrentLinkedQueue<>(); + + @Data + @ToString + @EqualsAndHashCode + @AllArgsConstructor + public static class CookieFuture + { + private String cookie; + private CompletableFuture future; + } + private final Unsafe unsafe = new Unsafe() { @Override @@ -653,6 +675,19 @@ public void handle(LoginPayloadResponse response) throws Exception disconnect( "Unexpected custom LoginPayloadResponse" ); } + @Override + public void handle(CookieResponse cookieResponse) + { + // be careful spigot could also make the client send a cookie response + CookieFuture future = requestedCookies.peek(); + if ( future != null && future.cookie.equals( cookieResponse.getCookie() ) ) + { + requestedCookies.remove(); + future.getFuture().complete( cookieResponse.getData() ); + throw CancelSendSignal.INSTANCE; + } + } + @Override public void disconnect(String reason) { @@ -785,4 +820,26 @@ public void relayMessage(PluginMessage input) throws Exception brandMessage = input; } } + + public CompletableFuture retrieveCookie(String cookie) + { + Preconditions.checkState( getVersion() >= ProtocolConstants.MINECRAFT_1_20_5, "Cookies are only supported in 1.20.5 and above" ); + Preconditions.checkState( loginRequest != null, "Cannot retrieve cookies for Status or legacy connections" ); + if ( cookie.indexOf( ':' ) == -1 ) + { + // if we request an invalid resource location (no prefix) the client will respond with minecraft: prefix + cookie = "minecraft:" + cookie; + } + CompletableFuture future = new CompletableFuture<>(); + requestedCookies.add( new CookieFuture( cookie, future ) ); + unsafe.sendPacket( new CookieRequest( cookie ) ); + return future; + } + + public void storeCookie(String cookie, byte[] data) + { + Preconditions.checkState( getVersion() >= ProtocolConstants.MINECRAFT_1_20_5, "Cookies are only supported in 1.20.5 and above" ); + Preconditions.checkState( loginRequest != null, "Cannot retrieve cookies for Status or legacy connections" ); + unsafe().sendPacket( new StoreCookie( cookie, data ) ); + } } 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 460aa49159..95c7f3c4e8 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 @@ -32,6 +32,7 @@ import net.md_5.bungee.protocol.packet.ClientChat; import net.md_5.bungee.protocol.packet.ClientCommand; import net.md_5.bungee.protocol.packet.ClientSettings; +import net.md_5.bungee.protocol.packet.CookieResponse; import net.md_5.bungee.protocol.packet.FinishConfiguration; import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.LoginAcknowledged; @@ -363,6 +364,12 @@ public void handle(FinishConfiguration finishConfiguration) throws Exception con.sendQueuedPackets(); } + @Override + public void handle(CookieResponse cookieResponse) throws Exception + { + con.getPendingConnection().handle( cookieResponse ); + } + @Override public String toString() { From 0f81a99ea5e58c8bff6e4ad6b794c2b5344f6e04 Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sat, 20 Jan 2024 16:18:27 +0100 Subject: [PATCH 07/14] remove @apiNote --- .../java/net/md_5/bungee/api/connection/ProxiedPlayer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java index 5a267f2b5d..0dafb47e75 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java @@ -347,7 +347,7 @@ public enum MainHand * @param cookie the resource location of the cookie, for example "bungeecord:my_cookie" * * @return a {@link CompletableFuture} that will be completed when the Cookie response is received - * @apiNote Only useable for 1.20.5 clients or newer, + * Only useable for 1.20.5 clients or newer, * if the cookie is not set in the client, the {@link CompletableFuture} will complete with a null value */ CompletableFuture retrieveCookie(String cookie); @@ -359,7 +359,7 @@ public enum MainHand * @param cookie the resource location of the cookie, for example "bungeecord:my_cookie" * @param data the data to store in the cookie * - * @apiNote Only useable for 1.20.5 clients or newer + * Only useable for 1.20.5 clients or newer */ void storeCookie(String cookie, byte[] data); } From 5778b292f2a0a133e1482a2e4a79e380143687ca Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sat, 20 Jan 2024 19:12:17 +0100 Subject: [PATCH 08/14] added transfer api --- .../net/md_5/bungee/api/connection/ProxiedPlayer.java | 10 ++++++++++ .../src/main/java/net/md_5/bungee/UserConnection.java | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java index 0dafb47e75..ead7795eed 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java @@ -362,4 +362,14 @@ public enum MainHand * Only useable for 1.20.5 clients or newer */ void storeCookie(String cookie, byte[] data); + + /** + * Transfers this player to a different server specified by host and port. + * + * @param host the host of the server to transfer to + * @param port the port of the server to transfer to + * + * Only useable for 1.20.5 clients or newer + */ + void transfer(String host, int port); } diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 0aa8517ad2..45c14e9b8a 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -62,6 +62,7 @@ import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.protocol.packet.SystemChat; +import net.md_5.bungee.protocol.packet.Transfer; import net.md_5.bungee.tab.ServerUnique; import net.md_5.bungee.tab.TabList; import net.md_5.bungee.util.CaseInsensitiveSet; @@ -784,4 +785,11 @@ public void storeCookie(String cookie, byte[] data) { pendingConnection.storeCookie( cookie, data ); } + + @Override + public void transfer(String host, int port) + { + Preconditions.checkState( getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_20_5, "Transfers are only supported in 1.20.5 and above" ); + unsafe().sendPacket( new Transfer( host, port ) ); + } } From fb1563b27098f144c05c8b61166685ece7d29743 Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Sat, 20 Jan 2024 20:49:20 +0100 Subject: [PATCH 09/14] wrong protocol mapping for EntityStatus fixed --- protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 37b9a8ba31..05114642d3 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 @@ -403,7 +403,7 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_3, 0x19 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x1C ), map( ProtocolConstants.MINECRAFT_1_20_2, 0x1D ), - map( ProtocolConstants.MINECRAFT_1_20_3, 0x1E ) + map( ProtocolConstants.MINECRAFT_1_20_5, 0x1E ) ); TO_CLIENT.registerPacket( Commands.class, From 3827d275ad3932e904ca1fc5b6e6a5544562c7fb Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Mon, 22 Jan 2024 17:31:19 +0100 Subject: [PATCH 10/14] move store cookie api out off InitialHandler to UserConnection as it only is useable in Config and Game state --- proxy/src/main/java/net/md_5/bungee/UserConnection.java | 4 +++- .../java/net/md_5/bungee/connection/InitialHandler.java | 8 -------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 45c14e9b8a..ef88699ce0 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -61,6 +61,7 @@ import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter; import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.SetCompression; +import net.md_5.bungee.protocol.packet.StoreCookie; import net.md_5.bungee.protocol.packet.SystemChat; import net.md_5.bungee.protocol.packet.Transfer; import net.md_5.bungee.tab.ServerUnique; @@ -783,7 +784,8 @@ public CompletableFuture retrieveCookie(String cookie) @Override public void storeCookie(String cookie, byte[] data) { - pendingConnection.storeCookie( cookie, data ); + Preconditions.checkState( getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_20_5, "Cookies are only supported in 1.20.5 and above" ); + unsafe().sendPacket( new StoreCookie( cookie, data ) ); } @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 de6b91109e..5627f9291d 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 @@ -73,7 +73,6 @@ import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; -import net.md_5.bungee.protocol.packet.StoreCookie; import net.md_5.bungee.util.AllowedCharacters; import net.md_5.bungee.util.BufUtil; import net.md_5.bungee.util.QuietException; @@ -835,11 +834,4 @@ public CompletableFuture retrieveCookie(String cookie) unsafe.sendPacket( new CookieRequest( cookie ) ); return future; } - - public void storeCookie(String cookie, byte[] data) - { - Preconditions.checkState( getVersion() >= ProtocolConstants.MINECRAFT_1_20_5, "Cookies are only supported in 1.20.5 and above" ); - Preconditions.checkState( loginRequest != null, "Cannot retrieve cookies for Status or legacy connections" ); - unsafe().sendPacket( new StoreCookie( cookie, data ) ); - } } From 93cccf6a8a7178b286632bb20f0b6437ac93be04 Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Mon, 22 Jan 2024 23:21:48 +0100 Subject: [PATCH 11/14] add retrieveCookie to API of PendingConnection for use in early events --- .../bungee/api/connection/PendingConnection.java | 12 ++++++++++++ .../net/md_5/bungee/connection/InitialHandler.java | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java b/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java index f497395eb2..211205802f 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java @@ -2,6 +2,7 @@ import java.net.InetSocketAddress; import java.util.UUID; +import java.util.concurrent.CompletableFuture; import net.md_5.bungee.api.config.ListenerInfo; /** @@ -89,4 +90,15 @@ public interface PendingConnection extends Connection * @return Whether the client is using a legacy client. */ boolean isLegacy(); + + /** + * Retrieves a cookie from this pending connection. + * + * @param cookie the resource location of the cookie, for example "bungeecord:my_cookie" + * + * @return a {@link CompletableFuture} that will be completed when the Cookie response is received + * Only useable for 1.20.5 clients or newer during the login, config or game phase + * if the cookie is not set in the client, the {@link CompletableFuture} will complete with a null value + */ + CompletableFuture retrieveCookie(String cookie); } 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 5627f9291d..847bd1556f 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 @@ -820,13 +820,14 @@ public void relayMessage(PluginMessage input) throws Exception } } + @Override public CompletableFuture retrieveCookie(String cookie) { Preconditions.checkState( getVersion() >= ProtocolConstants.MINECRAFT_1_20_5, "Cookies are only supported in 1.20.5 and above" ); - Preconditions.checkState( loginRequest != null, "Cannot retrieve cookies for Status or legacy connections" ); + Preconditions.checkState( loginRequest != null, "Cannot retrieve cookies for status or legacy connections" ); if ( cookie.indexOf( ':' ) == -1 ) { - // if we request an invalid resource location (no prefix) the client will respond with minecraft: prefix + // if we request an invalid resource location (no prefix) the client will respond with "minecraft:" prefix cookie = "minecraft:" + cookie; } CompletableFuture future = new CompletableFuture<>(); From 8a2a05985a8850348286f1c3f187b630f61902cb Mon Sep 17 00:00:00 2001 From: Outfluencer <48880402+Outfluencer@users.noreply.github.com> Date: Wed, 24 Jan 2024 20:19:06 +0100 Subject: [PATCH 12/14] 24w04a --- .../main/java/net/md_5/bungee/protocol/ProtocolConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b9c82dd6aa..bedab8f810 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 = 1073741996; + public static final int MINECRAFT_1_20_5 = 1073741997; public static final List SUPPORTED_VERSIONS; public static final List SUPPORTED_VERSION_IDS; From 4d7451fd4a8817f89f0a820b7cb7c2f19438c955 Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Mon, 29 Jan 2024 13:26:12 +0100 Subject: [PATCH 13/14] improvements --- .../bungee/api/connection/PendingConnection.java | 5 +++-- .../bungee/api/connection/ProxiedPlayer.java | 16 +++++++++------- .../bungee/protocol/packet/CookieResponse.java | 14 ++------------ .../net/md_5/bungee/protocol/packet/Login.java | 8 +------- .../java/net/md_5/bungee/conf/Configuration.java | 1 - 5 files changed, 15 insertions(+), 29 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java b/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java index 211205802f..0337df2dba 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java @@ -4,6 +4,7 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import net.md_5.bungee.api.config.ListenerInfo; +import org.jetbrains.annotations.ApiStatus; /** * Represents a user attempting to log into the proxy. @@ -95,10 +96,10 @@ public interface PendingConnection extends Connection * Retrieves a cookie from this pending connection. * * @param cookie the resource location of the cookie, for example "bungeecord:my_cookie" - * * @return a {@link CompletableFuture} that will be completed when the Cookie response is received - * Only useable for 1.20.5 clients or newer during the login, config or game phase * if the cookie is not set in the client, the {@link CompletableFuture} will complete with a null value + * @throws IllegalStateException if the players version is not at least 1.20.5 */ + @ApiStatus.Experimental CompletableFuture retrieveCookie(String cookie); } diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java index ead7795eed..e3a7c1cf13 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java @@ -14,6 +14,7 @@ import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.event.ServerConnectEvent; import net.md_5.bungee.api.score.Scoreboard; +import org.jetbrains.annotations.ApiStatus; /** * Represents a player whose connection is being connected to somewhere else, @@ -345,11 +346,11 @@ public enum MainHand * Retrieves a cookie from this player. * * @param cookie the resource location of the cookie, for example "bungeecord:my_cookie" - * * @return a {@link CompletableFuture} that will be completed when the Cookie response is received - * Only useable for 1.20.5 clients or newer, * if the cookie is not set in the client, the {@link CompletableFuture} will complete with a null value + * @throws IllegalStateException if the players version is not at least 1.20.5 */ + @ApiStatus.Experimental CompletableFuture retrieveCookie(String cookie); @@ -358,18 +359,19 @@ public enum MainHand * * @param cookie the resource location of the cookie, for example "bungeecord:my_cookie" * @param data the data to store in the cookie - * - * Only useable for 1.20.5 clients or newer + * @throws IllegalStateException if the players version is not at least 1.20.5 */ + @ApiStatus.Experimental void storeCookie(String cookie, byte[] data); /** - * Transfers this player to a different server specified by host and port. + * Requests this player to connect to a different server specified by host and port. + * This is a client side transfer, host and port should not specify a BungeeCord Backend Server. * * @param host the host of the server to transfer to * @param port the port of the server to transfer to - * - * Only useable for 1.20.5 clients or newer + * @throws IllegalStateException if the players version is not at least 1.20.5 */ + @ApiStatus.Experimental void transfer(String host, int port); } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieResponse.java index a913693e21..77a541b622 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieResponse.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/CookieResponse.java @@ -23,24 +23,14 @@ public class CookieResponse extends DefinedPacket public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { cookie = readString( buf ); - if ( buf.readBoolean() ) - { - data = readArray( buf ); - } + data = readNullable( DefinedPacket::readArray, buf ); } @Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( cookie, buf ); - if ( data != null ) - { - buf.writeBoolean( true ); - writeArray( data, buf ); - } else - { - buf.writeBoolean( false ); - } + writeNullable( data, DefinedPacket::writeArray, buf ); } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java index 24f3b31afe..c3ca42d7b6 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java @@ -136,13 +136,7 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco dimension = readString( buf ); worldName = readString( buf ); seed = buf.readLong(); - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 ) - { - gameMode = buf.readByte(); - } else - { - gameMode = buf.readUnsignedByte(); - } + gameMode = buf.readUnsignedByte(); previousGameMode = buf.readByte(); } if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 ) diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java index 70a2635f3b..6967d4fcd2 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java @@ -70,7 +70,6 @@ public class Configuration implements ProxyConfig private boolean forgeSupport; private boolean rejectTransfers; - public void load() { ConfigurationAdapter adapter = ProxyServer.getInstance().getConfigurationAdapter(); From c2d6865eb1f903358801efafd455e7f1dd202021 Mon Sep 17 00:00:00 2001 From: Outfluencer Date: Mon, 29 Jan 2024 13:30:26 +0100 Subject: [PATCH 14/14] removed newline --- .../main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java index e3a7c1cf13..05076a510a 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java @@ -353,7 +353,6 @@ public enum MainHand @ApiStatus.Experimental CompletableFuture retrieveCookie(String cookie); - /** * Stores a cookie in this player's client. *