Make SChatMessage sendable

This commit is contained in:
Alexander Medvedev 2025-02-26 19:41:46 +01:00
parent b336a50955
commit 01e5719464

View File

@ -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<Bytes>,
pub signature: Option<Vec<u8>>,
pub message_count: VarInt,
pub acknowledged: FixedBitSet,
pub acknowledged: Vec<u8>,
}
impl SChatMessage {
pub fn new(
message: String,
timestamp: i64,
salt: i64,
signature: Option<Vec<u8>>,
message_count: VarInt,
acknowledged: Vec<u8>,
) -> Self {
Self {
message,
timestamp,
salt,
signature,
message_count,
acknowledged,
}
}
}
// TODO
impl ServerPacket for SChatMessage {
fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> {
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())?,
})
}
}