aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/account.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-10-23 14:46:06 -0500
committermat <github@matdoes.dev>2022-10-23 14:46:06 -0500
commita9ff79a10553026b0fa32f0e31f1e0442467ca78 (patch)
tree5ecda41c72d2202faeb70cda08aae0a9f1c17675 /azalea-client/src/account.rs
parent127126c2cc415887395f18119404ace362d4173a (diff)
downloadazalea-drasl-a9ff79a10553026b0fa32f0e31f1e0442467ca78.tar.xz
write more documentation
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
- }
}