diff options
Diffstat (limited to 'azalea-client/src/plugins')
| -rw-r--r-- | azalea-client/src/plugins/chat/handler.rs | 9 | ||||
| -rw-r--r-- | azalea-client/src/plugins/chat_signing.rs | 12 | ||||
| -rw-r--r-- | azalea-client/src/plugins/join.rs | 9 | ||||
| -rw-r--r-- | azalea-client/src/plugins/login.rs | 28 | ||||
| -rw-r--r-- | azalea-client/src/plugins/packet/login/events.rs | 2 | ||||
| -rw-r--r-- | azalea-client/src/plugins/packet/login/mod.rs | 2 |
6 files changed, 26 insertions, 36 deletions
diff --git a/azalea-client/src/plugins/chat/handler.rs b/azalea-client/src/plugins/chat/handler.rs index 626ce7c2..703a9846 100644 --- a/azalea-client/src/plugins/chat/handler.rs +++ b/azalea-client/src/plugins/chat/handler.rs @@ -9,7 +9,7 @@ use bevy_ecs::prelude::*; use super::ChatKind; use crate::packet::game::SendGamePacketEvent; #[cfg(feature = "online-mode")] -use crate::{Account, chat_signing::ChatSigningSession}; +use crate::{account::Account, chat_signing::ChatSigningSession}; /// Send a chat packet to the server of a specific kind (chat message or /// command). Usually you just want [`SendChatEvent`] instead. @@ -99,11 +99,12 @@ pub fn create_signature( ) -> azalea_crypto::signing::MessageSignature { use azalea_crypto::signing::SignChatMessageOptions; - let certs = account.certs.lock(); - let certs = certs.as_ref().expect("certs shouldn't be set back to None"); + let certs = account + .certs() + .expect("certs shouldn't be set back to None"); let signature = azalea_crypto::signing::sign_chat_message(&SignChatMessageOptions { - account_uuid: account.uuid.expect("account must have a uuid"), + account_uuid: account.uuid(), chat_session_uuid: chat_session.session_id, message_index: chat_session.messages_sent, salt, diff --git a/azalea-client/src/plugins/chat_signing.rs b/azalea-client/src/plugins/chat_signing.rs index 8e612f5b..2de9c6b0 100644 --- a/azalea-client/src/plugins/chat_signing.rs +++ b/azalea-client/src/plugins/chat_signing.rs @@ -13,7 +13,7 @@ use tracing::{debug, error}; use uuid::Uuid; use super::{chat, login::IsAuthenticated, packet::game::SendGamePacketEvent}; -use crate::{Account, InGameState}; +use crate::{InGameState, account::Account}; pub struct ChatSigningPlugin; impl Plugin for ChatSigningPlugin { @@ -70,7 +70,7 @@ pub fn poll_request_certs_task( commands.entity(entity).insert(QueuedCertsToSend { certs: certs.clone(), }); - *account.certs.lock() = Some(certs); + account.set_certs(certs); } Err(err) => { error!("Error requesting certs: {err:?}. Retrying in an hour."); @@ -108,8 +108,8 @@ pub fn request_certs_if_needed( continue; } - let certs = account.certs.lock(); - let should_refresh = if let Some(certs) = &*certs { + let certs = account.certs(); + let should_refresh = if let Some(certs) = certs { // certs were already requested and we're waiting for them to refresh // but maybe they weren't sent yet, in which case we still want to send the @@ -122,12 +122,10 @@ pub fn request_certs_if_needed( } else { true }; - drop(certs); - if should_refresh && let Some(access_token) = &account.access_token { + if should_refresh && let Some(access_token) = account.access_token() { let task_pool = IoTaskPool::get(); - let access_token = access_token.lock().clone(); debug!("Started task to fetch certs"); let task = task_pool.spawn(async_compat::Compat::new(async move { azalea_auth::certs::fetch_certificates(&access_token).await diff --git a/azalea-client/src/plugins/join.rs b/azalea-client/src/plugins/join.rs index 058f6c10..c254bc26 100644 --- a/azalea-client/src/plugins/join.rs +++ b/azalea-client/src/plugins/join.rs @@ -20,7 +20,8 @@ use tokio::sync::mpsc; use tracing::{debug, warn}; use crate::{ - Account, LocalPlayerBundle, + LocalPlayerBundle, + account::Account, connection::RawConnection, packet::login::{InLoginState, SendLoginPacketEvent}, }; @@ -94,7 +95,7 @@ pub fn handle_start_join_server_event( connection_query: Query<&RawConnection>, ) { for event in events.read() { - let uuid = event.account.uuid_or_offline(); + let uuid = event.account.uuid(); let entity = if let Some(entity) = entity_uuid_index.get(&uuid) { debug!("Reusing entity {entity:?} for client"); @@ -228,8 +229,8 @@ pub fn poll_create_connection_task( commands.trigger(SendLoginPacketEvent::new( entity, ServerboundHello { - name: account.username.clone(), - profile_id: account.uuid_or_offline(), + name: account.username().to_owned(), + profile_id: account.uuid(), }, )); } diff --git a/azalea-client/src/plugins/login.rs b/azalea-client/src/plugins/login.rs index 5bfefe44..b301d94b 100644 --- a/azalea-client/src/plugins/login.rs +++ b/azalea-client/src/plugins/login.rs @@ -14,7 +14,7 @@ use super::{ connection::RawConnection, packet::login::{ReceiveCustomQueryEvent, ReceiveHelloEvent, SendLoginPacketEvent}, }; -use crate::{Account, join::ConnectOpts}; +use crate::{account::Account, join::ConnectOpts}; /// Some systems that run during the `login` state. pub struct LoginPlugin; @@ -46,7 +46,7 @@ fn handle_receive_hello_event( None }; - let task = task_pool.spawn(auth_with_account(account, packet, connect_opts)); + let task = task_pool.spawn(async { auth_with_account(account, packet, connect_opts).await }); commands.entity(client).insert(AuthTask(task)); } @@ -123,7 +123,7 @@ pub async fn auth_with_account( #[cfg(feature = "online-mode")] if packet.should_authenticate { - let Some(access_token) = &account.access_token else { + if account.access_token().is_none() { // offline mode account, no need to do auth return Ok((key_packet, private_key)); }; @@ -135,26 +135,15 @@ pub async fn auth_with_account( let proxy = proxy.map(Proxy::into); while let Err(err) = { - use azalea_auth::sessionserver::{self, SessionServerJoinOpts}; - - let access_token = access_token.lock().clone(); - - let uuid = &account - .uuid - .expect("Uuid must be present if access token is present."); - let proxy = proxy.clone(); // this is necessary since reqwest usually depends on tokio and we're using // `futures` here - async_compat::Compat::new(sessionserver::join(SessionServerJoinOpts { - access_token: &access_token, - public_key: &packet.public_key, - private_key: &private_key, - uuid, - server_id: &packet.server_id, - proxy, - })) + async_compat::Compat::new(async { + account + .join(&packet.public_key, &private_key, &packet.server_id, proxy) + .await + }) .await } { if attempts >= 2 { @@ -169,6 +158,7 @@ pub async fn auth_with_account( ) { // uh oh, we got an invalid session and have // to reauthenticate now + async_compat::Compat::new(account.refresh()).await?; } else { return Err(err.into()); diff --git a/azalea-client/src/plugins/packet/login/events.rs b/azalea-client/src/plugins/packet/login/events.rs index 52e696cb..5b44e60c 100644 --- a/azalea-client/src/plugins/packet/login/events.rs +++ b/azalea-client/src/plugins/packet/login/events.rs @@ -10,7 +10,7 @@ use bevy_ecs::prelude::*; use tracing::{debug, error}; use super::InLoginState; -use crate::{Account, connection::RawConnection}; +use crate::{account::Account, connection::RawConnection}; #[derive(Clone, Debug, Message)] pub struct ReceiveLoginPacketEvent { diff --git a/azalea-client/src/plugins/packet/login/mod.rs b/azalea-client/src/plugins/packet/login/mod.rs index de44309c..aa630def 100644 --- a/azalea-client/src/plugins/packet/login/mod.rs +++ b/azalea-client/src/plugins/packet/login/mod.rs @@ -17,7 +17,7 @@ use tracing::{debug, error}; use super::as_system; use crate::{ - Account, InConfigState, connection::RawConnection, cookies::RequestCookieEvent, + InConfigState, account::Account, connection::RawConnection, cookies::RequestCookieEvent, disconnect::DisconnectEvent, packet::declare_packet_handlers, player::GameProfileComponent, }; |
