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 "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(2).startsWith("sasl")) { // Freenode (at least) sends "sasl " with a trailing space for some reason!
149 // if the current identity has a cert set, use SASL EXTERNAL
151 if (!coreNetwork(e)->identityPtr()->sslCert().isNull()) {
152 coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE EXTERNAL"));
155 // Only working with PLAIN atm, blowfish later
156 coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE PLAIN"));
165 void CoreSessionEventProcessor::processIrcEventInvite(IrcEvent *e)
167 if (checkParamCount(e, 2)) {
168 e->network()->updateNickFromMask(e->prefix());
173 void CoreSessionEventProcessor::processIrcEventJoin(IrcEvent *e)
175 if (e->testFlag(EventManager::Fake)) // generated by handleEarlyNetsplitJoin
178 if (!checkParamCount(e, 1))
181 CoreNetwork *net = coreNetwork(e);
182 QString channel = e->params()[0];
183 IrcUser *ircuser = net->updateNickFromMask(e->prefix());
185 bool handledByNetsplit = false;
186 foreach(Netsplit* n, _netsplits.value(e->network())) {
187 handledByNetsplit = n->userJoined(e->prefix(), channel);
188 if (handledByNetsplit)
192 if (!handledByNetsplit)
193 ircuser->joinChannel(channel);
195 e->setFlag(EventManager::Netsplit);
197 if (net->isMe(ircuser)) {
198 net->setChannelJoined(channel);
200 net->putRawLine(net->serverEncode("MODE " + channel)); // we want to know the modes of the channel we just joined, so we ask politely
205 void CoreSessionEventProcessor::lateProcessIrcEventKick(IrcEvent *e)
207 if (checkParamCount(e, 2)) {
208 e->network()->updateNickFromMask(e->prefix());
209 IrcUser *victim = e->network()->ircUser(e->params().at(1));
211 victim->partChannel(e->params().at(0));
212 //if(e->network()->isMe(victim)) e->network()->setKickedFromChannel(channel);
218 void CoreSessionEventProcessor::processIrcEventMode(IrcEvent *e)
220 if (!checkParamCount(e, 2))
223 if (e->network()->isChannelName(e->params().first())) {
226 IrcChannel *channel = e->network()->ircChannel(e->params()[0]);
228 // we received mode information for a channel we're not in. that means probably we've just been kicked out or something like that
229 // anyways: we don't have a place to store the data --> discard the info.
233 QString modes = e->params()[1];
236 for (int c = 0; c < modes.length(); c++) {
237 if (modes[c] == '+') {
241 if (modes[c] == '-') {
246 if (e->network()->prefixModes().contains(modes[c])) {
247 // user channel modes (op, voice, etc...)
248 if (paramOffset < e->params().count()) {
249 IrcUser *ircUser = e->network()->ircUser(e->params()[paramOffset]);
251 qWarning() << Q_FUNC_INFO << "Unknown IrcUser:" << e->params()[paramOffset];
255 bool handledByNetsplit = false;
256 QHash<QString, Netsplit *> splits = _netsplits.value(e->network());
257 foreach(Netsplit* n, _netsplits.value(e->network())) {
258 handledByNetsplit = n->userAlreadyJoined(ircUser->hostmask(), channel->name());
259 if (handledByNetsplit) {
260 n->addMode(ircUser->hostmask(), channel->name(), QString(modes[c]));
264 if (!handledByNetsplit)
265 channel->addUserMode(ircUser, QString(modes[c]));
268 channel->removeUserMode(ircUser, QString(modes[c]));
272 qWarning() << "Received MODE with too few parameters:" << e->params();
277 // regular channel modes
279 Network::ChannelModeType modeType = e->network()->channelModeType(modes[c]);
280 if (modeType == Network::A_CHANMODE || modeType == Network::B_CHANMODE || (modeType == Network::C_CHANMODE && add)) {
281 if (paramOffset < e->params().count()) {
282 value = e->params()[paramOffset];
285 qWarning() << "Received MODE with too few parameters:" << e->params();
291 channel->addChannelMode(modes[c], value);
293 channel->removeChannelMode(modes[c], value);
299 IrcUser *ircUser = e->network()->newIrcUser(e->params().first());
300 QString modeString(e->params()[1]);
304 for (int c = 0; c < modeString.count(); c++) {
305 if (modeString[c] == '+') {
309 if (modeString[c] == '-') {
314 addModes += modeString[c];
316 removeModes += modeString[c];
318 if (!addModes.isEmpty())
319 ircUser->addUserModes(addModes);
320 if (!removeModes.isEmpty())
321 ircUser->removeUserModes(removeModes);
323 if (e->network()->isMe(ircUser)) {
324 coreNetwork(e)->updatePersistentModes(addModes, removeModes);
330 void CoreSessionEventProcessor::lateProcessIrcEventNick(IrcEvent *e)
332 if (checkParamCount(e, 1)) {
333 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
335 qWarning() << Q_FUNC_INFO << "Unknown IrcUser!";
338 QString newnick = e->params().at(0);
339 QString oldnick = ircuser->nick();
341 // the order is cruicial
342 // otherwise the client would rename the buffer, see that the assigned ircuser doesn't match anymore
343 // and remove the ircuser from the querybuffer leading to a wrong on/offline state
344 ircuser->setNick(newnick);
345 coreSession()->renameBuffer(e->networkId(), newnick, oldnick);
350 void CoreSessionEventProcessor::lateProcessIrcEventPart(IrcEvent *e)
352 if (checkParamCount(e, 1)) {
353 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
355 qWarning() << Q_FUNC_INFO<< "Unknown IrcUser!";
358 QString channel = e->params().at(0);
359 ircuser->partChannel(channel);
360 if (e->network()->isMe(ircuser))
361 qobject_cast<CoreNetwork *>(e->network())->setChannelParted(channel);
366 void CoreSessionEventProcessor::processIrcEventPing(IrcEvent *e)
368 QString param = e->params().count() ? e->params().first() : QString();
370 coreNetwork(e)->putRawLine("PONG " + coreNetwork(e)->serverEncode(param));
374 void CoreSessionEventProcessor::processIrcEventPong(IrcEvent *e)
376 // the server is supposed to send back what we passed as param. and we send a timestamp
377 // but using quote and whatnought one can send arbitrary pings, so we have to do some sanity checks
378 if (checkParamCount(e, 2)) {
379 QString timestamp = e->params().at(1);
380 QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz");
381 if (sendTime.isValid())
382 e->network()->setLatency(sendTime.msecsTo(QTime::currentTime()) / 2);
387 void CoreSessionEventProcessor::processIrcEventQuit(IrcEvent *e)
389 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
394 if (e->params().count() > 0)
395 msg = e->params()[0];
398 if (Netsplit::isNetsplit(msg)) {
400 if (!_netsplits[e->network()].contains(msg)) {
401 n = new Netsplit(e->network(), this);
402 connect(n, SIGNAL(finished()), this, SLOT(handleNetsplitFinished()));
403 connect(n, SIGNAL(netsplitJoin(Network*, QString, QStringList, QStringList, QString)),
404 this, SLOT(handleNetsplitJoin(Network*, QString, QStringList, QStringList, QString)));
405 connect(n, SIGNAL(netsplitQuit(Network*, QString, QStringList, QString)),
406 this, SLOT(handleNetsplitQuit(Network*, QString, QStringList, QString)));
407 connect(n, SIGNAL(earlyJoin(Network*, QString, QStringList, QStringList)),
408 this, SLOT(handleEarlyNetsplitJoin(Network*, QString, QStringList, QStringList)));
409 _netsplits[e->network()].insert(msg, n);
412 n = _netsplits[e->network()][msg];
414 // add this user to the netsplit
415 n->userQuit(e->prefix(), ircuser->channels(), msg);
416 e->setFlag(EventManager::Netsplit);
418 // normal quit is handled in lateProcessIrcEventQuit()
422 void CoreSessionEventProcessor::lateProcessIrcEventQuit(IrcEvent *e)
424 if (e->testFlag(EventManager::Netsplit))
427 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
435 void CoreSessionEventProcessor::processIrcEventTopic(IrcEvent *e)
437 if (checkParamCount(e, 2)) {
438 e->network()->updateNickFromMask(e->prefix());
439 IrcChannel *channel = e->network()->ircChannel(e->params().at(0));
441 channel->setTopic(e->params().at(1));
447 void CoreSessionEventProcessor::processKeyEvent(KeyEvent *e)
449 if (!Cipher::neededFeaturesAvailable()) {
450 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()));
453 CoreNetwork *net = qobject_cast<CoreNetwork*>(e->network());
454 Cipher *c = net->cipher(e->target());
455 if (!c) // happens when there is no CoreIrcChannel for the target (i.e. never?)
458 if (e->exchangeType() == KeyEvent::Init) {
459 QByteArray pubKey = c->parseInitKeyX(e->key());
460 if (pubKey.isEmpty()) {
461 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()));
464 net->setCipherKey(e->target(), c->key());
465 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()));
467 p << net->serverEncode(e->target()) << net->serverEncode("DH1080_FINISH ")+pubKey;
468 net->putCmd("NOTICE", p);
471 if (c->parseFinishKeyX(e->key())) {
472 net->setCipherKey(e->target(), c->key());
473 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()));
475 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()));
483 void CoreSessionEventProcessor::processIrcEvent001(IrcEventNumeric *e)
485 e->network()->setCurrentServer(e->prefix());
486 e->network()->setMyNick(e->target());
491 // TODO Complete 005 handling, also use sensible defaults for non-sent stuff
492 void CoreSessionEventProcessor::processIrcEvent005(IrcEvent *e)
494 if (!checkParamCount(e, 1))
498 for (int i = 0; i < e->params().count() - 1; i++) {
499 QString key = e->params()[i].section("=", 0, 0);
500 QString value = e->params()[i].section("=", 1);
501 e->network()->addSupport(key, value);
504 /* determine our prefixes here to get an accurate result */
505 e->network()->determinePrefixes();
509 /* RPL_UMODEIS - "<user_modes> [<user_mode_params>]" */
510 void CoreSessionEventProcessor::processIrcEvent221(IrcEvent *)
512 // TODO: save information in network object
516 /* RPL_STATSCONN - "Highest connection cout: 8000 (7999 clients)" */
517 void CoreSessionEventProcessor::processIrcEvent250(IrcEvent *)
519 // TODO: save information in network object
523 /* RPL_LOCALUSERS - "Current local user: 5024 Max: 7999 */
524 void CoreSessionEventProcessor::processIrcEvent265(IrcEvent *)
526 // TODO: save information in network object
530 /* RPL_GLOBALUSERS - "Current global users: 46093 Max: 47650" */
531 void CoreSessionEventProcessor::processIrcEvent266(IrcEvent *)
533 // TODO: save information in network object
539 Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
541 "<nick> :<away message>"
543 Replies 352 and 315 paired are used to answer a WHO message.
546 Replies 314 and 369 are responses to a WHOWAS message.
550 /* RPL_AWAY - "<nick> :<away message>" */
551 void CoreSessionEventProcessor::processIrcEvent301(IrcEvent *e)
553 if (!checkParamCount(e, 2))
556 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
558 ircuser->setAway(true);
559 ircuser->setAwayMessage(e->params().at(1));
560 //ircuser->setLastAwayMessage(now);
565 /* RPL_UNAWAY - ":You are no longer marked as being away" */
566 void CoreSessionEventProcessor::processIrcEvent305(IrcEvent *e)
568 IrcUser *me = e->network()->me();
572 if (e->network()->autoAwayActive()) {
573 e->network()->setAutoAwayActive(false);
574 e->setFlag(EventManager::Silent);
579 /* RPL_NOWAWAY - ":You have been marked as being away" */
580 void CoreSessionEventProcessor::processIrcEvent306(IrcEvent *e)
582 IrcUser *me = e->network()->me();
588 /* RPL_WHOISSERVICE - "<user> is registered nick" */
589 void CoreSessionEventProcessor::processIrcEvent307(IrcEvent *e)
591 if (!checkParamCount(e, 1))
594 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
596 ircuser->setWhoisServiceReply(e->params().join(" "));
600 /* RPL_SUSERHOST - "<user> is available for help." */
601 void CoreSessionEventProcessor::processIrcEvent310(IrcEvent *e)
603 if (!checkParamCount(e, 1))
606 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
608 ircuser->setSuserHost(e->params().join(" "));
612 /* RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
613 void CoreSessionEventProcessor::processIrcEvent311(IrcEvent *e)
615 if (!checkParamCount(e, 3))
618 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
620 ircuser->setUser(e->params().at(1));
621 ircuser->setHost(e->params().at(2));
622 ircuser->setRealName(e->params().last());
627 /* RPL_WHOISSERVER - "<nick> <server> :<server info>" */
628 void CoreSessionEventProcessor::processIrcEvent312(IrcEvent *e)
630 if (!checkParamCount(e, 2))
633 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
635 ircuser->setServer(e->params().at(1));
639 /* RPL_WHOISOPERATOR - "<nick> :is an IRC operator" */
640 void CoreSessionEventProcessor::processIrcEvent313(IrcEvent *e)
642 if (!checkParamCount(e, 1))
645 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
647 ircuser->setIrcOperator(e->params().last());
651 /* RPL_ENDOFWHO: "<name> :End of WHO list" */
652 void CoreSessionEventProcessor::processIrcEvent315(IrcEvent *e)
654 if (!checkParamCount(e, 1))
657 if (coreNetwork(e)->setAutoWhoDone(e->params()[0]))
658 e->setFlag(EventManager::Silent);
662 /* RPL_WHOISIDLE - "<nick> <integer> :seconds idle"
663 (real life: "<nick> <integer> <integer> :seconds idle, signon time) */
664 void CoreSessionEventProcessor::processIrcEvent317(IrcEvent *e)
666 if (!checkParamCount(e, 2))
671 int idleSecs = e->params()[1].toInt();
672 if (e->params().count() > 3) { // if we have more then 3 params we have the above mentioned "real life" situation
673 int logintime = e->params()[2].toInt();
674 loginTime = QDateTime::fromTime_t(logintime);
677 IrcUser *ircuser = e->network()->ircUser(e->params()[0]);
679 ircuser->setIdleTime(e->timestamp().addSecs(-idleSecs));
680 if (loginTime.isValid())
681 ircuser->setLoginTime(loginTime);
686 /* RPL_LIST - "<channel> <# visible> :<topic>" */
687 void CoreSessionEventProcessor::processIrcEvent322(IrcEvent *e)
689 if (!checkParamCount(e, 1))
693 quint32 userCount = 0;
696 switch (e->params().count()) {
698 topic = e->params()[2];
700 userCount = e->params()[1].toUInt();
702 channelName = e->params()[0];
706 if (coreSession()->ircListHelper()->addChannel(e->networkId(), channelName, userCount, topic))
707 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
711 /* RPL_LISTEND ":End of LIST" */
712 void CoreSessionEventProcessor::processIrcEvent323(IrcEvent *e)
714 if (!checkParamCount(e, 1))
717 if (coreSession()->ircListHelper()->endOfChannelList(e->networkId()))
718 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
722 /* RPL_CHANNELMODEIS - "<channel> <mode> <mode params>" */
723 void CoreSessionEventProcessor::processIrcEvent324(IrcEvent *e)
725 processIrcEventMode(e);
730 void CoreSessionEventProcessor::processIrcEvent331(IrcEvent *e)
732 if (!checkParamCount(e, 1))
735 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
737 chan->setTopic(QString());
742 void CoreSessionEventProcessor::processIrcEvent332(IrcEvent *e)
744 if (!checkParamCount(e, 2))
747 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
749 chan->setTopic(e->params()[1]);
753 /* RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
754 ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
755 void CoreSessionEventProcessor::processIrcEvent352(IrcEvent *e)
757 if (!checkParamCount(e, 6))
760 QString channel = e->params()[0];
761 IrcUser *ircuser = e->network()->ircUser(e->params()[4]);
763 ircuser->setUser(e->params()[1]);
764 ircuser->setHost(e->params()[2]);
766 bool away = e->params()[5].startsWith("G");
767 ircuser->setAway(away);
768 ircuser->setServer(e->params()[3]);
769 ircuser->setRealName(e->params().last().section(" ", 1));
772 if (coreNetwork(e)->isAutoWhoInProgress(channel))
773 e->setFlag(EventManager::Silent);
778 void CoreSessionEventProcessor::processIrcEvent353(IrcEvent *e)
780 if (!checkParamCount(e, 3))
783 // param[0] is either "=", "*" or "@" indicating a public, private or secret channel
784 // we don't use this information at the time beeing
785 QString channelname = e->params()[1];
787 IrcChannel *channel = e->network()->ircChannel(channelname);
789 qWarning() << Q_FUNC_INFO << "Received unknown target channel:" << channelname;
796 foreach(QString nick, e->params()[2].split(' ', QString::SkipEmptyParts)) {
799 if (e->network()->prefixes().contains(nick[0])) {
800 mode = e->network()->prefixToMode(nick[0]);
808 channel->joinIrcUsers(nicks, modes);
812 /* ERR_ERRONEUSNICKNAME */
813 void CoreSessionEventProcessor::processIrcEvent432(IrcEventNumeric *e)
815 if (!checkParamCount(e, 1))
819 if (e->params().count() < 2) {
820 // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
822 // :irc.scortum.moep.net 432 @@@ :Erroneous Nickname: Illegal characters
823 // correct server reply:
824 // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
825 e->params().prepend(e->target());
828 errnick = e->params()[0];
830 tryNextNick(e, errnick, true /* erroneus */);
834 /* ERR_NICKNAMEINUSE */
835 void CoreSessionEventProcessor::processIrcEvent433(IrcEventNumeric *e)
837 if (!checkParamCount(e, 1))
840 QString errnick = e->params().first();
842 // if there is a problem while connecting to the server -> we handle it
843 // but only if our connection has not been finished yet...
844 if (!e->network()->currentServer().isEmpty())
847 tryNextNick(e, errnick);
851 /* ERR_UNAVAILRESOURCE */
852 void CoreSessionEventProcessor::processIrcEvent437(IrcEventNumeric *e)
854 if (!checkParamCount(e, 1))
857 QString errnick = e->params().first();
859 // if there is a problem while connecting to the server -> we handle it
860 // but only if our connection has not been finished yet...
861 if (!e->network()->currentServer().isEmpty())
864 if (!e->network()->isChannelName(errnick))
865 tryNextNick(e, errnick);
870 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
871 if(!checkParamCount(e, 1))
877 /* Handle signals from Netsplit objects */
879 void CoreSessionEventProcessor::handleNetsplitJoin(Network *net,
880 const QString &channel,
881 const QStringList &users,
882 const QStringList &modes,
883 const QString &quitMessage)
885 IrcChannel *ircChannel = net->ircChannel(channel);
889 QList<IrcUser *> ircUsers;
890 QStringList newModes = modes;
891 QStringList newUsers = users;
893 foreach(const QString &user, users) {
894 IrcUser *iu = net->ircUser(nickFromMask(user));
897 else { // the user already quit
898 int idx = users.indexOf(user);
899 newUsers.removeAt(idx);
900 newModes.removeAt(idx);
904 ircChannel->joinIrcUsers(ircUsers, newModes);
905 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitJoin, net, channel, newUsers, quitMessage);
906 emit newEvent(event);
910 void CoreSessionEventProcessor::handleNetsplitQuit(Network *net, const QString &channel, const QStringList &users, const QString &quitMessage)
912 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitQuit, net, channel, users, quitMessage);
913 emit newEvent(event);
914 foreach(QString user, users) {
915 IrcUser *iu = net->ircUser(nickFromMask(user));
922 void CoreSessionEventProcessor::handleEarlyNetsplitJoin(Network *net, const QString &channel, const QStringList &users, const QStringList &modes)
924 IrcChannel *ircChannel = net->ircChannel(channel);
926 qDebug() << "handleEarlyNetsplitJoin(): channel " << channel << " invalid";
929 QList<NetworkEvent *> events;
930 QList<IrcUser *> ircUsers;
931 QStringList newModes = modes;
933 foreach(QString user, users) {
934 IrcUser *iu = net->updateNickFromMask(user);
937 // fake event for scripts that consume join events
938 events << new IrcEvent(EventManager::IrcEventJoin, net, iu->hostmask(), QStringList() << channel);
941 newModes.removeAt(users.indexOf(user));
944 ircChannel->joinIrcUsers(ircUsers, newModes);
945 foreach(NetworkEvent *event, events) {
946 event->setFlag(EventManager::Fake); // ignore this in here!
947 emit newEvent(event);
952 void CoreSessionEventProcessor::handleNetsplitFinished()
954 Netsplit *n = qobject_cast<Netsplit *>(sender());
956 QHash<QString, Netsplit *> splithash = _netsplits.take(n->network());
957 splithash.remove(splithash.key(n));
958 if (splithash.count())
959 _netsplits[n->network()] = splithash;
964 void CoreSessionEventProcessor::destroyNetsplits(NetworkId netId)
966 Network *net = coreSession()->network(netId);
970 QHash<QString, Netsplit *> splits = _netsplits.take(net);
975 /*******************************/
976 /******** CTCP HANDLING ********/
977 /*******************************/
979 void CoreSessionEventProcessor::processCtcpEvent(CtcpEvent *e)
981 if (e->testFlag(EventManager::Self))
982 return; // ignore ctcp events generated by user input
984 if (e->type() != EventManager::CtcpEvent || e->ctcpType() != CtcpEvent::Query)
987 handle(e->ctcpCmd(), Q_ARG(CtcpEvent *, e));
991 void CoreSessionEventProcessor::defaultHandler(const QString &ctcpCmd, CtcpEvent *e)
993 // This handler is only there to avoid warnings for unknown CTCPs
999 void CoreSessionEventProcessor::handleCtcpAction(CtcpEvent *e)
1001 // This handler is only there to feed CLIENTINFO
1006 void CoreSessionEventProcessor::handleCtcpClientinfo(CtcpEvent *e)
1008 QStringList supportedHandlers;
1009 foreach(QString handler, providesHandlers())
1010 supportedHandlers << handler.toUpper();
1011 qSort(supportedHandlers);
1012 e->setReply(supportedHandlers.join(" "));
1016 // http://www.irchelp.org/irchelp/rfc/ctcpspec.html
1017 // http://en.wikipedia.org/wiki/Direct_Client-to-Client
1018 void CoreSessionEventProcessor::handleCtcpDcc(CtcpEvent *e)
1020 // DCC support is unfinished, experimental and potentially dangerous, so make it opt-in
1021 if (!Quassel::isOptionSet("enable-experimental-dcc")) {
1022 quInfo() << "DCC disabled, start core with --enable-experimental-dcc if you really want to try it out";
1026 // normal: SEND <filename> <ip> <port> [<filesize>]
1027 // reverse: SEND <filename> <ip> 0 <filesize> <token>
1028 QStringList params = e->param().split(' ');
1029 if (params.count()) {
1030 QString cmd = params[0].toUpper();
1031 if (cmd == "SEND") {
1032 if (params.count() < 4) {
1033 qWarning() << "Invalid DCC SEND request:" << e; // TODO emit proper error to client
1036 QString filename = params[1];
1037 QHostAddress address;
1038 quint16 port = params[3].toUShort();
1040 QString numIp = params[2]; // this is either IPv4 as a 32 bit value, or IPv6 (which always contains a colon)
1041 if (numIp.contains(':')) { // IPv6
1042 if (!address.setAddress(numIp)) {
1043 qWarning() << "Invalid IPv6:" << numIp;
1048 address.setAddress(numIp.toUInt());
1051 if (port == 0) { // Reverse DCC is indicated by a 0 port
1052 emit newEvent(new MessageEvent(Message::Error, e->network(), tr("Reverse DCC SEND not supported"), e->prefix(), e->target(), Message::None, e->timestamp()));
1056 qWarning() << "Privileged port requested:" << port; // FIXME ask user if this is ok
1060 if (params.count() > 4) { // filesize is optional
1061 size = params[4].toULong();
1064 // TODO: check if target is the right thing to use for the partner
1065 CoreTransfer *transfer = new CoreTransfer(Transfer::Receive, e->target(), filename, address, port, size, this);
1066 coreSession()->signalProxy()->synchronize(transfer);
1067 coreSession()->transferManager()->addTransfer(transfer);
1070 emit newEvent(new MessageEvent(Message::Error, e->network(), tr("DCC %1 not supported").arg(cmd), e->prefix(), e->target(), Message::None, e->timestamp()));
1077 void CoreSessionEventProcessor::handleCtcpPing(CtcpEvent *e)
1079 e->setReply(e->param().isNull() ? "" : e->param());
1083 void CoreSessionEventProcessor::handleCtcpTime(CtcpEvent *e)
1085 e->setReply(QDateTime::currentDateTime().toString());
1089 void CoreSessionEventProcessor::handleCtcpVersion(CtcpEvent *e)
1091 e->setReply(QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
1092 .arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate));