Event backend porting
[quassel.git] / src / core / coresessioneventprocessor.cpp
index ebfb007..2147071 100644 (file)
@@ -31,6 +31,20 @@ CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session)
 
 }
 
+bool CoreSessionEventProcessor::checkParamCount(IrcEvent *e, int minParams) {
+  if(e->params().count() < minParams) {
+    if(e->type() == EventManager::IrcEventNumeric) {
+      qWarning() << "Command " << static_cast<IrcEventNumeric *>(e)->number() << " requires " << minParams << "params, got: " << e->params();
+    } else {
+      QString name = coreSession()->eventManager()->enumName(e->type());
+      qWarning() << qPrintable(name) << "requires" << minParams << "params, got:" << e->params();
+    }
+    e->stop();
+    return false;
+  }
+  return true;
+}
+
 void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e) {
   switch(e->number()) {
 
@@ -43,3 +57,52 @@ void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e) {
     break;
   }
 }
+
+void CoreSessionEventProcessor::processIrcEventInvite(IrcEvent *e) {
+  if(checkParamCount(e, 2)) {
+    e->network()->updateNickFromMask(e->prefix());
+  }
+}
+
+void CoreSessionEventProcessor::processIrcEventKick(IrcEvent *e) {
+  if(checkParamCount(e, 2)) {
+    e->network()->updateNickFromMask(e->prefix());
+    IrcUser *victim = e->network()->ircUser(e->params().at(1));
+    if(victim) {
+      victim->partChannel(e->params().at(0));
+      //if(e->network()->isMe(victim)) e->network()->setKickedFromChannel(channel);
+    }
+  }
+}
+
+void CoreSessionEventProcessor::processIrcEventNick(IrcEvent *e) {
+  if(checkParamCount(e, 1)) {
+    IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
+    if(!ircuser) {
+      qWarning() << Q_FUNC_INFO << "Unknown IrcUser!";
+      return;
+    }
+    QString newnick = e->params().at(0);
+    QString oldnick = ircuser->nick();
+
+    // the order is cruicial
+    // otherwise the client would rename the buffer, see that the assigned ircuser doesn't match anymore
+    // and remove the ircuser from the querybuffer leading to a wrong on/offline state
+    ircuser->setNick(newnick);
+    coreSession()->renameBuffer(e->networkId(), newnick, oldnick);
+  }
+}
+
+void CoreSessionEventProcessor::processIrcEventPart(IrcEvent *e) {
+  if(checkParamCount(e, 1)) {
+    IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
+    if(!ircuser) {
+      qWarning() << Q_FUNC_INFO<< "Unknown IrcUser!";
+      return;
+    }
+    QString channel = e->params().at(0);
+    ircuser->partChannel(channel);
+    if(e->network()->isMe(ircuser))
+      qobject_cast<CoreNetwork *>(e->network())->setChannelParted(channel);
+  }
+}