diff --git a/pumpkin-protocol/src/server/play/chat_message.rs b/pumpkin-protocol/src/server/play/chat_message.rs index b349e606b..1e0e890c7 100644 --- a/pumpkin-protocol/src/server/play/chat_message.rs +++ b/pumpkin-protocol/src/server/play/chat_message.rs @@ -1,33 +1,54 @@ -use bytes::{Buf, Bytes}; +use bytes::Buf; use pumpkin_data::packet::serverbound::PLAY_CHAT; use pumpkin_macros::packet; +use serde::Serialize; use crate::{ - FixedBitSet, ServerPacket, VarInt, + ServerPacket, VarInt, bytebuf::{ByteBuf, ReadingError}, }; -// derive(Deserialize)] +#[derive(Serialize)] #[packet(PLAY_CHAT)] pub struct SChatMessage { pub message: String, pub timestamp: i64, pub salt: i64, - pub signature: Option, + pub signature: Option>, pub message_count: VarInt, - pub acknowledged: FixedBitSet, + pub acknowledged: Vec, +} + +impl SChatMessage { + pub fn new( + message: String, + timestamp: i64, + salt: i64, + signature: Option>, + message_count: VarInt, + acknowledged: Vec, + ) -> Self { + Self { + message, + timestamp, + salt, + signature, + message_count, + acknowledged, + } + } } // TODO impl ServerPacket for SChatMessage { fn read(bytebuf: &mut impl Buf) -> Result { Ok(Self { - message: bytebuf.try_get_string()?, + message: bytebuf.try_get_string_len(256)?, timestamp: bytebuf.try_get_i64()?, salt: bytebuf.try_get_i64()?, - signature: bytebuf.try_get_option(|v| v.try_copy_to_bytes(256))?, + signature: bytebuf.try_get_option(|v| v.try_copy_to_bytes(256).map(|s| s.to_vec()))?, message_count: bytebuf.try_get_var_int()?, - acknowledged: bytebuf.try_get_fixed_bitset(20)?, + acknowledged: bytebuf.try_get_fixed_bitset(20).map(|s| s.to_vec())?, }) } }