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"
33 CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session)
34 : BasicHandler("handleCtcp", session),
37 connect(coreSession(), SIGNAL(networkDisconnected(NetworkId)), this, SLOT(destroyNetsplits(NetworkId)));
38 connect(this, SIGNAL(newEvent(Event *)), coreSession()->eventManager(), SLOT(postEvent(Event *)));
42 bool CoreSessionEventProcessor::checkParamCount(IrcEvent *e, int minParams)
44 if (e->params().count() < minParams) {
45 if (e->type() == EventManager::IrcEventNumeric) {
46 qWarning() << "Command " << static_cast<IrcEventNumeric *>(e)->number() << " requires " << minParams << "params, got: " << e->params();
49 QString name = coreSession()->eventManager()->enumName(e->type());
50 qWarning() << qPrintable(name) << "requires" << minParams << "params, got:" << e->params();
59 void CoreSessionEventProcessor::tryNextNick(NetworkEvent *e, const QString &errnick, bool erroneus)
61 QStringList desiredNicks = coreSession()->identity(e->network()->identity())->nicks();
62 int nextNickIdx = desiredNicks.indexOf(errnick) + 1;
64 if (nextNickIdx > 0 && desiredNicks.size() > nextNickIdx) {
65 nextNick = desiredNicks[nextNickIdx];
69 // FIXME Make this an ErrorEvent or something like that, so it's translated in the client
70 MessageEvent *msgEvent = new MessageEvent(Message::Error, e->network(),
71 tr("No free and valid nicks in nicklist found. use: /nick <othernick> to continue"),
72 QString(), QString(), Message::None, e->timestamp());
73 emit newEvent(msgEvent);
77 nextNick = errnick + "_";
80 // FIXME Use a proper output event for this
81 coreNetwork(e)->putRawLine("NICK " + coreNetwork(e)->encodeServerString(nextNick));
85 void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e)
87 switch (e->number()) {
94 qobject_cast<CoreNetwork *>(e->network())->putRawLine("CAP END");
103 void CoreSessionEventProcessor::processIrcEventAuthenticate(IrcEvent *e)
105 if (!checkParamCount(e, 1))
108 if (e->params().at(0) != "+") {
109 qWarning() << "Invalid AUTHENTICATE" << e;
113 CoreNetwork *net = coreNetwork(e);
116 if (net->identityPtr()->sslCert().isNull()) {
118 QString construct = net->saslAccount();
119 construct.append(QChar(QChar::Null));
120 construct.append(net->saslAccount());
121 construct.append(QChar(QChar::Null));
122 construct.append(net->saslPassword());
123 QByteArray saslData = QByteArray(construct.toAscii().toBase64());
124 saslData.prepend("AUTHENTICATE ");
125 net->putRawLine(saslData);
128 net->putRawLine("AUTHENTICATE +");
134 void CoreSessionEventProcessor::processIrcEventCap(IrcEvent *e)
136 // for SASL, there will only be a single param of 'sasl', however you can check here for
137 // additional CAP messages (ls, multi-prefix, et cetera).
139 if (e->params().count() == 3) {
140 if (e->params().at(2).startsWith("sasl")) { // Freenode (at least) sends "sasl " with a trailing space for some reason!
142 // if the current identity has a cert set, use SASL EXTERNAL
144 if (!coreNetwork(e)->identityPtr()->sslCert().isNull()) {
145 coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE EXTERNAL"));
148 // Only working with PLAIN atm, blowfish later
149 coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE PLAIN"));
158 void CoreSessionEventProcessor::processIrcEventInvite(IrcEvent *e)
160 if (checkParamCount(e, 2)) {
161 e->network()->updateNickFromMask(e->prefix());
166 void CoreSessionEventProcessor::processIrcEventJoin(IrcEvent *e)
168 if (e->testFlag(EventManager::Fake)) // generated by handleEarlyNetsplitJoin
171 if (!checkParamCount(e, 1))
174 CoreNetwork *net = coreNetwork(e);
175 QString channel = e->params()[0];
176 IrcUser *ircuser = net->updateNickFromMask(e->prefix());
178 bool handledByNetsplit = false;
179 foreach(Netsplit* n, _netsplits.value(e->network())) {
180 handledByNetsplit = n->userJoined(e->prefix(), channel);
181 if (handledByNetsplit)
185 if (!handledByNetsplit)
186 ircuser->joinChannel(channel);
188 e->setFlag(EventManager::Netsplit);
190 if (net->isMe(ircuser)) {
191 net->setChannelJoined(channel);
193 net->putRawLine(net->serverEncode("MODE " + channel)); // we want to know the modes of the channel we just joined, so we ask politely
198 void CoreSessionEventProcessor::lateProcessIrcEventKick(IrcEvent *e)
200 if (checkParamCount(e, 2)) {
201 e->network()->updateNickFromMask(e->prefix());
202 IrcUser *victim = e->network()->ircUser(e->params().at(1));
204 victim->partChannel(e->params().at(0));
205 //if(e->network()->isMe(victim)) e->network()->setKickedFromChannel(channel);
211 void CoreSessionEventProcessor::processIrcEventMode(IrcEvent *e)
213 if (!checkParamCount(e, 2))
216 if (e->network()->isChannelName(e->params().first())) {
219 IrcChannel *channel = e->network()->ircChannel(e->params()[0]);
221 // we received mode information for a channel we're not in. that means probably we've just been kicked out or something like that
222 // anyways: we don't have a place to store the data --> discard the info.
226 QString modes = e->params()[1];
229 for (int c = 0; c < modes.length(); c++) {
230 if (modes[c] == '+') {
234 if (modes[c] == '-') {
239 if (e->network()->prefixModes().contains(modes[c])) {
240 // user channel modes (op, voice, etc...)
241 if (paramOffset < e->params().count()) {
242 IrcUser *ircUser = e->network()->ircUser(e->params()[paramOffset]);
244 qWarning() << Q_FUNC_INFO << "Unknown IrcUser:" << e->params()[paramOffset];
248 bool handledByNetsplit = false;
249 QHash<QString, Netsplit *> splits = _netsplits.value(e->network());
250 foreach(Netsplit* n, _netsplits.value(e->network())) {
251 handledByNetsplit = n->userAlreadyJoined(ircUser->hostmask(), channel->name());
252 if (handledByNetsplit) {
253 n->addMode(ircUser->hostmask(), channel->name(), QString(modes[c]));
257 if (!handledByNetsplit)
258 channel->addUserMode(ircUser, QString(modes[c]));
261 channel->removeUserMode(ircUser, QString(modes[c]));
265 qWarning() << "Received MODE with too few parameters:" << e->params();
270 // regular channel modes
272 Network::ChannelModeType modeType = e->network()->channelModeType(modes[c]);
273 if (modeType == Network::A_CHANMODE || modeType == Network::B_CHANMODE || (modeType == Network::C_CHANMODE && add)) {
274 if (paramOffset < e->params().count()) {
275 value = e->params()[paramOffset];
278 qWarning() << "Received MODE with too few parameters:" << e->params();
284 channel->addChannelMode(modes[c], value);
286 channel->removeChannelMode(modes[c], value);
292 IrcUser *ircUser = e->network()->newIrcUser(e->params().first());
293 QString modeString(e->params()[1]);
297 for (int c = 0; c < modeString.count(); c++) {
298 if (modeString[c] == '+') {
302 if (modeString[c] == '-') {
307 addModes += modeString[c];
309 removeModes += modeString[c];
311 if (!addModes.isEmpty())
312 ircUser->addUserModes(addModes);
313 if (!removeModes.isEmpty())
314 ircUser->removeUserModes(removeModes);
316 if (e->network()->isMe(ircUser)) {
317 coreNetwork(e)->updatePersistentModes(addModes, removeModes);
323 void CoreSessionEventProcessor::lateProcessIrcEventNick(IrcEvent *e)
325 if (checkParamCount(e, 1)) {
326 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
328 qWarning() << Q_FUNC_INFO << "Unknown IrcUser!";
331 QString newnick = e->params().at(0);
332 QString oldnick = ircuser->nick();
334 // the order is cruicial
335 // otherwise the client would rename the buffer, see that the assigned ircuser doesn't match anymore
336 // and remove the ircuser from the querybuffer leading to a wrong on/offline state
337 ircuser->setNick(newnick);
338 coreSession()->renameBuffer(e->networkId(), newnick, oldnick);
343 void CoreSessionEventProcessor::lateProcessIrcEventPart(IrcEvent *e)
345 if (checkParamCount(e, 1)) {
346 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
348 qWarning() << Q_FUNC_INFO<< "Unknown IrcUser!";
351 QString channel = e->params().at(0);
352 ircuser->partChannel(channel);
353 if (e->network()->isMe(ircuser))
354 qobject_cast<CoreNetwork *>(e->network())->setChannelParted(channel);
359 void CoreSessionEventProcessor::processIrcEventPing(IrcEvent *e)
361 QString param = e->params().count() ? e->params().first() : QString();
363 coreNetwork(e)->putRawLine("PONG " + coreNetwork(e)->serverEncode(param));
367 void CoreSessionEventProcessor::processIrcEventPong(IrcEvent *e)
369 // the server is supposed to send back what we passed as param. and we send a timestamp
370 // but using quote and whatnought one can send arbitrary pings, so we have to do some sanity checks
371 if (checkParamCount(e, 2)) {
372 QString timestamp = e->params().at(1);
373 QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz");
374 if (sendTime.isValid())
375 e->network()->setLatency(sendTime.msecsTo(QTime::currentTime()) / 2);
380 void CoreSessionEventProcessor::processIrcEventQuit(IrcEvent *e)
382 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
387 if (e->params().count() > 0)
388 msg = e->params()[0];
391 if (Netsplit::isNetsplit(msg)) {
393 if (!_netsplits[e->network()].contains(msg)) {
394 n = new Netsplit(e->network(), this);
395 connect(n, SIGNAL(finished()), this, SLOT(handleNetsplitFinished()));
396 connect(n, SIGNAL(netsplitJoin(Network*, QString, QStringList, QStringList, QString)),
397 this, SLOT(handleNetsplitJoin(Network*, QString, QStringList, QStringList, QString)));
398 connect(n, SIGNAL(netsplitQuit(Network*, QString, QStringList, QString)),
399 this, SLOT(handleNetsplitQuit(Network*, QString, QStringList, QString)));
400 connect(n, SIGNAL(earlyJoin(Network*, QString, QStringList, QStringList)),
401 this, SLOT(handleEarlyNetsplitJoin(Network*, QString, QStringList, QStringList)));
402 _netsplits[e->network()].insert(msg, n);
405 n = _netsplits[e->network()][msg];
407 // add this user to the netsplit
408 n->userQuit(e->prefix(), ircuser->channels(), msg);
409 e->setFlag(EventManager::Netsplit);
411 // normal quit is handled in lateProcessIrcEventQuit()
415 void CoreSessionEventProcessor::lateProcessIrcEventQuit(IrcEvent *e)
417 if (e->testFlag(EventManager::Netsplit))
420 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
428 void CoreSessionEventProcessor::processIrcEventTopic(IrcEvent *e)
430 if (checkParamCount(e, 2)) {
431 e->network()->updateNickFromMask(e->prefix());
432 IrcChannel *channel = e->network()->ircChannel(e->params().at(0));
434 channel->setTopic(e->params().at(1));
440 void CoreSessionEventProcessor::processIrcEvent001(IrcEvent *e)
442 if (!checkParamCount(e, 1))
445 QString myhostmask = e->params().at(0).section(' ', -1, -1);
446 e->network()->setCurrentServer(e->prefix());
447 e->network()->setMyNick(nickFromMask(myhostmask));
452 // TODO Complete 005 handling, also use sensible defaults for non-sent stuff
453 void CoreSessionEventProcessor::processIrcEvent005(IrcEvent *e)
455 if (!checkParamCount(e, 1))
459 for (int i = 0; i < e->params().count() - 1; i++) {
460 QString key = e->params()[i].section("=", 0, 0);
461 QString value = e->params()[i].section("=", 1);
462 e->network()->addSupport(key, value);
465 /* determine our prefixes here to get an accurate result */
466 e->network()->determinePrefixes();
470 /* RPL_UMODEIS - "<user_modes> [<user_mode_params>]" */
471 void CoreSessionEventProcessor::processIrcEvent221(IrcEvent *)
473 // TODO: save information in network object
477 /* RPL_STATSCONN - "Highest connection cout: 8000 (7999 clients)" */
478 void CoreSessionEventProcessor::processIrcEvent250(IrcEvent *)
480 // TODO: save information in network object
484 /* RPL_LOCALUSERS - "Current local user: 5024 Max: 7999 */
485 void CoreSessionEventProcessor::processIrcEvent265(IrcEvent *)
487 // TODO: save information in network object
491 /* RPL_GLOBALUSERS - "Current global users: 46093 Max: 47650" */
492 void CoreSessionEventProcessor::processIrcEvent266(IrcEvent *)
494 // TODO: save information in network object
500 Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
502 "<nick> :<away message>"
504 Replies 352 and 315 paired are used to answer a WHO message.
507 Replies 314 and 369 are responses to a WHOWAS message.
511 /* RPL_AWAY - "<nick> :<away message>" */
512 void CoreSessionEventProcessor::processIrcEvent301(IrcEvent *e)
514 if (!checkParamCount(e, 2))
517 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
519 ircuser->setAway(true);
520 ircuser->setAwayMessage(e->params().at(1));
521 //ircuser->setLastAwayMessage(now);
526 /* RPL_UNAWAY - ":You are no longer marked as being away" */
527 void CoreSessionEventProcessor::processIrcEvent305(IrcEvent *e)
529 IrcUser *me = e->network()->me();
533 if (e->network()->autoAwayActive()) {
534 e->network()->setAutoAwayActive(false);
535 e->setFlag(EventManager::Silent);
540 /* RPL_NOWAWAY - ":You have been marked as being away" */
541 void CoreSessionEventProcessor::processIrcEvent306(IrcEvent *e)
543 IrcUser *me = e->network()->me();
549 /* RPL_WHOISSERVICE - "<user> is registered nick" */
550 void CoreSessionEventProcessor::processIrcEvent307(IrcEvent *e)
552 if (!checkParamCount(e, 1))
555 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
557 ircuser->setWhoisServiceReply(e->params().join(" "));
561 /* RPL_SUSERHOST - "<user> is available for help." */
562 void CoreSessionEventProcessor::processIrcEvent310(IrcEvent *e)
564 if (!checkParamCount(e, 1))
567 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
569 ircuser->setSuserHost(e->params().join(" "));
573 /* RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
574 void CoreSessionEventProcessor::processIrcEvent311(IrcEvent *e)
576 if (!checkParamCount(e, 3))
579 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
581 ircuser->setUser(e->params().at(1));
582 ircuser->setHost(e->params().at(2));
583 ircuser->setRealName(e->params().last());
588 /* RPL_WHOISSERVER - "<nick> <server> :<server info>" */
589 void CoreSessionEventProcessor::processIrcEvent312(IrcEvent *e)
591 if (!checkParamCount(e, 2))
594 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
596 ircuser->setServer(e->params().at(1));
600 /* RPL_WHOISOPERATOR - "<nick> :is an IRC operator" */
601 void CoreSessionEventProcessor::processIrcEvent313(IrcEvent *e)
603 if (!checkParamCount(e, 1))
606 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
608 ircuser->setIrcOperator(e->params().last());
612 /* RPL_ENDOFWHO: "<name> :End of WHO list" */
613 void CoreSessionEventProcessor::processIrcEvent315(IrcEvent *e)
615 if (!checkParamCount(e, 1))
618 if (coreNetwork(e)->setAutoWhoDone(e->params()[0]))
619 e->setFlag(EventManager::Silent);
623 /* RPL_WHOISIDLE - "<nick> <integer> :seconds idle"
624 (real life: "<nick> <integer> <integer> :seconds idle, signon time) */
625 void CoreSessionEventProcessor::processIrcEvent317(IrcEvent *e)
627 if (!checkParamCount(e, 2))
632 int idleSecs = e->params()[1].toInt();
633 if (e->params().count() > 3) { // if we have more then 3 params we have the above mentioned "real life" situation
634 int logintime = e->params()[2].toInt();
635 loginTime = QDateTime::fromTime_t(logintime);
638 IrcUser *ircuser = e->network()->ircUser(e->params()[0]);
640 ircuser->setIdleTime(e->timestamp().addSecs(-idleSecs));
641 if (loginTime.isValid())
642 ircuser->setLoginTime(loginTime);
647 /* RPL_LIST - "<channel> <# visible> :<topic>" */
648 void CoreSessionEventProcessor::processIrcEvent322(IrcEvent *e)
650 if (!checkParamCount(e, 1))
654 quint32 userCount = 0;
657 switch (e->params().count()) {
659 topic = e->params()[2];
661 userCount = e->params()[1].toUInt();
663 channelName = e->params()[0];
667 if (coreSession()->ircListHelper()->addChannel(e->networkId(), channelName, userCount, topic))
668 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
672 /* RPL_LISTEND ":End of LIST" */
673 void CoreSessionEventProcessor::processIrcEvent323(IrcEvent *e)
675 if (!checkParamCount(e, 1))
678 if (coreSession()->ircListHelper()->endOfChannelList(e->networkId()))
679 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
683 /* RPL_CHANNELMODEIS - "<channel> <mode> <mode params>" */
684 void CoreSessionEventProcessor::processIrcEvent324(IrcEvent *e)
686 processIrcEventMode(e);
691 void CoreSessionEventProcessor::processIrcEvent331(IrcEvent *e)
693 if (!checkParamCount(e, 1))
696 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
698 chan->setTopic(QString());
703 void CoreSessionEventProcessor::processIrcEvent332(IrcEvent *e)
705 if (!checkParamCount(e, 2))
708 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
710 chan->setTopic(e->params()[1]);
714 /* RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
715 ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
716 void CoreSessionEventProcessor::processIrcEvent352(IrcEvent *e)
718 if (!checkParamCount(e, 6))
721 QString channel = e->params()[0];
722 IrcUser *ircuser = e->network()->ircUser(e->params()[4]);
724 ircuser->setUser(e->params()[1]);
725 ircuser->setHost(e->params()[2]);
727 bool away = e->params()[5].startsWith("G");
728 ircuser->setAway(away);
729 ircuser->setServer(e->params()[3]);
730 ircuser->setRealName(e->params().last().section(" ", 1));
733 if (coreNetwork(e)->isAutoWhoInProgress(channel))
734 e->setFlag(EventManager::Silent);
739 void CoreSessionEventProcessor::processIrcEvent353(IrcEvent *e)
741 if (!checkParamCount(e, 3))
744 // param[0] is either "=", "*" or "@" indicating a public, private or secret channel
745 // we don't use this information at the time beeing
746 QString channelname = e->params()[1];
748 IrcChannel *channel = e->network()->ircChannel(channelname);
750 qWarning() << Q_FUNC_INFO << "Received unknown target channel:" << channelname;
757 foreach(QString nick, e->params()[2].split(' ')) {
760 if (e->network()->prefixes().contains(nick[0])) {
761 mode = e->network()->prefixToMode(nick[0]);
769 channel->joinIrcUsers(nicks, modes);
773 /* ERR_ERRONEUSNICKNAME */
774 void CoreSessionEventProcessor::processIrcEvent432(IrcEventNumeric *e)
776 if (!checkParamCount(e, 1))
780 if (e->params().count() < 2) {
781 // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
783 // :irc.scortum.moep.net 432 @@@ :Erroneous Nickname: Illegal characters
784 // correct server reply:
785 // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
786 e->params().prepend(e->target());
789 errnick = e->params()[0];
791 tryNextNick(e, errnick, true /* erroneus */);
795 /* ERR_NICKNAMEINUSE */
796 void CoreSessionEventProcessor::processIrcEvent433(IrcEventNumeric *e)
798 if (!checkParamCount(e, 1))
801 QString errnick = e->params().first();
803 // if there is a problem while connecting to the server -> we handle it
804 // but only if our connection has not been finished yet...
805 if (!e->network()->currentServer().isEmpty())
808 tryNextNick(e, errnick);
812 /* ERR_UNAVAILRESOURCE */
813 void CoreSessionEventProcessor::processIrcEvent437(IrcEventNumeric *e)
815 if (!checkParamCount(e, 1))
818 QString errnick = e->params().first();
820 // if there is a problem while connecting to the server -> we handle it
821 // but only if our connection has not been finished yet...
822 if (!e->network()->currentServer().isEmpty())
825 if (!e->network()->isChannelName(errnick))
826 tryNextNick(e, errnick);
831 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
832 if(!checkParamCount(e, 1))
838 /* Handle signals from Netsplit objects */
840 void CoreSessionEventProcessor::handleNetsplitJoin(Network *net,
841 const QString &channel,
842 const QStringList &users,
843 const QStringList &modes,
844 const QString &quitMessage)
846 IrcChannel *ircChannel = net->ircChannel(channel);
850 QList<IrcUser *> ircUsers;
851 QStringList newModes = modes;
852 QStringList newUsers = users;
854 foreach(const QString &user, users) {
855 IrcUser *iu = net->ircUser(nickFromMask(user));
858 else { // the user already quit
859 int idx = users.indexOf(user);
860 newUsers.removeAt(idx);
861 newModes.removeAt(idx);
865 ircChannel->joinIrcUsers(ircUsers, newModes);
866 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitJoin, net, channel, newUsers, quitMessage);
867 emit newEvent(event);
871 void CoreSessionEventProcessor::handleNetsplitQuit(Network *net, const QString &channel, const QStringList &users, const QString &quitMessage)
873 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitQuit, net, channel, users, quitMessage);
874 emit newEvent(event);
875 foreach(QString user, users) {
876 IrcUser *iu = net->ircUser(nickFromMask(user));
883 void CoreSessionEventProcessor::handleEarlyNetsplitJoin(Network *net, const QString &channel, const QStringList &users, const QStringList &modes)
885 IrcChannel *ircChannel = net->ircChannel(channel);
887 qDebug() << "handleEarlyNetsplitJoin(): channel " << channel << " invalid";
890 QList<NetworkEvent *> events;
891 QList<IrcUser *> ircUsers;
892 QStringList newModes = modes;
894 foreach(QString user, users) {
895 IrcUser *iu = net->updateNickFromMask(user);
898 // fake event for scripts that consume join events
899 events << new IrcEvent(EventManager::IrcEventJoin, net, iu->hostmask(), QStringList() << channel);
902 newModes.removeAt(users.indexOf(user));
905 ircChannel->joinIrcUsers(ircUsers, newModes);
906 foreach(NetworkEvent *event, events) {
907 event->setFlag(EventManager::Fake); // ignore this in here!
908 emit newEvent(event);
913 void CoreSessionEventProcessor::handleNetsplitFinished()
915 Netsplit *n = qobject_cast<Netsplit *>(sender());
917 QHash<QString, Netsplit *> splithash = _netsplits.take(n->network());
918 splithash.remove(splithash.key(n));
919 if (splithash.count())
920 _netsplits[n->network()] = splithash;
925 void CoreSessionEventProcessor::destroyNetsplits(NetworkId netId)
927 Network *net = coreSession()->network(netId);
931 QHash<QString, Netsplit *> splits = _netsplits.take(net);
936 /*******************************/
937 /******** CTCP HANDLING ********/
938 /*******************************/
940 void CoreSessionEventProcessor::processCtcpEvent(CtcpEvent *e)
942 if (e->testFlag(EventManager::Self))
943 return; // ignore ctcp events generated by user input
945 if (e->type() != EventManager::CtcpEvent || e->ctcpType() != CtcpEvent::Query)
948 handle(e->ctcpCmd(), Q_ARG(CtcpEvent *, e));
952 void CoreSessionEventProcessor::defaultHandler(const QString &ctcpCmd, CtcpEvent *e)
954 // This handler is only there to avoid warnings for unknown CTCPs
960 void CoreSessionEventProcessor::handleCtcpAction(CtcpEvent *e)
962 // This handler is only there to feed CLIENTINFO
967 void CoreSessionEventProcessor::handleCtcpClientinfo(CtcpEvent *e)
969 QStringList supportedHandlers;
970 foreach(QString handler, providesHandlers())
971 supportedHandlers << handler.toUpper();
972 qSort(supportedHandlers);
973 e->setReply(supportedHandlers.join(" "));
977 void CoreSessionEventProcessor::handleCtcpPing(CtcpEvent *e)
979 e->setReply(e->param());
983 void CoreSessionEventProcessor::handleCtcpTime(CtcpEvent *e)
985 e->setReply(QDateTime::currentDateTime().toString());
989 void CoreSessionEventProcessor::handleCtcpVersion(CtcpEvent *e)
991 e->setReply(QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
992 .arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate));