diff options
| author | mat <github@matdoes.dev> | 2021-12-15 13:43:57 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-15 13:43:57 -0600 |
| commit | 732de94d7b9f1bf2bc9239c8138a37c53242b470 (patch) | |
| tree | eaeaddbf73bf5379fbb1924e57a28b8dad5be48b /minecraft-client/src | |
| parent | ace140500734d33fe53126086a8d9278fa861e21 (diff) | |
| download | azalea-drasl-732de94d7b9f1bf2bc9239c8138a37c53242b470.tar.xz | |
oh yeah it compiles
Diffstat (limited to 'minecraft-client/src')
| -rw-r--r-- | minecraft-client/src/connect.rs | 20 | ||||
| -rw-r--r-- | minecraft-client/src/ping.rs | 19 |
2 files changed, 18 insertions, 21 deletions
diff --git a/minecraft-client/src/connect.rs b/minecraft-client/src/connect.rs index 5329cdc0..e6a23612 100644 --- a/minecraft-client/src/connect.rs +++ b/minecraft-client/src/connect.rs @@ -1,11 +1,10 @@ ///! Connect to Minecraft servers. use minecraft_protocol::{ - connect::Connection, + connect::HandshakeConnection, packets::{ handshake::client_intention_packet::ClientIntentionPacket, - login::serverbound_hello_packet::ServerboundHelloPacket, - status::clientbound_status_response_packet::ClientboundStatusResponsePacket, - ConnectionProtocol, Packet, PROTOCOL_VERSION, + login::{serverbound_hello_packet::ServerboundHelloPacket, LoginPacket}, + ConnectionProtocol, PROTOCOL_VERSION, }, resolver, ServerAddress, }; @@ -15,10 +14,10 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> { let resolved_address = resolver::resolve_address(address).await?; - let mut conn = Connection::new(&resolved_address).await?; + let mut conn = HandshakeConnection::new(&resolved_address).await?; // handshake - conn.send_packet( + conn.write( ClientIntentionPacket { protocol_version: PROTOCOL_VERSION, hostname: address.host.clone(), @@ -28,16 +27,15 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> { .get(), ) .await; - conn.switch_state(ConnectionProtocol::Login); + let mut conn = conn.login(); // login start - conn.send_packet(ServerboundHelloPacket { username }.get()) - .await; + conn.write(ServerboundHelloPacket { username }.get()).await; // encryption request - let packet = conn.read_packet().await.unwrap(); + let packet = conn.read().await.unwrap(); let encryption_request_packet = match packet { - Packet::ClientboundHelloPacket(p) => p, + LoginPacket::ClientboundHelloPacket(p) => p, _ => Err(format!("Invalid packet type: {:?}", packet))?, }; diff --git a/minecraft-client/src/ping.rs b/minecraft-client/src/ping.rs index 05ea16da..88c0a24a 100644 --- a/minecraft-client/src/ping.rs +++ b/minecraft-client/src/ping.rs @@ -1,13 +1,13 @@ ///! Ping Minecraft servers. use minecraft_protocol::{ - connect::Connection, + connect::HandshakeConnection, packets::{ handshake::client_intention_packet::ClientIntentionPacket, status::{ clientbound_status_response_packet::ClientboundStatusResponsePacket, - serverbound_status_request_packet::ServerboundStatusRequestPacket, + serverbound_status_request_packet::ServerboundStatusRequestPacket, StatusPacket, }, - ConnectionProtocol, Packet, PROTOCOL_VERSION, + ConnectionProtocol, PROTOCOL_VERSION, }, resolver, ServerAddress, }; @@ -17,10 +17,10 @@ pub async fn ping_server( ) -> Result<ClientboundStatusResponsePacket, String> { let resolved_address = resolver::resolve_address(address).await?; - let mut conn = Connection::new(&resolved_address).await?; + let mut conn = HandshakeConnection::new(&resolved_address).await?; // send the client intention packet and switch to the status state - conn.send_packet( + conn.write( ClientIntentionPacket { protocol_version: PROTOCOL_VERSION, hostname: address.host.clone(), @@ -30,16 +30,15 @@ pub async fn ping_server( .get(), ) .await; - conn.switch_state(ConnectionProtocol::Status); + let mut conn = conn.status(); // send the empty status request packet - conn.send_packet(ServerboundStatusRequestPacket {}.get()) - .await; + conn.write(ServerboundStatusRequestPacket {}.get()).await; - let packet = conn.read_packet().await.unwrap(); + let packet = conn.read().await.unwrap(); Ok(match packet { - Packet::ClientboundStatusResponsePacket(p) => p, + StatusPacket::ClientboundStatusResponsePacket(p) => p, _ => Err("Invalid packet type".to_string())?, }) } |
