From 4a1fdf01217b27d48741bb13dea4f0b5b57d42ca Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 6 May 2025 22:35:17 -0630 Subject: [PATCH] fix incorrect chat parsing when legacy color codes are mixed in --- azalea-chat/src/component.rs | 5 +++-- azalea-protocol/src/packets/game/c_system_chat.rs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index ed7a0648..8eaaf178 100644 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -529,8 +529,9 @@ impl FormattedText { component.append(FormattedText::from_nbt_tag(extra)?); } - let style = Style::from_compound(compound).ok()?; - component.get_base_mut().style = style; + let base_style = Style::from_compound(compound).ok()?; + let new_style = &mut component.get_base_mut().style; + *new_style = new_style.merged_with(&base_style); Some(component) } diff --git a/azalea-protocol/src/packets/game/c_system_chat.rs b/azalea-protocol/src/packets/game/c_system_chat.rs index 191f6ee4..356a31ff 100644 --- a/azalea-protocol/src/packets/game/c_system_chat.rs +++ b/azalea-protocol/src/packets/game/c_system_chat.rs @@ -56,4 +56,18 @@ mod tests { "Position in queue: 328\nYou can purchase priority queue status to join the server faster, visit shop.2b2t.org".to_string() ); } + + #[test] + fn test_skyblock_net_message() { + #[rustfmt::skip] + let bytes = [ + 10, 8, 0, 4, 116, 101, 120, 116, 0, 0, 8, 0, 9, 105, 110, 115, 101, 114, 116, 105, 111, 110, 0, 7, 109, 97, 116, 115, 99, 97, 110, 9, 0, 5, 101, 120, 116, 114, 97, 10, 0, 0, 0, 2, 8, 0, 4, 116, 101, 120, 116, 0, 15, 194, 167, 97, 109, 97, 116, 115, 99, 97, 110, 194, 167, 114, 58, 32, 10, 0, 11, 104, 111, 118, 101, 114, 95, 101, 118, 101, 110, 116, 8, 0, 6, 97, 99, 116, 105, 111, 110, 0, 9, 115, 104, 111, 119, 95, 116, 101, 120, 116, 10, 0, 5, 118, 97, 108, 117, 101, 8, 0, 4, 116, 101, 120, 116, 0, 0, 9, 0, 5, 101, 120, 116, 114, 97, 8, 0, 0, 0, 1, 0, 126, 194, 167, 97, 109, 97, 116, 115, 99, 97, 110, 10, 194, 167, 101, 82, 97, 110, 107, 58, 32, 194, 167, 102, 194, 167, 97, 83, 107, 121, 98, 108, 111, 99, 107, 101, 114, 10, 194, 167, 54, 76, 101, 118, 101, 108, 58, 32, 194, 167, 102, 48, 10, 194, 167, 97, 74, 111, 105, 110, 101, 100, 58, 32, 194, 167, 102, 52, 109, 32, 52, 51, 115, 32, 97, 103, 111, 10, 194, 167, 98, 80, 108, 97, 121, 116, 105, 109, 101, 58, 32, 194, 167, 102, 50, 51, 115, 10, 194, 167, 55, 194, 167, 111, 42, 67, 108, 105, 99, 107, 32, 116, 111, 32, 118, 105, 115, 105, 116, 32, 105, 115, 108, 97, 110, 100, 42, 0, 0, 0, 8, 0, 0, 0, 4, 109, 101, 111, 119, 0, 10, 0, 11, 99, 108, 105, 99, 107, 95, 101, 118, 101, 110, 116, 8, 0, 6, 97, 99, 116, 105, 111, 110, 0, 15, 115, 117, 103, 103, 101, 115, 116, 95, 99, 111, 109, 109, 97, 110, 100, 8, 0, 5, 118, 97, 108, 117, 101, 0, 14, 47, 118, 105, 115, 105, 116, 32, 109, 97, 116, 115, 99, 97, 110, 8, 0, 7, 99, 111, 109, 109, 97, 110, 100, 0, 14, 47, 118, 105, 115, 105, 116, 32, 109, 97, 116, 115, 99, 97, 110, 0, 0, 0 + ]; + let packet = ClientboundSystemChat::azalea_read(&mut Cursor::new(&bytes)).unwrap(); + + assert_eq!( + packet.content.to_ansi(), + "\u{1b}[38;2;85;255;85mmatscan\u{1b}[m\u{1b}[38;2;255;255;255m: meow\u{1b}[m" + ) + } }