1 /***************************************************************************
2 * Copyright (C) 2005-2013 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(IrcEvent *e)
482 if (!checkParamCount(e, 1))
485 QString myhostmask = e->params().at(0).section(' ', -1, -1);
486 e->network()->setCurrentServer(e->prefix());
487 e->network()->setMyNick(nickFromMask(myhostmask));
492 // TODO Complete 005 handling, also use sensible defaults for non-sent stuff
493 void CoreSessionEventProcessor::processIrcEvent005(IrcEvent *e)
495 if (!checkParamCount(e, 1))
499 for (int i = 0; i < e->params().count() - 1; i++) {
500 QString key = e->params()[i].section("=", 0, 0);
501 QString value = e->params()[i].section("=", 1);
502 e->network()->addSupport(key, value);
505 /* determine our prefixes here to get an accurate result */
506 e->network()->determinePrefixes();
510 /* RPL_UMODEIS - "<user_modes> [<user_mode_params>]" */
511 void CoreSessionEventProcessor::processIrcEvent221(IrcEvent *)
513 // TODO: save information in network object
517 /* RPL_STATSCONN - "Highest connection cout: 8000 (7999 clients)" */
518 void CoreSessionEventProcessor::processIrcEvent250(IrcEvent *)
520 // TODO: save information in network object
524 /* RPL_LOCALUSERS - "Current local user: 5024 Max: 7999 */
525 void CoreSessionEventProcessor::processIrcEvent265(IrcEvent *)
527 // TODO: save information in network object
531 /* RPL_GLOBALUSERS - "Current global users: 46093 Max: 47650" */
532 void CoreSessionEventProcessor::processIrcEvent266(IrcEvent *)
534 // TODO: save information in network object
540 Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
542 "<nick> :<away message>"
544 Replies 352 and 315 paired are used to answer a WHO message.
547 Replies 314 and 369 are responses to a WHOWAS message.
551 /* RPL_AWAY - "<nick> :<away message>" */
552 void CoreSessionEventProcessor::processIrcEvent301(IrcEvent *e)
554 if (!checkParamCount(e, 2))
557 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
559 ircuser->setAway(true);
560 ircuser->setAwayMessage(e->params().at(1));
561 //ircuser->setLastAwayMessage(now);
566 /* RPL_UNAWAY - ":You are no longer marked as being away" */
567 void CoreSessionEventProcessor::processIrcEvent305(IrcEvent *e)
569 IrcUser *me = e->network()->me();
573 if (e->network()->autoAwayActive()) {
574 e->network()->setAutoAwayActive(false);
575 e->setFlag(EventManager::Silent);
580 /* RPL_NOWAWAY - ":You have been marked as being away" */
581 void CoreSessionEventProcessor::processIrcEvent306(IrcEvent *e)
583 IrcUser *me = e->network()->me();
589 /* RPL_WHOISSERVICE - "<user> is registered nick" */
590 void CoreSessionEventProcessor::processIrcEvent307(IrcEvent *e)
592 if (!checkParamCount(e, 1))
595 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
597 ircuser->setWhoisServiceReply(e->params().join(" "));
601 /* RPL_SUSERHOST - "<user> is available for help." */
602 void CoreSessionEventProcessor::processIrcEvent310(IrcEvent *e)
604 if (!checkParamCount(e, 1))
607 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
609 ircuser->setSuserHost(e->params().join(" "));
613 /* RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
614 void CoreSessionEventProcessor::processIrcEvent311(IrcEvent *e)
616 if (!checkParamCount(e, 3))
619 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
621 ircuser->setUser(e->params().at(1));
622 ircuser->setHost(e->params().at(2));
623 ircuser->setRealName(e->params().last());
628 /* RPL_WHOISSERVER - "<nick> <server> :<server info>" */
629 void CoreSessionEventProcessor::processIrcEvent312(IrcEvent *e)
631 if (!checkParamCount(e, 2))
634 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
636 ircuser->setServer(e->params().at(1));
640 /* RPL_WHOISOPERATOR - "<nick> :is an IRC operator" */
641 void CoreSessionEventProcessor::processIrcEvent313(IrcEvent *e)
643 if (!checkParamCount(e, 1))
646 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
648 ircuser->setIrcOperator(e->params().last());
652 /* RPL_ENDOFWHO: "<name> :End of WHO list" */
653 void CoreSessionEventProcessor::processIrcEvent315(IrcEvent *e)
655 if (!checkParamCount(e, 1))
658 if (coreNetwork(e)->setAutoWhoDone(e->params()[0]))
659 e->setFlag(EventManager::Silent);
663 /* RPL_WHOISIDLE - "<nick> <integer> :seconds idle"
664 (real life: "<nick> <integer> <integer> :seconds idle, signon time) */
665 void CoreSessionEventProcessor::processIrcEvent317(IrcEvent *e)
667 if (!checkParamCount(e, 2))
672 int idleSecs = e->params()[1].toInt();
673 if (e->params().count() > 3) { // if we have more then 3 params we have the above mentioned "real life" situation
674 int logintime = e->params()[2].toInt();
675 loginTime = QDateTime::fromTime_t(logintime);
678 IrcUser *ircuser = e->network()->ircUser(e->params()[0]);
680 ircuser->setIdleTime(e->timestamp().addSecs(-idleSecs));
681 if (loginTime.isValid())
682 ircuser->setLoginTime(loginTime);
687 /* RPL_LIST - "<channel> <# visible> :<topic>" */
688 void CoreSessionEventProcessor::processIrcEvent322(IrcEvent *e)
690 if (!checkParamCount(e, 1))
694 quint32 userCount = 0;
697 switch (e->params().count()) {
699 topic = e->params()[2];
701 userCount = e->params()[1].toUInt();
703 channelName = e->params()[0];
707 if (coreSession()->ircListHelper()->addChannel(e->networkId(), channelName, userCount, topic))
708 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
712 /* RPL_LISTEND ":End of LIST" */
713 void CoreSessionEventProcessor::processIrcEvent323(IrcEvent *e)
715 if (!checkParamCount(e, 1))
718 if (coreSession()->ircListHelper()->endOfChannelList(e->networkId()))
719 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
723 /* RPL_CHANNELMODEIS - "<channel> <mode> <mode params>" */
724 void CoreSessionEventProcessor::processIrcEvent324(IrcEvent *e)
726 processIrcEventMode(e);
731 void CoreSessionEventProcessor::processIrcEvent331(IrcEvent *e)
733 if (!checkParamCount(e, 1))
736 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
738 chan->setTopic(QString());
743 void CoreSessionEventProcessor::processIrcEvent332(IrcEvent *e)
745 if (!checkParamCount(e, 2))
748 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
750 chan->setTopic(e->params()[1]);
754 /* RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
755 ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
756 void CoreSessionEventProcessor::processIrcEvent352(IrcEvent *e)
758 if (!checkParamCount(e, 6))
761 QString channel = e->params()[0];
762 IrcUser *ircuser = e->network()->ircUser(e->params()[4]);
764 ircuser->setUser(e->params()[1]);
765 ircuser->setHost(e->params()[2]);
767 bool away = e->params()[5].startsWith("G");
768 ircuser->setAway(away);
769 ircuser->setServer(e->params()[3]);
770 ircuser->setRealName(e->params().last().section(" ", 1));
773 if (coreNetwork(e)->isAutoWhoInProgress(channel))
774 e->setFlag(EventManager::Silent);
779 void CoreSessionEventProcessor::processIrcEvent353(IrcEvent *e)
781 if (!checkParamCount(e, 3))
784 // param[0] is either "=", "*" or "@" indicating a public, private or secret channel
785 // we don't use this information at the time beeing
786 QString channelname = e->params()[1];
788 IrcChannel *channel = e->network()->ircChannel(channelname);
790 qWarning() << Q_FUNC_INFO << "Received unknown target channel:" << channelname;
797 foreach(QString nick, e->params()[2].split(' ', QString::SkipEmptyParts)) {
800 if (e->network()->prefixes().contains(nick[0])) {
801 mode = e->network()->prefixToMode(nick[0]);
809 channel->joinIrcUsers(nicks, modes);
813 /* ERR_ERRONEUSNICKNAME */
814 void CoreSessionEventProcessor::processIrcEvent432(IrcEventNumeric *e)
816 if (!checkParamCount(e, 1))
820 if (e->params().count() < 2) {
821 // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
823 // :irc.scortum.moep.net 432 @@@ :Erroneous Nickname: Illegal characters
824 // correct server reply:
825 // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
826 e->params().prepend(e->target());
829 errnick = e->params()[0];
831 tryNextNick(e, errnick, true /* erroneus */);
835 /* ERR_NICKNAMEINUSE */
836 void CoreSessionEventProcessor::processIrcEvent433(IrcEventNumeric *e)
838 if (!checkParamCount(e, 1))
841 QString errnick = e->params().first();
843 // if there is a problem while connecting to the server -> we handle it
844 // but only if our connection has not been finished yet...
845 if (!e->network()->currentServer().isEmpty())
848 tryNextNick(e, errnick);
852 /* ERR_UNAVAILRESOURCE */
853 void CoreSessionEventProcessor::processIrcEvent437(IrcEventNumeric *e)
855 if (!checkParamCount(e, 1))
858 QString errnick = e->params().first();
860 // if there is a problem while connecting to the server -> we handle it
861 // but only if our connection has not been finished yet...
862 if (!e->network()->currentServer().isEmpty())
865 if (!e->network()->isChannelName(errnick))
866 tryNextNick(e, errnick);
871 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
872 if(!checkParamCount(e, 1))
878 /* Handle signals from Netsplit objects */
880 void CoreSessionEventProcessor::handleNetsplitJoin(Network *net,
881 const QString &channel,
882 const QStringList &users,
883 const QStringList &modes,
884 const QString &quitMessage)
886 IrcChannel *ircChannel = net->ircChannel(channel);
890 QList<IrcUser *> ircUsers;
891 QStringList newModes = modes;
892 QStringList newUsers = users;
894 foreach(const QString &user, users) {
895 IrcUser *iu = net->ircUser(nickFromMask(user));
898 else { // the user already quit
899 int idx = users.indexOf(user);
900 newUsers.removeAt(idx);
901 newModes.removeAt(idx);
905 ircChannel->joinIrcUsers(ircUsers, newModes);
906 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitJoin, net, channel, newUsers, quitMessage);
907 emit newEvent(event);
911 void CoreSessionEventProcessor::handleNetsplitQuit(Network *net, const QString &channel, const QStringList &users, const QString &quitMessage)
913 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitQuit, net, channel, users, quitMessage);
914 emit newEvent(event);
915 foreach(QString user, users) {
916 IrcUser *iu = net->ircUser(nickFromMask(user));
923 void CoreSessionEventProcessor::handleEarlyNetsplitJoin(Network *net, const QString &channel, const QStringList &users, const QStringList &modes)
925 IrcChannel *ircChannel = net->ircChannel(channel);
927 qDebug() << "handleEarlyNetsplitJoin(): channel " << channel << " invalid";
930 QList<NetworkEvent *> events;
931 QList<IrcUser *> ircUsers;
932 QStringList newModes = modes;
934 foreach(QString user, users) {
935 IrcUser *iu = net->updateNickFromMask(user);
938 // fake event for scripts that consume join events
939 events << new IrcEvent(EventManager::IrcEventJoin, net, iu->hostmask(), QStringList() << channel);
942 newModes.removeAt(users.indexOf(user));
945 ircChannel->joinIrcUsers(ircUsers, newModes);
946 foreach(NetworkEvent *event, events) {
947 event->setFlag(EventManager::Fake); // ignore this in here!
948 emit newEvent(event);
953 void CoreSessionEventProcessor::handleNetsplitFinished()
955 Netsplit *n = qobject_cast<Netsplit *>(sender());
957 QHash<QString, Netsplit *> splithash = _netsplits.take(n->network());
958 splithash.remove(splithash.key(n));
959 if (splithash.count())
960 _netsplits[n->network()] = splithash;
965 void CoreSessionEventProcessor::destroyNetsplits(NetworkId netId)
967 Network *net = coreSession()->network(netId);
971 QHash<QString, Netsplit *> splits = _netsplits.take(net);
976 /*******************************/
977 /******** CTCP HANDLING ********/
978 /*******************************/
980 void CoreSessionEventProcessor::processCtcpEvent(CtcpEvent *e)
982 if (e->testFlag(EventManager::Self))
983 return; // ignore ctcp events generated by user input
985 if (e->type() != EventManager::CtcpEvent || e->ctcpType() != CtcpEvent::Query)
988 handle(e->ctcpCmd(), Q_ARG(CtcpEvent *, e));
992 void CoreSessionEventProcessor::defaultHandler(const QString &ctcpCmd, CtcpEvent *e)
994 // This handler is only there to avoid warnings for unknown CTCPs
1000 void CoreSessionEventProcessor::handleCtcpAction(CtcpEvent *e)
1002 // This handler is only there to feed CLIENTINFO
1007 void CoreSessionEventProcessor::handleCtcpClientinfo(CtcpEvent *e)
1009 QStringList supportedHandlers;
1010 foreach(QString handler, providesHandlers())
1011 supportedHandlers << handler.toUpper();
1012 qSort(supportedHandlers);
1013 e->setReply(supportedHandlers.join(" "));
1017 void CoreSessionEventProcessor::handleCtcpPing(CtcpEvent *e)
1019 e->setReply(e->param().isNull() ? "" : e->param());
1023 void CoreSessionEventProcessor::handleCtcpTime(CtcpEvent *e)
1025 e->setReply(QDateTime::currentDateTime().toString());
1029 void CoreSessionEventProcessor::handleCtcpVersion(CtcpEvent *e)
1031 e->setReply(QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
1032 .arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate));