diff --git a/src-tauri/src/app/gui.rs b/src-tauri/src/app/gui.rs index fb1c741..c5d5f3f 100644 --- a/src-tauri/src/app/gui.rs +++ b/src-tauri/src/app/gui.rs @@ -132,16 +132,7 @@ async fn run_client(build_id: u32, account_data: MinecraftAccount, options: Laun let (account_name, uuid, token, user_type) = match account_data { MinecraftAccount::MsaAccount { name, uuid, token, .. } => (name, uuid, token, "msa".to_string()), - MinecraftAccount::OfflineAccount { name, uuid } => { - // A UUID of length less than 2 is invalid, so we generate a new one - let uuid = if uuid.len() < 2 { - Uuid::new_v4().to_string() - } else { - uuid - }; - - (name, uuid, "-".to_string(), "legacy".to_string()) - } + MinecraftAccount::OfflineAccount { name, uuid } => (name, uuid, "-".to_string(), "legacy".to_string()) }; // Random XUID diff --git a/src-tauri/src/minecraft/auth.rs b/src-tauri/src/minecraft/auth.rs index fe124d3..2f81d51 100644 --- a/src-tauri/src/minecraft/auth.rs +++ b/src-tauri/src/minecraft/auth.rs @@ -3,7 +3,7 @@ use anyhow::{anyhow, Result}; use miners::auth::{self, MsAuth}; use serde::{Deserialize, Serialize}; -use tracing::debug; +use tracing::{debug, warn}; use base64::{read::DecoderReader}; use byteorder::{ReadBytesExt, LE}; @@ -28,10 +28,23 @@ pub enum MinecraftAccount { #[serde(rename = "Offline")] OfflineAccount { name: String, + #[serde(deserialize_with = "check_uuid_format")] uuid: String } } +fn check_uuid_format<'de, D>(deserializer: D) -> Result where D: serde::Deserializer<'de> { + let uuid = String::deserialize(deserializer)?; + + // If the UUID is invalid, generate a new one + if uuid.len() < 2 { + warn!("Invalid UUID: {}, generating random new one.", uuid); + return Ok(Uuid::new_v4().to_string()); + } + + Ok(uuid) +} + impl MinecraftAccount { /// Authenticate using a Microsoft account