1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

fix incorrect chat parsing when legacy color codes are mixed in

This commit is contained in:
mat 2025-05-06 22:35:17 -06:30
parent aa0256da10
commit 4a1fdf0121
2 changed files with 17 additions and 2 deletions

View file

@ -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)
}

View file

@ -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"
)
}
}