diff options
| author | Shayne Hartford <shaybox@shaybox.com> | 2023-12-04 15:26:53 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-04 14:26:53 -0600 |
| commit | 888c2765037711f45a6dac8d8bad70dc9ee70998 (patch) | |
| tree | a1c72393b53fc5875713640ffa499f0f2b4d2483 /azalea-client/src | |
| parent | cc976c6873e3a0764a36b5950aba0f0767269d2f (diff) | |
| download | azalea-drasl-888c2765037711f45a6dac8d8bad70dc9ee70998.tar.xz | |
Add masked chat type/event (#118)
Diffstat (limited to 'azalea-client/src')
| -rwxr-xr-x | azalea-client/src/chat.rs | 14 | ||||
| -rw-r--r-- | azalea-client/src/packet_handling/game.rs | 13 |
2 files changed, 26 insertions, 1 deletions
diff --git a/azalea-client/src/chat.rs b/azalea-client/src/chat.rs index f805c20f..255e0898 100755 --- a/azalea-client/src/chat.rs +++ b/azalea-client/src/chat.rs @@ -2,6 +2,7 @@ use azalea_chat::FormattedText; use azalea_protocol::packets::game::{ + clientbound_disguised_chat_packet::ClientboundMaskedChatPacket, clientbound_player_chat_packet::ClientboundPlayerChatPacket, clientbound_system_chat_packet::ClientboundSystemChatPacket, serverbound_chat_command_packet::ServerboundChatCommandPacket, @@ -30,6 +31,7 @@ use crate::{ pub enum ChatPacket { System(Arc<ClientboundSystemChatPacket>), Player(Arc<ClientboundPlayerChatPacket>), + Masked(Arc<ClientboundMaskedChatPacket>), } macro_rules! regex { @@ -45,6 +47,7 @@ impl ChatPacket { match self { ChatPacket::System(p) => p.content.clone(), ChatPacket::Player(p) => p.message(), + ChatPacket::Masked(p) => p.message.clone(), } } @@ -74,6 +77,16 @@ impl ChatPacket { (None, message) } + ChatPacket::Masked(p) => { + let message = p.message.to_string(); + // It's a system message, so we'll have to match the content + // with regex + if let Some(m) = regex!("^<([a-zA-Z_0-9]{1,16})> (.+)$").captures(&message) { + return (Some(m[1].to_string()), m[2].to_string()); + } + + (None, message) + } } } @@ -91,6 +104,7 @@ impl ChatPacket { match self { ChatPacket::System(_) => None, ChatPacket::Player(m) => Some(m.sender), + ChatPacket::Masked(_) => None, } } diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs index 20facadb..6c4ea4f4 100644 --- a/azalea-client/src/packet_handling/game.rs +++ b/azalea-client/src/packet_handling/game.rs @@ -1382,7 +1382,18 @@ pub fn process_packet_events(ecs: &mut World) { ClientboundGamePacket::TabList(_) => {} ClientboundGamePacket::TagQuery(_) => {} ClientboundGamePacket::TakeItemEntity(_) => {} - ClientboundGamePacket::DisguisedChat(_) => {} + ClientboundGamePacket::MaskedChat(p) => { + debug!("Got masked chat packet {p:?}"); + + let mut system_state: SystemState<EventWriter<ChatReceivedEvent>> = + SystemState::new(ecs); + let mut chat_events = system_state.get_mut(ecs); + + chat_events.send(ChatReceivedEvent { + entity: player_entity, + packet: ChatPacket::Masked(Arc::new(p.clone())), + }); + } ClientboundGamePacket::Bundle(_) => {} ClientboundGamePacket::DamageEvent(_) => {} ClientboundGamePacket::HurtAnimation(_) => {} |
