X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fircserverhandler.cpp;h=06f968cbc0785b260f07af9a1e061cb00c46e75d;hp=58a230205d605a38d9feed3e4e091cced3f75809;hb=a5dfcc8ecf8b81025d24b3c5c816169e3e030ea4;hpb=50680e8d8548a9b856faa7c5d3d5d4ae4a6be2bd diff --git a/src/core/ircserverhandler.cpp b/src/core/ircserverhandler.cpp index 58a23020..06f968cb 100644 --- a/src/core/ircserverhandler.cpp +++ b/src/core/ircserverhandler.cpp @@ -23,32 +23,29 @@ #include "coresession.h" #include "coreirclisthelper.h" -#include "networkconnection.h" -#include "network.h" #include "identity.h" #include "ctcphandler.h" #include "ircuser.h" -#include "ircchannel.h" +#include "coreircchannel.h" #include "logger.h" #include -IrcServerHandler::IrcServerHandler(NetworkConnection *parent) +IrcServerHandler::IrcServerHandler(CoreNetwork *parent) : BasicHandler(parent), _whois(false) { } IrcServerHandler::~IrcServerHandler() { - } /*! Handle a raw message string sent by the server. We try to find a suitable handler, otherwise we call a default handler. */ void IrcServerHandler::handleServerMsg(QByteArray msg) { try { if(msg.isEmpty()) { - quWarning() << "Received empty string from server!"; + qWarning() << "Received empty string from server!"; return; } @@ -68,7 +65,7 @@ void IrcServerHandler::handleServerMsg(QByteArray msg) { QList params = msg.split(' '); if(!trailing.isEmpty()) params << trailing; if(params.count() < 1) { - quWarning() << "Received invalid string from server!"; + qWarning() << "Received invalid string from server!"; return; } @@ -79,7 +76,7 @@ void IrcServerHandler::handleServerMsg(QByteArray msg) { foo.remove(0, 1); prefix = foo; if(params.count() < 1) { - quWarning() << "Received invalid string from server!"; + qWarning() << "Received invalid string from server!"; return; } foo = serverDecode(params.takeFirst()); @@ -92,7 +89,7 @@ void IrcServerHandler::handleServerMsg(QByteArray msg) { uint num = cmd.toUInt(); if(num > 0) { if(params.count() == 0) { - quWarning() << "Message received from server violates RFC and is ignored!"; + qWarning() << "Message received from server violates RFC and is ignored!"; return; } params.removeFirst(); @@ -154,8 +151,8 @@ void IrcServerHandler::defaultHandler(QString cmd, const QString &prefix, const // many nets define their own WHOIS fields. we fetch those not in need of special attention here: emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", "[Whois] " + params.join(" "), prefix); } else { - if(networkConnection()->coreSession()->ircListHelper()->requestInProgress(network()->networkId())) - networkConnection()->coreSession()->ircListHelper()->reportError(params.join(" ")); + if(coreSession()->ircListHelper()->requestInProgress(network()->networkId())) + coreSession()->ircListHelper()->reportError(params.join(" ")); else emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", cmd + " " + params.join(" "), prefix); } @@ -180,7 +177,7 @@ void IrcServerHandler::handleJoin(const QString &prefix, const QList //qDebug() << "IrcServerHandler::handleJoin()" << prefix << params; ircuser->joinChannel(channel); if(network()->isMe(ircuser)) { - networkConnection()->setChannelJoined(channel); + network()->setChannelJoined(channel); putCmd("MODE", params[0]); // we want to know the modes of the channel we just joined, so we ask politely } } @@ -204,7 +201,7 @@ void IrcServerHandler::handleKick(const QString &prefix, const QList msg = victim->nick(); emit displayMsg(Message::Kick, BufferInfo::ChannelBuffer, channel, msg, prefix); - //if(network()->isMe(victim)) networkConnection()->setKickedFromChannel(channel); + //if(network()->isMe(victim)) network()->setKickedFromChannel(channel); } void IrcServerHandler::handleMode(const QString &prefix, const QList ¶ms) { @@ -216,6 +213,12 @@ void IrcServerHandler::handleMode(const QString &prefix, const QList emit displayMsg(Message::Mode, BufferInfo::ChannelBuffer, serverDecode(params[0]), serverDecode(params).join(" "), prefix); IrcChannel *channel = network()->ircChannel(params[0]); + if(!channel) { + // we received mode information for a channel we're not in. that means probably we've just been kicked out or something like that + // anyways: we don't have a place to store the data --> discard the info. + return; + } + QString modes = params[1]; bool add = true; int paramOffset = 2; @@ -238,7 +241,7 @@ void IrcServerHandler::handleMode(const QString &prefix, const QList else channel->removeUserMode(ircUser, QString(modes[c])); } else { - quWarning() << "Received MODE with too few parameters:" << serverDecode(params); + qWarning() << "Received MODE with too few parameters:" << serverDecode(params); } paramOffset++; } else { @@ -249,7 +252,7 @@ void IrcServerHandler::handleMode(const QString &prefix, const QList if(paramOffset < params.count()) { value = params[paramOffset]; } else { - quWarning() << "Received MODE with too few parameters:" << serverDecode(params); + qWarning() << "Received MODE with too few parameters:" << serverDecode(params); } paramOffset++; } @@ -298,7 +301,7 @@ void IrcServerHandler::handleNick(const QString &prefix, const QList IrcUser *ircuser = network()->updateNickFromMask(prefix); if(!ircuser) { - quWarning() << "IrcServerHandler::handleNick(): Unknown IrcUser!"; + qWarning() << "IrcServerHandler::handleNick(): Unknown IrcUser!"; return; } QString newnick = serverDecode(params[0]); @@ -308,7 +311,7 @@ void IrcServerHandler::handleNick(const QString &prefix, const QList ? newnick : prefix; - emit nickChanged(newnick, oldnick); + coreSession()->renameBuffer(network()->networkId(), newnick, oldnick); foreach(QString channel, ircuser->channels()) emit displayMsg(Message::Nick, BufferInfo::ChannelBuffer, channel, newnick, sender); @@ -320,12 +323,34 @@ 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; + } + } + } + + if(prefix.isEmpty() || target == "AUTH") { target = ""; - else if(!network()->isChannelName(target)) - target = nickFromMask(prefix); + } else { + if(!target.isEmpty() && network()->prefixes().contains(target[0])) + target = target.mid(1); + if(!network()->isChannelName(target)) + target = nickFromMask(prefix); + } - networkConnection()->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) { @@ -335,7 +360,7 @@ void IrcServerHandler::handlePart(const QString &prefix, const QList IrcUser *ircuser = network()->updateNickFromMask(prefix); QString channel = serverDecode(params[0]); if(!ircuser) { - quWarning() << "IrcServerHandler::handlePart(): Unknown IrcUser!"; + qWarning() << "IrcServerHandler::handlePart(): Unknown IrcUser!"; return; } @@ -346,7 +371,7 @@ void IrcServerHandler::handlePart(const QString &prefix, const QList msg = userDecode(ircuser->nick(), params[1]); emit displayMsg(Message::Part, BufferInfo::ChannelBuffer, channel, msg, prefix); - if(network()->isMe(ircuser)) networkConnection()->setChannelParted(channel); + if(network()->isMe(ircuser)) network()->setChannelParted(channel); } void IrcServerHandler::handlePing(const QString &prefix, const QList ¶ms) { @@ -377,12 +402,12 @@ void IrcServerHandler::handlePrivmsg(const QString &prefix, const QListupdateNickFromMask(prefix); if(!ircuser) { - quWarning() << "IrcServerHandler::handlePrivmsg(): Unknown IrcUser!"; + qWarning() << "IrcServerHandler::handlePrivmsg(): Unknown IrcUser!"; return; } if(params.isEmpty()) { - quWarning() << "IrcServerHandler::handlePrivmsg(): received PRIVMSG without target or message from:" << prefix; + qWarning() << "IrcServerHandler::handlePrivmsg(): received PRIVMSG without target or message from:" << prefix; return; } @@ -392,13 +417,12 @@ void IrcServerHandler::handlePrivmsg(const QString &prefix, const QListisMyNick(target)) - target = nickFromMask(ircuser->nick()); + if(!network()->isChannelName(target)) + target = nickFromMask(prefix); // it's possible to pack multiple privmsgs into one param using ctcp // - > we let the ctcpHandler do the work - networkConnection()->ctcpHandler()->parse(Message::Plain, prefix, target, msg); + network()->ctcpHandler()->parse(Message::Plain, prefix, target, msg); } void IrcServerHandler::handleQuit(const QString &prefix, const QList ¶ms) { @@ -412,7 +436,7 @@ void IrcServerHandler::handleQuit(const QString &prefix, const QList foreach(QString channel, ircuser->channels()) emit displayMsg(Message::Quit, BufferInfo::ChannelBuffer, channel, msg, prefix); - network()->removeIrcUser(nickFromMask(prefix)); + ircuser->quit(); } void IrcServerHandler::handleTopic(const QString &prefix, const QList ¶ms) { @@ -563,8 +587,12 @@ void IrcServerHandler::handle305(const QString &prefix, const QList if(me) me->setAway(false); - if(!params.isEmpty()) - emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", serverDecode(params[0])); + if(!network()->autoAwayActive()) { + if(!params.isEmpty()) + emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", serverDecode(params[0])); + } else { + network()->setAutoAwayActive(false); + } } // 306 RPL_NOWAWAY @@ -575,7 +603,7 @@ void IrcServerHandler::handle306(const QString &prefix, const QList if(me) me->setAway(true); - if(!params.isEmpty()) + if(!params.isEmpty() && !network()->autoAwayActive()) emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", serverDecode(params[0])); } @@ -676,7 +704,7 @@ void IrcServerHandler::handle315(const QString &prefix, const QList return; QStringList p = serverDecode(params); - if(networkConnection()->setAutoWhoDone(p[0])) { + if(network()->setAutoWhoDone(p[0])) { return; // stay silent } p.takeLast(); // should be "End of WHO list" @@ -768,7 +796,7 @@ void IrcServerHandler::handle322(const QString &prefix, const QList default: break; } - if(!networkConnection()->coreSession()->ircListHelper()->addChannel(network()->networkId(), channelName, userCount, topic)) + 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)); } @@ -777,7 +805,7 @@ void IrcServerHandler::handle323(const QString &prefix, const QList Q_UNUSED(prefix) Q_UNUSED(params) - if(!networkConnection()->coreSession()->ircListHelper()->endOfChannelList(network()->networkId())) + if(!coreSession()->ircListHelper()->endOfChannelList(network()->networkId())) emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("End of channel list")); } @@ -790,6 +818,10 @@ void IrcServerHandler::handle324(const QString &prefix, const QList /* 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... } @@ -800,7 +832,10 @@ void IrcServerHandler::handle331(const QString &prefix, const QList return; QString channel = serverDecode(params[0]); - network()->ircChannel(channel)->setTopic(QString()); + IrcChannel *chan = network()->ircChannel(channel); + if(chan) + chan->setTopic(QString()); + emit displayMsg(Message::Server, BufferInfo::ChannelBuffer, channel, tr("No topic is set for %1.").arg(channel)); } @@ -812,7 +847,10 @@ void IrcServerHandler::handle332(const QString &prefix, const QList QString channel = serverDecode(params[0]); QString topic = channelDecode(channel, params[1]); - network()->ircChannel(channel)->setTopic(topic); + IrcChannel *chan = network()->ircChannel(channel); + if(chan) + chan->setTopic(topic); + emit displayMsg(Message::Server, BufferInfo::ChannelBuffer, channel, tr("Topic for %1 is \"%2\"").arg(channel, topic)); } @@ -846,7 +884,7 @@ void IrcServerHandler::handle352(const QString &prefix, const QList ircuser->setRealName(serverDecode(params.last()).section(" ", 1)); } - if(!networkConnection()->isAutoWhoInProgress(channel)) { + if(!network()->isAutoWhoInProgress(channel)) { emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("[Who] %1").arg(serverDecode(params).join(" "))); } } @@ -854,7 +892,7 @@ void IrcServerHandler::handle352(const QString &prefix, const QList /* RPL_NAMREPLY */ void IrcServerHandler::handle353(const QString &prefix, const QList ¶ms) { Q_UNUSED(prefix); - if(!checkParamCount("IrcServerHandler::handle353()", params, 2)) + if(!checkParamCount("IrcServerHandler::handle353()", params, 3)) return; // param[0] is either "=", "*" or "@" indicating a public, private or secret channel @@ -863,7 +901,7 @@ void IrcServerHandler::handle353(const QString &prefix, const QList IrcChannel *channel = network()->ircChannel(channelname); if(!channel) { - quWarning() << "IrcServerHandler::handle353(): received unknown target channel:" << channelname; + qWarning() << "IrcServerHandler::handle353(): received unknown target channel:" << channelname; return; } @@ -936,7 +974,7 @@ void IrcServerHandler::handle433(const QString &prefix, const QList /* */ void IrcServerHandler::tryNextNick(const QString &errnick) { - QStringList desiredNicks = networkConnection()->coreSession()->identity(network()->identity())->nicks(); + QStringList desiredNicks = coreSession()->identity(network()->identity())->nicks(); int nextNick = desiredNicks.indexOf(errnick) + 1; if(desiredNicks.size() > nextNick) { putCmd("NICK", serverEncode(desiredNicks[nextNick])); @@ -947,7 +985,7 @@ void IrcServerHandler::tryNextNick(const QString &errnick) { bool IrcServerHandler::checkParamCount(const QString &methodName, const QList ¶ms, int minParams) { if(params.count() < minParams) { - quWarning() << qPrintable(methodName) << "requires" << minParams << "parameters but received only" << params.count() << serverDecode(params); + qWarning() << qPrintable(methodName) << "requires" << minParams << "parameters but received only" << params.count() << serverDecode(params); return false; } else { return true;