From 6559b49f2f2fa9e8b87076ee84d6c934adb5621b Mon Sep 17 00:00:00 2001 From: Alvsch <94403567+Alvsch@users.noreply.github.com> Date: Sun, 20 Oct 2024 14:01:20 +0200 Subject: [PATCH 1/2] made encryption config work --- pumpkin/src/client/client_packet.rs | 48 +++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index a0daf76f9..0d873d8ea 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -106,10 +106,23 @@ impl Client { profile_actions: None, }); - // TODO: check config for encryption - let verify_token: [u8; 4] = rand::random(); - self.send_packet(&server.encryption_request(&verify_token, BASIC_CONFIG.online_mode)) + if BASIC_CONFIG.encryption { + let verify_token: [u8; 4] = rand::random(); + self.send_packet( + &server.encryption_request(&verify_token, BASIC_CONFIG.online_mode), + ) .await; + } else { + if ADVANCED_CONFIG.packet_compression.enabled { + self.enable_compression().await; + } + self.finish_login( + gameprofile + .as_ref() + .expect("The GameProfile was just set to Some, this should never fail"), + ) + .await; + } } } @@ -118,34 +131,43 @@ impl Client { server: &Server, encryption_response: SEncryptionResponse, ) { - let shared_secret = server.decrypt(&encryption_response.shared_secret).unwrap(); + let shared_secret = match server.decrypt(&encryption_response.shared_secret) { + Ok(shared_secret) => shared_secret, + Err(error) => { + self.kick(&error.to_string()).await; + return; + } + }; if let Err(error) = self.set_encryption(Some(&shared_secret)).await { self.kick(&error.to_string()).await; return; } + let mut gameprofile = self.gameprofile.lock().await; + let Some(profile) = gameprofile.as_mut() else { + self.kick("No Game profile").await; + return; + }; + if BASIC_CONFIG.online_mode { match self - .autenticate(server, &shared_secret, &gameprofile.as_ref().unwrap().name) + .autenticate(server, &shared_secret, &profile.name) .await { - Ok(profile) => *gameprofile = Some(profile), + Ok(new_profile) => *profile = new_profile, Err(e) => { self.kick(&e.to_string()).await; + return; } } } - if let Some(profile) = gameprofile.as_ref() { - if ADVANCED_CONFIG.packet_compression.enabled { - self.enable_compression().await; - } - self.finish_login(profile).await; - } else { - self.kick("No Game profile").await; + if ADVANCED_CONFIG.packet_compression.enabled { + self.enable_compression().await; } + self.finish_login(profile).await; } async fn enable_compression(&self) { From e9833a798ce8f9b2cf2a167bf63e9acbe2ba0925 Mon Sep 17 00:00:00 2001 From: Alvsch <94403567+Alvsch@users.noreply.github.com> Date: Sun, 20 Oct 2024 14:33:44 +0200 Subject: [PATCH 2/2] use profile before moving --- pumpkin/src/client/client_packet.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index 0d873d8ea..04b00506e 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -99,12 +99,12 @@ impl Client { } } } else { - *gameprofile = Some(GameProfile { + let profile = GameProfile { id: login_start.uuid, name: login_start.name, properties: vec![], profile_actions: None, - }); + }; if BASIC_CONFIG.encryption { let verify_token: [u8; 4] = rand::random(); @@ -116,13 +116,10 @@ impl Client { if ADVANCED_CONFIG.packet_compression.enabled { self.enable_compression().await; } - self.finish_login( - gameprofile - .as_ref() - .expect("The GameProfile was just set to Some, this should never fail"), - ) - .await; + self.finish_login(&profile).await; } + + *gameprofile = Some(profile); } }