pub struct Account(/* private fields */);Expand description
Something that can join Minecraft servers.
By default, Azalea only supports either authentication with Microsoft
(online-mode), or no authentication at all (offline-mode). If you’d like to
do authentication in some other way, consider looking at AccountTrait.
To join a server using this account, you can either use
StartJoinServerEvent or azalea::ClientBuilder.
Note that Account is also an ECS component that’s present on our client
entities.
§Examples
let account = Account::microsoft("[email protected]").await;
// or Account::offline("example");Implementations§
Source§impl Account
impl Account
Sourcepub async fn microsoft(cache_key: &str) -> Result<Self, AuthError>
pub async fn microsoft(cache_key: &str) -> Result<Self, AuthError>
This will create an online-mode account by authenticating with Microsoft’s servers.
The cache key is used for avoiding having to log in every time. This is typically set to the account email, but it can be any string.
Examples found in repository?
36async fn main() -> AppExit {
37 let args = parse_args();
38
39 thread::spawn(deadlock_detection_thread);
40
41 let join_address = args.server.clone();
42
43 let mut builder = SwarmBuilder::new()
44 .set_handler(handle)
45 .set_swarm_handler(swarm_handle);
46
47 for username_or_email in &args.accounts {
48 let account = if username_or_email.contains('@') {
49 Account::microsoft(username_or_email).await.unwrap()
50 } else {
51 Account::offline(username_or_email)
52 };
53
54 builder = builder.add_account_with_state(account, State::new());
55 }
56
57 let mut commands = CommandDispatcher::new();
58 register_commands(&mut commands);
59
60 builder
61 .join_delay(Duration::from_millis(100))
62 .set_swarm_state(SwarmState {
63 args,
64 commands: Arc::new(commands),
65 })
66 .start(join_address)
67 .await
68}Sourcepub async fn microsoft_with_custom_client_id_and_scope(
cache_key: &str,
client_id: Option<&str>,
scope: Option<&str>,
) -> Result<Self, AuthError>
pub async fn microsoft_with_custom_client_id_and_scope( cache_key: &str, client_id: Option<&str>, scope: Option<&str>, ) -> Result<Self, AuthError>
Similar to Account::microsoft but you can use your own client_id
and scope.
Pass None if you want to use default ones.
Sourcepub async fn with_microsoft_access_token(
msa: ExpiringValue<AccessTokenResponse>,
) -> Result<Self, AuthError>
pub async fn with_microsoft_access_token( msa: ExpiringValue<AccessTokenResponse>, ) -> Result<Self, AuthError>
This will create an online-mode account through
azalea_auth::get_minecraft_token so you can have more control over
the authentication process (like doing your own caching or
displaying the Microsoft user code to the user in a different way).
This will refresh the given token if it’s expired.
let client = reqwest::Client::new();
let res = azalea_auth::get_ms_link_code(&client, None, None).await?;
// Or, `azalea_auth::get_ms_link_code(&client, Some(client_id), None).await?`
// if you want to use your own client_id
println!(
"Go to {} and enter the code {}",
res.verification_uri, res.user_code
);
let msa = azalea_auth::get_ms_auth_token(&client, res, None).await?;
Account::with_microsoft_access_token(msa).await?;Sourcepub async fn with_microsoft_access_token_and_custom_client_id_and_scope(
msa: ExpiringValue<AccessTokenResponse>,
client_id: Option<&str>,
scope: Option<&str>,
) -> Result<Self, AuthError>
pub async fn with_microsoft_access_token_and_custom_client_id_and_scope( msa: ExpiringValue<AccessTokenResponse>, client_id: Option<&str>, scope: Option<&str>, ) -> Result<Self, AuthError>
Similar to Account::with_microsoft_access_token but you can use
custom client_id and scope.
Source§impl Account
impl Account
Sourcepub fn offline(username: &str) -> Self
pub fn offline(username: &str) -> Self
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.
Examples found in repository?
More examples
36async fn main() -> AppExit {
37 let args = parse_args();
38
39 thread::spawn(deadlock_detection_thread);
40
41 let join_address = args.server.clone();
42
43 let mut builder = SwarmBuilder::new()
44 .set_handler(handle)
45 .set_swarm_handler(swarm_handle);
46
47 for username_or_email in &args.accounts {
48 let account = if username_or_email.contains('@') {
49 Account::microsoft(username_or_email).await.unwrap()
50 } else {
51 Account::offline(username_or_email)
52 };
53
54 builder = builder.add_account_with_state(account, State::new());
55 }
56
57 let mut commands = CommandDispatcher::new();
58 register_commands(&mut commands);
59
60 builder
61 .join_delay(Duration::from_millis(100))
62 .set_swarm_state(SwarmState {
63 args,
64 commands: Arc::new(commands),
65 })
66 .start(join_address)
67 .await
68}Trait Implementations§
Source§impl Component for Account
impl Component for Account
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>],
while immutable components will instead have [Component<Mutability = Immutable>]. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
on_add [ComponentHook] for this [Component] if one is defined.§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
on_insert [ComponentHook] for this [Component] if one is defined.§fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
on_replace [ComponentHook] for this [Component] if one is defined.§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
on_remove [ComponentHook] for this [Component] if one is defined.§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
on_despawn [ComponentHook] for this [Component] if one is defined.§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper]. This is used to remap entities in contexts like scenes and entity cloning.
When deriving [Component], this is populated by annotating fields containing entities with #[entities] Read moreAuto Trait Implementations§
impl Freeze for Account
impl !RefUnwindSafe for Account
impl Send for Account
impl Sync for Account
impl Unpin for Account
impl !UnwindSafe for Account
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ids: &mut impl FnMut(ComponentId), )
§fn get_component_ids(
components: &Components,
ids: &mut impl FnMut(Option<ComponentId>),
)
fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )
Bundle]’s component ids. This will be None if the component has not been registered.§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.