Skip to main content

Module protocol

Module protocol 

Source
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

  1. Create src/protocol/your_protocol.rs.
  2. Implement PingProtocol for a unit struct (zero-size, Copy).
  3. Re-export it here.
  4. Add a thin method on McClient that calls ping_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§

ResolvedTarget
A server address after DNS/SRV resolution, passed into PingProtocol::ping.

Traits§

PingProtocol
Low-level wire protocol for pinging a Minecraft server.