aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-07-29 04:56:21 +0000
committerGitHub <noreply@github.com>2022-07-29 04:56:21 +0000
commitaadf2de3cb751d563e743599a7fb345c08010f5a (patch)
treeaec2a9485c5057f1c148b87e23ee07a7a6b4978b /azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
parent3e43fc6c502573f9d48d801087e72cded37a30b8 (diff)
parent2211021105a7ce0ce9fcbc18f3b4f03b0f991a10 (diff)
downloadazalea-drasl-aadf2de3cb751d563e743599a7fb345c08010f5a.tar.xz
Merge pull request #8 from mat-1/1.19.1
Support 1.19.1. Signing stuff isn't implemented but auth isn't even in Azalea yet so that's fine.
Diffstat (limited to 'azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs')
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs99
1 files changed, 88 insertions, 11 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
index 4aac93f4..68f0ea21 100644
--- a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
@@ -1,22 +1,99 @@
-use azalea_buf::McBuf;
+use azalea_buf::{BitSet, McBuf, McBufReadable, McBufVarWritable};
+use azalea_buf::{McBufVarReadable, McBufWritable};
use azalea_chat::component::Component;
-use azalea_crypto::SaltSignaturePair;
+use azalea_crypto::{MessageSignature, SignedMessageHeader};
use packet_macros::GamePacket;
+use std::io::{Read, Write};
+use uuid::Uuid;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundPlayerChatPacket {
- pub signed_content: Component,
+ pub message: PlayerChatMessage,
+ pub chat_type: ChatTypeBound,
+}
+
+#[derive(Copy, Clone, Debug, McBuf)]
+pub enum ChatType {
+ Chat = 0,
+ SayCommand = 1,
+ MsgCommandIncoming = 2,
+ MsgCommandOutgoing = 3,
+ TeamMsgCommandIncoming = 4,
+ TeamMsgCommandOutgoing = 5,
+ EmoteCommand = 6,
+}
+
+#[derive(Clone, Debug, McBuf)]
+pub struct ChatTypeBound {
+ pub chat_type: ChatType,
+ pub name: Component,
+ pub target_name: Option<Component>,
+}
+
+#[derive(Clone, Debug, McBuf)]
+pub struct PlayerChatMessage {
+ pub signed_header: SignedMessageHeader,
+ pub header_signature: MessageSignature,
+ pub signed_body: SignedMessageBody,
pub unsigned_content: Option<Component>,
- #[var]
- pub type_id: i32,
- pub sender: ChatSender,
+ pub filter_mask: FilterMask,
+}
+
+#[derive(Clone, Debug, McBuf)]
+pub struct SignedMessageBody {
+ pub content: ChatMessageContent,
pub timestamp: u64,
- pub salt_signature: SaltSignaturePair,
+ pub salt: u64,
+ pub last_seen: Vec<LastSeenMessagesEntry>,
}
#[derive(Clone, Debug, McBuf)]
-pub struct ChatSender {
- pub uuid: uuid::Uuid,
- pub name: Component,
- pub team_name: Option<Component>,
+pub struct LastSeenMessagesEntry {
+ pub profile_id: Uuid,
+ pub last_signature: MessageSignature,
+}
+
+#[derive(Clone, Debug, McBuf)]
+pub struct LastSeenMessagesUpdate {
+ pub last_seen: Vec<LastSeenMessagesEntry>,
+ pub last_received: Option<LastSeenMessagesEntry>,
+}
+
+#[derive(Clone, Debug, McBuf)]
+pub struct ChatMessageContent {
+ pub plain: String,
+ /// Only sent if the decorated message is different than the plain.
+ pub decorated: Option<Component>,
+}
+
+#[derive(Clone, Debug)]
+pub enum FilterMask {
+ PassThrough,
+ FullyFiltered,
+ PartiallyFiltered(BitSet),
+}
+
+impl McBufReadable for FilterMask {
+ fn read_from(buf: &mut impl Read) -> Result<Self, String> {
+ let filter_mask = u32::var_read_from(buf)?;
+ match filter_mask {
+ 0 => Ok(FilterMask::PassThrough),
+ 1 => Ok(FilterMask::FullyFiltered),
+ 2 => Ok(FilterMask::PartiallyFiltered(BitSet::read_from(buf)?)),
+ _ => Err("Invalid filter mask".to_string()),
+ }
+ }
+}
+impl McBufWritable for FilterMask {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
+ match self {
+ FilterMask::PassThrough => 0u32.var_write_into(buf)?,
+ FilterMask::FullyFiltered => 1u32.var_write_into(buf)?,
+ FilterMask::PartiallyFiltered(bits) => {
+ 2u32.var_write_into(buf)?;
+ bits.write_into(buf)?;
+ }
+ }
+ Ok(())
+ }
}