mc_query/status/data.rs
1//! Implementation of the [Server List Ping](https://wiki.vg/Server_List_Ping) protocol
2
3use serde::{Deserialize, Serialize};
4
5/// Response from the server with status information.
6/// Represents [this JSON object](https://wiki.vg/Server_List_Ping#Status_Response)
7/// to be serialized and deserialized.
8#[derive(Debug, Serialize, Deserialize)]
9pub struct StatusResponse {
10 /// Information about the game and protocol version.
11 /// See [Version] for more information.
12 pub version: Version,
13
14 // Information about players on the server.
15 /// See [Players] for more information.
16 pub players: Players,
17
18 /// The "motd" - message shown in the server list by the client.
19 #[serde(rename = "description")]
20 pub motd: ChatObject,
21
22 /// URI to the server's favicon.
23 pub favicon: Option<String>,
24
25 /// Does the server preview chat?
26 #[serde(rename = "previewsChat")]
27 pub previews_chat: Option<bool>,
28
29 /// Does the server use signed chat messages?
30 /// Only returned for servers post 1.19.1
31 #[serde(rename = "enforcesSecureChat")]
32 pub enforces_secure_chat: Option<bool>,
33}
34
35/// Struct that stores information about players on the server.
36///
37/// Not intended to be used directly, but only as a part of [`StatusResponse`].
38#[derive(Debug, Serialize, Deserialize)]
39pub struct Players {
40 /// The maximum number of players allowed on the server.
41 pub max: u32,
42
43 /// The number of players currently online.
44 pub online: u32,
45
46 /// A listing of some online Players.
47 /// See [Sample] for more information.
48 pub sample: Option<Vec<Sample>>,
49}
50
51/// A player listed on the server's list ping information.
52///
53/// Not intended to be used directly, but only as a part of [`StatusResponse`].
54#[derive(Debug, Serialize, Deserialize)]
55pub struct Sample {
56 /// The player's username.
57 pub name: String,
58
59 /// The player's UUID.
60 pub id: String,
61}
62
63/// Struct that stores version information about the server.
64///
65/// Not intended to be used directly, but only as a part of [`StatusResponse`].
66#[derive(Debug, Serialize, Deserialize)]
67pub struct Version {
68 /// The game version (e.g: 1.19.1)
69 pub name: String,
70 /// The version of the [Protocol](https://wiki.vg/Protocol) being used.
71 ///
72 /// See [the wiki.vg page](https://wiki.vg/Protocol_version_numbers) for a
73 /// reference on what versions these correspond to.
74 pub protocol: u64,
75}
76
77/// Represents a chat object (the MOTD is sent as a chat object).
78#[derive(Debug, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum ChatObject {
81 /// An individual chat object
82 Object(ChatComponentObject),
83
84 /// Vector of multiple chat objects
85 Array(Vec<ChatObject>),
86
87 /// Unknown data - raw JSON
88 JsonPrimitive(serde_json::Value),
89}
90
91/// A piece of a `ChatObject`
92#[derive(Debug, Serialize, Deserialize)]
93pub struct ChatComponentObject {
94 /// Text of the chat message
95 pub text: Option<String>,
96
97 /// Translation key if the message needs to pull from the language file.
98 /// See [wiki.vg](https://wiki.vg/Chat#Translation_component)
99 pub translate: Option<String>,
100
101 /// Displays the keybind for the specified key, or the string itself if unknown.
102 pub keybind: Option<String>,
103
104 /// Should the text be rendered **bold**?
105 pub bold: Option<bool>,
106
107 /// Should the text be rendered *italic*?
108 pub italic: Option<bool>,
109
110 /// Should the text be rendered __underlined__?
111 pub underlined: Option<bool>,
112
113 /// Should the text be rendered as ~~strikethrough~~
114 pub strikethrough: Option<bool>,
115
116 /// Should the text be rendered as obfuscated?
117 /// Switching randomly between characters of the same width
118 pub obfuscated: Option<bool>,
119
120 /// The font to use to render, comes in three options:
121 /// * `minecraft:uniform` - Unicode font
122 /// * `minecraft:alt` - enchanting table font
123 /// * `minecraft:default` - font based on resource pack (1.16+)
124 ///
125 /// Any other value can be ignored
126 pub font: Option<String>,
127
128 /// The color to display the chat item in.
129 /// Can be a [chat color](https://wiki.vg/Chat#Colors),
130 /// [format code](https://wiki.vg/Chat#Styles),
131 /// or any valid web color
132 pub color: Option<String>,
133
134 /// Text to insert into the chat box when shift-clicking this component
135 pub insertion: Option<String>,
136
137 /// Defines an event that occurs when this chat item is clicked
138 #[serde(rename = "clickEvent")]
139 pub click_event: Option<ChatClickEvent>,
140
141 /// Defines an event that occurs when this chat item is hovered on
142 #[serde(rename = "hoverEvent")]
143 pub hover_event: Option<ChatHoverEvent>,
144
145 /// Sibling components to this chat item.
146 /// If present, will not be empty
147 pub extra: Option<Vec<ChatObject>>,
148}
149
150/// `ClickEvent` data for a chat component
151#[derive(Debug, Serialize, Deserialize)]
152pub struct ChatClickEvent {
153 // These are not renamed on purpose. (server returns them in snake_case)
154 /// Opens the URL in the user's default browser. Protocol must be `http` or `https`
155 pub open_url: Option<String>,
156
157 /// Runs the command.
158 /// Simply causes the user to say the string in chat -
159 /// so only has command effect if it starts with /
160 ///
161 /// Irrelevant for motd purposes.
162 pub run_command: Option<String>,
163
164 /// Replaces the content of the user's chat box with the given text.
165 ///
166 /// Irrelevant for motd purposes.
167 pub suggest_command: Option<String>,
168
169 /// Copies the given text into the client's clipboard.
170 pub copy_to_clipboard: Option<String>,
171}
172
173/// `HoverEvent` data for a chat component
174#[derive(Debug, Serialize, Deserialize)]
175pub struct ChatHoverEvent {
176 // These are not renamed on purpose. (server returns them in snake_case)
177 /// Text to show when the item is hovered over
178 pub show_text: Option<Box<ChatObject>>,
179
180 /// Same as `show_text`, but for servers < 1.16
181 pub value: Option<Box<ChatObject>>,
182
183 /// Displays the item of the given NBT
184 pub show_item: Option<String>,
185
186 /// Displays information about the entity with the given NBT
187 pub show_entity: Option<String>,
188}