1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
//! Shared top-level data models used across all protocol implementations.
use HashMap;
use ;
use crateMcError;
use ;
// ─── PingResult ───────────────────────────────────────────────────────────────
/// Raw result returned by a [`PingProtocol`](crate::protocol::PingProtocol)
/// before it is assembled into a [`ServerStatus`].
///
/// Separating `latency` from `data` keeps the trait signature clean — protocol
/// implementations don't need to embed timing inside their own models.
///
/// `meta` is a forward-compatibility escape hatch: protocol-specific fields
/// that don't yet have a typed [`ServerData`] variant go here as key-value
/// strings. Once a field is stable enough to model properly, it graduates into
/// the appropriate `ServerData` variant and is removed from `meta`.
///
/// # Implementing a new protocol
///
/// ```rust,ignore
/// use rust_mc_status::{PingResult, models::ServerData};
/// use rust_mc_status::protocol::{PingProtocol, ResolvedTarget};
/// use rust_mc_status::core::time::{start_timer, elapsed_ms};
/// 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<&rust_mc_status::ProxyConfig>,
/// ) -> Result<PingResult, McError> {
/// let start = start_timer();
/// // … UDP handshake, stat request, parse response …
/// Ok(PingResult::new(
/// ServerData::Query(Default::default()),
/// elapsed_ms(start),
/// ))
/// }
/// }
/// ```
// ─── ServerStatus ─────────────────────────────────────────────────────────────
/// Full server status returned to callers after a successful ping.
///
/// Assembled by [`McClient`](crate::McClient) from a [`PingResult`] (produced
/// by the wire protocol) plus resolved network metadata (IP, port, DNS info).
///
/// Most callers access this through the typed wrappers
/// [`JavaServerStatus`](crate::JavaServerStatus) and
/// [`BedrockServerStatus`](crate::BedrockServerStatus) which provide
/// ergonomic accessors. Use `.raw()` on those wrappers or match on
/// [`ServerData`] directly when you need fields not surfaced by the accessors.
///
/// # Serde
///
/// `ServerStatus` implements `Serialize` and `Deserialize`.
/// The `meta` field is skipped in serialisation when empty.
// ─── ServerData ───────────────────────────────────────────────────────────────
/// Edition-specific server data, stored inside [`ServerStatus`].
///
/// Match on this enum to access edition-specific fields:
///
/// ```rust,no_run
/// use rust_mc_status::{McClient, ServerData};
///
/// # #[tokio::main] async fn main() -> Result<(), rust_mc_status::McError> {
/// let client = McClient::builder().build();
/// let status = client.java("mc.hypixel.net").await?;
/// match &status.raw().data {
/// ServerData::Java(j) => println!("Protocol: {}", j.version.protocol),
/// ServerData::Bedrock(b) => println!("Edition: {}", b.edition),
/// _ => {}
/// }
/// # Ok(()) }
/// ```
///
/// # Future variants
///
/// `Legacy` and `Query` are placeholder variants with stub models.
/// They will be populated in a future release when those protocols are
/// implemented. Both are serialised with `#[serde(skip)]` until then.
// ─── Placeholder models ───────────────────────────────────────────────────────
/// Data returned by the pre-1.7 Java legacy ping (`0xFE 0x01`).
///
/// **Placeholder** — will be populated when `src/protocol/java_legacy.rs` is
/// implemented in a future release. All fields currently default to zero/empty.
/// Data returned by the UDP Query API (GameSpy4 / `enable-query` in server.properties).
///
/// **Placeholder** — will be populated when `src/protocol/query.rs` is
/// implemented in a future release. The Query API provides a richer view than
/// a regular ping: full player list, exact plugin list, and more.
///
/// Requires `enable-query=true` in `server.properties` on the target server.
// ─── DnsInfo ──────────────────────────────────────────────────────────────────
/// DNS resolution metadata attached to every [`ServerStatus`].
// ─── ServerInfo ───────────────────────────────────────────────────────────────
/// Address + edition pair — used as input to [`McClient::ping_many`](crate::McClient::ping_many).
// ─── ServerEdition ────────────────────────────────────────────────────────────
/// Which Minecraft edition to ping.
///
/// Parses from the strings `"java"` and `"bedrock"` (case-insensitive):
///
/// ```rust
/// use rust_mc_status::ServerEdition;
///
/// let e: ServerEdition = "java".parse().unwrap();
/// assert_eq!(e, ServerEdition::Java);
///
/// let e: ServerEdition = "BEDROCK".parse().unwrap();
/// assert_eq!(e, ServerEdition::Bedrock);
/// ```
// ─── CacheStats ───────────────────────────────────────────────────────────────
/// Snapshot of the current cache entry counts returned by
/// [`McClient::cache_stats`](crate::McClient::cache_stats).