Use late CoreSessionEventProcessor handler rather than early EventStringifier ones
[quassel.git] / src / core / eventstringifier.cpp
index 96cb054..c301dbf 100644 (file)
@@ -50,6 +50,33 @@ void EventStringifier::sendMessageEvent(MessageEvent *event) {
   coreSession()->eventManager()->sendEvent(event);
 }
 
+bool EventStringifier::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;
+}
+
+/* These are only for legacy reasons; remove as soon as we handle NetworkSplitEvents properly */
+void EventStringifier::processNetworkSplitJoin(NetworkSplitEvent *e) {
+  QString msg = e->users().join("#:#") + "#:#" + e->quitMessage();
+  displayMsg(e, Message::NetsplitJoin, msg, QString(), e->channel());
+}
+
+void EventStringifier::processNetworkSplitQuit(NetworkSplitEvent *e) {
+  QString msg = e->users().join("#:#") + "#:#" + e->quitMessage();
+  displayMsg(e, Message::NetsplitQuit, msg, QString(), e->channel());
+}
+
+/* End legacy */
+
 void EventStringifier::processIrcEventNumeric(IrcEventNumeric *e) {
   //qDebug() << e->number();
   switch(e->number()) {
@@ -91,11 +118,11 @@ void EventStringifier::processIrcEventNumeric(IrcEventNumeric *e) {
   }
 
   // Ignore these commands.
-  case 321: case 366: case 376:
+  case 321: case 353: case 366: case 376:
     break;
 
   // CAP stuff
-  case 903: case 904: case 905: case 906: case 907:
+  case 900: case 903: case 904: case 905: case 906: case 907:
   {
     displayMsg(e, Message::Info, "CAP: " + e->params().join(""));
     break;
@@ -120,7 +147,17 @@ void EventStringifier::processIrcEventInvite(IrcEvent *e) {
   displayMsg(e, Message::Invite, tr("%1 invited you to channel %2").arg(e->nick(), e->params().at(1)));
 }
 
-void EventStringifier::earlyProcessIrcEventKick(IrcEvent *e) {
+void EventStringifier::processIrcEventJoin(IrcEvent *e) {
+  if(e->testFlag(EventManager::Netsplit))
+    return;
+
+  displayMsg(e, Message::Join, e->params()[0], e->prefix(), e->params()[0]);
+}
+
+void EventStringifier::processIrcEventKick(IrcEvent *e) {
+  if(!checkParamCount(e, 2))
+    return;
+
   IrcUser *victim = e->network()->ircUser(e->params().at(1));
   if(victim) {
     QString channel = e->params().at(0);
@@ -132,9 +169,20 @@ void EventStringifier::earlyProcessIrcEventKick(IrcEvent *e) {
   }
 }
 
+void EventStringifier::processIrcEventMode(IrcEvent *e) {
+  if(e->network()->isChannelName(e->params().first())) {
+    // Channel Modes
+    displayMsg(e, Message::Mode, e->params().join(" "), e->prefix(), e->params().first());
+  } else {
+    // User Modes
+    // FIXME: redirect
+    displayMsg(e, Message::Mode, e->params().join(" "), e->prefix());
+  }
+}
+
 // this needs to be called before the ircuser is renamed!
-void EventStringifier::earlyProcessIrcEventNick(IrcEvent *e) {
-  if(e->params().count() < 1)
+void EventStringifier::processIrcEventNick(IrcEvent *e) {
+  if(!checkParamCount(e, 1))
     return;
 
   IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
@@ -151,8 +199,8 @@ void EventStringifier::earlyProcessIrcEventNick(IrcEvent *e) {
     displayMsg(e, Message::Nick, newnick, sender, channel);
 }
 
-void EventStringifier::earlyProcessIrcEventPart(IrcEvent *e) {
-  if(e->params().count() < 1)
+void EventStringifier::processIrcEventPart(IrcEvent *e) {
+  if(!checkParamCount(e, 1))
     return;
 
   QString channel = e->params().at(0);
@@ -168,11 +216,31 @@ void EventStringifier::processIrcEventPong(IrcEvent *e) {
     displayMsg(e, Message::Server, "PONG " + e->params().join(" "), e->prefix());
 }
 
+void EventStringifier::processIrcEventQuit(IrcEvent *e) {
+  if(e->testFlag(EventManager::Netsplit))
+    return;
+
+  IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
+  if(!ircuser)
+    return;
+
+  foreach(const QString &channel, ircuser->channels())
+    displayMsg(e, Message::Quit, e->params().count()? e->params().first() : QString(), e->prefix(), channel);
+}
+
 void EventStringifier::processIrcEventTopic(IrcEvent *e) {
   displayMsg(e, Message::Topic, tr("%1 has changed topic for %2 to: \"%3\"")
              .arg(e->nick(), e->params().at(0), e->params().at(1)), QString(), e->params().at(0));
 }
 
+/* RPL_ISUPPORT */
+void EventStringifier::processIrcEvent005(IrcEvent *e) {
+  if(!e->params().last().contains(QRegExp("are supported (by|on) this server")))
+    displayMsg(e, Message::Error, tr("Received non-RFC-compliant RPL_ISUPPORT: this can lead to unexpected behavior!"), e->prefix());
+  displayMsg(e, Message::Server, e->params().join(" "), e->prefix());
+}
+
+/* RPL_AWAY - "<nick> :<away message>" */
 void EventStringifier::processIrcEvent301(IrcEvent *e) {
   QString nick = e->params().at(0);
   QString awayMsg = e->params().at(1);
@@ -197,12 +265,12 @@ void EventStringifier::processIrcEvent301(IrcEvent *e) {
     displayMsg(e, Message::Server, msg + tr("%1 is away: \"%2\"").arg(nick, awayMsg), QString(), target);
 }
 
-/* RPL_UNAWAY */
+/* RPL_UNAWAY - ":You are no longer marked as being away" */
 void EventStringifier::processIrcEvent305(IrcEvent *e) {
   displayMsg(e, Message::Server, tr("You are no longer marked as being away"));
 }
 
-/* RPL_NOWAWAY */
+/* RPL_NOWAWAY - ":You have been marked as being away" */
 void EventStringifier::processIrcEvent306(IrcEvent *e) {
   if(!e->network()->autoAwayActive())
     displayMsg(e, Message::Server, tr("You have been marked as being away"));
@@ -246,7 +314,7 @@ void EventStringifier::processIrcEvent312(IrcEvent *e) {
 
 /*  RPL_WHOWASUSER - "<nick> <user> <host> * :<real name>" */
 void EventStringifier::processIrcEvent314(IrcEvent *e) {
-  if(e->params().count() < 3)
+  if(!checkParamCount(e, 3))
     return;
 
   displayMsg(e, Message::Server, tr("[Whowas] %1 was %2@%3 (%4)").arg(e->params()[0], e->params()[1], e->params()[2], e->params().last()));
@@ -280,7 +348,7 @@ void EventStringifier::processIrcEvent318(IrcEvent *e) {
 
 /*  RPL_WHOISCHANNELS - "<nick> :*( ( "@" / "+" ) <channel> " " )" */
 void EventStringifier::processIrcEvent319(IrcEvent *e) {
-  if(e->params().count() < 2)
+  if(!checkParamCount(e, 2))
     return;
 
   QString nick = e->params().first();
@@ -303,6 +371,60 @@ void EventStringifier::processIrcEvent319(IrcEvent *e) {
     displayMsg(e, Message::Server, tr("[Whois] %1 is an operator on channels: %2").arg(nick, op.join(" ")));
 }
 
+/* RPL_LIST -  "<channel> <# visible> :<topic>" */
+void EventStringifier::processIrcEvent322(IrcEvent *e) {
+  QString channelName;
+  quint32 userCount = 0;
+  QString topic;
+
+  switch(e->params().count()) {
+  case 3:
+    topic = e->params()[2];
+  case 2:
+    userCount = e->params()[1].toUInt();
+  case 1:
+    channelName = e->params()[0];
+  default:
+    break;
+  }
+  displayMsg(e, Message::Server, tr("Channel %1 has %2 users. Topic is: \"%3\"")
+             .arg(channelName).arg(userCount).arg(topic));
+}
+
+/* RPL_LISTEND ":End of LIST" */
+void EventStringifier::processIrcEvent323(IrcEvent *e) {
+  displayMsg(e, Message::Server, tr("End of channel list"));
+}
+
+/* RPL_CHANNELMODEIS - "<channel> <mode> <mode params>" */
+void EventStringifier::processIrcEvent324(IrcEvent *e) {
+  processIrcEventMode(e);
+}
+
+/* RPL_??? - "<channel> <homepage> */
+void EventStringifier::processIrcEvent328(IrcEvent *e) {
+  if(!checkParamCount(e, 2))
+    return;
+
+  QString channel = e->params()[0];
+  displayMsg(e, Message::Topic, tr("Homepage for %1 is %2").arg(channel, e->params()[1]), QString(), channel);
+}
+
+/* RPL_??? - "<channel> <creation time (unix)>" */
+void EventStringifier::processIrcEvent329(IrcEvent *e) {
+  if(!checkParamCount(e, 2))
+    return;
+
+  QString channel = e->params()[0];
+  uint unixtime = e->params()[1].toUInt();
+  if(!unixtime) {
+    qWarning() << Q_FUNC_INFO << "received invalid timestamp:" << e->params()[1];
+    return;
+  }
+  QDateTime time = QDateTime::fromTime_t(unixtime);
+  displayMsg(e, Message::Topic, tr("Channel %1 created on %2").arg(channel, time.toString()), QString(), channel);
+}
+
 /*  RPL_WHOISACCOUNT: "<nick> <account> :is authed as */
 void EventStringifier::processIrcEvent330(IrcEvent *e) {
   if(e->params().count() < 3)
@@ -311,6 +433,63 @@ void EventStringifier::processIrcEvent330(IrcEvent *e) {
   displayMsg(e, Message::Server, tr("[Whois] %1 is authed as %2").arg(e->params()[0], e->params()[1]));
 }
 
+/* RPL_NOTOPIC */
+void EventStringifier::processIrcEvent331(IrcEvent *e) {
+  QString channel = e->params().first();
+  displayMsg(e, Message::Topic, tr("No topic is set for %1.").arg(channel), QString(), channel);
+}
+
+/* RPL_TOPIC */
+void EventStringifier::processIrcEvent332(IrcEvent *e) {
+  QString channel = e->params().first();
+  displayMsg(e, Message::Topic, tr("Topic for %1 is \"%2\"").arg(channel, e->params()[1]), QString(), channel);
+}
+
+/* Topic set by... */
+void EventStringifier::processIrcEvent333(IrcEvent *e) {
+  if(!checkParamCount(e, 3))
+    return;
+
+  QString channel = e->params().first();
+  displayMsg(e, Message::Topic, tr("Topic set by %1 on %2")
+             .arg(e->params()[1], QDateTime::fromTime_t(e->params()[2].toInt()).toString()), QString(), channel);
+}
+
+/* RPL_INVITING - "<nick> <channel>*/
+void EventStringifier::processIrcEvent341(IrcEvent *e) {
+  if(!checkParamCount(e, 2))
+    return;
+
+  QString channel = e->params()[1];
+  displayMsg(e, Message::Server, tr("%1 has been invited to %2").arg(e->params().first(), channel), QString(), channel);
+}
+
+/*  RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
+              ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
+void EventStringifier::processIrcEvent352(IrcEvent *e) {
+  displayMsg(e, Message::Server, tr("[Who] %1").arg(e->params().join(" ")));
+}
+
+/*  RPL_ENDOFWHOWAS - "<nick> :End of WHOWAS" */
+void EventStringifier::processIrcEvent369(IrcEvent *e) {
+  displayMsg(e, Message::Server, tr("End of /WHOWAS"));
+}
+
+/* ERR_ERRONEUSNICKNAME */
+void EventStringifier::processIrcEvent432(IrcEvent *e) {
+  displayMsg(e, Message::Error, tr("Nick %1 contains illegal characters").arg(e->params()[0]));
+}
+
+/* ERR_NICKNAMEINUSE */
+void EventStringifier::processIrcEvent433(IrcEvent *e) {
+  displayMsg(e, Message::Error, tr("Nick already in use: %1").arg(e->params()[0]));
+}
+
+/* ERR_UNAVAILRESOURCE */
+void EventStringifier::processIrcEvent437(IrcEvent *e) {
+  displayMsg(e, Message::Error, tr("Nick/channel is temporarily unavailable: %1").arg(e->params()[0]));
+}
+
 // template
 /*