1 /***************************************************************************
2 * Copyright (C) 2005-2014 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "coresessioneventprocessor.h"
23 #include "coreirclisthelper.h"
24 #include "corenetwork.h"
25 #include "coresession.h"
26 #include "ctcpevent.h"
29 #include "messageevent.h"
34 # include "keyevent.h"
37 CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session)
38 : BasicHandler("handleCtcp", session),
41 connect(coreSession(), SIGNAL(networkDisconnected(NetworkId)), this, SLOT(destroyNetsplits(NetworkId)));
42 connect(this, SIGNAL(newEvent(Event *)), coreSession()->eventManager(), SLOT(postEvent(Event *)));
46 bool CoreSessionEventProcessor::checkParamCount(IrcEvent *e, int minParams)
48 if (e->params().count() < minParams) {
49 if (e->type() == EventManager::IrcEventNumeric) {
50 qWarning() << "Command " << static_cast<IrcEventNumeric *>(e)->number() << " requires " << minParams << "params, got: " << e->params();
53 QString name = coreSession()->eventManager()->enumName(e->type());
54 qWarning() << qPrintable(name) << "requires" << minParams << "params, got:" << e->params();
63 void CoreSessionEventProcessor::tryNextNick(NetworkEvent *e, const QString &errnick, bool erroneus)
65 QStringList desiredNicks = coreSession()->identity(e->network()->identity())->nicks();
66 int nextNickIdx = desiredNicks.indexOf(errnick) + 1;
68 if (nextNickIdx > 0 && desiredNicks.size() > nextNickIdx) {
69 nextNick = desiredNicks[nextNickIdx];
73 // FIXME Make this an ErrorEvent or something like that, so it's translated in the client
74 MessageEvent *msgEvent = new MessageEvent(Message::Error, e->network(),
75 tr("No free and valid nicks in nicklist found. use: /nick <othernick> to continue"),
76 QString(), QString(), Message::None, e->timestamp());
77 emit newEvent(msgEvent);
81 nextNick = errnick + "_";
84 // FIXME Use a proper output event for this
85 coreNetwork(e)->putRawLine("NICK " + coreNetwork(e)->encodeServerString(nextNick));
89 void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e)
91 switch (e->number()) {
98 qobject_cast<CoreNetwork *>(e->network())->putRawLine("CAP END");
107 void CoreSessionEventProcessor::processIrcEventAuthenticate(IrcEvent *e)
109 if (!checkParamCount(e, 1))
112 if (e->params().at(0) != "+") {
113 qWarning() << "Invalid AUTHENTICATE" << e;
117 CoreNetwork *net = coreNetwork(e);
120 if (net->identityPtr()->sslCert().isNull()) {
122 QString construct = net->saslAccount();
123 construct.append(QChar(QChar::Null));
124 construct.append(net->saslAccount());
125 construct.append(QChar(QChar::Null));
126 construct.append(net->saslPassword());
127 QByteArray saslData = QByteArray(construct.toAscii().toBase64());
128 saslData.prepend("AUTHENTICATE ");
129 net->putRawLine(saslData);
132 net->putRawLine("AUTHENTICATE +");
138 void CoreSessionEventProcessor::processIrcEventCap(IrcEvent *e)
140 // for SASL, there will only be a single param of 'sasl', however you can check here for
141 // additional CAP messages (ls, multi-prefix, et cetera).
143 if (e->params().count() == 3) {
144 if (e->params().at(2).startsWith("sasl")) { // Freenode (at least) sends "sasl " with a trailing space for some reason!
146 // if the current identity has a cert set, use SASL EXTERNAL
148 if (!coreNetwork(e)->identityPtr()->sslCert().isNull()) {
149 coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE EXTERNAL"));
152 // Only working with PLAIN atm, blowfish later
153 coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE PLAIN"));
162 void CoreSessionEventProcessor::processIrcEventInvite(IrcEvent *e)
164 if (checkParamCount(e, 2)) {
165 e->network()->updateNickFromMask(e->prefix());
170 void CoreSessionEventProcessor::processIrcEventJoin(IrcEvent *e)
172 if (e->testFlag(EventManager::Fake)) // generated by handleEarlyNetsplitJoin
175 if (!checkParamCount(e, 1))
178 CoreNetwork *net = coreNetwork(e);
179 QString channel = e->params()[0];
180 IrcUser *ircuser = net->updateNickFromMask(e->prefix());
182 bool handledByNetsplit = false;
183 foreach(Netsplit* n, _netsplits.value(e->network())) {
184 handledByNetsplit = n->userJoined(e->prefix(), channel);
185 if (handledByNetsplit)
189 if (!handledByNetsplit)
190 ircuser->joinChannel(channel);
192 e->setFlag(EventManager::Netsplit);
194 if (net->isMe(ircuser)) {
195 net->setChannelJoined(channel);
197 net->putRawLine(net->serverEncode("MODE " + channel)); // we want to know the modes of the channel we just joined, so we ask politely
202 void CoreSessionEventProcessor::lateProcessIrcEventKick(IrcEvent *e)
204 if (checkParamCount(e, 2)) {
205 e->network()->updateNickFromMask(e->prefix());
206 IrcUser *victim = e->network()->ircUser(e->params().at(1));
208 victim->partChannel(e->params().at(0));
209 //if(e->network()->isMe(victim)) e->network()->setKickedFromChannel(channel);
215 void CoreSessionEventProcessor::processIrcEventMode(IrcEvent *e)
217 if (!checkParamCount(e, 2))
220 if (e->network()->isChannelName(e->params().first())) {
223 IrcChannel *channel = e->network()->ircChannel(e->params()[0]);
225 // we received mode information for a channel we're not in. that means probably we've just been kicked out or something like that
226 // anyways: we don't have a place to store the data --> discard the info.
230 QString modes = e->params()[1];
233 for (int c = 0; c < modes.length(); c++) {
234 if (modes[c] == '+') {
238 if (modes[c] == '-') {
243 if (e->network()->prefixModes().contains(modes[c])) {
244 // user channel modes (op, voice, etc...)
245 if (paramOffset < e->params().count()) {
246 IrcUser *ircUser = e->network()->ircUser(e->params()[paramOffset]);
248 qWarning() << Q_FUNC_INFO << "Unknown IrcUser:" << e->params()[paramOffset];
252 bool handledByNetsplit = false;
253 QHash<QString, Netsplit *> splits = _netsplits.value(e->network());
254 foreach(Netsplit* n, _netsplits.value(e->network())) {
255 handledByNetsplit = n->userAlreadyJoined(ircUser->hostmask(), channel->name());
256 if (handledByNetsplit) {
257 n->addMode(ircUser->hostmask(), channel->name(), QString(modes[c]));
261 if (!handledByNetsplit)
262 channel->addUserMode(ircUser, QString(modes[c]));
265 channel->removeUserMode(ircUser, QString(modes[c]));
269 qWarning() << "Received MODE with too few parameters:" << e->params();
274 // regular channel modes
276 Network::ChannelModeType modeType = e->network()->channelModeType(modes[c]);
277 if (modeType == Network::A_CHANMODE || modeType == Network::B_CHANMODE || (modeType == Network::C_CHANMODE && add)) {
278 if (paramOffset < e->params().count()) {
279 value = e->params()[paramOffset];
282 qWarning() << "Received MODE with too few parameters:" << e->params();
288 channel->addChannelMode(modes[c], value);
290 channel->removeChannelMode(modes[c], value);
296 IrcUser *ircUser = e->network()->newIrcUser(e->params().first());
297 QString modeString(e->params()[1]);
301 for (int c = 0; c < modeString.count(); c++) {
302 if (modeString[c] == '+') {
306 if (modeString[c] == '-') {
311 addModes += modeString[c];
313 removeModes += modeString[c];
315 if (!addModes.isEmpty())
316 ircUser->addUserModes(addModes);
317 if (!removeModes.isEmpty())
318 ircUser->removeUserModes(removeModes);
320 if (e->network()->isMe(ircUser)) {
321 coreNetwork(e)->updatePersistentModes(addModes, removeModes);
327 void CoreSessionEventProcessor::lateProcessIrcEventNick(IrcEvent *e)
329 if (checkParamCount(e, 1)) {
330 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
332 qWarning() << Q_FUNC_INFO << "Unknown IrcUser!";
335 QString newnick = e->params().at(0);
336 QString oldnick = ircuser->nick();
338 // the order is cruicial
339 // otherwise the client would rename the buffer, see that the assigned ircuser doesn't match anymore
340 // and remove the ircuser from the querybuffer leading to a wrong on/offline state
341 ircuser->setNick(newnick);
342 coreSession()->renameBuffer(e->networkId(), newnick, oldnick);
347 void CoreSessionEventProcessor::lateProcessIrcEventPart(IrcEvent *e)
349 if (checkParamCount(e, 1)) {
350 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
352 qWarning() << Q_FUNC_INFO<< "Unknown IrcUser!";
355 QString channel = e->params().at(0);
356 ircuser->partChannel(channel);
357 if (e->network()->isMe(ircuser))
358 qobject_cast<CoreNetwork *>(e->network())->setChannelParted(channel);
363 void CoreSessionEventProcessor::processIrcEventPing(IrcEvent *e)
365 QString param = e->params().count() ? e->params().first() : QString();
367 coreNetwork(e)->putRawLine("PONG " + coreNetwork(e)->serverEncode(param));
371 void CoreSessionEventProcessor::processIrcEventPong(IrcEvent *e)
373 // the server is supposed to send back what we passed as param. and we send a timestamp
374 // but using quote and whatnought one can send arbitrary pings, so we have to do some sanity checks
375 if (checkParamCount(e, 2)) {
376 QString timestamp = e->params().at(1);
377 QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz");
378 if (sendTime.isValid())
379 e->network()->setLatency(sendTime.msecsTo(QTime::currentTime()) / 2);
384 void CoreSessionEventProcessor::processIrcEventQuit(IrcEvent *e)
386 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
391 if (e->params().count() > 0)
392 msg = e->params()[0];
395 if (Netsplit::isNetsplit(msg)) {
397 if (!_netsplits[e->network()].contains(msg)) {
398 n = new Netsplit(e->network(), this);
399 connect(n, SIGNAL(finished()), this, SLOT(handleNetsplitFinished()));
400 connect(n, SIGNAL(netsplitJoin(Network*, QString, QStringList, QStringList, QString)),
401 this, SLOT(handleNetsplitJoin(Network*, QString, QStringList, QStringList, QString)));
402 connect(n, SIGNAL(netsplitQuit(Network*, QString, QStringList, QString)),
403 this, SLOT(handleNetsplitQuit(Network*, QString, QStringList, QString)));
404 connect(n, SIGNAL(earlyJoin(Network*, QString, QStringList, QStringList)),
405 this, SLOT(handleEarlyNetsplitJoin(Network*, QString, QStringList, QStringList)));
406 _netsplits[e->network()].insert(msg, n);
409 n = _netsplits[e->network()][msg];
411 // add this user to the netsplit
412 n->userQuit(e->prefix(), ircuser->channels(), msg);
413 e->setFlag(EventManager::Netsplit);
415 // normal quit is handled in lateProcessIrcEventQuit()
419 void CoreSessionEventProcessor::lateProcessIrcEventQuit(IrcEvent *e)
421 if (e->testFlag(EventManager::Netsplit))
424 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
432 void CoreSessionEventProcessor::processIrcEventTopic(IrcEvent *e)
434 if (checkParamCount(e, 2)) {
435 e->network()->updateNickFromMask(e->prefix());
436 IrcChannel *channel = e->network()->ircChannel(e->params().at(0));
438 channel->setTopic(e->params().at(1));
444 void CoreSessionEventProcessor::processKeyEvent(KeyEvent *e)
446 if (!Cipher::neededFeaturesAvailable()) {
447 emit newEvent(new MessageEvent(Message::Error, e->network(), tr("Unable to perform key exchange, missing qca-ossl plugin."), e->prefix(), e->target(), Message::None, e->timestamp()));
450 CoreNetwork *net = qobject_cast<CoreNetwork*>(e->network());
451 Cipher *c = net->cipher(e->target());
452 if (!c) // happens when there is no CoreIrcChannel for the target (i.e. never?)
455 if (e->exchangeType() == KeyEvent::Init) {
456 QByteArray pubKey = c->parseInitKeyX(e->key());
457 if (pubKey.isEmpty()) {
458 emit newEvent(new MessageEvent(Message::Error, e->network(), tr("Unable to parse the DH1080_INIT. Key exchange failed."), e->prefix(), e->target(), Message::None, e->timestamp()));
461 net->setCipherKey(e->target(), c->key());
462 emit newEvent(new MessageEvent(Message::Info, e->network(), tr("Your key is set and messages will be encrypted."), e->prefix(), e->target(), Message::None, e->timestamp()));
464 p << net->serverEncode(e->target()) << net->serverEncode("DH1080_FINISH ")+pubKey;
465 net->putCmd("NOTICE", p);
468 if (c->parseFinishKeyX(e->key())) {
469 net->setCipherKey(e->target(), c->key());
470 emit newEvent(new MessageEvent(Message::Info, e->network(), tr("Your key is set and messages will be encrypted."), e->prefix(), e->target(), Message::None, e->timestamp()));
472 emit newEvent(new MessageEvent(Message::Info, e->network(), tr("Failed to parse DH1080_FINISH. Key exchange failed."), e->prefix(), e->target(), Message::None, e->timestamp()));
480 void CoreSessionEventProcessor::processIrcEvent001(IrcEventNumeric *e)
482 e->network()->setCurrentServer(e->prefix());
483 e->network()->setMyNick(e->target());
488 // TODO Complete 005 handling, also use sensible defaults for non-sent stuff
489 void CoreSessionEventProcessor::processIrcEvent005(IrcEvent *e)
491 if (!checkParamCount(e, 1))
495 for (int i = 0; i < e->params().count() - 1; i++) {
496 QString key = e->params()[i].section("=", 0, 0);
497 QString value = e->params()[i].section("=", 1);
498 e->network()->addSupport(key, value);
501 /* determine our prefixes here to get an accurate result */
502 e->network()->determinePrefixes();
506 /* RPL_UMODEIS - "<user_modes> [<user_mode_params>]" */
507 void CoreSessionEventProcessor::processIrcEvent221(IrcEvent *)
509 // TODO: save information in network object
513 /* RPL_STATSCONN - "Highest connection cout: 8000 (7999 clients)" */
514 void CoreSessionEventProcessor::processIrcEvent250(IrcEvent *)
516 // TODO: save information in network object
520 /* RPL_LOCALUSERS - "Current local user: 5024 Max: 7999 */
521 void CoreSessionEventProcessor::processIrcEvent265(IrcEvent *)
523 // TODO: save information in network object
527 /* RPL_GLOBALUSERS - "Current global users: 46093 Max: 47650" */
528 void CoreSessionEventProcessor::processIrcEvent266(IrcEvent *)
530 // TODO: save information in network object
536 Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
538 "<nick> :<away message>"
540 Replies 352 and 315 paired are used to answer a WHO message.
543 Replies 314 and 369 are responses to a WHOWAS message.
547 /* RPL_AWAY - "<nick> :<away message>" */
548 void CoreSessionEventProcessor::processIrcEvent301(IrcEvent *e)
550 if (!checkParamCount(e, 2))
553 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
555 ircuser->setAway(true);
556 ircuser->setAwayMessage(e->params().at(1));
557 //ircuser->setLastAwayMessage(now);
562 /* RPL_UNAWAY - ":You are no longer marked as being away" */
563 void CoreSessionEventProcessor::processIrcEvent305(IrcEvent *e)
565 IrcUser *me = e->network()->me();
569 if (e->network()->autoAwayActive()) {
570 e->network()->setAutoAwayActive(false);
571 e->setFlag(EventManager::Silent);
576 /* RPL_NOWAWAY - ":You have been marked as being away" */
577 void CoreSessionEventProcessor::processIrcEvent306(IrcEvent *e)
579 IrcUser *me = e->network()->me();
585 /* RPL_WHOISSERVICE - "<user> is registered nick" */
586 void CoreSessionEventProcessor::processIrcEvent307(IrcEvent *e)
588 if (!checkParamCount(e, 1))
591 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
593 ircuser->setWhoisServiceReply(e->params().join(" "));
597 /* RPL_SUSERHOST - "<user> is available for help." */
598 void CoreSessionEventProcessor::processIrcEvent310(IrcEvent *e)
600 if (!checkParamCount(e, 1))
603 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
605 ircuser->setSuserHost(e->params().join(" "));
609 /* RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
610 void CoreSessionEventProcessor::processIrcEvent311(IrcEvent *e)
612 if (!checkParamCount(e, 3))
615 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
617 ircuser->setUser(e->params().at(1));
618 ircuser->setHost(e->params().at(2));
619 ircuser->setRealName(e->params().last());
624 /* RPL_WHOISSERVER - "<nick> <server> :<server info>" */
625 void CoreSessionEventProcessor::processIrcEvent312(IrcEvent *e)
627 if (!checkParamCount(e, 2))
630 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
632 ircuser->setServer(e->params().at(1));
636 /* RPL_WHOISOPERATOR - "<nick> :is an IRC operator" */
637 void CoreSessionEventProcessor::processIrcEvent313(IrcEvent *e)
639 if (!checkParamCount(e, 1))
642 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
644 ircuser->setIrcOperator(e->params().last());
648 /* RPL_ENDOFWHO: "<name> :End of WHO list" */
649 void CoreSessionEventProcessor::processIrcEvent315(IrcEvent *e)
651 if (!checkParamCount(e, 1))
654 if (coreNetwork(e)->setAutoWhoDone(e->params()[0]))
655 e->setFlag(EventManager::Silent);
659 /* RPL_WHOISIDLE - "<nick> <integer> :seconds idle"
660 (real life: "<nick> <integer> <integer> :seconds idle, signon time) */
661 void CoreSessionEventProcessor::processIrcEvent317(IrcEvent *e)
663 if (!checkParamCount(e, 2))
668 int idleSecs = e->params()[1].toInt();
669 if (e->params().count() > 3) { // if we have more then 3 params we have the above mentioned "real life" situation
670 int logintime = e->params()[2].toInt();
671 loginTime = QDateTime::fromTime_t(logintime);
674 IrcUser *ircuser = e->network()->ircUser(e->params()[0]);
676 ircuser->setIdleTime(e->timestamp().addSecs(-idleSecs));
677 if (loginTime.isValid())
678 ircuser->setLoginTime(loginTime);
683 /* RPL_LIST - "<channel> <# visible> :<topic>" */
684 void CoreSessionEventProcessor::processIrcEvent322(IrcEvent *e)
686 if (!checkParamCount(e, 1))
690 quint32 userCount = 0;
693 switch (e->params().count()) {
695 topic = e->params()[2];
697 userCount = e->params()[1].toUInt();
699 channelName = e->params()[0];
703 if (coreSession()->ircListHelper()->addChannel(e->networkId(), channelName, userCount, topic))
704 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
708 /* RPL_LISTEND ":End of LIST" */
709 void CoreSessionEventProcessor::processIrcEvent323(IrcEvent *e)
711 if (!checkParamCount(e, 1))
714 if (coreSession()->ircListHelper()->endOfChannelList(e->networkId()))
715 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
719 /* RPL_CHANNELMODEIS - "<channel> <mode> <mode params>" */
720 void CoreSessionEventProcessor::processIrcEvent324(IrcEvent *e)
722 processIrcEventMode(e);
727 void CoreSessionEventProcessor::processIrcEvent331(IrcEvent *e)
729 if (!checkParamCount(e, 1))
732 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
734 chan->setTopic(QString());
739 void CoreSessionEventProcessor::processIrcEvent332(IrcEvent *e)
741 if (!checkParamCount(e, 2))
744 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
746 chan->setTopic(e->params()[1]);
750 /* RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
751 ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
752 void CoreSessionEventProcessor::processIrcEvent352(IrcEvent *e)
754 if (!checkParamCount(e, 6))
757 QString channel = e->params()[0];
758 IrcUser *ircuser = e->network()->ircUser(e->params()[4]);
760 ircuser->setUser(e->params()[1]);
761 ircuser->setHost(e->params()[2]);
763 bool away = e->params()[5].startsWith("G");
764 ircuser->setAway(away);
765 ircuser->setServer(e->params()[3]);
766 ircuser->setRealName(e->params().last().section(" ", 1));
769 if (coreNetwork(e)->isAutoWhoInProgress(channel))
770 e->setFlag(EventManager::Silent);
775 void CoreSessionEventProcessor::processIrcEvent353(IrcEvent *e)
777 if (!checkParamCount(e, 3))
780 // param[0] is either "=", "*" or "@" indicating a public, private or secret channel
781 // we don't use this information at the time beeing
782 QString channelname = e->params()[1];
784 IrcChannel *channel = e->network()->ircChannel(channelname);
786 qWarning() << Q_FUNC_INFO << "Received unknown target channel:" << channelname;
793 foreach(QString nick, e->params()[2].split(' ', QString::SkipEmptyParts)) {
796 if (e->network()->prefixes().contains(nick[0])) {
797 mode = e->network()->prefixToMode(nick[0]);
805 channel->joinIrcUsers(nicks, modes);
809 /* ERR_ERRONEUSNICKNAME */
810 void CoreSessionEventProcessor::processIrcEvent432(IrcEventNumeric *e)
812 if (!checkParamCount(e, 1))
816 if (e->params().count() < 2) {
817 // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
819 // :irc.scortum.moep.net 432 @@@ :Erroneous Nickname: Illegal characters
820 // correct server reply:
821 // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
822 e->params().prepend(e->target());
825 errnick = e->params()[0];
827 tryNextNick(e, errnick, true /* erroneus */);
831 /* ERR_NICKNAMEINUSE */
832 void CoreSessionEventProcessor::processIrcEvent433(IrcEventNumeric *e)
834 if (!checkParamCount(e, 1))
837 QString errnick = e->params().first();
839 // if there is a problem while connecting to the server -> we handle it
840 // but only if our connection has not been finished yet...
841 if (!e->network()->currentServer().isEmpty())
844 tryNextNick(e, errnick);
848 /* ERR_UNAVAILRESOURCE */
849 void CoreSessionEventProcessor::processIrcEvent437(IrcEventNumeric *e)
851 if (!checkParamCount(e, 1))
854 QString errnick = e->params().first();
856 // if there is a problem while connecting to the server -> we handle it
857 // but only if our connection has not been finished yet...
858 if (!e->network()->currentServer().isEmpty())
861 if (!e->network()->isChannelName(errnick))
862 tryNextNick(e, errnick);
867 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
868 if(!checkParamCount(e, 1))
874 /* Handle signals from Netsplit objects */
876 void CoreSessionEventProcessor::handleNetsplitJoin(Network *net,
877 const QString &channel,
878 const QStringList &users,
879 const QStringList &modes,
880 const QString &quitMessage)
882 IrcChannel *ircChannel = net->ircChannel(channel);
886 QList<IrcUser *> ircUsers;
887 QStringList newModes = modes;
888 QStringList newUsers = users;
890 foreach(const QString &user, users) {
891 IrcUser *iu = net->ircUser(nickFromMask(user));
894 else { // the user already quit
895 int idx = users.indexOf(user);
896 newUsers.removeAt(idx);
897 newModes.removeAt(idx);
901 ircChannel->joinIrcUsers(ircUsers, newModes);
902 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitJoin, net, channel, newUsers, quitMessage);
903 emit newEvent(event);
907 void CoreSessionEventProcessor::handleNetsplitQuit(Network *net, const QString &channel, const QStringList &users, const QString &quitMessage)
909 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitQuit, net, channel, users, quitMessage);
910 emit newEvent(event);
911 foreach(QString user, users) {
912 IrcUser *iu = net->ircUser(nickFromMask(user));
919 void CoreSessionEventProcessor::handleEarlyNetsplitJoin(Network *net, const QString &channel, const QStringList &users, const QStringList &modes)
921 IrcChannel *ircChannel = net->ircChannel(channel);
923 qDebug() << "handleEarlyNetsplitJoin(): channel " << channel << " invalid";
926 QList<NetworkEvent *> events;
927 QList<IrcUser *> ircUsers;
928 QStringList newModes = modes;
930 foreach(QString user, users) {
931 IrcUser *iu = net->updateNickFromMask(user);
934 // fake event for scripts that consume join events
935 events << new IrcEvent(EventManager::IrcEventJoin, net, iu->hostmask(), QStringList() << channel);
938 newModes.removeAt(users.indexOf(user));
941 ircChannel->joinIrcUsers(ircUsers, newModes);
942 foreach(NetworkEvent *event, events) {
943 event->setFlag(EventManager::Fake); // ignore this in here!
944 emit newEvent(event);
949 void CoreSessionEventProcessor::handleNetsplitFinished()
951 Netsplit *n = qobject_cast<Netsplit *>(sender());
953 QHash<QString, Netsplit *> splithash = _netsplits.take(n->network());
954 splithash.remove(splithash.key(n));
955 if (splithash.count())
956 _netsplits[n->network()] = splithash;
961 void CoreSessionEventProcessor::destroyNetsplits(NetworkId netId)
963 Network *net = coreSession()->network(netId);
967 QHash<QString, Netsplit *> splits = _netsplits.take(net);
972 /*******************************/
973 /******** CTCP HANDLING ********/
974 /*******************************/
976 void CoreSessionEventProcessor::processCtcpEvent(CtcpEvent *e)
978 if (e->testFlag(EventManager::Self))
979 return; // ignore ctcp events generated by user input
981 if (e->type() != EventManager::CtcpEvent || e->ctcpType() != CtcpEvent::Query)
984 handle(e->ctcpCmd(), Q_ARG(CtcpEvent *, e));
988 void CoreSessionEventProcessor::defaultHandler(const QString &ctcpCmd, CtcpEvent *e)
990 // This handler is only there to avoid warnings for unknown CTCPs
996 void CoreSessionEventProcessor::handleCtcpAction(CtcpEvent *e)
998 // This handler is only there to feed CLIENTINFO
1003 void CoreSessionEventProcessor::handleCtcpClientinfo(CtcpEvent *e)
1005 QStringList supportedHandlers;
1006 foreach(QString handler, providesHandlers())
1007 supportedHandlers << handler.toUpper();
1008 qSort(supportedHandlers);
1009 e->setReply(supportedHandlers.join(" "));
1013 void CoreSessionEventProcessor::handleCtcpPing(CtcpEvent *e)
1015 e->setReply(e->param().isNull() ? "" : e->param());
1019 void CoreSessionEventProcessor::handleCtcpTime(CtcpEvent *e)
1021 e->setReply(QDateTime::currentDateTime().toString());
1025 void CoreSessionEventProcessor::handleCtcpVersion(CtcpEvent *e)
1027 e->setReply(QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
1028 .arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate));