Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
More tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriTimoz committed Dec 25, 2023
1 parent 56bc96b commit 4adb08d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions minecraft-protocol/src/components/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl Chunk {
Ok(chunks)
}

#[cfg_attr(feature = "tracing", instrument(skip(output)))]
pub fn into_data(chunks: Vec<Chunk>) -> Result<Vec<u8>, &'static str> {
let mut output = Vec::new();

Expand Down
3 changes: 2 additions & 1 deletion minecraft-server/src/player_handler/connect.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::*;


#[instrument(skip_all)]
#[cfg_attr(feature = "tracing", instrument(skip_all))]

pub async fn handle_connection(
mut stream: TcpStream,
addr: SocketAddr,
Expand Down
3 changes: 2 additions & 1 deletion minecraft-server/src/player_handler/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pub struct LoggedInPlayerInfo {
pub(super) uuid: u128,
}

#[instrument(skip_all)]
#[cfg_attr(feature = "tracing", instrument(skip_all))]

pub async fn login(stream: &mut TcpStream, addr: SocketAddr) -> Result<LoggedInPlayerInfo, ()> {
// Receive login start
let packet = receive_packet(stream).await?;
Expand Down
6 changes: 3 additions & 3 deletions minecraft-server/src/player_handler/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ pub async fn receive_packet_split(stream: &mut OwnedReadHalf) -> Result<Vec<u8>,
Ok(data)
}

#[instrument]
#[cfg_attr(feature = "tracing", instrument)]
pub async fn send_packet_raw(stream: &mut TcpStream, packet: &[u8]) {
let length = VarInt::from(packet.len());
stream.write_all(length.serialize_minecraft_packet().unwrap().as_slice()).await.unwrap();
stream.write_all(packet).await.unwrap();
stream.flush().await.unwrap();
}

#[instrument]
#[cfg_attr(feature = "tracing", instrument)]
pub async fn send_packet_raw_split(stream: &mut OwnedWriteHalf, packet: &[u8]) {
let length = VarInt::from(packet.len());
stream.write_all(length.serialize_minecraft_packet().unwrap().as_slice()).await.unwrap();
stream.write_all(packet).await.unwrap();
stream.flush().await.unwrap();
}

#[instrument(skip_all)]
#[cfg_attr(feature = "tracing", instrument(skip_all))]
pub async fn send_packet<'a, P: MinecraftPacketPart<'a>>(stream: &mut TcpStream, packet: P) {
let packet = packet.serialize_minecraft_packet().unwrap();
send_packet_raw(stream, packet.as_slice()).await;
Expand Down
2 changes: 1 addition & 1 deletion minecraft-server/src/player_handler/status.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

#[instrument(skip_all)]
#[cfg_attr(feature = "tracing", instrument(skip_all))]
pub async fn status(stream: &mut TcpStream) -> Result<(), ()> {
loop {
let packet = receive_packet(stream).await?;
Expand Down

0 comments on commit 4adb08d

Please sign in to comment.