darkirc: truncate PRIVMSGs longer than 512

This commit is contained in:
dasman
2024-07-25 04:19:51 +03:00
parent 65e669f1a1
commit 3bb373c01c
2 changed files with 7 additions and 1 deletions

View File

@@ -40,7 +40,7 @@ use smol::{
};
use super::{
server::{IrcServer, MAX_NICK_LEN},
server::{IrcServer, MAX_MSG_LEN, MAX_NICK_LEN},
NickServ, Privmsg, SERVER_NAME,
};
@@ -413,6 +413,9 @@ impl Client {
let channel = args.split_ascii_whitespace().next().unwrap().to_string();
let msg_offset = args.find(':').unwrap() + 1;
let (_, msg) = args.split_at(msg_offset);
// Truncate messages longer than MAX_MSG_LEN
let msg = if msg.len() > MAX_MSG_LEN { msg.split_at(MAX_MSG_LEN).0 } else { msg };
let mut privmsg =
Privmsg { channel, nick: self.nickname.read().await.to_string(), msg: msg.to_string() };

View File

@@ -48,6 +48,9 @@ use crate::{
/// Max channel/nick length
pub const MAX_NICK_LEN: usize = 24;
/// Max message length
pub const MAX_MSG_LEN: usize = 512;
/// IRC server instance
pub struct IrcServer {
/// DarkIrc instance