1 /***************************************************************************
2 * Copyright (C) 2005-2015 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 "coretransfer.h"
27 #include "coretransfermanager.h"
28 #include "ctcpevent.h"
32 #include "messageevent.h"
37 # include "keyevent.h"
40 CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session)
41 : BasicHandler("handleCtcp", session),
44 connect(coreSession(), SIGNAL(networkDisconnected(NetworkId)), this, SLOT(destroyNetsplits(NetworkId)));
45 connect(this, SIGNAL(newEvent(Event *)), coreSession()->eventManager(), SLOT(postEvent(Event *)));
49 bool CoreSessionEventProcessor::checkParamCount(IrcEvent *e, int minParams)
51 if (e->params().count() < minParams) {
52 if (e->type() == EventManager::IrcEventNumeric) {
53 qWarning() << "Command " << static_cast<IrcEventNumeric *>(e)->number() << " requires " << minParams << "params, got: " << e->params();
56 QString name = coreSession()->eventManager()->enumName(e->type());
57 qWarning() << qPrintable(name) << "requires" << minParams << "params, got:" << e->params();
66 void CoreSessionEventProcessor::tryNextNick(NetworkEvent *e, const QString &errnick, bool erroneus)
68 QStringList desiredNicks = coreSession()->identity(e->network()->identity())->nicks();
69 int nextNickIdx = desiredNicks.indexOf(errnick) + 1;
71 if (nextNickIdx > 0 && desiredNicks.size() > nextNickIdx) {
72 nextNick = desiredNicks[nextNickIdx];
76 // FIXME Make this an ErrorEvent or something like that, so it's translated in the client
77 MessageEvent *msgEvent = new MessageEvent(Message::Error, e->network(),
78 tr("No free and valid nicks in nicklist found. use: /nick <othernick> to continue"),
79 QString(), QString(), Message::None, e->timestamp());
80 emit newEvent(msgEvent);
84 nextNick = errnick + "_";
87 // FIXME Use a proper output event for this
88 coreNetwork(e)->putRawLine("NICK " + coreNetwork(e)->encodeServerString(nextNick));
92 void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e)
94 switch (e->number()) {
101 qobject_cast<CoreNetwork *>(e->network())->putRawLine("CAP END");
110 void CoreSessionEventProcessor::processIrcEventAuthenticate(IrcEvent *e)
112 if (!checkParamCount(e, 1))
115 if (e->params().at(0) != "+") {
116 qWarning() << "Invalid AUTHENTICATE" << e;
120 CoreNetwork *net = coreNetwork(e);
123 if (net->identityPtr()->sslCert().isNull()) {
125 QString construct = net->saslAccount();
126 construct.append(QChar(QChar::Null));
127 construct.append(net->saslAccount());
128 construct.append(QChar(QChar::Null));
129 construct.append(net->saslPassword());
130 QByteArray saslData = QByteArray(construct.toLatin1().toBase64());
131 saslData.prepend("AUTHENTICATE ");
132 net->putRawLine(saslData);
135 net->putRawLine("AUTHENTICATE +");
141 void CoreSessionEventProcessor::processIrcEventCap(IrcEvent *e)
143 // for SASL, there will only be a single param of 'sasl', however you can check here for
144 // additional CAP messages (ls, multi-prefix, et cetera).
146 if (e->params().count() == 3) {
147 if (e->params().at(1) == "NAK") {
148 // CAP REQ sasl was denied
149 coreNetwork(e)->putRawLine("CAP END");
151 else if (e->params().at(1) == "ACK") {
152 if (e->params().at(2).startsWith("sasl")) { // Freenode (at least) sends "sasl " with a trailing space for some reason!
154 // if the current identity has a cert set, use SASL EXTERNAL
156 if (!coreNetwork(e)->identityPtr()->sslCert().isNull()) {
157 coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE EXTERNAL"));
160 // Only working with PLAIN atm, blowfish later
161 coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE PLAIN"));
171 void CoreSessionEventProcessor::processIrcEventInvite(IrcEvent *e)
173 if (checkParamCount(e, 2)) {
174 e->network()->updateNickFromMask(e->prefix());
179 void CoreSessionEventProcessor::processIrcEventJoin(IrcEvent *e)
181 if (e->testFlag(EventManager::Fake)) // generated by handleEarlyNetsplitJoin
184 if (!checkParamCount(e, 1))
187 CoreNetwork *net = coreNetwork(e);
188 QString channel = e->params()[0];
189 IrcUser *ircuser = net->updateNickFromMask(e->prefix());
191 bool handledByNetsplit = false;
192 foreach(Netsplit* n, _netsplits.value(e->network())) {
193 handledByNetsplit = n->userJoined(e->prefix(), channel);
194 if (handledByNetsplit)
198 if (!handledByNetsplit)
199 ircuser->joinChannel(channel);
201 e->setFlag(EventManager::Netsplit);
203 if (net->isMe(ircuser)) {
204 net->setChannelJoined(channel);
206 net->putRawLine(net->serverEncode("MODE " + channel)); // we want to know the modes of the channel we just joined, so we ask politely
211 void CoreSessionEventProcessor::lateProcessIrcEventKick(IrcEvent *e)
213 if (checkParamCount(e, 2)) {
214 e->network()->updateNickFromMask(e->prefix());
215 IrcUser *victim = e->network()->ircUser(e->params().at(1));
217 victim->partChannel(e->params().at(0));
218 //if(e->network()->isMe(victim)) e->network()->setKickedFromChannel(channel);
224 void CoreSessionEventProcessor::processIrcEventMode(IrcEvent *e)
226 if (!checkParamCount(e, 2))
229 if (e->network()->isChannelName(e->params().first())) {
232 IrcChannel *channel = e->network()->ircChannel(e->params()[0]);
234 // we received mode information for a channel we're not in. that means probably we've just been kicked out or something like that
235 // anyways: we don't have a place to store the data --> discard the info.
239 QString modes = e->params()[1];
242 for (int c = 0; c < modes.length(); c++) {
243 if (modes[c] == '+') {
247 if (modes[c] == '-') {
252 if (e->network()->prefixModes().contains(modes[c])) {
253 // user channel modes (op, voice, etc...)
254 if (paramOffset < e->params().count()) {
255 IrcUser *ircUser = e->network()->ircUser(e->params()[paramOffset]);
257 qWarning() << Q_FUNC_INFO << "Unknown IrcUser:" << e->params()[paramOffset];
261 bool handledByNetsplit = false;
262 QHash<QString, Netsplit *> splits = _netsplits.value(e->network());
263 foreach(Netsplit* n, _netsplits.value(e->network())) {
264 handledByNetsplit = n->userAlreadyJoined(ircUser->hostmask(), channel->name());
265 if (handledByNetsplit) {
266 n->addMode(ircUser->hostmask(), channel->name(), QString(modes[c]));
270 if (!handledByNetsplit)
271 channel->addUserMode(ircUser, QString(modes[c]));
274 channel->removeUserMode(ircUser, QString(modes[c]));
278 qWarning() << "Received MODE with too few parameters:" << e->params();
283 // regular channel modes
285 Network::ChannelModeType modeType = e->network()->channelModeType(modes[c]);
286 if (modeType == Network::A_CHANMODE || modeType == Network::B_CHANMODE || (modeType == Network::C_CHANMODE && add)) {
287 if (paramOffset < e->params().count()) {
288 value = e->params()[paramOffset];
291 qWarning() << "Received MODE with too few parameters:" << e->params();
297 channel->addChannelMode(modes[c], value);
299 channel->removeChannelMode(modes[c], value);
305 IrcUser *ircUser = e->network()->newIrcUser(e->params().first());
306 QString modeString(e->params()[1]);
310 for (int c = 0; c < modeString.count(); c++) {
311 if (modeString[c] == '+') {
315 if (modeString[c] == '-') {
320 addModes += modeString[c];
322 removeModes += modeString[c];
324 if (!addModes.isEmpty())
325 ircUser->addUserModes(addModes);
326 if (!removeModes.isEmpty())
327 ircUser->removeUserModes(removeModes);
329 if (e->network()->isMe(ircUser)) {
330 coreNetwork(e)->updatePersistentModes(addModes, removeModes);
336 void CoreSessionEventProcessor::lateProcessIrcEventNick(IrcEvent *e)
338 if (checkParamCount(e, 1)) {
339 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
341 qWarning() << Q_FUNC_INFO << "Unknown IrcUser!";
344 QString newnick = e->params().at(0);
345 QString oldnick = ircuser->nick();
347 // the order is cruicial
348 // otherwise the client would rename the buffer, see that the assigned ircuser doesn't match anymore
349 // and remove the ircuser from the querybuffer leading to a wrong on/offline state
350 ircuser->setNick(newnick);
351 coreSession()->renameBuffer(e->networkId(), newnick, oldnick);
356 void CoreSessionEventProcessor::lateProcessIrcEventPart(IrcEvent *e)
358 if (checkParamCount(e, 1)) {
359 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
361 qWarning() << Q_FUNC_INFO<< "Unknown IrcUser!";
364 QString channel = e->params().at(0);
365 ircuser->partChannel(channel);
366 if (e->network()->isMe(ircuser))
367 qobject_cast<CoreNetwork *>(e->network())->setChannelParted(channel);
372 void CoreSessionEventProcessor::processIrcEventPing(IrcEvent *e)
374 QString param = e->params().count() ? e->params().first() : QString();
376 // Take priority so this won't get stuck behind other queued messages.
377 coreNetwork(e)->putRawLine("PONG " + coreNetwork(e)->serverEncode(param), true);
381 void CoreSessionEventProcessor::processIrcEventPong(IrcEvent *e)
383 // the server is supposed to send back what we passed as param. and we send a timestamp
384 // but using quote and whatnought one can send arbitrary pings, so we have to do some sanity checks
385 if (checkParamCount(e, 2)) {
386 QString timestamp = e->params().at(1);
387 QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz");
388 if (sendTime.isValid())
389 e->network()->setLatency(sendTime.msecsTo(QTime::currentTime()) / 2);
394 void CoreSessionEventProcessor::processIrcEventQuit(IrcEvent *e)
396 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
401 if (e->params().count() > 0)
402 msg = e->params()[0];
405 if (Netsplit::isNetsplit(msg)) {
407 if (!_netsplits[e->network()].contains(msg)) {
408 n = new Netsplit(e->network(), this);
409 connect(n, SIGNAL(finished()), this, SLOT(handleNetsplitFinished()));
410 connect(n, SIGNAL(netsplitJoin(Network*, QString, QStringList, QStringList, QString)),
411 this, SLOT(handleNetsplitJoin(Network*, QString, QStringList, QStringList, QString)));
412 connect(n, SIGNAL(netsplitQuit(Network*, QString, QStringList, QString)),
413 this, SLOT(handleNetsplitQuit(Network*, QString, QStringList, QString)));
414 connect(n, SIGNAL(earlyJoin(Network*, QString, QStringList, QStringList)),
415 this, SLOT(handleEarlyNetsplitJoin(Network*, QString, QStringList, QStringList)));
416 _netsplits[e->network()].insert(msg, n);
419 n = _netsplits[e->network()][msg];
421 // add this user to the netsplit
422 n->userQuit(e->prefix(), ircuser->channels(), msg);
423 e->setFlag(EventManager::Netsplit);
425 // normal quit is handled in lateProcessIrcEventQuit()
429 void CoreSessionEventProcessor::lateProcessIrcEventQuit(IrcEvent *e)
431 if (e->testFlag(EventManager::Netsplit))
434 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
442 void CoreSessionEventProcessor::processIrcEventTopic(IrcEvent *e)
444 if (checkParamCount(e, 2)) {
445 e->network()->updateNickFromMask(e->prefix());
446 IrcChannel *channel = e->network()->ircChannel(e->params().at(0));
448 channel->setTopic(e->params().at(1));
454 void CoreSessionEventProcessor::processKeyEvent(KeyEvent *e)
456 if (!Cipher::neededFeaturesAvailable()) {
457 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()));
460 CoreNetwork *net = qobject_cast<CoreNetwork*>(e->network());
461 Cipher *c = net->cipher(e->target());
462 if (!c) // happens when there is no CoreIrcChannel for the target (i.e. never?)
465 if (e->exchangeType() == KeyEvent::Init) {
466 QByteArray pubKey = c->parseInitKeyX(e->key());
467 if (pubKey.isEmpty()) {
468 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()));
471 net->setCipherKey(e->target(), c->key());
472 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()));
474 p << net->serverEncode(e->target()) << net->serverEncode("DH1080_FINISH ")+pubKey;
475 net->putCmd("NOTICE", p);
478 if (c->parseFinishKeyX(e->key())) {
479 net->setCipherKey(e->target(), c->key());
480 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()));
482 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()));
490 void CoreSessionEventProcessor::processIrcEvent001(IrcEventNumeric *e)
492 e->network()->setCurrentServer(e->prefix());
493 e->network()->setMyNick(e->target());
498 // TODO Complete 005 handling, also use sensible defaults for non-sent stuff
499 void CoreSessionEventProcessor::processIrcEvent005(IrcEvent *e)
501 if (!checkParamCount(e, 1))
505 for (int i = 0; i < e->params().count() - 1; i++) {
506 QString key = e->params()[i].section("=", 0, 0);
507 QString value = e->params()[i].section("=", 1);
508 e->network()->addSupport(key, value);
511 /* determine our prefixes here to get an accurate result */
512 e->network()->determinePrefixes();
516 /* RPL_UMODEIS - "<user_modes> [<user_mode_params>]" */
517 void CoreSessionEventProcessor::processIrcEvent221(IrcEvent *)
519 // TODO: save information in network object
523 /* RPL_STATSCONN - "Highest connection cout: 8000 (7999 clients)" */
524 void CoreSessionEventProcessor::processIrcEvent250(IrcEvent *)
526 // TODO: save information in network object
530 /* RPL_LOCALUSERS - "Current local user: 5024 Max: 7999 */
531 void CoreSessionEventProcessor::processIrcEvent265(IrcEvent *)
533 // TODO: save information in network object
537 /* RPL_GLOBALUSERS - "Current global users: 46093 Max: 47650" */
538 void CoreSessionEventProcessor::processIrcEvent266(IrcEvent *)
540 // TODO: save information in network object
546 Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
548 "<nick> :<away message>"
550 Replies 352 and 315 paired are used to answer a WHO message.
553 Replies 314 and 369 are responses to a WHOWAS message.
557 /* RPL_AWAY - "<nick> :<away message>" */
558 void CoreSessionEventProcessor::processIrcEvent301(IrcEvent *e)
560 if (!checkParamCount(e, 2))
563 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
565 ircuser->setAway(true);
566 ircuser->setAwayMessage(e->params().at(1));
567 //ircuser->setLastAwayMessage(now);
572 /* RPL_UNAWAY - ":You are no longer marked as being away" */
573 void CoreSessionEventProcessor::processIrcEvent305(IrcEvent *e)
575 IrcUser *me = e->network()->me();
579 if (e->network()->autoAwayActive()) {
580 e->network()->setAutoAwayActive(false);
581 e->setFlag(EventManager::Silent);
586 /* RPL_NOWAWAY - ":You have been marked as being away" */
587 void CoreSessionEventProcessor::processIrcEvent306(IrcEvent *e)
589 IrcUser *me = e->network()->me();
595 /* RPL_WHOISSERVICE - "<user> is registered nick" */
596 void CoreSessionEventProcessor::processIrcEvent307(IrcEvent *e)
598 if (!checkParamCount(e, 1))
601 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
603 ircuser->setWhoisServiceReply(e->params().join(" "));
607 /* RPL_SUSERHOST - "<user> is available for help." */
608 void CoreSessionEventProcessor::processIrcEvent310(IrcEvent *e)
610 if (!checkParamCount(e, 1))
613 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
615 ircuser->setSuserHost(e->params().join(" "));
619 /* RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
620 void CoreSessionEventProcessor::processIrcEvent311(IrcEvent *e)
622 if (!checkParamCount(e, 3))
625 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
627 ircuser->setUser(e->params().at(1));
628 ircuser->setHost(e->params().at(2));
629 ircuser->setRealName(e->params().last());
634 /* RPL_WHOISSERVER - "<nick> <server> :<server info>" */
635 void CoreSessionEventProcessor::processIrcEvent312(IrcEvent *e)
637 if (!checkParamCount(e, 2))
640 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
642 ircuser->setServer(e->params().at(1));
646 /* RPL_WHOISOPERATOR - "<nick> :is an IRC operator" */
647 void CoreSessionEventProcessor::processIrcEvent313(IrcEvent *e)
649 if (!checkParamCount(e, 1))
652 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
654 ircuser->setIrcOperator(e->params().last());
658 /* RPL_ENDOFWHO: "<name> :End of WHO list" */
659 void CoreSessionEventProcessor::processIrcEvent315(IrcEvent *e)
661 if (!checkParamCount(e, 1))
664 if (coreNetwork(e)->setAutoWhoDone(e->params()[0]))
665 e->setFlag(EventManager::Silent);
669 /* RPL_WHOISIDLE - "<nick> <integer> :seconds idle"
670 (real life: "<nick> <integer> <integer> :seconds idle, signon time) */
671 void CoreSessionEventProcessor::processIrcEvent317(IrcEvent *e)
673 if (!checkParamCount(e, 2))
678 int idleSecs = e->params()[1].toInt();
679 if (e->params().count() > 3) { // if we have more then 3 params we have the above mentioned "real life" situation
680 int logintime = e->params()[2].toInt();
681 loginTime = QDateTime::fromTime_t(logintime);
684 IrcUser *ircuser = e->network()->ircUser(e->params()[0]);
686 ircuser->setIdleTime(e->timestamp().addSecs(-idleSecs));
687 if (loginTime.isValid())
688 ircuser->setLoginTime(loginTime);
693 /* RPL_LIST - "<channel> <# visible> :<topic>" */
694 void CoreSessionEventProcessor::processIrcEvent322(IrcEvent *e)
696 if (!checkParamCount(e, 1))
700 quint32 userCount = 0;
703 switch (e->params().count()) {
705 topic = e->params()[2];
707 userCount = e->params()[1].toUInt();
709 channelName = e->params()[0];
713 if (coreSession()->ircListHelper()->addChannel(e->networkId(), channelName, userCount, topic))
714 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
718 /* RPL_LISTEND ":End of LIST" */
719 void CoreSessionEventProcessor::processIrcEvent323(IrcEvent *e)
721 if (!checkParamCount(e, 1))
724 if (coreSession()->ircListHelper()->endOfChannelList(e->networkId()))
725 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
729 /* RPL_CHANNELMODEIS - "<channel> <mode> <mode params>" */
730 void CoreSessionEventProcessor::processIrcEvent324(IrcEvent *e)
732 processIrcEventMode(e);
737 void CoreSessionEventProcessor::processIrcEvent331(IrcEvent *e)
739 if (!checkParamCount(e, 1))
742 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
744 chan->setTopic(QString());
749 void CoreSessionEventProcessor::processIrcEvent332(IrcEvent *e)
751 if (!checkParamCount(e, 2))
754 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
756 chan->setTopic(e->params()[1]);
760 /* RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
761 ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
762 void CoreSessionEventProcessor::processIrcEvent352(IrcEvent *e)
764 if (!checkParamCount(e, 6))
767 QString channel = e->params()[0];
768 IrcUser *ircuser = e->network()->ircUser(e->params()[4]);
770 ircuser->setUser(e->params()[1]);
771 ircuser->setHost(e->params()[2]);
773 bool away = e->params()[5].startsWith("G");
774 ircuser->setAway(away);
775 ircuser->setServer(e->params()[3]);
776 ircuser->setRealName(e->params().last().section(" ", 1));
779 if (coreNetwork(e)->isAutoWhoInProgress(channel))
780 e->setFlag(EventManager::Silent);
785 void CoreSessionEventProcessor::processIrcEvent353(IrcEvent *e)
787 if (!checkParamCount(e, 3))
790 // param[0] is either "=", "*" or "@" indicating a public, private or secret channel
791 // we don't use this information at the time beeing
792 QString channelname = e->params()[1];
794 IrcChannel *channel = e->network()->ircChannel(channelname);
796 qWarning() << Q_FUNC_INFO << "Received unknown target channel:" << channelname;
803 foreach(QString nick, e->params()[2].split(' ', QString::SkipEmptyParts)) {
806 if (e->network()->prefixes().contains(nick[0])) {
807 mode = e->network()->prefixToMode(nick[0]);
815 channel->joinIrcUsers(nicks, modes);
819 /* ERR_ERRONEUSNICKNAME */
820 void CoreSessionEventProcessor::processIrcEvent432(IrcEventNumeric *e)
822 if (!checkParamCount(e, 1))
826 if (e->params().count() < 2) {
827 // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
829 // :irc.scortum.moep.net 432 @@@ :Erroneous Nickname: Illegal characters
830 // correct server reply:
831 // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
832 e->params().prepend(e->target());
835 errnick = e->params()[0];
837 tryNextNick(e, errnick, true /* erroneus */);
841 /* ERR_NICKNAMEINUSE */
842 void CoreSessionEventProcessor::processIrcEvent433(IrcEventNumeric *e)
844 if (!checkParamCount(e, 1))
847 QString errnick = e->params().first();
849 // if there is a problem while connecting to the server -> we handle it
850 // but only if our connection has not been finished yet...
851 if (!e->network()->currentServer().isEmpty())
854 tryNextNick(e, errnick);
858 /* ERR_UNAVAILRESOURCE */
859 void CoreSessionEventProcessor::processIrcEvent437(IrcEventNumeric *e)
861 if (!checkParamCount(e, 1))
864 QString errnick = e->params().first();
866 // if there is a problem while connecting to the server -> we handle it
867 // but only if our connection has not been finished yet...
868 if (!e->network()->currentServer().isEmpty())
871 if (!e->network()->isChannelName(errnick))
872 tryNextNick(e, errnick);
877 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
878 if(!checkParamCount(e, 1))
884 /* Handle signals from Netsplit objects */
886 void CoreSessionEventProcessor::handleNetsplitJoin(Network *net,
887 const QString &channel,
888 const QStringList &users,
889 const QStringList &modes,
890 const QString &quitMessage)
892 IrcChannel *ircChannel = net->ircChannel(channel);
896 QList<IrcUser *> ircUsers;
897 QStringList newModes = modes;
898 QStringList newUsers = users;
900 foreach(const QString &user, users) {
901 IrcUser *iu = net->ircUser(nickFromMask(user));
904 else { // the user already quit
905 int idx = users.indexOf(user);
906 newUsers.removeAt(idx);
907 newModes.removeAt(idx);
911 ircChannel->joinIrcUsers(ircUsers, newModes);
912 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitJoin, net, channel, newUsers, quitMessage);
913 emit newEvent(event);
917 void CoreSessionEventProcessor::handleNetsplitQuit(Network *net, const QString &channel, const QStringList &users, const QString &quitMessage)
919 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitQuit, net, channel, users, quitMessage);
920 emit newEvent(event);
921 foreach(QString user, users) {
922 IrcUser *iu = net->ircUser(nickFromMask(user));
929 void CoreSessionEventProcessor::handleEarlyNetsplitJoin(Network *net, const QString &channel, const QStringList &users, const QStringList &modes)
931 IrcChannel *ircChannel = net->ircChannel(channel);
933 qDebug() << "handleEarlyNetsplitJoin(): channel " << channel << " invalid";
936 QList<NetworkEvent *> events;
937 QList<IrcUser *> ircUsers;
938 QStringList newModes = modes;
940 foreach(QString user, users) {
941 IrcUser *iu = net->updateNickFromMask(user);
944 // fake event for scripts that consume join events
945 events << new IrcEvent(EventManager::IrcEventJoin, net, iu->hostmask(), QStringList() << channel);
948 newModes.removeAt(users.indexOf(user));
951 ircChannel->joinIrcUsers(ircUsers, newModes);
952 foreach(NetworkEvent *event, events) {
953 event->setFlag(EventManager::Fake); // ignore this in here!
954 emit newEvent(event);
959 void CoreSessionEventProcessor::handleNetsplitFinished()
961 Netsplit *n = qobject_cast<Netsplit *>(sender());
963 QHash<QString, Netsplit *> splithash = _netsplits.take(n->network());
964 splithash.remove(splithash.key(n));
965 if (splithash.count())
966 _netsplits[n->network()] = splithash;
971 void CoreSessionEventProcessor::destroyNetsplits(NetworkId netId)
973 Network *net = coreSession()->network(netId);
977 QHash<QString, Netsplit *> splits = _netsplits.take(net);
982 /*******************************/
983 /******** CTCP HANDLING ********/
984 /*******************************/
986 void CoreSessionEventProcessor::processCtcpEvent(CtcpEvent *e)
988 if (e->testFlag(EventManager::Self))
989 return; // ignore ctcp events generated by user input
991 if (e->type() != EventManager::CtcpEvent || e->ctcpType() != CtcpEvent::Query)
994 handle(e->ctcpCmd(), Q_ARG(CtcpEvent *, e));
998 void CoreSessionEventProcessor::defaultHandler(const QString &ctcpCmd, CtcpEvent *e)
1000 // This handler is only there to avoid warnings for unknown CTCPs
1006 void CoreSessionEventProcessor::handleCtcpAction(CtcpEvent *e)
1008 // This handler is only there to feed CLIENTINFO
1013 void CoreSessionEventProcessor::handleCtcpClientinfo(CtcpEvent *e)
1015 QStringList supportedHandlers;
1016 foreach(QString handler, providesHandlers())
1017 supportedHandlers << handler.toUpper();
1018 qSort(supportedHandlers);
1019 e->setReply(supportedHandlers.join(" "));
1023 // http://www.irchelp.org/irchelp/rfc/ctcpspec.html
1024 // http://en.wikipedia.org/wiki/Direct_Client-to-Client
1025 void CoreSessionEventProcessor::handleCtcpDcc(CtcpEvent *e)
1027 // DCC support is unfinished, experimental and potentially dangerous, so make it opt-in
1028 if (!Quassel::isOptionSet("enable-experimental-dcc")) {
1029 quInfo() << "DCC disabled, start core with --enable-experimental-dcc if you really want to try it out";
1033 // normal: SEND <filename> <ip> <port> [<filesize>]
1034 // reverse: SEND <filename> <ip> 0 <filesize> <token>
1035 QStringList params = e->param().split(' ');
1036 if (params.count()) {
1037 QString cmd = params[0].toUpper();
1038 if (cmd == "SEND") {
1039 if (params.count() < 4) {
1040 qWarning() << "Invalid DCC SEND request:" << e; // TODO emit proper error to client
1043 QString filename = params[1];
1044 QHostAddress address;
1045 quint16 port = params[3].toUShort();
1047 QString numIp = params[2]; // this is either IPv4 as a 32 bit value, or IPv6 (which always contains a colon)
1048 if (numIp.contains(':')) { // IPv6
1049 if (!address.setAddress(numIp)) {
1050 qWarning() << "Invalid IPv6:" << numIp;
1055 address.setAddress(numIp.toUInt());
1058 if (port == 0) { // Reverse DCC is indicated by a 0 port
1059 emit newEvent(new MessageEvent(Message::Error, e->network(), tr("Reverse DCC SEND not supported"), e->prefix(), e->target(), Message::None, e->timestamp()));
1063 qWarning() << "Privileged port requested:" << port; // FIXME ask user if this is ok
1067 if (params.count() > 4) { // filesize is optional
1068 size = params[4].toULong();
1071 // TODO: check if target is the right thing to use for the partner
1072 CoreTransfer *transfer = new CoreTransfer(Transfer::Receive, e->target(), filename, address, port, size, this);
1073 coreSession()->signalProxy()->synchronize(transfer);
1074 coreSession()->transferManager()->addTransfer(transfer);
1077 emit newEvent(new MessageEvent(Message::Error, e->network(), tr("DCC %1 not supported").arg(cmd), e->prefix(), e->target(), Message::None, e->timestamp()));
1084 void CoreSessionEventProcessor::handleCtcpPing(CtcpEvent *e)
1086 e->setReply(e->param().isNull() ? "" : e->param());
1090 void CoreSessionEventProcessor::handleCtcpTime(CtcpEvent *e)
1092 e->setReply(QDateTime::currentDateTime().toString());
1096 void CoreSessionEventProcessor::handleCtcpVersion(CtcpEvent *e)
1098 e->setReply(QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
1099 .arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().commitDate));