Account

Struct Account 

Source
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

Source

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?
azalea/examples/testbot/main.rs (line 49)
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}
Source

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.

Source

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?;
Source

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

Source

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?
azalea/examples/nearest_entity.rs (line 23)
22async fn main() -> AppExit {
23    let account = Account::offline("bot");
24
25    ClientBuilder::new()
26        .add_plugins(LookAtStuffPlugin)
27        .start(account, "localhost")
28        .await
29}
More examples
Hide additional examples
azalea/examples/steal.rs (line 12)
11async fn main() -> AppExit {
12    let account = Account::offline("bot");
13    // or let bot = Account::microsoft("email").await.unwrap();
14
15    ClientBuilder::new()
16        .set_handler(handle)
17        .start(account, "localhost")
18        .await
19}
azalea/examples/echo.rs (line 7)
6async fn main() -> AppExit {
7    let account = Account::offline("bot");
8    // or let account = Account::microsoft("email").await.unwrap();
9
10    ClientBuilder::new()
11        .set_handler(handle)
12        .start(account, "localhost")
13        .await
14}
azalea/examples/testbot/main.rs (line 51)
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}
Source§

impl Account

Source

pub fn uuid_or_offline(&self) -> Uuid

👎Deprecated: moved to uuid().

Trait Implementations§

Source§

impl Clone for Account

Source§

fn clone(&self) -> Account

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for Account
where Self: Send + Sync + 'static,

Source§

const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table

A constant indicating the storage type used for this component.
Source§

type Mutability = Mutable

A marker type to assist Bevy with determining if this component is mutable, or immutable. Mutable components will have [Component<Mutability = Mutable>], while immutable components will instead have [Component<Mutability = Immutable>]. Read more
Source§

fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )

Registers required components. Read more
Source§

fn clone_behavior() -> ComponentCloneBehavior

Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
§

fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_add [ComponentHook] for this [Component] if one is defined.
§

fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_insert [ComponentHook] for this [Component] if one is defined.
§

fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_replace [ComponentHook] for this [Component] if one is defined.
§

fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_remove [ComponentHook] for this [Component] if one is defined.
§

fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_despawn [ComponentHook] for this [Component] if one is defined.
§

fn map_entities<E>(_this: &mut Self, _mapper: &mut E)
where E: EntityMapper,

Maps the entities on this component using the given [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 more
Source§

impl Debug for Account

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Account

Source§

type Target = dyn AccountTrait

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: AccountTrait + 'static> From<T> for Account

Source§

fn from(value: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<C> Bundle for C
where 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>), )

Gets this [Bundle]’s component ids. This will be None if the component has not been registered.
§

impl<C> BundleFromComponents for C
where C: Component,

§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<C> DynamicBundle for C
where C: Component,

§

type Effect = ()

An operation on the entity that happens after inserting this bundle.
§

unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect

Moves the components out of the bundle. Read more
§

unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )

Applies the after-effects of spawning this bundle. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
§

impl<A> Is for A
where A: Any,

§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ConditionalSend for T
where T: Send,