aboutsummaryrefslogtreecommitdiff
path: root/azalea-client
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-client')
-rw-r--r--azalea-client/Cargo.toml1
-rw-r--r--azalea-client/src/client.rs11
-rwxr-xr-xazalea-client/src/ping.rs29
3 files changed, 35 insertions, 6 deletions
diff --git a/azalea-client/Cargo.toml b/azalea-client/Cargo.toml
index 78411ed9..b79f694a 100644
--- a/azalea-client/Cargo.toml
+++ b/azalea-client/Cargo.toml
@@ -43,6 +43,7 @@ azalea-entity = { version = "0.9.0", path = "../azalea-entity" }
serde_json = "1.0.113"
serde = "1.0.196"
minecraft_folder_path = "0.1.2"
+socks5-impl = "0.5.6"
[features]
default = ["log"]
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index af535415..8ca0bbef 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -34,7 +34,7 @@ use azalea_entity::{
};
use azalea_physics::PhysicsPlugin;
use azalea_protocol::{
- connect::{Connection, ConnectionError},
+ connect::{Connection, ConnectionError, Proxy},
packets::{
configuration::{
serverbound_client_information_packet::ClientInformation,
@@ -183,6 +183,7 @@ impl Client {
pub async fn join(
account: &Account,
address: impl TryInto<ServerAddress>,
+ proxy: Option<Proxy>,
) -> Result<(Self, mpsc::UnboundedReceiver<Event>), JoinError> {
let address: ServerAddress = address.try_into().map_err(|_| JoinError::InvalidAddress)?;
let resolved_address = resolver::resolve_address(&address).await?;
@@ -200,6 +201,7 @@ impl Client {
account,
&address,
&resolved_address,
+ proxy,
run_schedule_sender,
)
.await
@@ -212,6 +214,7 @@ impl Client {
account: &Account,
address: &ServerAddress,
resolved_address: &SocketAddr,
+ proxy: Option<Proxy>,
run_schedule_sender: mpsc::UnboundedSender<()>,
) -> Result<(Self, mpsc::UnboundedReceiver<Event>), JoinError> {
// check if an entity with our uuid already exists in the ecs and if so then
@@ -239,7 +242,11 @@ impl Client {
entity
};
- let conn = Connection::new(resolved_address).await?;
+ let conn = if let Some(proxy) = proxy {
+ Connection::new_with_proxy(resolved_address, proxy).await?
+ } else {
+ Connection::new(resolved_address).await?
+ };
let (conn, game_profile) =
Self::handshake(ecs_lock.clone(), entity, conn, account, address).await?;
diff --git a/azalea-client/src/ping.rs b/azalea-client/src/ping.rs
index 9064065c..c74a62be 100755
--- a/azalea-client/src/ping.rs
+++ b/azalea-client/src/ping.rs
@@ -1,9 +1,12 @@
//! Ping Minecraft servers.
use azalea_protocol::{
- connect::{Connection, ConnectionError},
+ connect::{Connection, ConnectionError, Proxy},
packets::{
- handshaking::client_intention_packet::ClientIntentionPacket,
+ handshaking::{
+ client_intention_packet::ClientIntentionPacket, ClientboundHandshakePacket,
+ ServerboundHandshakePacket,
+ },
status::{
clientbound_status_response_packet::ClientboundStatusResponsePacket,
serverbound_status_request_packet::ServerboundStatusRequestPacket,
@@ -47,11 +50,29 @@ pub async fn ping_server(
address: impl TryInto<ServerAddress>,
) -> Result<ClientboundStatusResponsePacket, PingError> {
let address: ServerAddress = address.try_into().map_err(|_| PingError::InvalidAddress)?;
-
let resolved_address = resolver::resolve_address(&address).await?;
+ let conn = Connection::new(&resolved_address).await?;
+ ping_server_with_connection(address, conn).await
+}
- let mut conn = Connection::new(&resolved_address).await?;
+/// Ping a Minecraft server through a Socks5 proxy.
+pub async fn ping_server_with_proxy(
+ address: impl TryInto<ServerAddress>,
+ proxy: Proxy,
+) -> Result<ClientboundStatusResponsePacket, PingError> {
+ let address: ServerAddress = address.try_into().map_err(|_| PingError::InvalidAddress)?;
+ let resolved_address = resolver::resolve_address(&address).await?;
+ let conn = Connection::new_with_proxy(&resolved_address, proxy).await?;
+ ping_server_with_connection(address, conn).await
+}
+/// Ping a Minecraft server after we've already created a [`Connection`]. The
+/// `Connection` must still be in the handshake state (which is the state it's
+/// in immediately after it's created).
+pub async fn ping_server_with_connection(
+ address: ServerAddress,
+ mut conn: Connection<ClientboundHandshakePacket, ServerboundHandshakePacket>,
+) -> Result<ClientboundStatusResponsePacket, PingError> {
// send the client intention packet and switch to the status state
conn.write(
ClientIntentionPacket {