X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fircserverhandler.cpp;h=3a3d4f01a9a30c458d371dada4d312b0c475c774;hp=92eaf68d705db77b0440623605d8fac043658777;hb=299bc5da644f9325b4116fd186f7de7e24955c78;hpb=7f5b1f4ce671afc43762b93d09c2664180df5ef9 diff --git a/src/core/ircserverhandler.cpp b/src/core/ircserverhandler.cpp index 92eaf68d..3a3d4f01 100644 --- a/src/core/ircserverhandler.cpp +++ b/src/core/ircserverhandler.cpp @@ -57,11 +57,23 @@ void IrcServerHandler::handleServerMsg(QByteArray msg) { // NOTE: This assumes that this is true in raw encoding, but well, hopefully there are no servers running in japanese on protocol level... int idx = msg.indexOf(" :"); if(idx >= 0) { - if(msg.length() > idx + 2) trailing = msg.mid(idx + 2); + if(msg.length() > idx + 2) + trailing = msg.mid(idx + 2); msg = msg.left(idx); } // OK, now it is safe to split... QList params = msg.split(' '); + + // This could still contain empty elements due to (faulty?) ircds sending multiple spaces in a row + // Also, QByteArray is not nearly as convenient to work with as QString for such things :) + QList::iterator iter = params.begin(); + while(iter != params.end()) { + if(iter->isEmpty()) + iter = params.erase(iter); + else + ++iter; + } + if(!trailing.isEmpty()) params << trailing; if(params.count() < 1) { qWarning() << "Received invalid string from server!"; @@ -327,35 +339,41 @@ void IrcServerHandler::handleNotice(const QString &prefix, const QListisChannelName(target)) { - QString msg = serverDecode(params[1]); - QRegExp welcomeRegExp("^\\[([^\\]]+)\\] "); - if(welcomeRegExp.indexIn(msg) != -1) { - QString channelname = welcomeRegExp.cap(1); - msg = msg.mid(welcomeRegExp.matchedLength()); - CoreIrcChannel *chan = static_cast(network()->ircChannel(channelname)); // we only have CoreIrcChannels in the core, so this cast is safe - if(chan && !chan->receivedWelcomeMsg()) { - chan->setReceivedWelcomeMsg(); - emit displayMsg(Message::Notice, BufferInfo::ChannelBuffer, channelname, msg, prefix); - return; + + QStringList targets = serverDecode(params[0]).split(',', QString::SkipEmptyParts); + QStringList::const_iterator targetIter; + for(targetIter = targets.constBegin(); targetIter != targets.constEnd(); targetIter++) { + QString target = *targetIter; + + // special treatment for welcome messages like: + // :ChanServ!ChanServ@services. NOTICE egst :[#apache] Welcome, this is #apache. Please read the in-channel topic message. This channel is being logged by IRSeekBot. If you have any question please see http://blog.freenode.net/?p=68 + if(!network()->isChannelName(target)) { + QString msg = serverDecode(params[1]); + QRegExp welcomeRegExp("^\\[([^\\]]+)\\] "); + if(welcomeRegExp.indexIn(msg) != -1) { + QString channelname = welcomeRegExp.cap(1); + msg = msg.mid(welcomeRegExp.matchedLength()); + CoreIrcChannel *chan = static_cast(network()->ircChannel(channelname)); // we only have CoreIrcChannels in the core, so this cast is safe + if(chan && !chan->receivedWelcomeMsg()) { + chan->setReceivedWelcomeMsg(); + emit displayMsg(Message::Notice, BufferInfo::ChannelBuffer, channelname, msg, prefix); + continue; + } } } - } - if(prefix.isEmpty() || target == "AUTH") { - target = ""; - } else { - if(!target.isEmpty() && network()->prefixes().contains(target[0])) - target = target.mid(1); - if(!network()->isChannelName(target)) - target = nickFromMask(prefix); + if(prefix.isEmpty() || target == "AUTH") { + target = ""; + } else { + if(!target.isEmpty() && network()->prefixes().contains(target[0])) + target = target.mid(1); + if(!network()->isChannelName(target)) + target = nickFromMask(prefix); + } + + network()->ctcpHandler()->parse(Message::Notice, prefix, target, params[1]); } - network()->ctcpHandler()->parse(Message::Notice, prefix, target, params[1]); } void IrcServerHandler::handlePart(const QString &prefix, const QList ¶ms) { @@ -416,18 +434,23 @@ void IrcServerHandler::handlePrivmsg(const QString &prefix, const QListisChannelName(target)) - target = nickFromMask(prefix); + QStringList targets = serverDecode(params[0]).split(',', QString::SkipEmptyParts); + QStringList::const_iterator targetIter; + for(targetIter = targets.constBegin(); targetIter != targets.constEnd(); targetIter++) { + const QString &target = network()->isChannelName(*targetIter) + ? *targetIter + : senderNick; - // 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); + // 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); + } } void IrcServerHandler::handleQuit(const QString &prefix, const QList ¶ms) { @@ -820,14 +843,34 @@ void IrcServerHandler::handle324(const QString &prefix, const QList handleMode(prefix, params); } +/* RPL_??? - " */ +void IrcServerHandler::handle328(const QString &prefix, const QList ¶ms) { + 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_??? - " " */ void IrcServerHandler::handle329(const QString &prefix, const QList ¶ms) { Q_UNUSED(prefix); - Q_UNUSED(params) -#ifdef __GNUC__ -# warning "Implement handle329 (Channel creation time)" -#endif - // FIXME implement this... + 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_NOTOPIC */