46 lines
2.5 KiB
Rust
46 lines
2.5 KiB
Rust
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
//! Authority-stream messages: periodic state pushed from server to client.
|
|
//!
|
|
//! The authority stream ([`StreamLayout::authority`](super::StreamLayout::authority), id 2) carries state the server is the sole authority over and pushes without being asked. Diagnostics are the first such payload; simulation snapshots will join them on the same stream.
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Messages carried on the authority stream (stream 2): periodic server-authoritative state.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
pub enum AuthorityMessage {
|
|
/// Periodic simulation diagnostics, emitted on a fixed wall-clock cadence rather than per tick.
|
|
ServerStats(ServerStats),
|
|
}
|
|
|
|
/// A snapshot of the server's simulation health, sent roughly once per second.
|
|
///
|
|
/// The measured figures exist because the nominal tick rate advertised in [`HandshakeAck::tick_rate_hint`](super::HandshakeAck::tick_rate_hint) is a constant: it states what the server intends to run at and can never reveal that it is falling behind. Everything here is observed.
|
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Default)]
|
|
pub struct ServerStats {
|
|
/// Ticks actually completed in the reporting window, expressed per second. Below the nominal rate when the server is overrunning its budget.
|
|
pub measured_tps: f32,
|
|
/// Mean wall-clock duration of a tick body in the reporting window, in milliseconds, excluding the sleep that pads the tick out to its period.
|
|
pub mean_tick_ms: f32,
|
|
/// Longest tick body observed in the reporting window, in milliseconds. A mean within budget alongside a spiking maximum indicates intermittent stalls rather than sustained overload.
|
|
pub max_tick_ms: f32,
|
|
/// Share of the nominal tick period consumed by the mean tick body, in percent. Values at or above 100 mean the server no longer has headroom.
|
|
pub tick_budget_percent: f32,
|
|
/// Chunks resident in the server's world cache.
|
|
pub loaded_chunks: u32,
|
|
/// Chunk generation jobs outstanding in the server's worker pool.
|
|
pub chunks_in_flight: u32,
|
|
/// Clients with an established session.
|
|
pub connected_clients: u32,
|
|
/// Entities in the server's ECS world, players included.
|
|
pub entities: u32,
|
|
/// Players currently in the world.
|
|
pub players: u32,
|
|
/// Wall-clock time since the simulation loop started, in seconds.
|
|
pub uptime_secs: u64,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "../tests/protocol_authority.rs"]
|
|
mod tests;
|