X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Feventstringifier.cpp;h=94c967de89433dba323eff4dd323993c04bba898;hp=c29a457bdb2ae3b0d1118b8d4e5b506a49b3eaf4;hb=5ff4265bbd3a682a6d6542480760eaf4a2b85d77;hpb=46a76ffbf0e9e7af3d4ceb074c0b8dff461b4a86 diff --git a/src/core/eventstringifier.cpp b/src/core/eventstringifier.cpp index c29a457b..94c967de 100644 --- a/src/core/eventstringifier.cpp +++ b/src/core/eventstringifier.cpp @@ -42,6 +42,7 @@ void EventStringifier::displayMsg(NetworkEvent *event, Message::Type msgType, co MessageEvent *EventStringifier::createMessageEvent(NetworkEvent *event, Message::Type msgType, const QString &msg, const QString &sender, const QString &target, Message::Flags msgFlags) { MessageEvent *msgEvent = new MessageEvent(msgType, event->network(), msg, sender, target, msgFlags); + msgEvent->setTimestamp(event->timestamp()); return msgEvent; } @@ -49,6 +50,20 @@ 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(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 EventStringifier::processIrcEventNumeric(IrcEventNumeric *e) { //qDebug() << e->number(); switch(e->number()) { @@ -133,7 +148,7 @@ void EventStringifier::earlyProcessIrcEventKick(IrcEvent *e) { // this needs to be called before the ircuser is renamed! void EventStringifier::earlyProcessIrcEventNick(IrcEvent *e) { - if(e->params().count() < 1) + if(!checkParamCount(e, 1)) return; IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix()); @@ -151,7 +166,7 @@ void EventStringifier::earlyProcessIrcEventNick(IrcEvent *e) { } void EventStringifier::earlyProcessIrcEventPart(IrcEvent *e) { - if(e->params().count() < 1) + if(!checkParamCount(e, 1)) return; QString channel = e->params().at(0); @@ -172,6 +187,14 @@ void EventStringifier::processIrcEventTopic(IrcEvent *e) { .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 - " :" */ void EventStringifier::processIrcEvent301(IrcEvent *e) { QString nick = e->params().at(0); QString awayMsg = e->params().at(1); @@ -196,13 +219,216 @@ 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")); } + +/* +WHOIS-Message: + Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message. + and 301 (RPL_AWAY) + " :" +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_WHOISUSER - " * :" */ +void EventStringifier::processIrcEvent311(IrcEvent *e) { + _whois = true; + + const QString whoisUserString = tr("[Whois] %1 is %2 (%3)"); + + IrcUser *ircuser = e->network()->ircUser(e->params().at(0)); + if(ircuser) + displayMsg(e, Message::Server, whoisUserString.arg(ircuser->nick(), ircuser->hostmask(), ircuser->realName())); + else { + QString host = QString("%1!%2@%3").arg(e->params().at(0), e->params().at(1), e->params().at(2)); + displayMsg(e, Message::Server, whoisUserString.arg(e->params().at(0), host, e->params().last())); + } +} + +/* RPL_WHOISSERVER - " :" */ +void EventStringifier::processIrcEvent312(IrcEvent *e) { + if(_whois) + displayMsg(e, Message::Server, tr("[Whois] %1 is online via %2 (%3)").arg(e->params().at(0), e->params().at(1), e->params().last())); + else + displayMsg(e, Message::Server, tr("[Whowas] %1 was online via %2 (%3)").arg(e->params().at(0), e->params().at(1), e->params().last())); +} + +/* RPL_WHOWASUSER - " * :" */ +void EventStringifier::processIrcEvent314(IrcEvent *e) { + 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())); +} + +/* RPL_ENDOFWHO: " :End of WHO list" */ +void EventStringifier::processIrcEvent315(IrcEvent *e) { + QStringList p = e->params(); + p.takeLast(); // should be "End of WHO list" + displayMsg(e, Message::Server, tr("[Who] End of /WHO list for %1").arg(p.join(" "))); +} + +/* RPL_WHOISIDLE - " :seconds idle" + (real life: " :seconds idle, signon time) */ +void EventStringifier::processIrcEvent317(IrcEvent *e) { + int idleSecs = e->params()[1].toInt(); + + if(e->params().count() > 3) { // if we have more then 3 params we have the above mentioned "real life" situation + QDateTime loginTime = QDateTime::fromTime_t(e->params()[2].toInt()); + displayMsg(e, Message::Server, tr("[Whois] %1 is logged in since %2").arg(e->params()[0], loginTime.toString())); + } + displayMsg(e, Message::Server, tr("[Whois] %1 is idling for %2 (since %3)") + .arg(e->params()[0], secondsToString(idleSecs), e->timestamp().toLocalTime().addSecs(-idleSecs).toString())); +} + +/* RPL_ENDOFWHOIS - " :End of WHOIS list" */ +void EventStringifier::processIrcEvent318(IrcEvent *e) { + _whois = false; + displayMsg(e, Message::Server, tr("[Whois] End of /WHOIS list")); +} + +/* RPL_WHOISCHANNELS - " :*( ( "@" / "+" ) " " )" */ +void EventStringifier::processIrcEvent319(IrcEvent *e) { + if(!checkParamCount(e, 2)) + return; + + QString nick = e->params().first(); + QStringList op; + QStringList voice; + QStringList user; + foreach(QString channel, e->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()) + displayMsg(e, Message::Server, tr("[Whois] %1 is a user on channels: %2").arg(nick, user.join(" "))); + if(!voice.isEmpty()) + displayMsg(e, Message::Server, tr("[Whois] %1 has voice on channels: %2").arg(nick, voice.join(" "))); + if(!op.isEmpty()) + displayMsg(e, Message::Server, tr("[Whois] %1 is an operator on channels: %2").arg(nick, op.join(" "))); +} + +/* RPL_LIST - " <# visible> :" */ +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_??? - " */ +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_??? - " " */ +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: " :is authed as */ +void EventStringifier::processIrcEvent330(IrcEvent *e) { + if(e->params().count() < 3) + return; + + 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 - " */ +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: " + ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] : " */ +void EventStringifier::processIrcEvent352(IrcEvent *e) { + displayMsg(e, Message::Server, tr("[Who] %1").arg(e->params().join(" "))); +} + +/* RPL_ENDOFWHOWAS - " :End of WHOWAS" */ +void EventStringifier::processIrcEvent369(IrcEvent *e) { + displayMsg(e, Message::Server, tr("End of /WHOWAS")); +} + +// template +/* + +void EventStringifier::processIrcEvent(IrcEvent *e) { + +} + +*/