Event backend porting
[quassel.git] / src / core / ircserverhandler.cpp
index debe2ef..dfb3009 100644 (file)
@@ -399,433 +399,12 @@ void IrcServerHandler::handleQuit(const QString &prefix, const QList<QByteArray>
   }
 }
 
-/* RPL_ISUPPORT */
-// TODO Complete 005 handling, also use sensible defaults for non-sent stuff
-void IrcServerHandler::handle005(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  const int numParams = params.size();
-  if(numParams == 0) {
-    emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Received RPL_ISUPPORT (005) without parameters!"), prefix);
-    return;
-  }
-
-  emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", serverDecode(params).join(" "), prefix);
-
-  QString rpl_isupport_suffix = serverDecode(params.last());
-  if(!rpl_isupport_suffix.toLower().contains("are supported by this server")) {
-    emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Received non RFC compliant RPL_ISUPPORT: this can lead to unexpected behavior!"), prefix);
-  }
-
-  QString rawSupport;
-  QString key, value;
-  for(int i = 0; i < numParams - 1; i++) {
-    QString rawSupport = serverDecode(params[i]);
-    QString key = rawSupport.section("=", 0, 0);
-    QString value = rawSupport.section("=", 1);
-    network()->addSupport(key, value);
-  }
-
-  /* determine our prefixes here to get an accurate result */
-  network()->determinePrefixes();
-}
-
-/*
-WHOIS-Message:
-   Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
-  and 301 (RPL_AWAY)
-              "<nick> :<away message>"
-WHO-Message:
-   Replies 352 and 315 paired are used to answer a WHO message.
-
-WHOWAS-Message:
-   Replies 314 and 369 are responses to a WHOWAS message.
-
-*/
-
-/* RPL_WHOISSERVICE - "<user> is registered nick" */
-void IrcServerHandler::handle307(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  if(!checkParamCount("IrcServerHandler::handle307()", params, 1))
-    return;
-
-  QString whoisServiceReply = serverDecode(params).join(" ");
-  IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
-  if(ircuser) {
-    ircuser->setWhoisServiceReply(whoisServiceReply);
-  }
-  emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(whoisServiceReply));
-}
-
-/* RPL_SUSERHOST - "<user> is available for help." */
-void IrcServerHandler::handle310(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  if(!checkParamCount("IrcServerHandler::handle310()", params, 1))
-    return;
-
-  QString suserHost = serverDecode(params).join(" ");
-  IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
-  if(ircuser) {
-    ircuser->setSuserHost(suserHost);
-  }
-  emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(suserHost));
-}
-
-/*  RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
-void IrcServerHandler::handle311(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  if(!checkParamCount("IrcServerHandler::handle311()", params, 3))
-    return;
-
-  _whois = true;
-  IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
-  if(ircuser) {
-    ircuser->setUser(serverDecode(params[1]));
-    ircuser->setHost(serverDecode(params[2]));
-    ircuser->setRealName(serverDecode(params.last()));
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is %2 (%3)") .arg(ircuser->nick()).arg(ircuser->hostmask()).arg(ircuser->realName()));
-  } else {
-    QString host = QString("%1!%2@%3").arg(serverDecode(params[0])).arg(serverDecode(params[1])).arg(serverDecode(params[2]));
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is %2 (%3)") .arg(serverDecode(params[0])).arg(host).arg(serverDecode(params.last())));
-  }
-}
-
-/*  RPL_WHOISSERVER -  "<nick> <server> :<server info>" */
-void IrcServerHandler::handle312(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  if(!checkParamCount("IrcServerHandler::handle312()", params, 2))
-    return;
-
-  IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
-  if(ircuser) {
-    ircuser->setServer(serverDecode(params[1]));
-  }
-
-  QString returnString = tr("%1 is online via %2 (%3)").arg(serverDecode(params[0])).arg(serverDecode(params[1])).arg(serverDecode(params.last()));
-  if(_whois) {
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(returnString));
-  } else {
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whowas] %1").arg(returnString));
-  }
-}
-
-/*  RPL_WHOISOPERATOR - "<nick> :is an IRC operator" */
-void IrcServerHandler::handle313(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  if(!checkParamCount("IrcServerHandler::handle313()", params, 1))
-    return;
-
-  IrcUser *ircuser = network()->ircUser(serverDecode(params[0]));
-  if(ircuser) {
-    ircuser->setIrcOperator(params.last());
-  }
-  emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(serverDecode(params).join(" ")));
-}
-
-/*  RPL_WHOWASUSER - "<nick> <user> <host> * :<real name>" */
-void IrcServerHandler::handle314(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  if(!checkParamCount("IrcServerHandler::handle314()", params, 3))
-    return;
-
-  QString nick = serverDecode(params[0]);
-  QString hostmask = QString("%1@%2").arg(serverDecode(params[1])).arg(serverDecode(params[2]));
-  QString realName = serverDecode(params.last());
-  emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whowas] %1 was %2 (%3)").arg(nick).arg(hostmask).arg(realName));
-}
-
-/*  RPL_ENDOFWHO: "<name> :End of WHO list" */
-void IrcServerHandler::handle315(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle315()", params, 1))
-    return;
-
-  QStringList p = serverDecode(params);
-  if(network()->setAutoWhoDone(p[0])) {
-    return; // stay silent
-  }
-  p.takeLast(); // should be "End of WHO list"
-  emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Who] End of /WHO list for %1").arg(p.join(" ")));
-}
-
-/*  RPL_WHOISIDLE - "<nick> <integer> :seconds idle"
-   (real life: "<nick> <integer> <integer> :seconds idle, signon time) */
-void IrcServerHandler::handle317(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle317()", params, 2))
-    return;
-
-  QString nick = serverDecode(params[0]);
-  IrcUser *ircuser = network()->ircUser(nick);
-
-  QDateTime now = QDateTime::currentDateTime();
-  int idleSecs = serverDecode(params[1]).toInt();
-  idleSecs *= -1;
-
-  if(ircuser) {
-    ircuser->setIdleTime(now.addSecs(idleSecs));
-    if(params.size() > 3) { // if we have more then 3 params we have the above mentioned "real life" situation
-      int loginTime = serverDecode(params[2]).toInt();
-      ircuser->setLoginTime(QDateTime::fromTime_t(loginTime));
-      emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is logged in since %2").arg(ircuser->nick()).arg(ircuser->loginTime().toString()));
-    }
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is idling for %2 (%3)").arg(ircuser->nick()).arg(secondsToString(ircuser->idleTime().secsTo(now))).arg(ircuser->idleTime().toString()));
-  } else {
-    QDateTime idleSince = now.addSecs(idleSecs);
-    if (params.size() > 3) { // we have a signon time
-      int loginTime = serverDecode(params[2]).toInt();
-      QDateTime datetime = QDateTime::fromTime_t(loginTime);
-      emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is logged in since %2").arg(nick).arg(datetime.toString()));
-    }
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is idling for %2 (%3)").arg(nick).arg(secondsToString(idleSince.secsTo(now))).arg(idleSince.toString()));
-  }
-}
-
-/*  RPL_ENDOFWHOIS - "<nick> :End of WHOIS list" */
-void IrcServerHandler::handle318(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  _whois = false;
-  QStringList parameter = serverDecode(params);
-  parameter.removeFirst();
-  emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(parameter.join(" ")));
-}
-
-/*  RPL_WHOISCHANNELS - "<nick> :*( ( "@" / "+" ) <channel> " " )" */
-void IrcServerHandler::handle319(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  if(!checkParamCount("IrcServerHandler::handle319()", params, 2))
-    return;
-
-  QString nick = serverDecode(params.first());
-  QStringList op;
-  QStringList voice;
-  QStringList user;
-  foreach (QString channel, serverDecode(params.last()).split(" ")) {
-    if(channel.startsWith("@"))
-       op.append(channel.remove(0,1));
-    else if(channel.startsWith("+"))
-      voice.append(channel.remove(0,1));
-    else
-      user.append(channel);
-  }
-  if(!user.isEmpty())
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is a user on channels: %2").arg(nick).arg(user.join(" ")));
-  if(!voice.isEmpty())
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 has voice on channels: %2").arg(nick).arg(voice.join(" ")));
-  if(!op.isEmpty())
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1 is an operator on channels: %2").arg(nick).arg(op.join(" ")));
-}
-
-/*  RPL_WHOISVIRT - "<nick> is identified to services" */
-void IrcServerHandler::handle320(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whois] %1").arg(serverDecode(params).join(" ")));
-}
-
-/* RPL_LIST -  "<channel> <# visible> :<topic>" */
-void IrcServerHandler::handle322(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  QString channelName;
-  quint32 userCount = 0;
-  QString topic;
-
-  int paramCount = params.count();
-  switch(paramCount) {
-  case 3:
-    topic = serverDecode(params[2]);
-  case 2:
-    userCount = serverDecode(params[1]).toUInt();
-  case 1:
-    channelName = serverDecode(params[0]);
-  default:
-    break;
-  }
-  if(!coreSession()->ircListHelper()->addChannel(network()->networkId(), channelName, userCount, topic))
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Channel %1 has %2 users. Topic is: %3").arg(channelName).arg(userCount).arg(topic));
-}
-
-/* RPL_LISTEND ":End of LIST" */
-void IrcServerHandler::handle323(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  Q_UNUSED(params)
-
-  if(!coreSession()->ircListHelper()->endOfChannelList(network()->networkId()))
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("End of channel list"));
-}
-
 /* RPL_CHANNELMODEIS - "<channel> <mode> <mode params>" */
 void IrcServerHandler::handle324(const QString &prefix, const QList<QByteArray> &params) {
   Q_UNUSED(prefix);
   handleMode(prefix, params);
 }
 
