aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/account.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-client/src/account.rs')
-rw-r--r--azalea-client/src/account.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/azalea-client/src/account.rs b/azalea-client/src/account.rs
index fc34d6c4..f63d342e 100644
--- a/azalea-client/src/account.rs
+++ b/azalea-client/src/account.rs
@@ -1,13 +1,14 @@
//! Connect to Minecraft servers.
-use crate::{client::JoinError, get_mc_dir, Client, Event};
-use azalea_protocol::ServerAddress;
-use tokio::sync::mpsc::UnboundedReceiver;
+use crate::get_mc_dir;
use uuid::Uuid;
/// Something that can join Minecraft servers.
+///
+/// To join a server using this account, use [`crate::Client::join`].
#[derive(Clone, Debug)]
pub struct Account {
+ /// The Minecraft username of the account.
pub username: String,
/// The access token for authentication. You can obtain one of these
/// manually from azalea-auth.
@@ -15,7 +16,11 @@ pub struct Account {
/// Only required for online-mode accounts.
pub uuid: Option<uuid::Uuid>,
}
+
impl Account {
+ /// An offline account does not authenticate with Microsoft's servers, and
+ /// as such can only join offline mode servers. This is useful for testing
+ /// in LAN worlds.
pub fn offline(username: &str) -> Self {
Self {
username: username.to_string(),
@@ -24,6 +29,10 @@ impl Account {
}
}
+ /// This will create an online-mode account by authenticating with
+ /// Microsoft's servers. Note that the email given is actually only used as
+ /// a key for the cache, but it's recommended to use the real email to
+ /// avoid confusion.
pub async fn microsoft(email: &str) -> Result<Self, azalea_auth::AuthError> {
let minecraft_dir = get_mc_dir::minecraft_dir().unwrap();
let auth_result = azalea_auth::auth(
@@ -40,12 +49,4 @@ impl Account {
uuid: Some(Uuid::parse_str(&auth_result.profile.id).expect("Invalid UUID")),
})
}
-
- /// Joins the Minecraft server on the given address using this account.
- pub async fn join(
- &self,
- address: &ServerAddress,
- ) -> Result<(Client, UnboundedReceiver<Event>), JoinError> {
- Client::join(self, address).await
- }
}