Просмотр исходного кода

bin/ircd: implement a function for Privmsg to build irc msg

ghassmo 4 лет назад
Родитель
Сommit
62e84c017a
2 измененных файлов с 12 добавлено и 9 удалено
  1. 2 9
      bin/ircd/src/main.rs
  2. 10 0
      bin/ircd/src/privmsg.rs

+ 2 - 9
bin/ircd/src/main.rs

@@ -43,13 +43,6 @@ use crate::{
 
 
 const SIZE_OF_MSGS_BUFFER: usize = 4096;
 const SIZE_OF_MSGS_BUFFER: usize = 4096;
 
 
-fn build_irc_msg(msg: &Privmsg) -> String {
-    debug!("ABOUT TO SEND: {:?}", msg);
-    let irc_msg =
-        format!(":{}!anon@dark.fi PRIVMSG {} :{}\r\n", msg.nickname, msg.channel, msg.message);
-    irc_msg
-}
-
 fn clean_input(mut line: String, peer_addr: &SocketAddr) -> Result<String> {
 fn clean_input(mut line: String, peer_addr: &SocketAddr) -> Result<String> {
     if line.is_empty() {
     if line.is_empty() {
         warn!("Received empty line from {}. ", peer_addr);
         warn!("Received empty line from {}. ", peer_addr);
@@ -61,6 +54,7 @@ fn clean_input(mut line: String, peer_addr: &SocketAddr) -> Result<String> {
         warn!("Closing connection.");
         warn!("Closing connection.");
         return Err(Error::ChannelStopped)
         return Err(Error::ChannelStopped)
     }
     }
+
     // Remove CRLF
     // Remove CRLF
     line.pop();
     line.pop();
     line.pop();
     line.pop();
@@ -142,8 +136,7 @@ impl Ircd {
                             (*privmsgs_buffer.lock().await).push(msg.clone());
                             (*privmsgs_buffer.lock().await).push(msg.clone());
                         }
                         }
 
 
-                        let irc_msg = build_irc_msg(&msg);
-                        conn.reply(&irc_msg).await?;
+                        conn.reply(&msg.to_irc_msg()).await?;
                     }
                     }
                     err = reader.read_line(&mut line).fuse() => {
                     err = reader.read_line(&mut line).fuse() => {
                         if let Err(e) = err {
                         if let Err(e) = err {

+ 10 - 0
bin/ircd/src/privmsg.rs

@@ -17,3 +17,13 @@ pub struct Privmsg {
     pub channel: String,
     pub channel: String,
     pub message: String,
     pub message: String,
 }
 }
+
+impl Privmsg {
+    pub fn to_irc_msg(&self) -> String {
+        let irc_msg = format!(
+            ":{}!anon@dark.fi PRIVMSG {} :{}\r\n",
+            self.nickname, self.channel, self.message
+        );
+        irc_msg
+    }
+}