feat: better looking motd, and kubernetes native motd handling

This commit is contained in:
Tamipes 2025-12-11 23:16:05 +01:00
parent 402e315a93
commit 1454945f32
3 changed files with 34 additions and 6 deletions

View file

@ -339,6 +339,29 @@ impl MinecraftServerHandle for Server {
let port = a.iter().find(|x| x.name.clone().unwrap() == "mc-router")?; let port = a.iter().find(|x| x.name.clone().unwrap() == "mc-router")?;
port.node_port.map(|x| x.to_string()) port.node_port.map(|x| x.to_string())
} }
fn get_motd(&self) -> Option<String> {
let all_container_motds = self
.dep
.spec
.clone()?
.template
.spec?
.containers
.iter()
.map(|cont| match cont.env.clone() {
Some(es) => es
.iter()
.filter(|e| e.name.as_str() == "MOTD")
.map(|x| x.value.clone())
.collect::<Vec<Option<String>>>()
.first()?
.clone(),
None => None,
})
.collect::<Vec<Option<String>>>();
all_container_motds.first()?.clone()
}
} }
impl Server { impl Server {

View file

@ -159,9 +159,13 @@ async fn handle_status<T: MinecraftServerHandle>(
return Ok(()); return Ok(());
} }
}; };
tracing::debug!("kube server status: {:?}", server.query_status().await?);
let status = server.query_status().await?; let status = server.query_status().await?;
tracing::info!(status = ?status, "status request"); tracing::info!(status = ?status, "status request");
let motd = server
.get_motd()
.unwrap_or("A minecraft server (proxy motd)".to_string());
tracing::trace!(motd);
match status { match status {
ServerDeploymentStatus::Connectable(mut server_stream) => { ServerDeploymentStatus::Connectable(mut server_stream) => {
return server return server
@ -171,13 +175,13 @@ async fn handle_status<T: MinecraftServerHandle>(
ServerDeploymentStatus::Starting | ServerDeploymentStatus::PodOk => { ServerDeploymentStatus::Starting | ServerDeploymentStatus::PodOk => {
status_struct.players.max = 1; status_struct.players.max = 1;
status_struct.players.online = 1; status_struct.players.online = 1;
status_struct.description.text = format!("\n§2Server is starting...§r{bye_message}"); status_struct.description.text =
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 = format!( status_struct.description.text =
"Server is currently §onot§r running. \n§aJoin to start it!§r {bye_message}" format!("{motd}\n§4Offline§r §2§oJoin to start!§r{bye_message}");
);
} }
}; };

View file

@ -69,6 +69,7 @@ pub trait MinecraftServerHandle: Clone {
fn get_internal_address(&self) -> Option<String>; fn get_internal_address(&self) -> Option<String>;
fn get_addr(&self) -> Option<String>; fn get_addr(&self) -> Option<String>;
fn get_port(&self) -> Option<String>; fn get_port(&self) -> Option<String>;
fn get_motd(&self) -> Option<String>;
async fn query_server_connectable(&self) -> Result<TcpStream, OpaqueError> { async fn query_server_connectable(&self) -> Result<TcpStream, OpaqueError> {
let address = self let address = self