Skip to content

Commit

Permalink
feat: add more java parsing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
doinkythederp committed Jul 15, 2024
1 parent 2d6eb06 commit f899f37
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ impl From<BedrockServerInfo> for crate::JavaServerInfo {
description: crate::parse::TextComponent::Plain(description),
favicon: None,
mod_info: None,
enforces_secure_chat: None,
prevents_chat_reports: None,
previews_chat: None,
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Hash, Clone, PartialEq, Eq)]
#[non_exhaustive]
#[serde(rename_all = "camelCase")]
pub struct JavaServerInfo {
pub version: Option<ServerVersion>,
pub players: Option<ServerPlayers>,
pub description: TextComponent,
pub favicon: Option<String>,
#[serde(rename = "modinfo")]
pub mod_info: Option<ServerModInfo>,
/// Servers with the No Chat Reports mod installed will set this field to `true` to indicate
/// to players that all chat messages sent on this server are not reportable to Mojang.
pub prevents_chat_reports: Option<bool>,
/// If the server supports Chat Preview (added in 1.19 and removed in 1.19.3), this field is set to `true`.
pub previews_chat: Option<bool>,
/// Servers will set this field to `true` if they block chat messages that cannot be reported to Mojang.
pub enforces_secure_chat: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug, Hash, Clone, PartialEq, Eq)]
Expand All @@ -26,13 +34,25 @@ pub struct ServerPlayers {
pub sample: Option<Vec<ServerPlayersSample>>,
}

/// Contains basic information about one of the players in a server.
#[derive(Serialize, Deserialize, Debug, Hash, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ServerPlayersSample {
/// The player's username
pub name: Option<String>,
/// The player's UUID
pub id: Option<String>,
}

impl ServerPlayersSample {
/// Returns whether the server has chosen to hide this player's identity and is reporting placeholder information. This is generally caused by a player having the [Allow Server Listings](https://wiki.vg/Protocol#Client_Information_.28configuration.29) option set to `false`.
pub fn is_anonymous(&self) -> bool {
self.id
.as_deref()
.map_or(true, |id| id == "00000000-0000-0000-0000-000000000000")
}
}

#[derive(Serialize, Deserialize, Debug, Hash, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ServerModInfo {
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub enum ServerState {
}

impl Frame {
pub const PROTOCOL_VERSION: i32 = 754;
pub const PROTOCOL_VERSION: i32 = 767;
pub const HANDSHAKE_ID: i32 = 0x00;
pub const STATUS_REQUEST_ID: i32 = 0x00;
pub const STATUS_RESPONSE_ID: i32 = 0x00;
Expand Down

0 comments on commit f899f37

Please sign in to comment.