From 7fc1c702921a6c88c1617a4a40fd2792e5def36a Mon Sep 17 00:00:00 2001 From: Garen Tyler Date: Fri, 6 Jun 2025 19:56:00 -0600 Subject: [PATCH] Finish server login and stub configuration --- asn1der.txt | 2 ++ docker-compose.yml | 2 ++ src/net/connection/downstream/mod.rs | 13 +++++++++++-- src/protocol/mod.rs | 2 ++ src/protocol/packets.rs | 24 +++++++++++++++++++++--- 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 asn1der.txt diff --git a/asn1der.txt b/asn1der.txt new file mode 100644 index 0000000..a424168 --- /dev/null +++ b/asn1der.txt @@ -0,0 +1,2 @@ +reference 30819F300D06092A864886F70D010101050003818D0030818902818100E74798B642B8B855C6C24C32E49B7B842F02739F74BDC0F206C606D28B95BE63B4CC0BB263A038A27B9D2BCDA1375A2E91D3106938FCDC735DE8639C67FC03C8F45E1937390EAE7B358F39DC0C731627B614A61CB6B37F51FD4068149E9A29A854B913FA2DBA529D651BEAF67EEE65BF1019720F0D000C777DB4CE61062E911D0203010001 +ours 30819506092A864886F70D0101010500028180A43795E1BF36BDA93EFAE6EC1EBF638BBA0B3075F0FCA2B54A822C756BE9B6A9F959D64EB1EB32EC54179A659D3D25A16DF7258CCFCD886C2BDA3556455073D0282C25CED058FDAC7AA9C99631D071CAAFA1D2D7AD178C6DFE480D9B5D9BF7485F136F0AE07653851D48323D614EB72EE6559895AF1D695467A0D90D2469D4510203010001 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 6d1f8f1..6b2c274 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,3 +10,5 @@ services: environment: EULA: "TRUE" VERSION: "1.21.1" + ONLINE_MODE: "false" + NETWORK_COMPRESSION_THRESHOLD: "-1" diff --git a/src/net/connection/downstream/mod.rs b/src/net/connection/downstream/mod.rs index a2ad248..140b35d 100644 --- a/src/net/connection/downstream/mod.rs +++ b/src/net/connection/downstream/mod.rs @@ -10,6 +10,7 @@ use crate::{ }, }; use tokio::net::TcpStream; +use tracing::trace; /// The connection's current state. /// Similar to crate::protocol::ClientState, @@ -126,7 +127,7 @@ impl DownstreamConnection { let login_start = self.read_specific_packet::().await?; // Enable encryption and authenticate with Mojang. - self.enable_encryption().await?; + // self.enable_encryption().await?; // Enable compression. self.enable_compression().await?; @@ -193,6 +194,8 @@ impl DownstreamConnection { .expect("failed to decrypt shared secret"); // Enable encryption on the connection. + trace!("Enabling encryption for connection {}", self.inner.id); + todo!("Fix AES encryption implementation"); let encryptor = Aes128Cfb8Encryptor::new((&(*shared_secret)).into(), (&(*shared_secret)).into()); let decryptor = @@ -212,7 +215,10 @@ impl DownstreamConnection { self.inner.send_packet(packet).await } pub async fn disconnect(&mut self, reason: Option) -> Result<(), Error> { - use packets::{login::clientbound::LoginDisconnect, play::clientbound::PlayDisconnect}; + use packets::{ + configuration::clientbound::ConfigurationDisconnect, + login::clientbound::LoginDisconnect, play::clientbound::PlayDisconnect, + }; // let reason = reason.unwrap_or(serde_json::json!({ // "text": "You have been disconnected!" @@ -226,6 +232,9 @@ impl DownstreamConnection { ClientState::Login => { let _ = self.send_packet(LoginDisconnect { reason }).await; } + ClientState::Configuration => { + let _ = self.send_packet(ConfigurationDisconnect { reason }).await; + } ClientState::Play => { let _ = self.send_packet(PlayDisconnect { reason }).await; } diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 9e934a8..9fc28ec 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -40,6 +40,8 @@ pub enum ClientState { /// /// The `Login` state includes authentication, encryption, compression, and plugins. Login, + /// The client is in the `Configuration` state. + Configuration, /// The main connection state. The client has authenticated and is playing on the server. Play, /// The client has disconnected, and the connection struct should be removed. No packets should be sent or received. diff --git a/src/protocol/packets.rs b/src/protocol/packets.rs index 8630a29..6be0266 100644 --- a/src/protocol/packets.rs +++ b/src/protocol/packets.rs @@ -110,7 +110,7 @@ macro_rules! packets { pub fn state_change(&self) -> Option { match self { Packet::Handshake(handshake) => Some(handshake.next_state), - Packet::LoginSuccess(_) => Some(ClientState::Play), + Packet::LoginAcknowledged(_) => Some(ClientState::Configuration), Packet::LoginDisconnect(_) => Some(ClientState::Disconnected), Packet::PlayDisconnect(_) => Some(ClientState::Disconnected), Packet::PingResponse(_) => Some(ClientState::Disconnected), @@ -205,7 +205,12 @@ packets!( } packet LoginPluginResponse 0x02 { field message_id: VarInt, - field successful: bool, + // TODO: Implement + rest data, + } + packet LoginAcknowledged 0x03 {} + packet LoginCookieResponse 0x04 { + // TODO: Implement rest data, } } @@ -222,7 +227,7 @@ packets!( packet LoginSuccess 0x02 { field uuid: Uuid, field username: String, - // TODO: Re-implement CL02LoginSuccessProperty + // TODO: Implement rest properties, } packet SetCompression 0x03 { @@ -231,8 +236,21 @@ packets!( packet LoginPluginRequest 0x04 { field message_id: VarInt, field channel: String, + // TODO: Implement rest data, } + packet LoginCookieRequest 0x05 { + // TODO: Implement + rest data, + } + } + } + configuration Configuration { + serverbound Serverbound {} + clientbound Clientbound { + packet ConfigurationDisconnect 0x02 { + field reason: Chat, + } } } play Play {