feat: add better logging span to process_connection
This commit is contained in:
parent
ee7a05152e
commit
1229127101
1 changed files with 40 additions and 26 deletions
22
src/main.rs
22
src/main.rs
|
|
@ -103,11 +103,17 @@ async fn process_connection<T: MinecraftServerHandle>(
|
||||||
api: impl MinecraftAPI<T>,
|
api: impl MinecraftAPI<T>,
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Result<(), OpaqueError> {
|
) -> Result<(), OpaqueError> {
|
||||||
let client_packet = Packet::parse(&mut client_stream).await?;
|
// this is wrapper so that async doesnt mess up the span, and
|
||||||
|
// to make sure this doesn't propagate to later `handle_*`
|
||||||
|
#[tracing::instrument(level = "info", skip(client_stream, config))]
|
||||||
|
async fn first_packet(
|
||||||
|
client_stream: &mut TcpStream,
|
||||||
|
config: Config,
|
||||||
|
) -> Result<Option<packets::serverbound::handshake::Handshake>, OpaqueError> {
|
||||||
|
let client_packet = Packet::parse(client_stream).await?;
|
||||||
|
|
||||||
// --- Handshake ---
|
// --- Handshake ---
|
||||||
let handshake;
|
let handshake;
|
||||||
let next_server_state;
|
|
||||||
let packet_id = client_packet.id.get_int();
|
let packet_id = client_packet.id.get_int();
|
||||||
if packet_id != 0 {
|
if packet_id != 0 {
|
||||||
return Err(OpaqueError::create(&format!(
|
return Err(OpaqueError::create(&format!(
|
||||||
|
|
@ -127,11 +133,19 @@ async fn process_connection<T: MinecraftServerHandle>(
|
||||||
if filter {
|
if filter {
|
||||||
// TODO: if the server just returns here, the client does not know it
|
// TODO: if the server just returns here, the client does not know it
|
||||||
// and sends a packet with the 122 WeirdID
|
// and sends a packet with the 122 WeirdID
|
||||||
return Ok(());
|
tracing::trace!("filtered out the connection");
|
||||||
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
next_server_state = handshake.get_next_state();
|
Ok(Some(handshake))
|
||||||
|
}
|
||||||
|
let handshake = match first_packet(&mut client_stream, config).await? {
|
||||||
|
Some(x) => x,
|
||||||
|
// this is needed because of the filter
|
||||||
|
None => return Ok(()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let next_server_state = handshake.get_next_state();
|
||||||
match next_server_state {
|
match next_server_state {
|
||||||
packets::ProtocolState::Status => {
|
packets::ProtocolState::Status => {
|
||||||
handle_status(&mut client_stream, &handshake, api).await?;
|
handle_status(&mut client_stream, &handshake, api).await?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue