summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2025-02-12 14:21:33 -0600
committerLibravatar bigfoot547 <[email protected]>2025-02-12 14:21:33 -0600
commitbeea99db3faea47dbd7c527da1d2f3151da3debe (patch)
treeb65fd4db721f2917901c473f428d3bc857969416
parentunstupid some stuff (diff)
minecraft
-rw-r--r--ozone-cli/src/cli.rs16
-rw-r--r--ozone-cli/src/main.rs13
-rw-r--r--ozone/src/auth.rs12
-rw-r--r--ozone/src/auth/types.rs27
4 files changed, 54 insertions, 14 deletions
diff --git a/ozone-cli/src/cli.rs b/ozone-cli/src/cli.rs
index d145e89..15a00da 100644
--- a/ozone-cli/src/cli.rs
+++ b/ozone-cli/src/cli.rs
@@ -161,6 +161,19 @@ impl InstanceArgs {
}
#[derive(Subcommand, Debug)]
+pub enum AccountCommand {
+ Select,
+ Forget,
+ SignIn
+}
+
+#[derive(Args, Debug)]
+pub struct AccountArgs {
+ #[command(subcommand)]
+ pub command: AccountCommand
+}
+
+#[derive(Subcommand, Debug)]
pub enum RootCommand {
/// Manages instances.
///
@@ -169,6 +182,9 @@ pub enum RootCommand {
/// settings. Each instance runs the game in a separate directory.
Instance(InstanceArgs),
+ /// Manages accounts.
+ Account(AccountArgs),
+
/// Launches the selected instance with the selected account.
Launch
}
diff --git a/ozone-cli/src/main.rs b/ozone-cli/src/main.rs
index 5174348..c53eade 100644
--- a/ozone-cli/src/main.rs
+++ b/ozone-cli/src/main.rs
@@ -7,8 +7,17 @@ use clap::Parser;
use ozone::launcher::{Instance, JavaRuntimeSetting, Launcher, Settings};
use ozone::launcher::version::{VersionList, VersionResult};
use uuid::Uuid;
+use ozone::auth::{Account, AuthenticationDatabase};
use crate::cli::{Cli, InstanceCommand, RootCommand};
+fn find_account(auth: &AuthenticationDatabase, input: &str) -> Option<Account> {
+ for user in auth.users.iter() {
+
+ }
+
+ todo!()
+}
+
async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> {
let Some(home) = cli.home.or_else(Launcher::sensible_home) else {
error!("Could not choose a launcher home directory. Please choose one with `--home'.");
@@ -218,8 +227,4 @@ async fn main() -> ExitCode {
ExitCode::FAILURE
})
-
- /*let launcher = Launcher::new("./work", true).await?;
-
- */
}
diff --git a/ozone/src/auth.rs b/ozone/src/auth.rs
index 9e8f6d8..0ca96ad 100644
--- a/ozone/src/auth.rs
+++ b/ozone/src/auth.rs
@@ -99,7 +99,7 @@ fn build_json_request(client: &reqwest::Client, url: impl IntoUrl, method: Metho
.header(reqwest::header::ACCEPT, "application/json")
}
-impl MsaUser {
+impl MsaAccount {
pub fn create_client() -> reqwest::Client {
util::build_client()
.redirect(reqwest::redirect::Policy::none())
@@ -270,7 +270,9 @@ impl MsaUser {
}
pub async fn log_in_silent(&mut self, client: &reqwest::Client) -> Result<(), AuthError> {
- let now: DateTime<Utc> = DateTime::from(SystemTime::now()) + TimeDelta::hours(12);
+ // see it's kind of funny that I call this variable "now" despite the fact that it's
+ // unconditionally 12 hours in the future - figboot
+ let now = Utc::now() + TimeDelta::hours(12);
self.ensure_xbl(client, now).await?;
self.ensure_mc_token(client, now).await?;
@@ -290,9 +292,9 @@ mod test {
simple_logger::SimpleLogger::new().with_colors(true).with_level(log::LevelFilter::Trace).init().unwrap();
let mut user = match tokio::fs::read_to_string("../test_stuff/test.json").await {
- Ok(s) => serde_json::from_str::<MsaUser>(&s).unwrap(),
+ Ok(s) => serde_json::from_str::<MsaAccount>(&s).unwrap(),
Err(e) if e.kind() == tokio::io::ErrorKind::NotFound => {
- MsaUser {
+ MsaAccount {
player_profile: None,
xuid: None,
gamertag: None,
@@ -308,7 +310,7 @@ mod test {
Err(e) => panic!("i/o error: {}", e)
};
- let client = MsaUser::create_client();
+ let client = MsaAccount::create_client();
loop {
match user.log_in_silent(&client).await {
diff --git a/ozone/src/auth/types.rs b/ozone/src/auth/types.rs
index b9cdaad..a4eeba1 100644
--- a/ozone/src/auth/types.rs
+++ b/ozone/src/auth/types.rs
@@ -24,7 +24,24 @@ pub struct PlayerProfile {
pub name: String,
#[serde(default, skip_serializing_if = "MultiMap::is_empty", with = "property_map")]
- pub properties: PropertyMap
+ pub properties: PropertyMap,
+
+ #[serde(skip)]
+ _private: ()
+}
+
+impl PlayerProfile {
+ pub fn new<S: Into<String>>(uuid: Uuid, name: S) -> PlayerProfile {
+ let name = name.into();
+ assert!((1..=16).contains(&name.len()), "name must be between 0 and 16 characters long");
+
+ PlayerProfile {
+ id: uuid,
+ name,
+ properties: Default::default(),
+ _private: ()
+ }
+ }
}
#[derive(Serialize, Deserialize)]
@@ -98,7 +115,7 @@ pub struct MinecraftPlayerInfo {
}
#[derive(Debug, Serialize, Deserialize)]
-pub struct MsaUser {
+pub struct MsaAccount {
#[serde(skip_serializing_if = "Option::is_none")]
pub player_profile: Option<PlayerProfile>,
pub xuid: Option<String>,
@@ -119,12 +136,12 @@ pub struct MsaUser {
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
-pub enum User {
+pub enum Account {
Dummy(PlayerProfile),
- MSA(Box<MsaUser>)
+ MSA(Box<MsaAccount>)
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AuthenticationDatabase {
- pub users: Vec<User>
+ pub users: Vec<Account>
}