azalea_client/account/
offline.rs

1use uuid::Uuid;
2
3use crate::account::{Account, AccountTrait};
4
5/// A type of account that does not perform any authentication and cannot join
6/// online-mode servers.
7///
8/// This type is not intended to be used directly by the user. To actually make
9/// an offline-mode account, see [`Account::offline`].
10#[derive(Debug)]
11pub struct OfflineAccount {
12    username: String,
13}
14impl AccountTrait for OfflineAccount {
15    fn username(&self) -> &str {
16        &self.username
17    }
18    fn uuid(&self) -> Uuid {
19        azalea_crypto::offline::generate_uuid(&self.username)
20    }
21    fn access_token(&self) -> Option<String> {
22        None
23    }
24}
25
26impl Account {
27    /// An offline account does not authenticate with Microsoft's servers, and
28    /// as such can only join offline mode servers.
29    ///
30    /// This is useful for testing in LAN worlds.
31    pub fn offline(username: &str) -> Self {
32        OfflineAccount {
33            username: username.to_owned(),
34        }
35        .into()
36    }
37}