Преглед изворни кода

darkirc: prefix ':' for PRIVMSG and USER commands if not already, supporting more clients e.g thelounge

dasman пре 1 година
родитељ
комит
880e2a9c4d
2 измењених фајлова са 15 додато и 9 уклоњено
  1. 15 0
      bin/darkirc/src/irc/client.rs
  2. 0 9
      bin/darkirc/src/irc/command.rs

+ 15 - 0
bin/darkirc/src/irc/client.rs

@@ -332,6 +332,21 @@ impl Client {
             return Err(Error::ParseFailed("Line doesn't end with CR/LF"))
         }
 
+        // Prefix the message part of PRIVMSG with ':' if is not already.
+        // Or realname part of USER command.
+        let mut words: Vec<String> = line.split_whitespace().map(|s| s.to_string()).collect();
+        if words[0].to_uppercase() == "PRIVMSG" {
+            if words.len() > 1 && !words[2].starts_with(':') {
+                words[2] = format!(":{}", words[2]);
+            }
+            line = words.join(" ");
+        } else if words[0].to_uppercase() == "USER" {
+            if words.len() > 1 && !words[4].starts_with(':') {
+                words[4] = format!(":{}", words[4]);
+            }
+            line = words.join(" ");
+        }
+
         // Parse the line
         let mut tokens = line.split_ascii_whitespace();
         // Commands can begin with :garbage, but we will reject clients

+ 0 - 9
bin/darkirc/src/irc/command.rs

@@ -275,15 +275,6 @@ impl Client {
             }
         }
 
-        // We need at least one channel.
-        if channels.is_empty() {
-            self.penalty.fetch_add(1, SeqCst);
-            return Ok(vec![ReplyType::Server((
-                ERR_NEEDMOREPARAMS,
-                format!("{} JOIN :{}", nick, INVALID_SYNTAX),
-            ))])
-        }
-
         // Weechat sends channels as `#chan1,#chan2,#chan3`. Handle it.
         if channels.len() == 1 {
             let list = channels.iter().next().unwrap().clone();