aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/account/offline.rs
blob: f0ee49bd3f7c3d885d3b031c9f262ec1f44ef9bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use uuid::Uuid;

use crate::account::{Account, AccountTrait};

/// A type of account that does not perform any authentication and cannot join
/// online-mode servers.
///
/// This type is not intended to be used directly by the user. To actually make
/// an offline-mode account, see [`Account::offline`].
#[derive(Debug)]
pub struct OfflineAccount {
    username: String,
}
impl AccountTrait for OfflineAccount {
    fn username(&self) -> &str {
        &self.username
    }
    fn uuid(&self) -> Uuid {
        azalea_crypto::offline::generate_uuid(&self.username)
    }
    fn access_token(&self) -> Option<String> {
        None
    }
}

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 {
        OfflineAccount {
            username: username.to_owned(),
        }
        .into()
    }
}