diff options
| -rw-r--r-- | azalea-auth/src/sessionserver.rs | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/azalea-auth/src/sessionserver.rs b/azalea-auth/src/sessionserver.rs index 6c304942..02ec9c60 100644 --- a/azalea-auth/src/sessionserver.rs +++ b/azalea-auth/src/sessionserver.rs @@ -66,6 +66,13 @@ pub struct SessionServerJoinOpts<'a> { /// Tell Mojang's servers that you are going to join a multiplayer server, /// which is required to join online-mode servers. pub async fn join(opts: SessionServerJoinOpts<'_>) -> Result<(), ClientSessionServerError> { + join_with_backend_url(opts, "https://sessionserver.mojang.com/session").await +} + +pub async fn join_with_backend_url( + opts: SessionServerJoinOpts<'_>, + backend: &str, +) -> Result<(), ClientSessionServerError> { let client = if let Some(proxy) = opts.proxy { // reusing the client is too complicated if we're using proxies, so don't bother reqwest::ClientBuilder::new().proxy(proxy).build()? @@ -84,7 +91,14 @@ pub async fn join(opts: SessionServerJoinOpts<'_>) -> Result<(), ClientSessionSe opts.private_key, )); - join_with_server_id_hash(&client, opts.access_token, opts.uuid, &server_hash).await + join_with_server_id_hash_and_backend_url( + &client, + opts.access_token, + opts.uuid, + &server_hash, + backend, + ) + .await } pub async fn join_with_server_id_hash( @@ -93,6 +107,23 @@ pub async fn join_with_server_id_hash( uuid: &Uuid, server_hash: &str, ) -> Result<(), ClientSessionServerError> { + join_with_server_id_hash_and_backend_url( + client, + access_token, + uuid, + server_hash, + "https://sessionserver.mojang.com/session", + ) + .await +} + +pub async fn join_with_server_id_hash_and_backend_url( + client: &reqwest::Client, + access_token: &str, + uuid: &Uuid, + server_hash: &str, + backend: &str, +) -> Result<(), ClientSessionServerError> { let mut encode_buffer = Uuid::encode_buffer(); let undashed_uuid = uuid.simple().encode_lower(&mut encode_buffer); @@ -102,7 +133,7 @@ pub async fn join_with_server_id_hash( "serverId": server_hash }); let res = client - .post("https://sessionserver.mojang.com/session/minecraft/join") + .post(format!("{backend}/minecraft/join")) .json(&data) .send() .await?; @@ -147,6 +178,23 @@ pub async fn serverside_auth( private_key: &[u8; 16], ip: Option<&str>, ) -> Result<GameProfile, ServerSessionServerError> { + serverside_auth_with_backend_url( + username, + public_key, + private_key, + ip, + "https://sessionserver.mojang.com/session", + ) + .await +} + +pub async fn serverside_auth_with_backend_url( + username: &str, + public_key: &[u8], + private_key: &[u8; 16], + ip: Option<&str>, + backend: &str, +) -> Result<GameProfile, ServerSessionServerError> { let hash = azalea_crypto::hex_digest(&azalea_crypto::digest_data( "".as_bytes(), public_key, @@ -154,7 +202,7 @@ pub async fn serverside_auth( )); let url = reqwest::Url::parse_with_params( - "https://sessionserver.mojang.com/session/minecraft/hasJoined", + &format!("{backend}/minecraft/hasJoined"), if let Some(ip) = ip { vec![("username", username), ("serverId", &hash), ("ip", ip)] } else { |
