diff options
| -rw-r--r-- | ozone-cli/src/main.rs | 48 | ||||
| -rw-r--r-- | ozone/src/launcher.rs | 1 |
2 files changed, 41 insertions, 8 deletions
diff --git a/ozone-cli/src/main.rs b/ozone-cli/src/main.rs index f033a19..d383cb7 100644 --- a/ozone-cli/src/main.rs +++ b/ozone-cli/src/main.rs @@ -12,6 +12,8 @@ use ozone::auth::{Account, AccountStorage, MsaAccount}; use ozone::auth::error::AuthErrorKind; use crate::cli::{AccountCommand, Cli, InstanceCommand, ProfileSelectArgs, RootCommand}; +const ACCOUNT_DB_PATH: &str = "ozone_accounts.json"; + fn find_account<'a>(auth: &'a AccountStorage, input: &ProfileSelectArgs) -> Result<Vec<(&'a String, &'a Account)>, ()> { if let Some(uuid) = input.uuid { Ok(auth.iter_accounts().filter(|(_, a)| match *a { @@ -260,7 +262,7 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> { } }, RootCommand::Account(account_args) => { - let accounts_path = home.join("ozone_accounts.json"); + let accounts_path = home.join(ACCOUNT_DB_PATH); let mut accounts = AccountStorage::load(&accounts_path).await?; match &account_args.command { @@ -388,9 +390,9 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> { eprintln!("No account selected."); return Ok(ExitCode::FAILURE); }; - + let client = MsaAccount::create_client(); - + match account { Account::MSA(msa_acct) => { msa_acct.log_in_silent(&client).await?; @@ -401,7 +403,7 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> { return Ok(ExitCode::FAILURE); } } - + accounts.save(&accounts_path).await?; } } @@ -413,9 +415,39 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> { }; let inst = settings.instances.get(&selection).expect("settings inconsistency"); - settings.save().await?; + let accounts_path = home.join(ACCOUNT_DB_PATH); + let mut accounts = AccountStorage::load(&accounts_path).await?; + let Some(account) = accounts.get_selected_account_mut() else { + eprintln!("No account selected."); + return Ok(ExitCode::FAILURE); + }; + + match account { + Account::MSA(msa_acct) => { + let client = MsaAccount::create_client(); + + println!("Looking up account information..."); + match msa_acct.log_in_silent(&client).await { + Ok(_) => (), + Err(e) if e.kind() == AuthErrorKind::InteractionRequired => { + eprintln!("This account requires interactive authentication: {}", account); + eprintln!("Details: {e}"); + return Ok(ExitCode::FAILURE); + }, + Err(e) => { + eprintln!("Error refreshing account: {e}"); + return Ok(ExitCode::FAILURE); + } + } + + accounts.save(&accounts_path).await?; + } + _ => () // nothing to be done + } + + println!("Preparing the game files..."); let launcher = Launcher::new(&home, !cli.offline).await?; let launch = launcher.prepare_launch(inst, Settings::get_instance_path(selection), settings.client_id).await.map_err(|e| { @@ -424,7 +456,9 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> { })?; dbg!(&launch); - info!("ok"); + info!("ok!"); + + println!("Launching the game!"); ozone::launcher::run_the_game(&launch)?; } @@ -436,7 +470,7 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> { #[tokio::main] async fn main() -> ExitCode { // use Warn as the default level to minimize noise on the command line - simple_logger::SimpleLogger::new().with_level(LevelFilter::Warn).env().init().unwrap(); + simple_logger::SimpleLogger::new().env().init().unwrap(); let arg = Cli::parse(); diff --git a/ozone/src/launcher.rs b/ozone/src/launcher.rs index 9add08c..add9f36 100644 --- a/ozone/src/launcher.rs +++ b/ozone/src/launcher.rs @@ -318,7 +318,6 @@ impl Launcher { /* TODO: * - launch game using JNI - * - auth */ pub async fn prepare_launch(&self, instance: &Instance, inst_home: impl AsRef<Path>, client_id: Uuid) -> Result<Launch, LaunchError> { let start = Instant::now(); |
