22
33use std:: sync:: Arc ;
44
5- use azalea_auth :: {
6- AccessTokenResponse ,
7- certs :: { Certificates , FetchCertificatesError } ,
8- } ;
5+ # [ cfg ( feature = "online-mode" ) ]
6+ use azalea_auth :: AccessTokenResponse ;
7+ # [ cfg ( feature = "online-mode" ) ]
8+ use azalea_auth :: certs :: { Certificates , FetchCertificatesError } ;
99use bevy_ecs:: component:: Component ;
1010use parking_lot:: Mutex ;
11+ #[ cfg( feature = "online-mode" ) ]
1112use thiserror:: Error ;
12- use tracing:: trace;
1313use uuid:: Uuid ;
1414
1515/// Something that can join Minecraft servers.
@@ -58,6 +58,7 @@ pub struct Account {
5858 ///
5959 /// This is set when you call [`Self::request_certs`], but you only
6060 /// need to if the servers you're joining require it.
61+ #[ cfg( feature = "online-mode" ) ]
6162 pub certs : Arc < Mutex < Option < Certificates > > > ,
6263}
6364
@@ -67,9 +68,11 @@ pub enum AccountOpts {
6768 Offline {
6869 username : String ,
6970 } ,
71+ #[ cfg( feature = "online-mode" ) ]
7072 Microsoft {
7173 email : String ,
7274 } ,
75+ #[ cfg( feature = "online-mode" ) ]
7376 MicrosoftWithAccessToken {
7477 msa : Arc < Mutex < azalea_auth:: cache:: ExpiringValue < AccessTokenResponse > > > ,
7578 } ,
@@ -88,6 +91,7 @@ impl Account {
8891 account_opts : AccountOpts :: Offline {
8992 username : username. to_string ( ) ,
9093 } ,
94+ #[ cfg( feature = "online-mode" ) ]
9195 certs : Arc :: new ( Mutex :: new ( None ) ) ,
9296 }
9397 }
@@ -97,6 +101,7 @@ impl Account {
97101 ///
98102 /// The cache key is used for avoiding having to log in every time. This is
99103 /// typically set to the account email, but it can be any string.
104+ #[ cfg( feature = "online-mode" ) ]
100105 pub async fn microsoft ( cache_key : & str ) -> Result < Self , azalea_auth:: AuthError > {
101106 Self :: microsoft_with_custom_client_id_and_scope ( cache_key, None , None ) . await
102107 }
@@ -105,6 +110,7 @@ impl Account {
105110 /// and `scope`.
106111 ///
107112 /// Pass `None` if you want to use default ones.
113+ #[ cfg( feature = "online-mode" ) ]
108114 pub async fn microsoft_with_custom_client_id_and_scope (
109115 cache_key : & str ,
110116 client_id : Option < & str > ,
@@ -162,6 +168,7 @@ impl Account {
162168 /// # Ok(())
163169 /// # }
164170 /// ```
171+ #[ cfg( feature = "online-mode" ) ]
165172 pub async fn with_microsoft_access_token (
166173 msa : azalea_auth:: cache:: ExpiringValue < AccessTokenResponse > ,
167174 ) -> Result < Self , azalea_auth:: AuthError > {
@@ -170,6 +177,7 @@ impl Account {
170177
171178 /// Similar to [`Account::with_microsoft_access_token`] but you can use
172179 /// custom `client_id` and `scope`.
180+ #[ cfg( feature = "online-mode" ) ]
173181 pub async fn with_microsoft_access_token_and_custom_client_id_and_scope (
174182 mut msa : azalea_auth:: cache:: ExpiringValue < AccessTokenResponse > ,
175183 client_id : Option < & str > ,
@@ -178,6 +186,8 @@ impl Account {
178186 let client = reqwest:: Client :: new ( ) ;
179187
180188 if msa. is_expired ( ) {
189+ use tracing:: trace;
190+
181191 trace ! ( "refreshing Microsoft auth token" ) ;
182192 msa = azalea_auth:: refresh_ms_auth_token (
183193 & client,
@@ -209,6 +219,7 @@ impl Account {
209219 /// This requires the `auth_opts` field to be set correctly (which is done
210220 /// by default if you used the constructor functions). Note that if the
211221 /// Account is offline-mode then this function won't do anything.
222+ #[ cfg( feature = "online-mode" ) ]
212223 pub async fn refresh ( & self ) -> Result < ( ) , azalea_auth:: AuthError > {
213224 match & self . account_opts {
214225 // offline mode doesn't need to refresh so just don't do anything lol
@@ -240,6 +251,13 @@ impl Account {
240251 }
241252 }
242253
254+ /// Stub function that does nothing when the `online-mode` feature is
255+ /// disabled.
256+ #[ cfg( not( feature = "online-mode" ) ) ]
257+ pub async fn refresh ( & self ) -> Result < ( ) , ( ) > {
258+ Ok ( ( ) )
259+ }
260+
243261 /// Get the UUID of this account.
244262 ///
245263 /// If the `uuid` field is None, the UUID will be determined by using
@@ -250,6 +268,7 @@ impl Account {
250268 }
251269}
252270
271+ #[ cfg( feature = "online-mode" ) ]
253272#[ derive( Error , Debug ) ]
254273pub enum RequestCertError {
255274 #[ error( "Failed to fetch certificates" ) ]
@@ -261,6 +280,7 @@ pub enum RequestCertError {
261280impl Account {
262281 /// Request the certificates used for chat signing and set it in
263282 /// [`Self::certs`].
283+ #[ cfg( feature = "online-mode" ) ]
264284 pub async fn request_certs ( & mut self ) -> Result < ( ) , RequestCertError > {
265285 let access_token = self
266286 . access_token
0 commit comments