Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
More descriptive errors from socket code
Browse files Browse the repository at this point in the history
  • Loading branch information
tropicbliss committed Oct 27, 2021
1 parent 4dabb92 commit d34becd
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,35 @@ pub async fn snipe_executor(
.to_std()
.unwrap_or(std::time::Duration::ZERO);
sleep(sleep_duration).await;
let socket = TcpStream::connect(&addr).await.unwrap();
let socket = TcpStream::connect(&addr)
.await
.expect("Failed to establish a TCP connection with api.minecraftservices.com");
let mut socket = cx
.connect("api.minecraftservices.com", socket)
.await
.unwrap();
socket.write_all(&payload).await.unwrap();
.expect("Failed to initiate a TLS handshake with api.minecraftservices.com");
socket
.write_all(&payload)
.await
.expect("Failed to write to buffer");
let sleep_duration = (snipe_time - Local::now())
.to_std()
.unwrap_or(std::time::Duration::ZERO);
sleep(sleep_duration).await;
socket.write_all(b"\r\n").await.unwrap();
socket
.write_all(b"\r\n")
.await
.expect("Failed to write to buffer");
c.wait().await;
socket.read_exact(&mut buf).await.unwrap();
socket
.read_exact(&mut buf)
.await
.expect("Failed to read from buffer");
let timestamp = Local::now();
let res = String::from_utf8_lossy(&buf[..]);
let status: u16 = res[9..].parse().unwrap();
let status: u16 = res[9..]
.parse()
.expect("Failed to parse HTTP status code from string");
let res_data = ResData {
status,
timestamp,
Expand Down

0 comments on commit d34becd

Please sign in to comment.