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:
parent
b4c62d0987
commit
91d97adb4f
1 changed files with 9 additions and 2 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue