improve query support
simple string MOTDs; optional player sample
This commit is contained in:
parent
8a30e93a89
commit
694c2f07d8
1 changed files with 27 additions and 14 deletions
|
|
@ -19,7 +19,7 @@ pub struct MinecraftPlayer {
|
|||
pub struct MinecraftPlayers {
|
||||
pub online: u32,
|
||||
pub max: u32,
|
||||
pub sample: Vec<MinecraftPlayer>,
|
||||
pub sample: Option<Vec<MinecraftPlayer>>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
|
|
@ -30,7 +30,14 @@ enum MinecraftDescriptionExtra {
|
|||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct MinecraftDescription {
|
||||
#[serde(untagged)]
|
||||
pub enum MinecraftDescription {
|
||||
Rich(MinecraftRichDescription),
|
||||
Plain(String)
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct MinecraftRichDescription {
|
||||
text: String,
|
||||
extra: Option<Vec<MinecraftDescriptionExtra>>,
|
||||
bold: Option<bool>,
|
||||
|
|
@ -103,7 +110,6 @@ impl MinecraftStatus {
|
|||
}
|
||||
let msg = std::str::from_utf8(&data[offset..]).unwrap().trim();
|
||||
let sanitised: String = msg.chars().filter(|&c| c >= '\u{20}' || c == '\n' || c == '\r' || c == '\t').collect();
|
||||
// println!("{sanitised}");
|
||||
let status: MinecraftStatus = serde_json::from_slice(sanitised.as_bytes()).unwrap();
|
||||
|
||||
Ok(status)
|
||||
|
|
@ -119,6 +125,8 @@ impl MinecraftStatus {
|
|||
}
|
||||
|
||||
fn _description(description: &MinecraftDescription) -> String {
|
||||
match description {
|
||||
MinecraftDescription::Rich(description) => {
|
||||
if description.extra.is_some() {
|
||||
let mut extras = String::new();
|
||||
for extra in description.extra.as_ref().unwrap() {
|
||||
|
|
@ -134,6 +142,11 @@ fn _description(description: &MinecraftDescription) -> String {
|
|||
return description.text.clone() + &extras;
|
||||
}
|
||||
description.text.clone()
|
||||
}
|
||||
MinecraftDescription::Plain(description) => {
|
||||
description.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn send_packet(stream: &mut TcpStream, data: &[u8]) -> Result<()> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue