feat: add Text component format or raw JSON text disconnect messages

This commit is contained in:
Tamipes 2026-02-03 21:04:21 +01:00
parent 6fab222d1e
commit 8a9ae9f735

View file

@ -20,6 +20,8 @@ mod opaque_error;
mod packets; mod packets;
mod types; mod types;
static BYE_MESSAGE: &str = concat!("§dTami§r with §d<3§r §8(rev: ", env!("COMMIT_HASH"), ")§r");
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
// ---- Tracing setup ---- // ---- Tracing setup ----
@ -160,7 +162,6 @@ async fn handle_status<T: MinecraftServerHandle>(
let commit_hash: &'static str = env!("COMMIT_HASH"); let commit_hash: &'static str = env!("COMMIT_HASH");
let mut status_struct = StatusStructNew::create(); let mut status_struct = StatusStructNew::create();
status_struct.version.protocol = handshake.protocol_version.get_int(); status_struct.version.protocol = handshake.protocol_version.get_int();
let bye_message = format!(" - §dTami§r with §d<3§r §8(rev: {commit_hash})§r");
let server = match api let server = match api
.query_server( .query_server(
@ -175,7 +176,7 @@ async fn handle_status<T: MinecraftServerHandle>(
status_struct.players.max = 0; status_struct.players.max = 0;
status_struct.players.online = 0; status_struct.players.online = 0;
status_struct.description.text = format!( status_struct.description.text = format!(
"Could not find §kserver§r: §f§o{server_addr}§r\nMinecraft Ingress {bye_message}" "Could not find §kserver§r: §f§o{server_addr}§r\nMinecraft Ingress - {BYE_MESSAGE}"
); );
mc_server::complete_status_request(client_stream, status_struct) mc_server::complete_status_request(client_stream, status_struct)
@ -219,12 +220,12 @@ async fn handle_status<T: MinecraftServerHandle>(
status_struct.players.max = 1; status_struct.players.max = 1;
status_struct.players.online = 1; status_struct.players.online = 1;
status_struct.description.text = status_struct.description.text =
format!("{motd}\n§2Starting!§r §b§oWait a bit§r§b ^^§r{bye_message}"); format!("{motd}\n§2Starting!§r §b§oWait a bit§r§b ^^§r - {BYE_MESSAGE}");
} }
ServerDeploymentStatus::Offline => { ServerDeploymentStatus::Offline => {
status_struct.players.max = 1; status_struct.players.max = 1;
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}");
} }
}; };
@ -289,13 +290,13 @@ async fn handle_login<T: MinecraftServerHandle>(
} }
} }
ServerDeploymentStatus::PodOk | ServerDeploymentStatus::Starting => { ServerDeploymentStatus::PodOk | ServerDeploymentStatus::Starting => {
mc_server::send_disconnect(client_stream, "Starting...§d<3§r").await?; mc_server::send_disconnect(client_stream, format!("[\"\",{{\"text\":\"The server is still starting up...\n wait a bit more please ^^\n\n\"}},{{\"text\":\"{BYE_MESSAGE}\"}}]").as_str()).await?;
} }
ServerDeploymentStatus::Offline => { ServerDeploymentStatus::Offline => {
server.start().await?; server.start().await?;
api.start_watch(server.clone(), Duration::from_secs(600)) api.start_watch(server.clone(), Duration::from_secs(600))
.await?; .await?;
mc_server::send_disconnect(client_stream, "Okayy_starting_it...§d<3§r").await?; mc_server::send_disconnect(client_stream, format!("[\"\",{{\"text\":\"Okayy, §2starting§r the server!\n\n\"}},{{\"text\":\"{BYE_MESSAGE}\"}}]").as_str()).await?;
} }
} }
Ok(()) Ok(())