Files
DomiStream/crates/domistream/src/http/serverinfo.rs
T

59 lines
2.1 KiB
Rust

//! `GET /serverinfo` (`docs/PROTOCOL.md` 1.2).
/// Maximum size of a serverinfo body, in bytes.
pub const MAX_SERVERINFO_BYTES: usize = 64 * 1024;
/// Maximum length of any string field in serverinfo, in bytes.
pub const MAX_SERVERINFO_FIELD_BYTES: usize = 256;
/// What the host says about itself. Optional fields are `None` when the element is missing or empty.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ServerInfo {
/// `hostname`.
pub hostname: String,
/// `appversion`, e.g. `7.1.431.-1`.
pub app_version: String,
/// `GfeVersion`.
pub gfe_version: Option<String>,
/// `uniqueid`: the host's stable id.
pub unique_id: String,
/// `HttpsPort`.
pub https_port: u16,
/// `ExternalPort` (the HTTP port).
pub http_port: Option<u16>,
/// `mac`, for Wake-on-LAN, as `aa:bb:cc:dd:ee:ff`.
pub mac: Option<[u8; 6]>,
/// `LocalIP`, as the host wrote it.
pub local_ip: Option<String>,
/// `MaxLumaPixelsHEVC`; 0 = no HEVC.
pub max_luma_pixels_hevc: Option<u64>,
/// `ServerCodecModeSupport` bitmask (bit meanings UNKNOWN U25).
pub codec_mode_support: Option<u32>,
/// `PairStatus == 1`. Only meaningful over HTTPS.
pub paired: bool,
/// `currentgame`: id of the running app, 0 = none.
pub current_game: u32,
/// `state`, raw (host-specific `…_SERVER_BUSY` / `…_SERVER_FREE`).
pub state: String,
}
impl ServerInfo {
/// Whether the host reports a running app (`state` ends in `_BUSY` or `currentgame != 0`).
///
/// # Errors
/// Phase A: always [`crate::Error::Unimplemented`].
pub fn is_busy(&self) -> crate::Result<bool> {
Err(crate::Error::Unimplemented)
}
}
/// Parses a serverinfo body.
///
/// # Errors
/// [`crate::Error::TooLarge`] over [`MAX_SERVERINFO_BYTES`], [`crate::Error::HostStatus`] for a non-200 answer,
/// [`crate::Error::Malformed`] for a missing required element (`hostname`, `uniqueid`, `HttpsPort`) or a bad
/// number. Phase A: always [`crate::Error::Unimplemented`].
pub fn parse_server_info(body: &[u8]) -> crate::Result<ServerInfo> {
let _ = body;
Err(crate::Error::Unimplemented)
}