mc_ping/mc_text.rs
1use serde::Deserialize;
2
3/// Structure for the Minecraft server status response.
4///
5/// Corresponds to the JSON response returned by the server status query.
6#[derive(Debug, Deserialize)]
7pub struct ServerStatus {
8 /// Server version information.
9 pub version: Version,
10
11 /// Server description, usually the MOTD (Message Of The Day).
12 pub description: Description,
13
14 /// Player information: maximum allowed and currently online.
15 pub players: Players,
16
17 /// List of server mods, if any (may be absent).
18 /// If no mods are present, this will be an empty array.
19 #[serde(default)]
20 pub mods: Vec<Mod>,
21
22 /// Other additional fields that might be present, e.g. favicon.
23 /// If absent in the response, will be None.
24 #[serde(default)]
25 pub favicon: Option<String>,
26
27 /// Additional properties for future extensions.
28 #[serde(flatten)]
29 pub extra: serde_json::Value,
30}
31
32/// Server version.
33#[derive(Debug, Deserialize)]
34pub struct Version {
35 /// Version name, e.g. "Purpur 1.21"
36 pub name: String,
37
38 /// Protocol version number, e.g. 767.
39 pub protocol: i32,
40}
41
42/// Server description — usually the MOTD.
43///
44/// Can be either a string or a more complex JSON object,
45/// so it's best represented by the `Description` type.
46#[derive(Debug, Deserialize)]
47#[serde(untagged)]
48pub enum Description {
49 /// Simple text description.
50 Text(String),
51
52 /// Complex description (text components with colors and formatting).
53 Complex(serde_json::Value),
54}
55
56/// Player information.
57#[derive(Debug, Deserialize)]
58pub struct Players {
59 /// Maximum number of players allowed on the server.
60 pub max: i32,
61
62 /// Current number of online players.
63 pub online: i32,
64
65 /// List of sample players, if present (usually empty or missing).
66 #[serde(default)]
67 pub sample: Vec<Player>,
68}
69
70/// Player entry, if a player list is available.
71#[derive(Debug, Deserialize)]
72pub struct Player {
73 /// Player's name.
74 pub name: String,
75
76 /// Player's UUID.
77 pub id: String,
78}
79
80/// Server mod, if a mod list is present.
81#[derive(Debug, Deserialize)]
82pub struct Mod {
83 /// Mod identifier.
84 pub id: String,
85
86 /// Mod name.
87 pub name: String,
88}