1 /***************************************************************************
2 * Copyright (C) 2005-2012 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 *)));
41 bool CoreSessionEventProcessor::checkParamCount(IrcEvent *e, int minParams) {
42 if(e->params().count() < minParams) {
43 if(e->type() == EventManager::IrcEventNumeric) {
44 qWarning() << "Command " << static_cast<IrcEventNumeric *>(e)->number() << " requires " << minParams << "params, got: " << e->params();
46 QString name = coreSession()->eventManager()->enumName(e->type());
47 qWarning() << qPrintable(name) << "requires" << minParams << "params, got:" << e->params();
55 void CoreSessionEventProcessor::tryNextNick(NetworkEvent *e, const QString &errnick, bool erroneus) {
56 QStringList desiredNicks = coreSession()->identity(e->network()->identity())->nicks();
57 int nextNickIdx = desiredNicks.indexOf(errnick) + 1;
59 if(nextNickIdx > 0 && desiredNicks.size() > nextNickIdx) {
60 nextNick = desiredNicks[nextNickIdx];
63 // FIXME Make this an ErrorEvent or something like that, so it's translated in the client
64 MessageEvent *msgEvent = new MessageEvent(Message::Error, e->network(),
65 tr("No free and valid nicks in nicklist found. use: /nick <othernick> to continue"),
66 QString(), QString(), Message::None, e->timestamp());
67 emit newEvent(msgEvent);
70 nextNick = errnick + "_";
73 // FIXME Use a proper output event for this
74 coreNetwork(e)->putRawLine("NICK " + coreNetwork(e)->encodeServerString(nextNick));
77 void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e) {
81 case 903: case 904: case 905: case 906: case 907:
82 qobject_cast<CoreNetwork *>(e->network())->putRawLine("CAP END");
90 void CoreSessionEventProcessor::processIrcEventAuthenticate(IrcEvent *e) {
91 if(!checkParamCount(e, 1))
94 if(e->params().at(0) != "+") {
95 qWarning() << "Invalid AUTHENTICATE" << e;
99 CoreNetwork *net = coreNetwork(e);
101 QString construct = net->saslAccount();
102 construct.append(QChar(QChar::Null));
103 construct.append(net->saslAccount());
104 construct.append(QChar(QChar::Null));
105 construct.append(net->saslPassword());
106 QByteArray saslData = QByteArray(construct.toAscii().toBase64());
107 saslData.prepend("AUTHENTICATE ");
108 net->putRawLine(saslData);
111 void CoreSessionEventProcessor::processIrcEventCap(IrcEvent *e) {
112 // for SASL, there will only be a single param of 'sasl', however you can check here for
113 // additional CAP messages (ls, multi-prefix, et cetera).
115 if(e->params().count() == 3) {
116 if(e->params().at(2) == "sasl") {
118 coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE PLAIN")); // Only working with PLAIN atm, blowfish later
123 void CoreSessionEventProcessor::processIrcEventInvite(IrcEvent *e) {
124 if(checkParamCount(e, 2)) {
125 e->network()->updateNickFromMask(e->prefix());
129 void CoreSessionEventProcessor::processIrcEventJoin(IrcEvent *e) {
130 if(e->testFlag(EventManager::Fake)) // generated by handleEarlyNetsplitJoin
133 if(!checkParamCount(e, 1))
136 CoreNetwork *net = coreNetwork(e);
137 QString channel = e->params()[0];
138 IrcUser *ircuser = net->updateNickFromMask(e->prefix());
140 bool handledByNetsplit = false;
141 foreach(Netsplit* n, _netsplits.value(e->network())) {
142 handledByNetsplit = n->userJoined(e->prefix(), channel);
143 if(handledByNetsplit)
147 if(!handledByNetsplit)
148 ircuser->joinChannel(channel);
150 e->setFlag(EventManager::Netsplit);
152 if(net->isMe(ircuser)) {
153 net->setChannelJoined(channel);
155 net->putRawLine(net->serverEncode("MODE " + channel)); // we want to know the modes of the channel we just joined, so we ask politely
159 void CoreSessionEventProcessor::lateProcessIrcEventKick(IrcEvent *e) {
160 if(checkParamCount(e, 2)) {
161 e->network()->updateNickFromMask(e->prefix());
162 IrcUser *victim = e->network()->ircUser(e->params().at(1));
164 victim->partChannel(e->params().at(0));
165 //if(e->network()->isMe(victim)) e->network()->setKickedFromChannel(channel);
170 void CoreSessionEventProcessor::processIrcEventMode(IrcEvent *e) {
171 if(!checkParamCount(e, 2))
174 if(e->network()->isChannelName(e->params().first())) {
177 IrcChannel *channel = e->network()->ircChannel(e->params()[0]);
179 // we received mode information for a channel we're not in. that means probably we've just been kicked out or something like that
180 // anyways: we don't have a place to store the data --> discard the info.
184 QString modes = e->params()[1];
187 for(int c = 0; c < modes.length(); c++) {
188 if(modes[c] == '+') {
192 if(modes[c] == '-') {
197 if(e->network()->prefixModes().contains(modes[c])) {
198 // user channel modes (op, voice, etc...)
199 if(paramOffset < e->params().count()) {
200 IrcUser *ircUser = e->network()->ircUser(e->params()[paramOffset]);
202 qWarning() << Q_FUNC_INFO << "Unknown IrcUser:" << e->params()[paramOffset];
205 bool handledByNetsplit = false;
206 QHash<QString, Netsplit *> splits = _netsplits.value(e->network());
207 foreach(Netsplit* n, _netsplits.value(e->network())) {
208 handledByNetsplit = n->userAlreadyJoined(ircUser->hostmask(), channel->name());
209 if(handledByNetsplit) {
210 n->addMode(ircUser->hostmask(), channel->name(), QString(modes[c]));
214 if(!handledByNetsplit)
215 channel->addUserMode(ircUser, QString(modes[c]));
218 channel->removeUserMode(ircUser, QString(modes[c]));
221 qWarning() << "Received MODE with too few parameters:" << e->params();
225 // regular channel modes
227 Network::ChannelModeType modeType = e->network()->channelModeType(modes[c]);
228 if(modeType == Network::A_CHANMODE || modeType == Network::B_CHANMODE || (modeType == Network::C_CHANMODE && add)) {
229 if(paramOffset < e->params().count()) {
230 value = e->params()[paramOffset];
232 qWarning() << "Received MODE with too few parameters:" << e->params();
238 channel->addChannelMode(modes[c], value);
240 channel->removeChannelMode(modes[c], value);
246 IrcUser *ircUser = e->network()->newIrcUser(e->params().first());
247 QString modeString(e->params()[1]);
251 for(int c = 0; c < modeString.count(); c++) {
252 if(modeString[c] == '+') {
256 if(modeString[c] == '-') {
261 addModes += modeString[c];
263 removeModes += modeString[c];
265 if(!addModes.isEmpty())
266 ircUser->addUserModes(addModes);
267 if(!removeModes.isEmpty())
268 ircUser->removeUserModes(removeModes);
270 if(e->network()->isMe(ircUser)) {
271 coreNetwork(e)->updatePersistentModes(addModes, removeModes);
276 void CoreSessionEventProcessor::lateProcessIrcEventNick(IrcEvent *e) {
277 if(checkParamCount(e, 1)) {
278 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
280 qWarning() << Q_FUNC_INFO << "Unknown IrcUser!";
283 QString newnick = e->params().at(0);
284 QString oldnick = ircuser->nick();
286 // the order is cruicial
287 // otherwise the client would rename the buffer, see that the assigned ircuser doesn't match anymore
288 // and remove the ircuser from the querybuffer leading to a wrong on/offline state
289 ircuser->setNick(newnick);
290 coreSession()->renameBuffer(e->networkId(), newnick, oldnick);
294 void CoreSessionEventProcessor::lateProcessIrcEventPart(IrcEvent *e) {
295 if(checkParamCount(e, 1)) {
296 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
298 qWarning() << Q_FUNC_INFO<< "Unknown IrcUser!";
301 QString channel = e->params().at(0);
302 ircuser->partChannel(channel);
303 if(e->network()->isMe(ircuser))
304 qobject_cast<CoreNetwork *>(e->network())->setChannelParted(channel);
308 void CoreSessionEventProcessor::processIrcEventPing(IrcEvent *e) {
309 QString param = e->params().count()? e->params().first() : QString();
311 coreNetwork(e)->putRawLine("PONG " + coreNetwork(e)->serverEncode(param));
314 void CoreSessionEventProcessor::processIrcEventPong(IrcEvent *e) {
315 // the server is supposed to send back what we passed as param. and we send a timestamp
316 // but using quote and whatnought one can send arbitrary pings, so we have to do some sanity checks
317 if(checkParamCount(e, 2)) {
318 QString timestamp = e->params().at(1);
319 QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz");
320 if(sendTime.isValid())
321 e->network()->setLatency(sendTime.msecsTo(QTime::currentTime()) / 2);
325 void CoreSessionEventProcessor::processIrcEventQuit(IrcEvent *e) {
326 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
331 if(e->params().count() > 0)
332 msg = e->params()[0];
335 if(Netsplit::isNetsplit(msg)) {
337 if(!_netsplits[e->network()].contains(msg)) {
338 n = new Netsplit(e->network(), this);
339 connect(n, SIGNAL(finished()), this, SLOT(handleNetsplitFinished()));
340 connect(n, SIGNAL(netsplitJoin(Network*,QString,QStringList,QStringList,QString)),
341 this, SLOT(handleNetsplitJoin(Network*,QString,QStringList,QStringList,QString)));
342 connect(n, SIGNAL(netsplitQuit(Network*,QString,QStringList,QString)),
343 this, SLOT(handleNetsplitQuit(Network*,QString,QStringList,QString)));
344 connect(n, SIGNAL(earlyJoin(Network*,QString,QStringList,QStringList)),
345 this, SLOT(handleEarlyNetsplitJoin(Network*,QString,QStringList,QStringList)));
346 _netsplits[e->network()].insert(msg, n);
349 n = _netsplits[e->network()][msg];
351 // add this user to the netsplit
352 n->userQuit(e->prefix(), ircuser->channels(), msg);
353 e->setFlag(EventManager::Netsplit);
355 // normal quit is handled in lateProcessIrcEventQuit()
358 void CoreSessionEventProcessor::lateProcessIrcEventQuit(IrcEvent *e) {
359 if(e->testFlag(EventManager::Netsplit))
362 IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
369 void CoreSessionEventProcessor::processIrcEventTopic(IrcEvent *e) {
370 if(checkParamCount(e, 2)) {
371 e->network()->updateNickFromMask(e->prefix());
372 IrcChannel *channel = e->network()->ircChannel(e->params().at(0));
374 channel->setTopic(e->params().at(1));
379 void CoreSessionEventProcessor::processIrcEvent001(IrcEvent *e) {
380 if(!checkParamCount(e, 1))
383 QString myhostmask = e->params().at(0).section(' ', -1, -1);
384 e->network()->setCurrentServer(e->prefix());
385 e->network()->setMyNick(nickFromMask(myhostmask));
389 // TODO Complete 005 handling, also use sensible defaults for non-sent stuff
390 void CoreSessionEventProcessor::processIrcEvent005(IrcEvent *e) {
391 if(!checkParamCount(e, 1))
395 for(int i = 0; i < e->params().count() - 1; i++) {
396 QString key = e->params()[i].section("=", 0, 0);
397 QString value = e->params()[i].section("=", 1);
398 e->network()->addSupport(key, value);
401 /* determine our prefixes here to get an accurate result */
402 e->network()->determinePrefixes();
405 /* RPL_UMODEIS - "<user_modes> [<user_mode_params>]" */
406 void CoreSessionEventProcessor::processIrcEvent221(IrcEvent *) {
407 // TODO: save information in network object
410 /* RPL_STATSCONN - "Highest connection cout: 8000 (7999 clients)" */
411 void CoreSessionEventProcessor::processIrcEvent250(IrcEvent *) {
412 // TODO: save information in network object
415 /* RPL_LOCALUSERS - "Current local user: 5024 Max: 7999 */
416 void CoreSessionEventProcessor::processIrcEvent265(IrcEvent *) {
417 // TODO: save information in network object
420 /* RPL_GLOBALUSERS - "Current global users: 46093 Max: 47650" */
421 void CoreSessionEventProcessor::processIrcEvent266(IrcEvent *) {
422 // TODO: save information in network object
427 Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
429 "<nick> :<away message>"
431 Replies 352 and 315 paired are used to answer a WHO message.
434 Replies 314 and 369 are responses to a WHOWAS message.
438 /* RPL_AWAY - "<nick> :<away message>" */
439 void CoreSessionEventProcessor::processIrcEvent301(IrcEvent *e) {
440 if(!checkParamCount(e, 2))
443 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
445 ircuser->setAway(true);
446 ircuser->setAwayMessage(e->params().at(1));
447 //ircuser->setLastAwayMessage(now);
451 /* RPL_UNAWAY - ":You are no longer marked as being away" */
452 void CoreSessionEventProcessor::processIrcEvent305(IrcEvent *e) {
453 IrcUser *me = e->network()->me();
457 if(e->network()->autoAwayActive()) {
458 e->network()->setAutoAwayActive(false);
459 e->setFlag(EventManager::Silent);
463 /* RPL_NOWAWAY - ":You have been marked as being away" */
464 void CoreSessionEventProcessor::processIrcEvent306(IrcEvent *e) {
465 IrcUser *me = e->network()->me();
470 /* RPL_WHOISSERVICE - "<user> is registered nick" */
471 void CoreSessionEventProcessor::processIrcEvent307(IrcEvent *e) {
472 if(!checkParamCount(e, 1))
475 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
477 ircuser->setWhoisServiceReply(e->params().join(" "));
480 /* RPL_SUSERHOST - "<user> is available for help." */
481 void CoreSessionEventProcessor::processIrcEvent310(IrcEvent *e) {
482 if(!checkParamCount(e, 1))
485 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
487 ircuser->setSuserHost(e->params().join(" "));
490 /* RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
491 void CoreSessionEventProcessor::processIrcEvent311(IrcEvent *e) {
492 if(!checkParamCount(e, 3))
495 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
497 ircuser->setUser(e->params().at(1));
498 ircuser->setHost(e->params().at(2));
499 ircuser->setRealName(e->params().last());
503 /* RPL_WHOISSERVER - "<nick> <server> :<server info>" */
504 void CoreSessionEventProcessor::processIrcEvent312(IrcEvent *e) {
505 if(!checkParamCount(e, 2))
508 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
510 ircuser->setServer(e->params().at(1));
513 /* RPL_WHOISOPERATOR - "<nick> :is an IRC operator" */
514 void CoreSessionEventProcessor::processIrcEvent313(IrcEvent *e) {
515 if(!checkParamCount(e, 1))
518 IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
520 ircuser->setIrcOperator(e->params().last());
523 /* RPL_ENDOFWHO: "<name> :End of WHO list" */
524 void CoreSessionEventProcessor::processIrcEvent315(IrcEvent *e) {
525 if(!checkParamCount(e, 1))
528 if(coreNetwork(e)->setAutoWhoDone(e->params()[0]))
529 e->setFlag(EventManager::Silent);
532 /* RPL_WHOISIDLE - "<nick> <integer> :seconds idle"
533 (real life: "<nick> <integer> <integer> :seconds idle, signon time) */
534 void CoreSessionEventProcessor::processIrcEvent317(IrcEvent *e) {
535 if(!checkParamCount(e, 2))
540 int idleSecs = e->params()[1].toInt();
541 if(e->params().count() > 3) { // if we have more then 3 params we have the above mentioned "real life" situation
542 int logintime = e->params()[2].toInt();
543 loginTime = QDateTime::fromTime_t(logintime);
546 IrcUser *ircuser = e->network()->ircUser(e->params()[0]);
548 ircuser->setIdleTime(e->timestamp().addSecs(-idleSecs));
549 if(loginTime.isValid())
550 ircuser->setLoginTime(loginTime);
554 /* RPL_LIST - "<channel> <# visible> :<topic>" */
555 void CoreSessionEventProcessor::processIrcEvent322(IrcEvent *e) {
556 if(!checkParamCount(e, 1))
560 quint32 userCount = 0;
563 switch(e->params().count()) {
565 topic = e->params()[2];
567 userCount = e->params()[1].toUInt();
569 channelName = e->params()[0];
573 if(coreSession()->ircListHelper()->addChannel(e->networkId(), channelName, userCount, topic))
574 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
577 /* RPL_LISTEND ":End of LIST" */
578 void CoreSessionEventProcessor::processIrcEvent323(IrcEvent *e) {
579 if(!checkParamCount(e, 1))
582 if(coreSession()->ircListHelper()->endOfChannelList(e->networkId()))
583 e->stop(); // consumed by IrcListHelper, so don't further process/show this event
586 /* RPL_CHANNELMODEIS - "<channel> <mode> <mode params>" */
587 void CoreSessionEventProcessor::processIrcEvent324(IrcEvent *e) {
588 processIrcEventMode(e);
592 void CoreSessionEventProcessor::processIrcEvent331(IrcEvent *e) {
593 if(!checkParamCount(e, 1))
596 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
598 chan->setTopic(QString());
602 void CoreSessionEventProcessor::processIrcEvent332(IrcEvent *e) {
603 if(!checkParamCount(e, 2))
606 IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
608 chan->setTopic(e->params()[1]);
611 /* RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
612 ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
613 void CoreSessionEventProcessor::processIrcEvent352(IrcEvent *e) {
614 if(!checkParamCount(e, 6))
617 QString channel = e->params()[0];
618 IrcUser *ircuser = e->network()->ircUser(e->params()[4]);
620 ircuser->setUser(e->params()[1]);
621 ircuser->setHost(e->params()[2]);
623 bool away = e->params()[5].startsWith("G");
624 ircuser->setAway(away);
625 ircuser->setServer(e->params()[3]);
626 ircuser->setRealName(e->params().last().section(" ", 1));
629 if(coreNetwork(e)->isAutoWhoInProgress(channel))
630 e->setFlag(EventManager::Silent);
634 void CoreSessionEventProcessor::processIrcEvent353(IrcEvent *e) {
635 if(!checkParamCount(e, 3))
638 // param[0] is either "=", "*" or "@" indicating a public, private or secret channel
639 // we don't use this information at the time beeing
640 QString channelname = e->params()[1];
642 IrcChannel *channel = e->network()->ircChannel(channelname);
644 qWarning() << Q_FUNC_INFO << "Received unknown target channel:" << channelname;
651 foreach(QString nick, e->params()[2].split(' ')) {
654 if(e->network()->prefixes().contains(nick[0])) {
655 mode = e->network()->prefixToMode(nick[0]);
663 channel->joinIrcUsers(nicks, modes);
666 /* ERR_ERRONEUSNICKNAME */
667 void CoreSessionEventProcessor::processIrcEvent432(IrcEventNumeric *e) {
668 if(!checkParamCount(e, 1))
672 if(e->params().count() < 2) {
673 // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
675 // :irc.scortum.moep.net 432 @@@ :Erroneous Nickname: Illegal characters
676 // correct server reply:
677 // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
678 e->params().prepend(e->target());
681 errnick = e->params()[0];
683 tryNextNick(e, errnick, true /* erroneus */);
686 /* ERR_NICKNAMEINUSE */
687 void CoreSessionEventProcessor::processIrcEvent433(IrcEventNumeric *e) {
688 if(!checkParamCount(e, 1))
691 QString errnick = e->params().first();
693 // if there is a problem while connecting to the server -> we handle it
694 // but only if our connection has not been finished yet...
695 if(!e->network()->currentServer().isEmpty())
698 tryNextNick(e, errnick);
701 /* ERR_UNAVAILRESOURCE */
702 void CoreSessionEventProcessor::processIrcEvent437(IrcEventNumeric *e) {
703 if(!checkParamCount(e, 1))
706 QString errnick = e->params().first();
708 // if there is a problem while connecting to the server -> we handle it
709 // but only if our connection has not been finished yet...
710 if(!e->network()->currentServer().isEmpty())
713 if(!e->network()->isChannelName(errnick))
714 tryNextNick(e, errnick);
718 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
719 if(!checkParamCount(e, 1))
725 /* Handle signals from Netsplit objects */
727 void CoreSessionEventProcessor::handleNetsplitJoin(Network *net,
728 const QString &channel,
729 const QStringList &users,
730 const QStringList &modes,
731 const QString& quitMessage)
733 IrcChannel *ircChannel = net->ircChannel(channel);
737 QList<IrcUser *> ircUsers;
738 QStringList newModes = modes;
739 QStringList newUsers = users;
741 foreach(const QString &user, users) {
742 IrcUser *iu = net->ircUser(nickFromMask(user));
745 else { // the user already quit
746 int idx = users.indexOf(user);
747 newUsers.removeAt(idx);
748 newModes.removeAt(idx);
752 ircChannel->joinIrcUsers(ircUsers, newModes);
753 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitJoin, net, channel, newUsers, quitMessage);
754 emit newEvent(event);
757 void CoreSessionEventProcessor::handleNetsplitQuit(Network *net, const QString &channel, const QStringList &users, const QString& quitMessage) {
758 NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitQuit, net, channel, users, quitMessage);
759 emit newEvent(event);
760 foreach(QString user, users) {
761 IrcUser *iu = net->ircUser(nickFromMask(user));
767 void CoreSessionEventProcessor::handleEarlyNetsplitJoin(Network *net, const QString &channel, const QStringList &users, const QStringList &modes) {
768 IrcChannel *ircChannel = net->ircChannel(channel);
770 qDebug() << "handleEarlyNetsplitJoin(): channel " << channel << " invalid";
773 QList<NetworkEvent *> events;
774 QList<IrcUser *> ircUsers;
775 QStringList newModes = modes;
777 foreach(QString user, users) {
778 IrcUser *iu = net->updateNickFromMask(user);
781 // fake event for scripts that consume join events
782 events << new IrcEvent(EventManager::IrcEventJoin, net, iu->hostmask(), QStringList() << channel);
785 newModes.removeAt(users.indexOf(user));
788 ircChannel->joinIrcUsers(ircUsers, newModes);
789 foreach(NetworkEvent *event, events) {
790 event->setFlag(EventManager::Fake); // ignore this in here!
791 emit newEvent(event);
795 void CoreSessionEventProcessor::handleNetsplitFinished() {
796 Netsplit* n = qobject_cast<Netsplit*>(sender());
798 QHash<QString, Netsplit *> splithash = _netsplits.take(n->network());
799 splithash.remove(splithash.key(n));
800 if(splithash.count())
801 _netsplits[n->network()] = splithash;
805 void CoreSessionEventProcessor::destroyNetsplits(NetworkId netId) {
806 Network *net = coreSession()->network(netId);
810 QHash<QString, Netsplit *> splits = _netsplits.take(net);
814 /*******************************/
815 /******** CTCP HANDLING ********/
816 /*******************************/
818 void CoreSessionEventProcessor::processCtcpEvent(CtcpEvent *e) {
819 if(e->testFlag(EventManager::Self))
820 return; // ignore ctcp events generated by user input
822 if(e->type() != EventManager::CtcpEvent || e->ctcpType() != CtcpEvent::Query)
825 handle(e->ctcpCmd(), Q_ARG(CtcpEvent *, e));
828 void CoreSessionEventProcessor::defaultHandler(const QString &ctcpCmd, CtcpEvent *e) {
829 // This handler is only there to avoid warnings for unknown CTCPs
834 void CoreSessionEventProcessor::handleCtcpAction(CtcpEvent *e) {
835 // This handler is only there to feed CLIENTINFO
839 void CoreSessionEventProcessor::handleCtcpClientinfo(CtcpEvent *e) {
840 QStringList supportedHandlers;
841 foreach(QString handler, providesHandlers())
842 supportedHandlers << handler.toUpper();
843 qSort(supportedHandlers);
844 e->setReply(supportedHandlers.join(" "));
847 void CoreSessionEventProcessor::handleCtcpPing(CtcpEvent *e) {
848 e->setReply(e->param());
851 void CoreSessionEventProcessor::handleCtcpTime(CtcpEvent *e) {
852 e->setReply(QDateTime::currentDateTime().toString());
855 void CoreSessionEventProcessor::handleCtcpVersion(CtcpEvent *e) {
856 e->setReply(QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
857 .arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate));