Add Clientbound Player Chat Message

This commit is contained in:
Snowiiii committed 2024-08-07 10:47:29 +02:00
1 parent 0e831dbe00
commit d0a8790d7b
3 files changed
+77 -13

No files matched your search

@@ -0,0 +1,70 @@
use num_derive::FromPrimitive;
use serde::Serialize;
use crate::{text::TextComponent, VarInt};
#[derive(Serialize)]
pub struct PlayerChatMessage<'a> {
sender: uuid::Uuid,
index: VarInt,
message_signature: Option<&'a [u8]>,
message: String,
timestamp: i64,
salt: i64,
previous_messages: &'a [PreviousMessage<'a>], // max 20
unsigned_content: Option<TextComponent>,
/// See `FilterType`
filter_type: VarInt,
chat_type: VarInt,
sender_name: TextComponent,
target_name: Option<TextComponent>,
}
impl<'a> PlayerChatMessage<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new(
sender: uuid::Uuid,
index: VarInt,
message_signature: Option<&'a [u8]>,
message: String,
timestamp: i64,
salt: i64,
previous_messages: &'a [PreviousMessage<'a>],
unsigned_content: Option<TextComponent>,
filter_type: VarInt,
chat_type: VarInt,
sender_name: TextComponent,
target_name: Option<TextComponent>,
) -> Self {
Self {
sender,
index,
message_signature,
message,
timestamp,
salt,
previous_messages,
unsigned_content,
filter_type,
chat_type,
sender_name,
target_name,
}
}
}
#[derive(Serialize)]
pub struct PreviousMessage<'a> {
message_id: VarInt,
signature: Option<&'a [u8]>,
}
#[derive(FromPrimitive)]
pub enum FilterType {
/// Message is not filtered at all
PassThrough,
/// Message is fully filtered
FullyFiltered,
/// Only some characters in the message are filtered
PartiallyFiltered,
}
+2
View File
@@ -5,6 +5,7 @@ mod c_head_rot;
mod c_login;
mod c_play_disconnect;
mod c_player_abilities;
mod c_player_chat_message;
mod c_player_info_update;
mod c_set_held_item;
mod c_spawn_player;
@@ -22,6 +23,7 @@ pub use c_head_rot::*;
pub use c_login::*;
pub use c_play_disconnect::*;
pub use c_player_abilities::*;
pub use c_player_chat_message::*;
pub use c_player_info_update::*;
pub use c_set_held_item::*;
pub use c_spawn_player::*;