diff options
| author | mat <git@matdoes.dev> | 2024-04-20 03:40:59 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2024-04-20 03:40:59 +0000 |
| commit | 353eda21ac8280213edcec3823cc3bd77fe17c44 (patch) | |
| tree | e57201568f99f3a3e9ebf7b8991b22b945bb65bc /azalea-client/src/ping.rs | |
| parent | fa96af786b6f549edd8f04f4a19ced01faffe114 (diff) | |
| download | azalea-drasl-353eda21ac8280213edcec3823cc3bd77fe17c44.tar.xz | |
socks5 support (#113)
Diffstat (limited to 'azalea-client/src/ping.rs')
| -rwxr-xr-x | azalea-client/src/ping.rs | 29 |
1 files changed, 25 insertions, 4 deletions
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 { |
