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

Remove invalid characters and truncate messages and commands to 256 (#78)

* Remove invalid characters and truncate messages and commands to 256

* Remove duplicated use statements

* Remove to_owned and use matches! macro
This commit is contained in:
Shayne Hartford 2023-02-27 22:44:45 -05:00 committed by GitHub
parent b4c62d0987
commit 91d97adb4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -149,6 +149,7 @@ impl Client {
entity: self.entity,
content: content.to_string(),
});
self.run_schedule_sender.send(()).unwrap();
}
}
@ -228,9 +229,15 @@ fn handle_send_chat_kind_event(
mut send_packet_events: EventWriter<SendPacketEvent>,
) {
for event in events.iter() {
let content = event
.content
.chars()
.filter(|c| !matches!(c, '\x00'..='\x1F' | '\x7F' | '§'))
.take(256)
.collect::<String>();
let packet = match event.kind {
ChatPacketKind::Message => ServerboundChatPacket {
message: event.content.clone(),
message: content,
timestamp: SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time shouldn't be before epoch")
@ -245,7 +252,7 @@ fn handle_send_chat_kind_event(
ChatPacketKind::Command => {
// TODO: chat signing
ServerboundChatCommandPacket {
command: event.content.clone(),
command: content,
timestamp: SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time shouldn't be before epoch")