-/* RPL_??? - "<channel> <homepage> */
-void IrcServerHandler::handle328(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle328()", params, 2))
-    return;
-
-  QString channel = serverDecode(params[0]);
-  QString homepage = serverDecode(params[1]);
-
-  emit displayMsg(Message::Server, BufferInfo::ChannelBuffer, channel, tr("Homepage for %1 is %2").arg(channel, homepage));
-}
-
-
-/* RPL_??? - "<channel> <creation time (unix)>" */
-void IrcServerHandler::handle329(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle329()", params, 2))
-    return;
-
-  QString channel = serverDecode(params[0]);
-  uint unixtime = params[1].toUInt();
-  if(!unixtime) {
-    qWarning() << Q_FUNC_INFO << "received invalid timestamp:" << params[1];
-    return;
-  }
-  QDateTime time = QDateTime::fromTime_t(unixtime);
-
-  emit displayMsg(Message::Server, BufferInfo::ChannelBuffer, channel, tr("Channel %1 created on %2").arg(channel, time.toString()));
-}
-
-/*  RPL_WHOISACCOUNT: "<nick> <account> :is authed as */
-void IrcServerHandler::handle330(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle330()", params, 3))
-    return;
-
-  QString nick = serverDecode(params[0]);
-  QString account = serverDecode(params[1]);
-
-  emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "",  tr("[Whois] %1 is authed as %2").arg(nick).arg(account));
-}
-
-/* RPL_NOTOPIC */
-void IrcServerHandler::handle331(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle331()", params, 1))
-    return;
-
-  QString channel = serverDecode(params[0]);
-  IrcChannel *chan = network()->ircChannel(channel);
-  if(chan)
-    chan->setTopic(QString());
-
-  emit displayMsg(Message::Topic, BufferInfo::ChannelBuffer, channel, tr("No topic is set for %1.").arg(channel));
-}
-
-/* RPL_TOPIC */
-void IrcServerHandler::handle332(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle332()", params, 2))
-    return;
-
-  QString channel = serverDecode(params[0]);
-  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);
-
-  emit displayMsg(Message::Topic, BufferInfo::ChannelBuffer, channel, tr("Topic for %1 is \"%2\"").arg(channel, topic));
-}
-
-/* Topic set by... */
-void IrcServerHandler::handle333(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle333()", params, 3))
-    return;
-
-  QString channel = serverDecode(params[0]);
-  emit displayMsg(Message::Topic, BufferInfo::ChannelBuffer, channel,
-                  tr("Topic set by %1 on %2") .arg(serverDecode(params[1]), QDateTime::fromTime_t(channelDecode(channel, params[2]).toUInt()).toString()));
-}
-
-/* RPL_INVITING - "<nick> <channel>*/
-void IrcServerHandler::handle341(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle341()", params, 2))
-    return;
-
-  QString nick = serverDecode(params[0]);
-
-  IrcChannel *channel = network()->ircChannel(serverDecode(params[1]));
-  if(!channel) {
-    qWarning() << "IrcServerHandler::handle341(): unknown channel:" << params[1];
-    return;
-  }
-
-  emit displayMsg(Message::Server, BufferInfo::ChannelBuffer, channel->name(), tr("%1 has been invited to %2").arg(nick).arg(channel->name()));
-}
-
-/*  RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
-              ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
-void IrcServerHandler::handle352(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  if(!checkParamCount("IrcServerHandler::handle352()", params, 6))
-    return;
-
-  QString channel = serverDecode(params[0]);
-  IrcUser *ircuser = network()->ircUser(serverDecode(params[4]));
-  if(ircuser) {
-    ircuser->setUser(serverDecode(params[1]));
-    ircuser->setHost(serverDecode(params[2]));
-
-    bool away = serverDecode(params[5]).startsWith("G") ? true : false;
-    ircuser->setAway(away);
-    ircuser->setServer(serverDecode(params[3]));
-    ircuser->setRealName(serverDecode(params.last()).section(" ", 1));
-  }
-
-  if(!network()->isAutoWhoInProgress(channel)) {
-    emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Who] %1").arg(serverDecode(params).join(" ")));
-  }
-}
-
-/* RPL_NAMREPLY */
-void IrcServerHandler::handle353(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle353()", params, 3))
-    return;
-
-  // param[0] is either "=", "*" or "@" indicating a public, private or secret channel
-  // we don't use this information at the time beeing
-  QString channelname = serverDecode(params[1]);
-
-  IrcChannel *channel = network()->ircChannel(channelname);
-  if(!channel) {
-    qWarning() << "IrcServerHandler::handle353(): received unknown target channel:" << channelname;
-    return;
-  }
-
-  QStringList nicks;
-  QStringList modes;
-
-  foreach(QString nick, serverDecode(params[2]).split(' ')) {
-    QString mode = QString();
-
-    if(network()->prefixes().contains(nick[0])) {
-      mode = network()->prefixToMode(nick[0]);
-      nick = nick.mid(1);
-    }
-
-    nicks << nick;
-    modes << mode;
-  }
-
-  channel->joinIrcUsers(nicks, modes);
-}
-
-/*  RPL_ENDOFWHOWAS - "<nick> :End of WHOWAS" */
-void IrcServerHandler::handle369(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix)
-  emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Whowas] %1").arg(serverDecode(params).join(" ")));
-}
-
 /* ERR_ERRONEUSNICKNAME */
 void IrcServerHandler::handle432(const QString &prefix, const QList<QByteArray> &params) {
   Q_UNUSED(prefix);