Add support for away-notify capability
[quassel.git] / src / core / ircparser.cpp
index f3db4fc..bc10d93 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   Copyright (C) 2005-2015 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -232,9 +232,9 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent *e)
 
 #ifdef HAVE_QCA2
                 // Handle DH1080 key exchange
-                if (params[1].startsWith("DH1080_INIT")) {
+                if (params[1].startsWith("DH1080_INIT") && !net->isChannelName(target)) {
                     events << new KeyEvent(EventManager::KeyEvent, net, prefix, target, KeyEvent::Init, params[1].mid(12));
-                } else if (params[1].startsWith("DH1080_FINISH")) {
+                } else if (params[1].startsWith("DH1080_FINISH") && !net->isChannelName(target)) {
                     events << new KeyEvent(EventManager::KeyEvent, net, prefix, target, KeyEvent::Finish, params[1].mid(14));
                 } else
 #endif
@@ -273,6 +273,15 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent *e)
         }
         break;
 
+    case EventManager::IrcEventAway:
+        {
+            QString nick = nickFromMask(prefix);
+            decParams << nick;
+            decParams << (params.count() >= 1 ? net->userDecode(nick, params.at(0)) : QString());
+            net->updateNickFromMask(prefix);
+        }
+        break;
+
     case EventManager::IrcEventNumeric:
         switch (num) {
         case 301: /* RPL_AWAY */
@@ -298,6 +307,17 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent *e)
                 decParams << net->channelDecode(channel, params.at(2));
             }
             break;
+        case 451: /* You have not registered... */
+            if (target.compare("CAP", Qt::CaseInsensitive) == 0) {
+                // :irc.server.com 451 CAP :You have not registered
+                // If server doesn't support capabilities, it will report this message.  Turn it
+                // into a nicer message since it's not a real error.
+                defaultHandling = false;
+                events << new MessageEvent(Message::Server, e->network(),
+                                           tr("Capability negotiation not supported"),
+                                           QString(), QString(), Message::None, e->timestamp());
+            }
+            break;
         }
 
     default:
@@ -308,6 +328,11 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent *e)
         for (int i = decParams.count(); i < params.count(); i++)
             decParams << net->serverDecode(params.at(i));
 
+        // We want to trim the last param just in case, except for PRIVMSG and NOTICE
+        // ... but those happen to be the only ones not using defaultHandling anyway
+        if (!decParams.isEmpty() && decParams.last().endsWith(' '))
+            decParams.append(decParams.takeLast().trimmed());
+
         IrcEvent *event;
         if (type == EventManager::IrcEventNumeric)
             event = new IrcEventNumeric(num, net, prefix, target);