feat: move start_watch into trait definition, to do that use async_traits
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
Tamipes 2026-06-04 19:31:20 +02:00
parent 8a7c3f5203
commit 750e8dcbf0
5 changed files with 111 additions and 101 deletions

View file

@ -100,9 +100,12 @@ async fn main() {
async fn process_connection<T: MinecraftServerHandle>(
mut client_stream: TcpStream,
addr: SocketAddr,
api: impl MinecraftAPI<T>,
api: impl MinecraftAPI<T> + Send + Sync + 'static + Clone,
config: Config,
) -> Result<(), OpaqueError> {
) -> Result<(), OpaqueError>
where
T: Send + Sync + 'static,
{
// 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))]
@ -185,7 +188,10 @@ async fn handle_status<T: MinecraftServerHandle>(
client_stream: &mut TcpStream,
handshake: &Handshake,
api: impl MinecraftAPI<T>,
) -> Result<(), OpaqueError> {
) -> Result<(), OpaqueError>
where
T: Send + Sync + 'static,
{
let client_packet = Packet::parse(client_stream).await?;
if client_packet.id.get_int() != 0 {
return Err(OpaqueError::create(&format!(
@ -276,8 +282,11 @@ async fn handle_login<T: MinecraftServerHandle>(
client_stream: &mut TcpStream,
handshake: &Handshake,
login_start: LoginStart,
api: impl MinecraftAPI<T>,
) -> Result<(), OpaqueError> {
api: impl MinecraftAPI<T> + Send + Sync + 'static + Clone,
) -> Result<(), OpaqueError>
where
T: Send + Sync + 'static,
{
let server = api
.query_server(
&handshake.get_server_address(),
@ -290,7 +299,7 @@ async fn handle_login<T: MinecraftServerHandle>(
tracing::debug!(msg = "server status", status = ?status);
match status {
ServerDeploymentStatus::Connectable(mut server_stream) => {
api.start_watch(server.clone(), Duration::from_secs(600))
api.start_watch(server.clone(), Duration::from_secs(60))
.await?;
// referenced from:
@ -341,7 +350,7 @@ async fn handle_login<T: MinecraftServerHandle>(
}
ServerDeploymentStatus::Offline => {
server.start().await?;
api.start_watch(server.clone(), Duration::from_secs(600))
api.start_watch(server.clone(), Duration::from_secs(60))
.await?;
mc_server::send_disconnect(client_stream, format!("[\"\",{{\"text\":\"Okayy, §2starting§r the server!\n\n\"}},{{\"text\":\"{BYE_MESSAGE}\"}}]").as_str()).await?;
}