azalea/
join_opts.rs

1use std::net::SocketAddr;
2
3use azalea_protocol::{address::ServerAddr, connect::Proxy};
4
5/// Optional settings when adding an account to a swarm or client.
6#[derive(Clone, Debug, Default)]
7#[non_exhaustive]
8pub struct JoinOpts {
9    /// The SOCKS5 proxy that this bot will use for connecting to the Minecraft
10    /// server.
11    pub server_proxy: Option<Proxy>,
12    /// The SOCKS5 proxy that will be used when authenticating the bot's join
13    /// with Mojang.
14    ///
15    /// This should typically be either the same as [`Self::server_proxy`] or
16    /// `None`.
17    ///
18    /// This is useful to set if a server has `prevent-proxy-connections`
19    /// enabled.
20    pub sessionserver_proxy: Option<Proxy>,
21    /// Override the server address that this specific bot will send in the
22    /// handshake packet.
23    #[doc(alias = "custom_address")]
24    pub custom_server_addr: Option<ServerAddr>,
25    /// Override the IP and port that this specific bot will use to connect
26    /// to the server.
27    #[doc(alias = "custom_resolved_address")]
28    pub custom_socket_addr: Option<SocketAddr>,
29}
30
31impl JoinOpts {
32    pub fn new() -> Self {
33        Self::default()
34    }
35
36    pub fn update(&mut self, other: &Self) {
37        if let Some(proxy) = other.server_proxy.clone() {
38            self.server_proxy = Some(proxy);
39        }
40        if let Some(proxy) = other.sessionserver_proxy.clone() {
41            self.sessionserver_proxy = Some(proxy);
42        }
43        if let Some(custom_server_addr) = other.custom_server_addr.clone() {
44            self.custom_server_addr = Some(custom_server_addr);
45        }
46        if let Some(custom_socket_addr) = other.custom_socket_addr {
47            self.custom_socket_addr = Some(custom_socket_addr);
48        }
49    }
50
51    /// Configure the SOCKS5 proxy used for connecting to the server and for
52    /// authenticating with Mojang.
53    ///
54    /// To configure these separately, for example to only use the proxy for the
55    /// Minecraft server and not for authentication, you may use
56    /// [`Self::server_proxy`] and [`Self::sessionserver_proxy`] individually.
57    #[must_use]
58    pub fn proxy(self, proxy: Proxy) -> Self {
59        self.server_proxy(proxy.clone()).sessionserver_proxy(proxy)
60    }
61    /// Configure the SOCKS5 proxy that will be used for connecting to the
62    /// Minecraft server.
63    ///
64    /// To avoid errors on servers with the "prevent-proxy-connections" option
65    /// set, you should usually use [`Self::proxy`] instead.
66    ///
67    /// Also see [`Self::sessionserver_proxy`].
68    #[must_use]
69    pub fn server_proxy(mut self, proxy: Proxy) -> Self {
70        self.server_proxy = Some(proxy);
71        self
72    }
73    /// Configure the SOCKS5 proxy that this bot will use for authenticating the
74    /// server join with Mojang's API.
75    ///
76    /// Also see [`Self::proxy`] and [`Self::server_proxy`].
77    #[must_use]
78    pub fn sessionserver_proxy(mut self, proxy: Proxy) -> Self {
79        self.sessionserver_proxy = Some(proxy);
80        self
81    }
82
83    /// Set the custom address that this bot will send in the handshake packet.
84    #[must_use]
85    pub fn custom_server_addr(mut self, server_addr: ServerAddr) -> Self {
86        self.custom_server_addr = Some(server_addr);
87        self
88    }
89    /// Set the custom resolved address that this bot will use to connect to the
90    /// server.
91    #[must_use]
92    pub fn custom_socket_addr(mut self, socket_addr: SocketAddr) -> Self {
93        self.custom_socket_addr = Some(socket_addr);
94        self
95    }
96
97    #[doc(hidden)]
98    #[deprecated = "renamed to `custom_server_addr`."]
99    pub fn custom_address(self, server_addr: ServerAddr) -> Self {
100        self.custom_server_addr(server_addr)
101    }
102    #[doc(hidden)]
103    #[deprecated = "renamed to `custom_socket_addr`."]
104    pub fn custom_resolved_address(self, socket_addr: SocketAddr) -> Self {
105        self.custom_socket_addr(socket_addr)
106    }
107}