Expand description
Protocol abstraction layer.
Each Minecraft ping variant lives in its own sub-module and implements
PingProtocol. McClient orchestrates DNS resolution
and then delegates the wire work to whichever protocol is needed.
§Adding a new protocol
- Create
src/protocol/your_protocol.rs. - Implement
PingProtocolfor a unit struct (zero-size,Copy). - Re-export it here.
- Add a thin method on
McClientthat callsping_with(…, &YourProtocol).
No other files need to change.
§Example skeleton
ⓘ
use rust_mc_status::protocol::{PingProtocol, ResolvedTarget, PingResult};
use rust_mc_status::models::{ServerData, QueryData};
use rust_mc_status::proxy::ProxyConfig;
use rust_mc_status::McError;
use std::time::Duration;
#[derive(Debug, Clone, Copy, Default)]
pub struct QueryProtocol;
impl PingProtocol for QueryProtocol {
fn name(&self) -> &'static str { "query" }
async fn ping(
&self,
target: &ResolvedTarget,
timeout: Duration,
proxy: Option<&ProxyConfig>,
) -> Result<PingResult, McError> {
let start = crate::core::time::start_timer();
// … UDP handshake, stat request, parse …
Ok(PingResult::new(
ServerData::Query(QueryData { /* … */ ..Default::default() }),
crate::core::time::elapsed_ms(start),
))
}
}Re-exports§
pub use java_modern::JavaModernProtocol;pub use bedrock::BedrockProtocol;
Modules§
- bedrock
- Bedrock Edition ping protocol (RakNet Unconnected Ping/Pong).
- java_
modern - Java Edition modern ping protocol (Minecraft 1.7+ / wire protocol 47+).
Structs§
- Resolved
Target - A server address after DNS/SRV resolution, passed into
PingProtocol::ping.
Traits§
- Ping
Protocol - Low-level wire protocol for pinging a Minecraft server.