Compare commits

..

No commits in common. "1bce912a1a0c64640aa2c6fa8a0f31952b0e5a0e" and "ee7a05152e054e9211362b169ac9c105081baec7" have entirely different histories.

3 changed files with 34 additions and 48 deletions

View file

@ -12,7 +12,11 @@ use tracing::Instrument;
use crate::{ use crate::{
mc_server::{sanitize_addr, MinecraftAPI, MinecraftServerHandle, ServerDeploymentStatus}, mc_server::{sanitize_addr, MinecraftAPI, MinecraftServerHandle, ServerDeploymentStatus},
packets::{clientbound::status::StatusTrait, SendPacket}, packets::{
clientbound::status::StatusTrait,
serverbound::handshake::{self},
SendPacket,
},
OpaqueError, OpaqueError,
}; };
@ -434,7 +438,6 @@ impl fmt::Debug for ServerDeploymentStatus {
Self::Starting => write!(f, "Starting"), Self::Starting => write!(f, "Starting"),
Self::PodOk => write!(f, "PodOk"), Self::PodOk => write!(f, "PodOk"),
Self::Offline => write!(f, "Offline"), Self::Offline => write!(f, "Offline"),
Self::Unavailable(s) => write!(f, "Unavailable ({s})"),
} }
} }
} }

View file

@ -103,17 +103,11 @@ async fn process_connection<T: MinecraftServerHandle>(
api: impl MinecraftAPI<T>, api: impl MinecraftAPI<T>,
config: Config, config: Config,
) -> Result<(), OpaqueError> { ) -> Result<(), OpaqueError> {
// this is wrapper so that async doesnt mess up the span, and let client_packet = Packet::parse(&mut client_stream).await?;
// 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!(
@ -133,19 +127,11 @@ 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
tracing::trace!("filtered out the connection"); return Ok(());
return Ok(None);
} }
Ok(Some(handshake)) next_server_state = handshake.get_next_state();
}
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?;
@ -235,9 +221,9 @@ async fn handle_status<T: MinecraftServerHandle>(
.instrument(span.clone()) .instrument(span.clone())
.await .await
.map_err(|_| tracing::debug!("failed to send pong packet")); .map_err(|_| tracing::debug!("failed to send pong packet"));
let _guard = span.enter();
let status = ServerDeploymentStatus::Unavailable(e.get_kind().to_string()); tracing::info!(status = "unavailable", "status request");
tracing::info!(status = ?status, "status request");
return Ok(()); return Ok(());
} }
}; };
@ -264,7 +250,6 @@ async fn handle_status<T: MinecraftServerHandle>(
status_struct.description.text = status_struct.description.text =
format!("{motd}\n§4Offline§r §oJoin to start!§r - {BYE_MESSAGE}"); format!("{motd}\n§4Offline§r §oJoin to start!§r - {BYE_MESSAGE}");
} }
ServerDeploymentStatus::Unavailable(_) => unreachable!(),
}; };
mc_server::complete_status_request(client_stream, status_struct).await?; mc_server::complete_status_request(client_stream, status_struct).await?;
@ -322,7 +307,7 @@ async fn handle_login<T: MinecraftServerHandle>(
match traffic.error { match traffic.error {
Some(e) => { Some(e) => {
tracing::warn!( tracing::info!(
tx = traffic.tx, tx = traffic.tx,
rx = traffic.rx, rx = traffic.rx,
err = ?e, err = ?e,
@ -345,7 +330,6 @@ async fn handle_login<T: MinecraftServerHandle>(
.await?; .await?;
mc_server::send_disconnect(client_stream, format!("[\"\",{{\"text\":\"Okayy, §2starting§r the server!\n\n\"}},{{\"text\":\"{BYE_MESSAGE}\"}}]").as_str()).await?; mc_server::send_disconnect(client_stream, format!("[\"\",{{\"text\":\"Okayy, §2starting§r the server!\n\n\"}},{{\"text\":\"{BYE_MESSAGE}\"}}]").as_str()).await?;
} }
ServerDeploymentStatus::Unavailable(_) => unreachable!(),
} }
Ok(()) Ok(())
} }

View file

@ -139,7 +139,6 @@ pub enum ServerDeploymentStatus {
Starting, Starting,
PodOk, PodOk,
Offline, Offline,
Unavailable(String),
} }
pub fn sanitize_addr(addr: &str) -> &str { pub fn sanitize_addr(addr: &str) -> &str {