Skip to content

Commit

Permalink
added uuid fix directly to deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Dec 12, 2023
1 parent c33c803 commit 9f8be7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
11 changes: 1 addition & 10 deletions src-tauri/src/app/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src-tauri/src/minecraft/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<String, D::Error> 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
Expand Down

0 comments on commit 9f8be7e

Please sign in to comment.