aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShayne Hartford <shaybox@shaybox.com>2023-02-27 22:44:45 -0500
committerGitHub <noreply@github.com>2023-02-27 21:44:45 -0600
commit91d97adb4f03acf2d53dedb598f5496e2c4d9063 (patch)
tree336470652c352b4d2c9d5e72b7705cb68e785d3d
parentb4c62d09872c9e9898585e86f8dc64ebd94edc1c (diff)
downloadazalea-drasl-91d97adb4f03acf2d53dedb598f5496e2c4d9063.tar.xz
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
-rwxr-xr-xazalea-client/src/chat.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/azalea-client/src/chat.rs b/azalea-client/src/chat.rs
index 202cf47c..e127f0d7 100755
--- a/azalea-client/src/chat.rs
+++ b/azalea-client/src/chat.rs
@@ -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")