2023-03-31 11:00:43 -07:00
|
|
|
#![cfg_attr(
|
|
|
|
|
all(not(debug_assertions), target_os = "windows"),
|
|
|
|
|
windows_subsystem = "windows"
|
|
|
|
|
)]
|
|
|
|
|
|
2025-05-01 16:13:13 -07:00
|
|
|
use enumset::EnumSet;
|
2023-04-05 19:04:09 -07:00
|
|
|
use theseus::prelude::*;
|
2025-04-26 18:09:58 -07:00
|
|
|
use theseus::worlds::get_recent_worlds;
|
2023-03-31 11:00:43 -07:00
|
|
|
|
2023-03-31 18:44:26 -07:00
|
|
|
// A simple Rust implementation of the authentication run
|
|
|
|
|
// 1) call the authenticate_begin_flow() function to get the URL to open (like you would in the frontend)
|
|
|
|
|
// 2) open the URL in a browser
|
|
|
|
|
// 3) call the authenticate_await_complete_flow() function to get the credentials (like you would in the frontend)
|
2023-03-31 11:00:43 -07:00
|
|
|
pub async fn authenticate_run() -> theseus::Result<Credentials> {
|
|
|
|
|
println!("A browser window will now open, follow the login flow there.");
|
2024-04-15 13:58:20 -07:00
|
|
|
let login = minecraft_auth::begin_login().await?;
|
2023-03-31 11:00:43 -07:00
|
|
|
|
2025-05-15 22:47:29 +02:00
|
|
|
println!("Open URL {} in a browser", login.redirect_uri.as_str());
|
2023-03-31 18:44:26 -07:00
|
|
|
|
2024-04-15 13:58:20 -07:00
|
|
|
println!("Please enter URL code: ");
|
|
|
|
|
let mut input = String::new();
|
|
|
|
|
std::io::stdin()
|
|
|
|
|
.read_line(&mut input)
|
|
|
|
|
.expect("error: unable to read user input");
|
|
|
|
|
|
|
|
|
|
println!("You entered: {}", input.trim());
|
|
|
|
|
|
|
|
|
|
let credentials = minecraft_auth::finish_login(&input, login).await?;
|
2023-03-31 18:44:26 -07:00
|
|
|
|
2023-08-17 17:26:21 -07:00
|
|
|
println!("Logged in user {}.", credentials.username);
|
|
|
|
|
Ok(credentials)
|
2023-03-31 11:00:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() -> theseus::Result<()> {
|
|
|
|
|
println!("Starting.");
|
|
|
|
|
|
2023-06-30 08:11:32 -07:00
|
|
|
let _log_guard = theseus::start_logger();
|
2023-05-08 12:14:08 -07:00
|
|
|
|
2023-03-31 11:00:43 -07:00
|
|
|
// Initialize state
|
2024-07-24 11:03:19 -07:00
|
|
|
State::init().await?;
|
2023-04-26 10:28:08 -07:00
|
|
|
|
2025-05-01 16:13:13 -07:00
|
|
|
let worlds = get_recent_worlds(4, EnumSet::all()).await?;
|
2025-04-26 18:09:58 -07:00
|
|
|
for world in worlds {
|
|
|
|
|
println!(
|
|
|
|
|
"World: {:?}/{:?} played at {:?}: {:#?}",
|
|
|
|
|
world.profile,
|
|
|
|
|
world.world.name,
|
|
|
|
|
world.world.last_played,
|
|
|
|
|
world.world.details
|
|
|
|
|
);
|
2023-03-31 11:00:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|