diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-12-07 21:09:58 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-07 21:09:58 -0600 |
| commit | 7d901e39bc10a855b545d7b6c167f45148a1fb0a (patch) | |
| tree | 88fe0a8f2f04f49f4df90e2f5462aa35a4278c68 /azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs | |
| parent | 9f5e5c092be9167e4d5222fdee4a1d2c419e5052 (diff) | |
| download | azalea-drasl-7d901e39bc10a855b545d7b6c167f45148a1fb0a.tar.xz | |
1.19.3 (#34)
* start updating to 22w42a
* work a bit more on 22w42a
* player chat packet
* serverbound hello packet
* Update mod.rs
* add more stuff to clientbound player chat packet
* ClientboundPlayerInfoUpdatePacket
* features enabled and container closed
* serverbound chat packets
* make it compile
* 22w43a
* ServerboundChatSessionUpdatePacket
* profile_public_key isn't Option anymore
* Update bitset.rs
* joining a server works
* fix entitydatavalue
* backtraces + fix clientbound chat message
* fix some warnings and add more ecomments
* 22w44a
* generate en_us.json
* add updating guide to codegen/readme
* fix some markdown
* update list of generated things
* metadata stuff
* Replace PJS generator mod with PixLyzer (#38)
* pixlizer extractor
* start working on shape extraction
* fix generating language
* fix pixlyzer shape generation
* use empty_shape
* generate blocks and shapes
* update pixlyzer dir
* Revert "update pixlyzer dir"
This reverts commit ee9a0e7a49936dd8569c610ba9b6455895eeff71.
* fix
* fix
* Revert "fix"
This reverts commit ad12ddcb009ccc4eeb13ddef0871db1d9322ab7d.
* fix
* detect pixlyzer fail
* fix pixlyzer
* 22w45a
* gen entities
* add async-trait dep
* update codegen/readme.md
* explain when rust_log should be used
* remove some unused code
* start fixing pixlyzer issues
* fix a thing in codegen
* almost fixed
* more progress towards 1.19.3
* 1.19.3-pre2
* fixes
* revert some hardcoded property names
* Delete clientbound_player_info_packet.rs
* handle 1.19.3 player info packets
* handle playerinforemove
* start updating to 1.19.3-rc1
* optional registries work
* fix some issues with 1.19.3
chat doesn't work yet
* aaaaaaaaaaaaaaaaa
* oh
* ignore unused shapes
* uncomment generate_blocks
* fix migrate
* 1.19.3-rc2
* fix clippy warnings
* 1.19.3-rc3
* split the azalea-buf macro into separate modules
* improve Recipe in protocol
* 1.19.3
Diffstat (limited to 'azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs')
| -rw-r--r--[-rwxr-xr-x] | azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs | 174 |
1 files changed, 111 insertions, 63 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 0e271e3d..f22fb608 100755..100644 --- a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs @@ -1,19 +1,57 @@ -use azalea_buf::McBuf; +use azalea_buf::{ + BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, +}; use azalea_chat::{ translatable_component::{StringOrComponent, TranslatableComponent}, Component, }; use azalea_core::BitSet; -use azalea_crypto::{MessageSignature, SignedMessageHeader}; +use azalea_crypto::MessageSignature; use azalea_protocol_macros::ClientboundGamePacket; +use std::io::{Cursor, Write}; use uuid::Uuid; #[derive(Clone, Debug, McBuf, ClientboundGamePacket, PartialEq)] pub struct ClientboundPlayerChatPacket { - pub message: PlayerChatMessage, + pub sender: Uuid, + #[var] + pub index: u32, + pub signature: Option<MessageSignature>, + pub body: PackedSignedMessageBody, + pub unsigned_content: Option<Component>, + pub filter_mask: FilterMask, pub chat_type: ChatTypeBound, } +#[derive(Clone, Debug, PartialEq, McBuf)] +pub struct PackedSignedMessageBody { + // the error is here, for some reason it skipped a byte earlier and here + // it's reading `0` when it should be `11` + pub content: String, + pub timestamp: u64, + pub salt: u64, + pub last_seen: PackedLastSeenMessages, +} + +#[derive(Clone, Debug, PartialEq, McBuf)] +pub struct PackedLastSeenMessages { + pub entries: Vec<PackedMessageSignature>, +} + +/// Messages can be deleted by either their signature or message id. +#[derive(Clone, Debug, PartialEq)] +pub enum PackedMessageSignature { + Signature(Box<MessageSignature>), + Id(u32), +} + +#[derive(Clone, Debug, PartialEq, McBuf)] +pub enum FilterMask { + PassThrough, + FullyFiltered, + PartiallyFiltered(BitSet), +} + #[derive(Copy, Clone, Debug, McBuf, PartialEq, Eq)] pub enum ChatType { Chat = 0, @@ -32,47 +70,36 @@ pub struct ChatTypeBound { pub target_name: Option<Component>, } -#[derive(Clone, Debug, McBuf, PartialEq)] -pub struct PlayerChatMessage { - pub signed_header: SignedMessageHeader, - pub header_signature: MessageSignature, - pub signed_body: SignedMessageBody, - pub unsigned_content: Option<Component>, - pub filter_mask: FilterMask, +// must be in Client +#[derive(Clone, Debug, PartialEq)] +pub struct MessageSignatureCache { + pub entries: Vec<Option<MessageSignature>>, } -#[derive(Clone, Debug, PartialEq, McBuf)] -pub struct SignedMessageBody { - pub content: ChatMessageContent, - pub timestamp: u64, - pub salt: u64, - pub last_seen: Vec<LastSeenMessagesEntry>, -} +// impl MessageSignatureCache { +// pub fn unpacker(&self) -> impl Fn(u32) -> Option<SignedMessageBody> { + +// } +// } -impl PlayerChatMessage { +// impl PackedSignedMessageBody { +// pub fn unpack(&self, unpacker: impl Fn(u32) -> Option<SignedMessageBody>) {} +// } + +impl ClientboundPlayerChatPacket { /// Returns the content of the message. If you want to get the Component /// for the whole message including the sender part, use /// [`ClientboundPlayerChatPacket::message`]. - pub fn content(&self, only_secure_chat: bool) -> Component { - if only_secure_chat { - return self - .signed_body - .content - .decorated - .clone() - .unwrap_or_else(|| Component::from(self.signed_body.content.plain.clone())); - } + pub fn content(&self) -> Component { self.unsigned_content .clone() - .unwrap_or_else(|| self.content(true)) + .unwrap_or_else(|| Component::from(self.body.content.clone())) } -} -impl ClientboundPlayerChatPacket { /// Get the full message, including the sender part. - pub fn message(&self, only_secure_chat: bool) -> Component { + pub fn message(&self) -> Component { let sender = self.chat_type.name.clone(); - let content = self.message.content(only_secure_chat); + let content = self.content(); let target = self.chat_type.target_name.clone(); let translation_key = self.chat_type.chat_type.chat_translation_key(); @@ -117,45 +144,66 @@ impl ChatType { } } -#[derive(Clone, Debug, McBuf, PartialEq)] -pub struct LastSeenMessagesEntry { - pub profile_id: Uuid, - pub last_signature: MessageSignature, -} - -#[derive(Clone, Debug, McBuf, Default)] -pub struct LastSeenMessagesUpdate { - pub last_seen: Vec<LastSeenMessagesEntry>, - pub last_received: Option<LastSeenMessagesEntry>, -} +impl McBufReadable for PackedMessageSignature { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let id = u32::var_read_from(buf)?; + if id == 0 { + let full_signature = MessageSignature::read_from(buf)?; -#[derive(Clone, Debug, McBuf, PartialEq)] -pub struct ChatMessageContent { - pub plain: String, - /// Only sent if the decorated message is different than the plain. - pub decorated: Option<Component>, + Ok(PackedMessageSignature::Signature(Box::new(full_signature))) + } else { + Ok(PackedMessageSignature::Id(id - 1)) + } + } } - -#[derive(Clone, Debug, McBuf, PartialEq)] -pub enum FilterMask { - PassThrough, - FullyFiltered, - PartiallyFiltered(BitSet), +impl McBufWritable for PackedMessageSignature { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + match self { + PackedMessageSignature::Signature(full_signature) => { + 0u32.var_write_into(buf)?; + full_signature.write_into(buf)?; + } + PackedMessageSignature::Id(id) => { + (id + 1).var_write_into(buf)?; + } + } + Ok(()) + } } #[cfg(test)] mod tests { use super::*; - use azalea_buf::McBufReadable; - use std::io::Cursor; + use std::backtrace::Backtrace; + // you can remove or update this test if it breaks because mojang changed the structure of the packet again #[test] - fn test_chat_type() { - let chat_type_enum = ChatType::read_from(&mut Cursor::new(&[0x06])).unwrap(); - assert_eq!(chat_type_enum, ChatType::EmoteCommand); - assert_eq!( - ChatType::read_from(&mut Cursor::new(&[0x07])).unwrap(), - ChatType::Chat - ); + fn test_player_chat_packet() { + let data: [u8; 295] = [ + 47, 247, 69, 164, 160, 108, 63, 217, 178, 34, 4, 161, 47, 115, 192, 126, 0, 0, 11, 72, + 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 0, 1, 132, 209, 9, 72, 139, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 242, 1, 123, 34, 105, 110, 115, 101, 114, 116, 105, 111, + 110, 34, 58, 34, 98, 111, 116, 48, 34, 44, 34, 99, 108, 105, 99, 107, 69, 118, 101, + 110, 116, 34, 58, 123, 34, 97, 99, 116, 105, 111, 110, 34, 58, 34, 115, 117, 103, 103, + 101, 115, 116, 95, 99, 111, 109, 109, 97, 110, 100, 34, 44, 34, 118, 97, 108, 117, 101, + 34, 58, 34, 47, 116, 101, 108, 108, 32, 98, 111, 116, 48, 32, 34, 125, 44, 34, 104, + 111, 118, 101, 114, 69, 118, 101, 110, 116, 34, 58, 123, 34, 97, 99, 116, 105, 111, + 110, 34, 58, 34, 115, 104, 111, 119, 95, 101, 110, 116, 105, 116, 121, 34, 44, 34, 99, + 111, 110, 116, 101, 110, 116, 115, 34, 58, 123, 34, 116, 121, 112, 101, 34, 58, 34, + 109, 105, 110, 101, 99, 114, 97, 102, 116, 58, 112, 108, 97, 121, 101, 114, 34, 44, 34, + 105, 100, 34, 58, 34, 50, 102, 102, 55, 52, 53, 97, 52, 45, 97, 48, 54, 99, 45, 51, + 102, 100, 57, 45, 98, 50, 50, 50, 45, 48, 52, 97, 49, 50, 102, 55, 51, 99, 48, 55, 101, + 34, 44, 34, 110, 97, 109, 101, 34, 58, 123, 34, 116, 101, 120, 116, 34, 58, 34, 98, + 111, 116, 48, 34, 125, 125, 125, 44, 34, 116, 101, 120, 116, 34, 58, 34, 98, 111, 116, + 48, 34, 125, 0, + ]; + // just make sure it doesn't panic + if let Err(e) = ClientboundPlayerChatPacket::read_from(&mut Cursor::new(&data)) { + let default_backtrace = Backtrace::capture(); + let backtrace = std::any::request_ref::<Backtrace>(&e).unwrap_or(&default_backtrace); + eprintln!("{e}\n{backtrace}"); + + panic!("failed to read player chat packet"); + } } } |
