diff --git a/src/mc/favicon.rs b/src/mc/favicon.rs index 6b7e461..9450c6b 100644 --- a/src/mc/favicon.rs +++ b/src/mc/favicon.rs @@ -1,3 +1,8 @@ +use crate::proto::client::ClientInfo; + +/// Protocol version since when favicons are supported. +const FAVICON_PROTOCOL_VERSION: i32 = 4; + /// Get default server status favicon. pub fn default_favicon() -> String { encode_favicon(include_bytes!("../../res/unknown_server_optimized.png")) @@ -9,3 +14,13 @@ pub fn default_favicon() -> String { pub fn encode_favicon(data: &[u8]) -> String { format!("{}{}", "data:image/png;base64,", base64::encode(data)) } + +/// Check whether the status response favicon is supported based on the given client info. +/// +/// Defaults to `true` if unsure. +pub fn supports_favicon(client_info: &ClientInfo) -> bool { + client_info + .protocol_version + .map(|p| p >= FAVICON_PROTOCOL_VERSION) + .unwrap_or(true) +} diff --git a/src/status.rs b/src/status.rs index 460db50..3a65102 100644 --- a/src/status.rs +++ b/src/status.rs @@ -99,7 +99,7 @@ pub async fn serve( // Hijack server status packet if client_state == ClientState::Status && packet.id == packets::status::SERVER_STATUS { - let server_status = server_status(&config, &server).await; + let server_status = server_status(&client_info, &config, &server).await; let packet = StatusResponse { server_status }; let mut data = Vec::new(); @@ -197,7 +197,7 @@ pub async fn serve( } /// Build server status object to respond to client with. -async fn server_status(config: &Config, server: &Server) -> ServerStatus { +async fn server_status(client_info: &ClientInfo, config: &Config, server: &Server) -> ServerStatus { let status = server.status().await; let server_state = server.state(); @@ -233,11 +233,13 @@ async fn server_status(config: &Config, server: &Server) -> ServerStatus { // Extract favicon from real server status, load from disk, or use default let mut favicon = None; - if config.motd.from_server && status.is_some() { - favicon = status.as_ref().unwrap().favicon.clone() - } - if favicon.is_none() { - favicon = Some(server_favicon(&config).await); + if favicon::supports_favicon(client_info) { + if config.motd.from_server && status.is_some() { + favicon = status.as_ref().unwrap().favicon.clone() + } + if favicon.is_none() { + favicon = Some(server_favicon(&config).await); + } } // Build status resposne