diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-12-11 22:47:16 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-11 22:47:16 -0600 |
| commit | 4a66f002c276a57e028e9456f6800b0b3c248885 (patch) | |
| tree | f87cbdc51c09d497548f972b9b1633ceb7606443 /azalea/src | |
| parent | ff1e28f88e93ba83cf76569b5613445b841efd45 (diff) | |
| download | azalea-drasl-4a66f002c276a57e028e9456f6800b0b3c248885.tar.xz | |
Add options to request Mojang sessionserver with a proxy (#293)
* add options to request mojang sessionserver with a socks5 proxy
* update changelog
* rename auth_proxy to sessionserver_proxy
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/lib.rs | 53 | ||||
| -rw-r--r-- | azalea/src/swarm/mod.rs | 6 |
2 files changed, 50 insertions, 9 deletions
diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs index daed8451..bf188791 100644 --- a/azalea/src/lib.rs +++ b/azalea/src/lib.rs @@ -264,8 +264,18 @@ pub struct NoState; #[derive(Clone, Debug, Default)] #[non_exhaustive] pub struct JoinOpts { - /// The Socks5 proxy that this bot will use. - pub proxy: Option<Proxy>, + /// The SOCKS5 proxy that this bot will use for connecting to the Minecraft + /// server. + pub server_proxy: Option<Proxy>, + /// The SOCKS5 proxy that will be used when authenticating the bot's join + /// with Mojang. + /// + /// This should typically be either the same as [`Self::server_proxy`] or + /// `None`. + /// + /// This is useful to set if a server has `prevent-proxy-connections` + /// enabled. + pub sessionserver_proxy: Option<Proxy>, /// Override the server address that this specific bot will send in the /// handshake packet. pub custom_address: Option<ServerAddress>, @@ -280,8 +290,11 @@ impl JoinOpts { } pub fn update(&mut self, other: &Self) { - if let Some(proxy) = other.proxy.clone() { - self.proxy = Some(proxy); + if let Some(proxy) = other.server_proxy.clone() { + self.server_proxy = Some(proxy); + } + if let Some(proxy) = other.sessionserver_proxy.clone() { + self.sessionserver_proxy = Some(proxy); } if let Some(custom_address) = other.custom_address.clone() { self.custom_address = Some(custom_address); @@ -291,12 +304,38 @@ impl JoinOpts { } } - /// Set the proxy that this bot will use. + /// Configure the SOCKS5 proxy used for connecting to the server and for + /// authenticating with Mojang. + /// + /// To configure these separately, for example to only use the proxy for the + /// Minecraft server and not for authentication, you may use + /// [`Self::server_proxy`] and [`Self::sessionserver_proxy`] individually. + #[must_use] + pub fn proxy(self, proxy: Proxy) -> Self { + self.server_proxy(proxy.clone()).sessionserver_proxy(proxy) + } + /// Configure the SOCKS5 proxy that will be used for connecting to the + /// Minecraft server. + /// + /// To avoid errors on servers with the "prevent-proxy-connections" option + /// set, you should usually use [`Self::proxy`] instead. + /// + /// Also see [`Self::sessionserver_proxy`]. #[must_use] - pub fn proxy(mut self, proxy: Proxy) -> Self { - self.proxy = Some(proxy); + pub fn server_proxy(mut self, proxy: Proxy) -> Self { + self.server_proxy = Some(proxy); self } + /// Configure the SOCKS5 proxy that this bot will use for authenticating the + /// server join with Mojang's API. + /// + /// Also see [`Self::proxy`] and [`Self::server_proxy`]. + #[must_use] + pub fn sessionserver_proxy(mut self, proxy: Proxy) -> Self { + self.sessionserver_proxy = Some(proxy); + self + } + /// Set the custom address that this bot will send in the handshake packet. #[must_use] pub fn custom_address(mut self, custom_address: ServerAddress) -> Self { diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index a744e0bc..e77f3713 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -748,7 +748,8 @@ impl Swarm { let resolved_address = join_opts .custom_resolved_address .unwrap_or_else(|| *self.resolved_address.read()); - let proxy = join_opts.proxy.clone(); + let server_proxy = join_opts.server_proxy.clone(); + let sessionserver_proxy = join_opts.sessionserver_proxy.clone(); let (tx, rx) = mpsc::unbounded_channel(); @@ -758,7 +759,8 @@ impl Swarm { connect_opts: ConnectOpts { address, resolved_address, - proxy, + server_proxy, + sessionserver_proxy, }, event_sender: Some(tx), }) |
