aboutsummaryrefslogtreecommitdiff
path: root/minecraft-protocol
diff options
context:
space:
mode:
Diffstat (limited to 'minecraft-protocol')
-rw-r--r--minecraft-protocol/Cargo.toml2
-rw-r--r--minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs39
2 files changed, 36 insertions, 5 deletions
diff --git a/minecraft-protocol/Cargo.toml b/minecraft-protocol/Cargo.toml
index 80e2b625..7894ecfd 100644
--- a/minecraft-protocol/Cargo.toml
+++ b/minecraft-protocol/Cargo.toml
@@ -14,3 +14,5 @@ tokio = {version = "^1.14.0", features = ["io-util", "net", "macros"]}
tokio-util = "^0.6.9"
trust-dns-resolver = "^0.20.3"
async-trait = "0.1.51"
+minecraft-chat = { path = "../minecraft-chat" }
+serde_json = "^1.0.72"
diff --git a/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs b/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs
index b61562cf..5099952c 100644
--- a/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs
+++ b/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs
@@ -1,5 +1,6 @@
use async_trait::async_trait;
-use std::hash::Hash;
+use minecraft_chat::component::Component;
+use serde_json::Value;
use tokio::io::BufReader;
use crate::{
@@ -7,9 +8,29 @@ use crate::{
packets::{Packet, PacketTrait},
};
-#[derive(Hash, Clone, Debug)]
+#[derive(Clone, Debug)]
+struct Version {
+ name: String,
+ protocol: u32,
+}
+
+#[derive(Clone, Debug)]
+struct SamplePlayer {
+ id: String,
+ name: String,
+}
+
+#[derive(Clone, Debug)]
+struct Players {
+ max: u32,
+ online: u32,
+ sample: Vec<SamplePlayer>,
+}
+
+#[derive(Clone, Debug)]
pub struct ClientboundStatusResponsePacket {
- status: String,
+ // version: Version,
+ description: Component,
}
#[async_trait]
@@ -23,8 +44,16 @@ impl PacketTrait for ClientboundStatusResponsePacket {
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
buf: &mut BufReader<T>,
) -> Result<Packet, String> {
- let status = mc_buf::read_utf(buf).await?;
+ let status_string = mc_buf::read_utf(buf).await?;
+ let status_json: Value =
+ serde_json::from_str(status_string.as_str()).expect("Server status isn't valid JSON");
+ let description_string: &Value = status_json.get("description").unwrap();
+
// this.status = GsonHelper.fromJson(GSON, friendlyByteBuf.readUtf(32767), ServerStatus.class);
- Ok(ClientboundStatusResponsePacket { status }.get())
+ Ok(ClientboundStatusResponsePacket {
+ // version: status_json.get("version"),
+ description: Component::new(&description_string)?,
+ }
+ .get())
}
}