aboutsummaryrefslogtreecommitdiff
path: root/minecraft-protocol/src/server_status_pinger.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-12-11 18:03:07 -0600
committermat <github@matdoes.dev>2021-12-11 18:03:07 -0600
commit3763d086f6e6f6c49ac996ec2b787d9de0d3bab7 (patch)
tree271bf8d78c36e282bf1c116290893232aed4ffa6 /minecraft-protocol/src/server_status_pinger.rs
parentba911a8a207eb47df7a055410570767b2e33c2ae (diff)
downloadazalea-drasl-3763d086f6e6f6c49ac996ec2b787d9de0d3bab7.tar.xz
misc polish
Diffstat (limited to 'minecraft-protocol/src/server_status_pinger.rs')
-rw-r--r--minecraft-protocol/src/server_status_pinger.rs49
1 files changed, 11 insertions, 38 deletions
diff --git a/minecraft-protocol/src/server_status_pinger.rs b/minecraft-protocol/src/server_status_pinger.rs
index ae41ed51..0c1f2076 100644
--- a/minecraft-protocol/src/server_status_pinger.rs
+++ b/minecraft-protocol/src/server_status_pinger.rs
@@ -2,20 +2,22 @@ use crate::{
connection::Connection,
packets::{
handshake::client_intention_packet::ClientIntentionPacket,
- status::serverbound_status_request_packet::ServerboundStatusRequestPacket,
+ status::{
+ clientbound_status_response_packet::ClientboundStatusResponsePacket,
+ serverbound_status_request_packet::ServerboundStatusRequestPacket,
+ },
ConnectionProtocol, Packet, PacketTrait,
},
resolver, ServerAddress,
};
-pub async fn ping_server(address: &ServerAddress) -> Result<(), String> {
+pub async fn ping_server(
+ address: &ServerAddress,
+) -> Result<ClientboundStatusResponsePacket, String> {
let resolved_address = resolver::resolve_address(address).await?;
let mut conn = Connection::new(&resolved_address).await?;
- println!("resolved_address {}", &resolved_address.ip);
- println!("writing intention packet {}", address.host);
-
// send the client intention packet and switch to the status state
conn.send_packet(
ClientIntentionPacket {
@@ -35,37 +37,8 @@ pub async fn ping_server(address: &ServerAddress) -> Result<(), String> {
let packet = conn.read_packet().await.unwrap();
- match packet {
- Packet::ClientboundStatusResponsePacket(p) => {
- println!("{:?}", p);
- println!("{}", p.description.to_ansi(None));
- }
- _ => {
- println!("unexpected packet {:?}", packet);
- }
- }
-
- Ok(())
-
- // let data = mc_buf::read_varint(conn.stream);
- // println!("data {}", data);
-
- // // log what the server sends back
- // loop {
- // if 0 == conn.stream.read_buf(&mut conn.buffer).await.unwrap() {
- // // The remote closed the connection. For this to be a clean
- // // shutdown, there should be no data in the read buffer. If
- // // there is, this means that the peer closed the socket while
- // // sending a frame.
-
- // // log conn.buffer
- // println!("{:?}", conn.buffer);
- // if conn.buffer.is_empty() {
- // println!("buffer is empty ok");
- // return Ok(());
- // } else {
- // return Err("connection reset by peer".into());
- // }
- // }
- // }
+ Ok(match packet {
+ Packet::ClientboundStatusResponsePacket(p) => p,
+ _ => Err("Invalid packet type".to_string())?,
+ })
}