aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-19 21:29:07 -0500
committermat <github@matdoes.dev>2022-04-19 21:29:07 -0500
commit65dd2eacc2eb8c76ae8f496c8473537e380dbc17 (patch)
tree113e879b9bea299f797f16370ef105586c1232b3 /azalea-protocol/src
parentdf318dba73750ce38afea675854a8ce6ccbc65e5 (diff)
parentcafa4dd76fecc9e331f35145e10539e1f5ac85f6 (diff)
downloadazalea-drasl-65dd2eacc2eb8c76ae8f496c8473537e380dbc17.tar.xz
Merge branch 'declare-commands-packet'
Diffstat (limited to 'azalea-protocol/src')
-rw-r--r--azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs133
-rw-r--r--azalea-protocol/src/packets/game/mod.rs4
2 files changed, 99 insertions, 38 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
index 1bcf0dd4..1403630d 100644
--- a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
@@ -1,37 +1,96 @@
-// use std::hash::Hash;
-
-// use crate::mc_buf::Readable;
-
-// use super::LoginPacket;
-
-// #[derive(Hash, Clone, Debug)]
-// pub struct ClientboundDeclareCommandsPacket {
-// pub root: RootCommandNode<SharedSuggestionProvider>,
-// pub public_key: Vec<u8>,
-// pub nonce: Vec<u8>,
-// }
-
-// impl ClientboundHelloPacket {
-// pub fn get(self) -> LoginPacket {
-// LoginPacket::ClientboundHelloPacket(self)
-// }
-
-// pub fn write(&self, _buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
-// panic!("ClientboundHelloPacket::write not implemented")
-// }
-
-// pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
-// buf: &mut T,
-// ) -> Result<LoginPacket, String> {
-// let server_id = buf.read_utf_with_len(20).await?;
-// let public_key = buf.read_byte_array().await?;
-// let nonce = buf.read_byte_array().await?;
-
-// Ok(ClientboundHelloPacket {
-// server_id,
-// public_key,
-// nonce,
-// }
-// .get())
-// }
-// }
+use std::hash::Hash;
+
+use async_trait::async_trait;
+use tokio::io::AsyncRead;
+
+use crate::mc_buf::{McBufReadable, Readable};
+
+use super::GamePacket;
+
+#[derive(Hash, Clone, Debug)]
+pub struct ClientboundDeclareCommandsPacket {
+ pub entries: Vec<BrigadierNodeStub>,
+ pub root_index: i32,
+}
+
+impl ClientboundDeclareCommandsPacket {
+ pub fn get(self) -> GamePacket {
+ GamePacket::ClientboundDeclareCommandsPacket(self)
+ }
+
+ pub fn write(&self, _buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ panic!("ClientboundDeclareCommandsPacket::write not implemented")
+ }
+
+ pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
+ buf: &mut T,
+ ) -> Result<GamePacket, String> {
+ let node_count = buf.read_varint().await?;
+ println!("node_count: {}", node_count);
+ let mut nodes = Vec::with_capacity(node_count as usize);
+ for _ in 0..node_count {
+ let node = BrigadierNodeStub::read_into(buf).await?;
+ nodes.push(node);
+ }
+ let root_index = buf.read_varint().await?;
+ Ok(GamePacket::ClientboundDeclareCommandsPacket(
+ ClientboundDeclareCommandsPacket {
+ entries: nodes,
+ root_index,
+ },
+ ))
+ }
+}
+
+#[derive(Hash, Debug, Clone)]
+pub struct BrigadierNodeStub {}
+
+// azalea_brigadier::tree::CommandNode
+#[async_trait]
+impl McBufReadable for BrigadierNodeStub {
+ async fn read_into<R>(buf: &mut R) -> Result<Self, String>
+ where
+ R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ {
+ let flags = u8::read_into(buf).await?;
+
+ let node_type = flags & 0x03;
+ let is_executable = flags & 0x04 != 0;
+ let has_redirect = flags & 0x08 != 0;
+ let has_suggestions_type = flags & 0x10 != 0;
+ println!("flags: {}, node_type: {}, is_executable: {}, has_redirect: {}, has_suggestions_type: {}", flags, node_type, is_executable, has_redirect, has_suggestions_type);
+
+ let children = buf.read_int_id_list().await?;
+ println!("children: {:?}", children);
+ let redirect_node = if has_redirect {
+ buf.read_varint().await?
+ } else {
+ 0
+ };
+ println!("redirect_node: {}", redirect_node);
+
+ if node_type == 2 {
+ let name = buf.read_utf().await?;
+ println!("name: {}", name);
+
+ let resource_location = if has_suggestions_type {
+ Some(buf.read_resource_location().await?)
+ } else {
+ None
+ };
+ println!(
+ "node_type=2, flags={}, name={}, resource_location={:?}",
+ flags, name, resource_location
+ );
+ return Ok(BrigadierNodeStub {});
+ }
+ if node_type == 1 {
+ let name = buf.read_utf().await?;
+ println!("node_type=1, flags={}, name={}", flags, name);
+ return Ok(BrigadierNodeStub {});
+ }
+ println!("node_type={}, flags={}", node_type, flags);
+ Ok(BrigadierNodeStub {})
+ // return Err("Unknown node type".to_string());
+ }
+}
diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs
index a4304d9f..2dbf7f24 100644
--- a/azalea-protocol/src/packets/game/mod.rs
+++ b/azalea-protocol/src/packets/game/mod.rs
@@ -1,5 +1,6 @@
pub mod clientbound_change_difficulty_packet;
pub mod clientbound_custom_payload_packet;
+pub mod clientbound_declare_commands_packet;
pub mod clientbound_login_packet;
pub mod clientbound_update_view_distance_packet;
@@ -10,8 +11,9 @@ declare_state_packets!(
Serverbound => {},
Clientbound => {
0x0e: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket,
+ 0x12: clientbound_declare_commands_packet::ClientboundDeclareCommandsPacket,
0x18: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket,
0x26: clientbound_login_packet::ClientboundLoginPacket,
- 0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket,
+ 0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket
}
);