handle incoming invite, fixes #961
[quassel.git] / src / core / ircserverhandler.cpp
index ea59836..033d6c8 100644 (file)
 
 #include <QDebug>
 
+#ifdef HAVE_QCA2
+#  include "cipher.h"
+#endif
+
 IrcServerHandler::IrcServerHandler(CoreNetwork *parent)
   : CoreBasicHandler(parent),
     _whois(false)
@@ -193,6 +197,21 @@ void IrcServerHandler::defaultHandler(QString cmd, const QString &prefix, const
 //******************************/
 // IRC SERVER HANDLER
 //******************************/
+void IrcServerHandler::handleInvite(const QString &prefix, const QList<QByteArray> &params) {
+  if(!checkParamCount("IrcServerHandler::handleInvite()", params, 2))
+    return;
+//   qDebug() << "IrcServerHandler::handleInvite()" << prefix << params;
+
+  IrcUser *ircuser = network()->updateNickFromMask(prefix);
+  if(!ircuser) {
+    return;
+  }
+
+  QString channel = serverDecode(params[1]);
+
+  emit displayMsg(Message::Invite, BufferInfo::StatusBuffer, "", tr("%1 invited you to channel %2").arg(ircuser->nick()).arg(channel));
+}
+
 void IrcServerHandler::handleJoin(const QString &prefix, const QList<QByteArray> &params) {
   if(!checkParamCount("IrcServerHandler::handleJoin()", params, 1))
     return;
@@ -494,6 +513,9 @@ void IrcServerHandler::handlePrivmsg(const QString &prefix, const QList<QByteArr
       ? *targetIter
       : senderNick;
 
+#ifdef HAVE_QCA2
+    msg = decrypt(target, msg);
+#endif
     // it's possible to pack multiple privmsgs into one param using ctcp
     // - > we let the ctcpHandler do the work
     network()->ctcpHandler()->parse(Message::Plain, prefix, target, msg);
@@ -549,8 +571,13 @@ void IrcServerHandler::handleTopic(const QString &prefix, const QList<QByteArray
     return;
 
   QString topic;
-  if(params.count() > 1)
-    topic = channelDecode(channel->name(), params[1]);
+  if(params.count() > 1) {
+    QByteArray rawTopic = params[1];
+#ifdef HAVE_QCA2
+    rawTopic = decrypt(channel->name(), rawTopic, true);
+#endif
+    topic = channelDecode(channel->name(), rawTopic);
+  }
 
   channel->setTopic(topic);
 
@@ -988,7 +1015,12 @@ void IrcServerHandler::handle332(const QString &prefix, const QList<QByteArray>
     return;
 
   QString channel = serverDecode(params[0]);
-  QString topic = channelDecode(channel, params[1]);
+  QByteArray rawTopic = params[1];
+#ifdef HAVE_QCA2
+  rawTopic = decrypt(channel, rawTopic, true);
+#endif
+  QString topic = channelDecode(channel, rawTopic);
+
   IrcChannel *chan = network()->ircChannel(channel);
   if(chan)
     chan->setTopic(topic);
@@ -1230,6 +1262,17 @@ void IrcServerHandler::destroyNetsplits() {
   _netsplits.clear();
 }
 
-/***********************************************************************************/
+#ifdef HAVE_QCA2
+QByteArray IrcServerHandler::decrypt(const QString &bufferName, const QByteArray &message_, bool isTopic) {
+  if(message_.isEmpty())
+    return message_;
 
+  Cipher *cipher = network()->cipher(bufferName);
+  if(!cipher)
+    return message_;
 
+  QByteArray message = message_;
+  message = isTopic? cipher->decryptTopic(message) : cipher->decrypt(message);
+  return message;
+}
+#endif