Send extra modes via non-breaking protocol change
[quassel.git] / src / core / coresessioneventprocessor.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2015 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "coresessioneventprocessor.h"
22
23 #include "coreirclisthelper.h"
24 #include "corenetwork.h"
25 #include "coresession.h"
26 #include "coretransfer.h"
27 #include "coretransfermanager.h"
28 #include "ctcpevent.h"
29 #include "ircevent.h"
30 #include "ircuser.h"
31 #include "logger.h"
32 #include "messageevent.h"
33 #include "netsplit.h"
34 #include "quassel.h"
35
36 #ifdef HAVE_QCA2
37 #  include "keyevent.h"
38 #endif
39
40 CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session)
41     : BasicHandler("handleCtcp", session),
42     _coreSession(session)
43 {
44     connect(coreSession(), SIGNAL(networkDisconnected(NetworkId)), this, SLOT(destroyNetsplits(NetworkId)));
45     connect(this, SIGNAL(newEvent(Event *)), coreSession()->eventManager(), SLOT(postEvent(Event *)));
46 }
47
48
49 bool CoreSessionEventProcessor::checkParamCount(IrcEvent *e, int minParams)
50 {
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();
54         }
55         else {
56             QString name = coreSession()->eventManager()->enumName(e->type());
57             qWarning() << qPrintable(name) << "requires" << minParams << "params, got:" << e->params();
58         }
59         e->stop();
60         return false;
61     }
62     return true;
63 }
64
65
66 void CoreSessionEventProcessor::tryNextNick(NetworkEvent *e, const QString &errnick, bool erroneus)
67 {
68     QStringList desiredNicks = coreSession()->identity(e->network()->identity())->nicks();
69     int nextNickIdx = desiredNicks.indexOf(errnick) + 1;
70     QString nextNick;
71     if (nextNickIdx > 0 && desiredNicks.size() > nextNickIdx) {
72         nextNick = desiredNicks[nextNickIdx];
73     }
74     else {
75         if (erroneus) {
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);
81             return;
82         }
83         else {
84             nextNick = errnick + "_";
85         }
86     }
87     // FIXME Use a proper output event for this
88     coreNetwork(e)->putRawLine("NICK " + coreNetwork(e)->encodeServerString(nextNick));
89 }
90
91
92 void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e)
93 {
94     switch (e->number()) {
95     // SASL authentication replies
96     // See: http://ircv3.net/specs/extensions/sasl-3.1.html
97     // TODO Handle errors to stop connection if appropriate
98     case 903:  // RPL_SASLSUCCESS
99     case 904:  // ERR_SASLFAIL
100     case 905:  // ERR_SASLTOOLONG
101     case 906:  // ERR_SASLABORTED
102     case 907:  // ERR_SASLALREADY
103         // Move on to the next capability
104         sendNextCap(e->network());
105         break;
106
107     default:
108         break;
109     }
110 }
111
112
113 void CoreSessionEventProcessor::processIrcEventAuthenticate(IrcEvent *e)
114 {
115     if (!checkParamCount(e, 1))
116         return;
117
118     if (e->params().at(0) != "+") {
119         qWarning() << "Invalid AUTHENTICATE" << e;
120         return;
121     }
122
123     CoreNetwork *net = coreNetwork(e);
124
125 #ifdef HAVE_SSL
126     if (net->identityPtr()->sslCert().isNull()) {
127 #endif
128         QString construct = net->saslAccount();
129         construct.append(QChar(QChar::Null));
130         construct.append(net->saslAccount());
131         construct.append(QChar(QChar::Null));
132         construct.append(net->saslPassword());
133         QByteArray saslData = QByteArray(construct.toLatin1().toBase64());
134         saslData.prepend("AUTHENTICATE ");
135         net->putRawLine(saslData);
136 #ifdef HAVE_SSL
137     } else {
138         net->putRawLine("AUTHENTICATE +");
139     }
140 #endif
141 }
142
143 void CoreSessionEventProcessor::sendNextCap(Network *net)
144 {
145     CoreNetwork *coreNet = qobject_cast<CoreNetwork *>(net);
146     if (coreNet->capNegotiationInProgress()) {
147         // Request the next capability and remove it from the list
148         // Handle one at a time so one capability failing won't NAK all of 'em
149         coreNet->putRawLine(coreNet->serverEncode(QString("CAP REQ :%1").arg(coreNet->takeQueuedCap())));
150     } else {
151         // If SASL requested but not available, print a warning
152         if (coreNet->networkInfo().useSasl && !coreNet->useCapSASL())
153             emit newEvent(new MessageEvent(Message::Error, net, tr("SASL authentication not supported by server, continuing without"), QString(), QString(), Message::None, QDateTime::currentDateTimeUtc()));
154
155         // No pending desired capabilities, end negotiation
156         coreNet->putRawLine(coreNet->serverEncode(QString("CAP END")));
157         emit newEvent(new MessageEvent(Message::Server, net, tr("Capability negotiation finished"), QString(), QString(), Message::None, QDateTime::currentDateTimeUtc()));
158     }
159 }
160
161 void CoreSessionEventProcessor::processIrcEventCap(IrcEvent *e)
162 {
163     // Handle capability negotiation
164     // See: http://ircv3.net/specs/core/capability-negotiation-3.2.html
165     // And: http://ircv3.net/specs/core/capability-negotiation-3.1.html
166     if (e->params().count() >= 3) {
167         CoreNetwork *coreNet = coreNetwork(e);
168         if (e->params().at(1).compare("LS", Qt::CaseInsensitive) == 0) {
169             // Server: CAP * LS * :multi-prefix extended-join account-notify batch invite-notify tls
170             // Server: CAP * LS * :cap-notify server-time example.org/dummy-cap=dummyvalue example.org/second-dummy-cap
171             // Server: CAP * LS :userhost-in-names sasl=EXTERNAL,DH-AES,DH-BLOWFISH,ECDSA-NIST256P-CHALLENGE,PLAIN
172             bool capListFinished;
173             QStringList availableCaps;
174             if (e->params().count() == 4) {
175                 // Middle of multi-line reply, ignore the asterisk
176                 capListFinished = false;
177                 availableCaps = e->params().at(3).split(' ');
178             } else {
179                 // Single line reply
180                 capListFinished = true;
181                 availableCaps = e->params().at(2).split(' ');
182             }
183             // We know what capabilities are available, request what we want.
184             QStringList availableCapPair;
185             bool queueCurrentCap;
186             for (int i = 0; i < availableCaps.count(); ++i) {
187                 // Capability may include values, e.g. CAP * LS :multi-prefix sasl=EXTERNAL
188                 availableCapPair = availableCaps[i].trimmed().split('=');
189                 queueCurrentCap = false;
190                 if (availableCapPair.at(0).startsWith("sasl")) {
191                     // Only request SASL if it's enabled
192                     if (coreNet->networkInfo().useSasl)
193                         queueCurrentCap = true;
194                 } else if (availableCapPair.at(0).startsWith("away-notify") ||
195                            availableCapPair.at(0).startsWith("account-notify") ||
196                            availableCapPair.at(0).startsWith("extended-join") ||
197                            availableCapPair.at(0).startsWith("userhost-in-names") ||
198                            availableCapPair.at(0).startsWith("multi-prefix")) {
199                     // Always request these capabilities if available
200                     queueCurrentCap = true;
201                 }
202                 if (queueCurrentCap) {
203                     if(availableCapPair.count() >= 2)
204                         coreNet->queuePendingCap(availableCapPair.at(0).trimmed(), availableCapPair.at(1).trimmed());
205                     else
206                         coreNet->queuePendingCap(availableCapPair.at(0).trimmed());
207                 }
208             }
209             // Begin capability requests when capability listing complete
210             if (capListFinished) {
211                 emit newEvent(new MessageEvent(Message::Server, e->network(), tr("Negotiating capabilities..."), QString(), QString(), Message::None, e->timestamp()));
212                 sendNextCap(coreNet);
213             }
214         } else if (e->params().at(1).compare("ACK", Qt::CaseInsensitive) == 0) {
215             // Server: CAP * ACK :multi-prefix sasl
216             // Got the capability we want, enable, handle as needed.
217             // As only one capability is requested at a time, no need to split
218             // Lower-case the list to make later comparisons easier
219             // Capability may include values, e.g. CAP * LS :multi-prefix sasl=EXTERNAL
220             QStringList acceptedCap = e->params().at(2).trimmed().split('=');
221
222             // Mark this cap as accepted
223             if(acceptedCap.count() >= 2)
224                 coreNet->addCap(acceptedCap.at(0), acceptedCap.at(1));
225             else
226                 coreNet->addCap(acceptedCap.at(0));
227
228             // Handle special cases
229             if (acceptedCap.at(0).startsWith("sasl")) {
230                 // Freenode (at least) sends "sasl " with a trailing space for some reason!
231                 // if the current identity has a cert set, use SASL EXTERNAL
232                 // FIXME use event
233                 // TODO If value of sasl capability is not empty, limit to accepted
234 #ifdef HAVE_SSL
235                 if (!coreNet->identityPtr()->sslCert().isNull()) {
236                     coreNet->putRawLine(coreNet->serverEncode("AUTHENTICATE EXTERNAL"));
237                 } else {
238 #endif
239                     // Only working with PLAIN atm, blowfish later
240                     coreNet->putRawLine(coreNet->serverEncode("AUTHENTICATE PLAIN"));
241 #ifdef HAVE_SSL
242                 }
243 #endif
244             } else {
245                 // Special handling not needed, move on to next cap
246                 sendNextCap(coreNet);
247             }
248         } else if (e->params().at(1).compare("NAK", Qt::CaseInsensitive) == 0) {
249             // Something went wrong with this capability, disable, go to next cap
250             // As only one capability is requested at a time, no need to split
251             // Lower-case the list to make later comparisons easier
252             QString deniedCap = e->params().at(2).trimmed();
253             coreNet->removeCap(deniedCap);
254             sendNextCap(coreNet);
255         }
256     }
257 }
258
259 /* IRCv3 account-notify
260  * Log in:  ":nick!user@host ACCOUNT accountname"
261  * Log out: ":nick!user@host ACCOUNT *" */
262 void CoreSessionEventProcessor::processIrcEventAccount(IrcEvent *e)
263 {
264     if (!checkParamCount(e, 1))
265         return;
266
267     IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
268     if (ircuser) {
269         // FIXME Keep track of authed user account, requires adding support to ircuser.h/cpp
270         /*
271         if (e->params().at(0) != "*") {
272             // Account logged in
273             qDebug() << "account-notify:" << ircuser->nick() << "logged in to" << e->params().at(0);
274         } else {
275             // Account logged out
276             qDebug() << "account-notify:" << ircuser->nick() << "logged out";
277         }
278         */
279     } else {
280         qDebug() << "Received account-notify data for unknown user" << e->prefix();
281     }
282 }
283
284 /* IRCv3 away-notify - ":nick!user@host AWAY [:message]" */
285 void CoreSessionEventProcessor::processIrcEventAway(IrcEvent *e)
286 {
287     if (!checkParamCount(e, 2))
288         return;
289
290     // Nick is sent as part of parameters in order to split user/server decoding
291     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
292     if (ircuser) {
293         if (!e->params().at(1).isEmpty()) {
294             ircuser->setAway(true);
295             ircuser->setAwayMessage(e->params().at(1));
296         } else {
297             ircuser->setAway(false);
298         }
299     } else {
300         qDebug() << "Received away-notify data for unknown user" << e->params().at(0);
301     }
302 }
303
304 void CoreSessionEventProcessor::processIrcEventInvite(IrcEvent *e)
305 {
306     if (checkParamCount(e, 2)) {
307         e->network()->updateNickFromMask(e->prefix());
308     }
309 }
310
311
312 void CoreSessionEventProcessor::processIrcEventJoin(IrcEvent *e)
313 {
314     if (e->testFlag(EventManager::Fake)) // generated by handleEarlyNetsplitJoin
315         return;
316
317     if (!checkParamCount(e, 1))
318         return;
319
320     CoreNetwork *net = coreNetwork(e);
321     QString channel = e->params()[0];
322     IrcUser *ircuser = net->updateNickFromMask(e->prefix());
323
324     if (net->useCapExtendedJoin()) {
325         if (!checkParamCount(e, 3))
326             return;
327         // If logged in, :nick!user@host JOIN #channelname accountname :Real Name
328         // If logged out, :nick!user@host JOIN #channelname * :Real Name
329         // See:  http://ircv3.net/specs/extensions/extended-join-3.1.html
330         // FIXME Keep track of authed user account, requires adding support to ircuser.h/cpp
331         ircuser->setRealName(e->params()[2]);
332     }
333     // Else :nick!user@host JOIN #channelname
334
335     bool handledByNetsplit = false;
336     foreach(Netsplit* n, _netsplits.value(e->network())) {
337         handledByNetsplit = n->userJoined(e->prefix(), channel);
338         if (handledByNetsplit)
339             break;
340     }
341
342     // If using away-notify, check new users.  Works around buggy IRC servers
343     // forgetting to send :away messages for users who join channels when away.
344     if (coreNetwork(e)->useCapAwayNotify()) {
345         coreNetwork(e)->queueAutoWhoOneshot(ircuser->nick());
346     }
347
348     if (!handledByNetsplit)
349         ircuser->joinChannel(channel);
350     else
351         e->setFlag(EventManager::Netsplit);
352
353     if (net->isMe(ircuser)) {
354         net->setChannelJoined(channel);
355         // FIXME use event
356         net->putRawLine(net->serverEncode("MODE " + channel)); // we want to know the modes of the channel we just joined, so we ask politely
357     }
358 }
359
360
361 void CoreSessionEventProcessor::lateProcessIrcEventKick(IrcEvent *e)
362 {
363     if (checkParamCount(e, 2)) {
364         e->network()->updateNickFromMask(e->prefix());
365         IrcUser *victim = e->network()->ircUser(e->params().at(1));
366         if (victim) {
367             victim->partChannel(e->params().at(0));
368             //if(e->network()->isMe(victim)) e->network()->setKickedFromChannel(channel);
369         }
370     }
371 }
372
373
374 void CoreSessionEventProcessor::processIrcEventMode(IrcEvent *e)
375 {
376     if (!checkParamCount(e, 2))
377         return;
378
379     if (e->network()->isChannelName(e->params().first())) {
380         // Channel Modes
381
382         IrcChannel *channel = e->network()->ircChannel(e->params()[0]);
383         if (!channel) {
384             // we received mode information for a channel we're not in. that means probably we've just been kicked out or something like that
385             // anyways: we don't have a place to store the data --> discard the info.
386             return;
387         }
388
389         QString modes = e->params()[1];
390         bool add = true;
391         int paramOffset = 2;
392         for (int c = 0; c < modes.length(); c++) {
393             if (modes[c] == '+') {
394                 add = true;
395                 continue;
396             }
397             if (modes[c] == '-') {
398                 add = false;
399                 continue;
400             }
401
402             if (e->network()->prefixModes().contains(modes[c])) {
403                 // user channel modes (op, voice, etc...)
404                 if (paramOffset < e->params().count()) {
405                     IrcUser *ircUser = e->network()->ircUser(e->params()[paramOffset]);
406                     if (!ircUser) {
407                         qWarning() << Q_FUNC_INFO << "Unknown IrcUser:" << e->params()[paramOffset];
408                     }
409                     else {
410                         if (add) {
411                             bool handledByNetsplit = false;
412                             QHash<QString, Netsplit *> splits = _netsplits.value(e->network());
413                             foreach(Netsplit* n, _netsplits.value(e->network())) {
414                                 handledByNetsplit = n->userAlreadyJoined(ircUser->hostmask(), channel->name());
415                                 if (handledByNetsplit) {
416                                     n->addMode(ircUser->hostmask(), channel->name(), QString(modes[c]));
417                                     break;
418                                 }
419                             }
420                             if (!handledByNetsplit)
421                                 channel->addUserMode(ircUser, QString(modes[c]));
422                         }
423                         else
424                             channel->removeUserMode(ircUser, QString(modes[c]));
425                     }
426                 }
427                 else {
428                     qWarning() << "Received MODE with too few parameters:" << e->params();
429                 }
430                 ++paramOffset;
431             }
432             else {
433                 // regular channel modes
434                 QString value;
435                 Network::ChannelModeType modeType = e->network()->channelModeType(modes[c]);
436                 if (modeType == Network::A_CHANMODE || modeType == Network::B_CHANMODE || (modeType == Network::C_CHANMODE && add)) {
437                     if (paramOffset < e->params().count()) {
438                         value = e->params()[paramOffset];
439                     }
440                     else {
441                         qWarning() << "Received MODE with too few parameters:" << e->params();
442                     }
443                     ++paramOffset;
444                 }
445
446                 if (add)
447                     channel->addChannelMode(modes[c], value);
448                 else
449                     channel->removeChannelMode(modes[c], value);
450             }
451         }
452     }
453     else {
454         // pure User Modes
455         IrcUser *ircUser = e->network()->newIrcUser(e->params().first());
456         QString modeString(e->params()[1]);
457         QString addModes;
458         QString removeModes;
459         bool add = false;
460         for (int c = 0; c < modeString.count(); c++) {
461             if (modeString[c] == '+') {
462                 add = true;
463                 continue;
464             }
465             if (modeString[c] == '-') {
466                 add = false;
467                 continue;
468             }
469             if (add)
470                 addModes += modeString[c];
471             else
472                 removeModes += modeString[c];
473         }
474         if (!addModes.isEmpty())
475             ircUser->addUserModes(addModes);
476         if (!removeModes.isEmpty())
477             ircUser->removeUserModes(removeModes);
478
479         if (e->network()->isMe(ircUser)) {
480             coreNetwork(e)->updatePersistentModes(addModes, removeModes);
481         }
482     }
483 }
484
485
486 void CoreSessionEventProcessor::lateProcessIrcEventNick(IrcEvent *e)
487 {
488     if (checkParamCount(e, 1)) {
489         IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
490         if (!ircuser) {
491             qWarning() << Q_FUNC_INFO << "Unknown IrcUser!";
492             return;
493         }
494         QString newnick = e->params().at(0);
495         QString oldnick = ircuser->nick();
496
497         // the order is cruicial
498         // otherwise the client would rename the buffer, see that the assigned ircuser doesn't match anymore
499         // and remove the ircuser from the querybuffer leading to a wrong on/offline state
500         ircuser->setNick(newnick);
501         coreSession()->renameBuffer(e->networkId(), newnick, oldnick);
502     }
503 }
504
505
506 void CoreSessionEventProcessor::lateProcessIrcEventPart(IrcEvent *e)
507 {
508     if (checkParamCount(e, 1)) {
509         IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
510         if (!ircuser) {
511             qWarning() << Q_FUNC_INFO<< "Unknown IrcUser!";
512             return;
513         }
514         QString channel = e->params().at(0);
515         ircuser->partChannel(channel);
516         if (e->network()->isMe(ircuser))
517             qobject_cast<CoreNetwork *>(e->network())->setChannelParted(channel);
518     }
519 }
520
521
522 void CoreSessionEventProcessor::processIrcEventPing(IrcEvent *e)
523 {
524     QString param = e->params().count() ? e->params().first() : QString();
525     // FIXME use events
526     coreNetwork(e)->putRawLine("PONG " + coreNetwork(e)->serverEncode(param));
527 }
528
529
530 void CoreSessionEventProcessor::processIrcEventPong(IrcEvent *e)
531 {
532     // the server is supposed to send back what we passed as param. and we send a timestamp
533     // but using quote and whatnought one can send arbitrary pings, so we have to do some sanity checks
534     if (checkParamCount(e, 2)) {
535         QString timestamp = e->params().at(1);
536         QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz");
537         if (sendTime.isValid())
538             e->network()->setLatency(sendTime.msecsTo(QTime::currentTime()) / 2);
539     }
540 }
541
542
543 void CoreSessionEventProcessor::processIrcEventQuit(IrcEvent *e)
544 {
545     IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
546     if (!ircuser)
547         return;
548
549     QString msg;
550     if (e->params().count() > 0)
551         msg = e->params()[0];
552
553     // check if netsplit
554     if (Netsplit::isNetsplit(msg)) {
555         Netsplit *n;
556         if (!_netsplits[e->network()].contains(msg)) {
557             n = new Netsplit(e->network(), this);
558             connect(n, SIGNAL(finished()), this, SLOT(handleNetsplitFinished()));
559             connect(n, SIGNAL(netsplitJoin(Network*, QString, QStringList, QStringList, QString)),
560                 this, SLOT(handleNetsplitJoin(Network*, QString, QStringList, QStringList, QString)));
561             connect(n, SIGNAL(netsplitQuit(Network*, QString, QStringList, QString)),
562                 this, SLOT(handleNetsplitQuit(Network*, QString, QStringList, QString)));
563             connect(n, SIGNAL(earlyJoin(Network*, QString, QStringList, QStringList)),
564                 this, SLOT(handleEarlyNetsplitJoin(Network*, QString, QStringList, QStringList)));
565             _netsplits[e->network()].insert(msg, n);
566         }
567         else {
568             n = _netsplits[e->network()][msg];
569         }
570         // add this user to the netsplit
571         n->userQuit(e->prefix(), ircuser->channels(), msg);
572         e->setFlag(EventManager::Netsplit);
573     }
574     // normal quit is handled in lateProcessIrcEventQuit()
575 }
576
577
578 void CoreSessionEventProcessor::lateProcessIrcEventQuit(IrcEvent *e)
579 {
580     if (e->testFlag(EventManager::Netsplit))
581         return;
582
583     IrcUser *ircuser = e->network()->updateNickFromMask(e->prefix());
584     if (!ircuser)
585         return;
586
587     ircuser->quit();
588 }
589
590
591 void CoreSessionEventProcessor::processIrcEventTopic(IrcEvent *e)
592 {
593     if (checkParamCount(e, 2)) {
594         e->network()->updateNickFromMask(e->prefix());
595         IrcChannel *channel = e->network()->ircChannel(e->params().at(0));
596         if (channel)
597             channel->setTopic(e->params().at(1));
598     }
599 }
600
601
602 #ifdef HAVE_QCA2
603 void CoreSessionEventProcessor::processKeyEvent(KeyEvent *e)
604 {
605     if (!Cipher::neededFeaturesAvailable()) {
606         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()));
607         return;
608     }
609     CoreNetwork *net = qobject_cast<CoreNetwork*>(e->network());
610     Cipher *c = net->cipher(e->target());
611     if (!c) // happens when there is no CoreIrcChannel for the target (i.e. never?)
612         return;
613
614     if (e->exchangeType() == KeyEvent::Init) {
615         QByteArray pubKey = c->parseInitKeyX(e->key());
616         if (pubKey.isEmpty()) {
617             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()));
618             return;
619         } else {
620             net->setCipherKey(e->target(), c->key());
621             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()));
622             QList<QByteArray> p;
623             p << net->serverEncode(e->target()) << net->serverEncode("DH1080_FINISH ")+pubKey;
624             net->putCmd("NOTICE", p);
625         }
626     } else {
627         if (c->parseFinishKeyX(e->key())) {
628             net->setCipherKey(e->target(), c->key());
629             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()));
630         } else {
631             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()));
632         }
633     }
634 }
635 #endif
636
637
638 /* RPL_WELCOME */
639 void CoreSessionEventProcessor::processIrcEvent001(IrcEventNumeric *e)
640 {
641     e->network()->setCurrentServer(e->prefix());
642     e->network()->setMyNick(e->target());
643 }
644
645
646 /* RPL_ISUPPORT */
647 // TODO Complete 005 handling, also use sensible defaults for non-sent stuff
648 void CoreSessionEventProcessor::processIrcEvent005(IrcEvent *e)
649 {
650     if (!checkParamCount(e, 1))
651         return;
652
653     QString key, value;
654     for (int i = 0; i < e->params().count() - 1; i++) {
655         QString key = e->params()[i].section("=", 0, 0);
656         QString value = e->params()[i].section("=", 1);
657         e->network()->addSupport(key, value);
658     }
659
660     /* determine our prefixes here to get an accurate result */
661     e->network()->determinePrefixes();
662 }
663
664
665 /* RPL_UMODEIS - "<user_modes> [<user_mode_params>]" */
666 void CoreSessionEventProcessor::processIrcEvent221(IrcEvent *)
667 {
668     // TODO: save information in network object
669 }
670
671
672 /* RPL_STATSCONN - "Highest connection cout: 8000 (7999 clients)" */
673 void CoreSessionEventProcessor::processIrcEvent250(IrcEvent *)
674 {
675     // TODO: save information in network object
676 }
677
678
679 /* RPL_LOCALUSERS - "Current local user: 5024  Max: 7999 */
680 void CoreSessionEventProcessor::processIrcEvent265(IrcEvent *)
681 {
682     // TODO: save information in network object
683 }
684
685
686 /* RPL_GLOBALUSERS - "Current global users: 46093  Max: 47650" */
687 void CoreSessionEventProcessor::processIrcEvent266(IrcEvent *)
688 {
689     // TODO: save information in network object
690 }
691
692
693 /*
694 WHOIS-Message:
695    Replies 311 - 313, 317 - 319 are all replies generated in response to a WHOIS message.
696   and 301 (RPL_AWAY)
697               "<nick> :<away message>"
698 WHO-Message:
699    Replies 352 and 315 paired are used to answer a WHO message.
700
701 WHOWAS-Message:
702    Replies 314 and 369 are responses to a WHOWAS message.
703
704 */
705
706 /* RPL_AWAY - "<nick> :<away message>" */
707 void CoreSessionEventProcessor::processIrcEvent301(IrcEvent *e)
708 {
709     if (!checkParamCount(e, 2))
710         return;
711
712     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
713     if (ircuser) {
714         ircuser->setAway(true);
715         ircuser->setAwayMessage(e->params().at(1));
716         //ircuser->setLastAwayMessage(now);
717     }
718 }
719
720
721 /* RPL_UNAWAY - ":You are no longer marked as being away" */
722 void CoreSessionEventProcessor::processIrcEvent305(IrcEvent *e)
723 {
724     IrcUser *me = e->network()->me();
725     if (me)
726         me->setAway(false);
727
728     if (e->network()->autoAwayActive()) {
729         e->network()->setAutoAwayActive(false);
730         e->setFlag(EventManager::Silent);
731     }
732 }
733
734
735 /* RPL_NOWAWAY - ":You have been marked as being away" */
736 void CoreSessionEventProcessor::processIrcEvent306(IrcEvent *e)
737 {
738     IrcUser *me = e->network()->me();
739     if (me)
740         me->setAway(true);
741 }
742
743
744 /* RPL_WHOISSERVICE - "<user> is registered nick" */
745 void CoreSessionEventProcessor::processIrcEvent307(IrcEvent *e)
746 {
747     if (!checkParamCount(e, 1))
748         return;
749
750     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
751     if (ircuser)
752         ircuser->setWhoisServiceReply(e->params().join(" "));
753 }
754
755
756 /* RPL_SUSERHOST - "<user> is available for help." */
757 void CoreSessionEventProcessor::processIrcEvent310(IrcEvent *e)
758 {
759     if (!checkParamCount(e, 1))
760         return;
761
762     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
763     if (ircuser)
764         ircuser->setSuserHost(e->params().join(" "));
765 }
766
767
768 /*  RPL_WHOISUSER - "<nick> <user> <host> * :<real name>" */
769 void CoreSessionEventProcessor::processIrcEvent311(IrcEvent *e)
770 {
771     if (!checkParamCount(e, 3))
772         return;
773
774     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
775     if (ircuser) {
776         ircuser->setUser(e->params().at(1));
777         ircuser->setHost(e->params().at(2));
778         ircuser->setRealName(e->params().last());
779     }
780 }
781
782
783 /*  RPL_WHOISSERVER -  "<nick> <server> :<server info>" */
784 void CoreSessionEventProcessor::processIrcEvent312(IrcEvent *e)
785 {
786     if (!checkParamCount(e, 2))
787         return;
788
789     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
790     if (ircuser)
791         ircuser->setServer(e->params().at(1));
792 }
793
794
795 /*  RPL_WHOISOPERATOR - "<nick> :is an IRC operator" */
796 void CoreSessionEventProcessor::processIrcEvent313(IrcEvent *e)
797 {
798     if (!checkParamCount(e, 1))
799         return;
800
801     IrcUser *ircuser = e->network()->ircUser(e->params().at(0));
802     if (ircuser)
803         ircuser->setIrcOperator(e->params().last());
804 }
805
806
807 /*  RPL_ENDOFWHO: "<name> :End of WHO list" */
808 void CoreSessionEventProcessor::processIrcEvent315(IrcEvent *e)
809 {
810     if (!checkParamCount(e, 1))
811         return;
812
813     if (coreNetwork(e)->setAutoWhoDone(e->params()[0]))
814         e->setFlag(EventManager::Silent);
815 }
816
817
818 /*  RPL_WHOISIDLE - "<nick> <integer> :seconds idle"
819    (real life: "<nick> <integer> <integer> :seconds idle, signon time) */
820 void CoreSessionEventProcessor::processIrcEvent317(IrcEvent *e)
821 {
822     if (!checkParamCount(e, 2))
823         return;
824
825     QDateTime loginTime;
826
827     int idleSecs = e->params()[1].toInt();
828     if (e->params().count() > 3) { // if we have more then 3 params we have the above mentioned "real life" situation
829         int logintime = e->params()[2].toInt();
830         loginTime = QDateTime::fromTime_t(logintime);
831     }
832
833     IrcUser *ircuser = e->network()->ircUser(e->params()[0]);
834     if (ircuser) {
835         ircuser->setIdleTime(e->timestamp().addSecs(-idleSecs));
836         if (loginTime.isValid())
837             ircuser->setLoginTime(loginTime);
838     }
839 }
840
841
842 /* RPL_LIST -  "<channel> <# visible> :<topic>" */
843 void CoreSessionEventProcessor::processIrcEvent322(IrcEvent *e)
844 {
845     if (!checkParamCount(e, 1))
846         return;
847
848     QString channelName;
849     quint32 userCount = 0;
850     QString topic;
851
852     switch (e->params().count()) {
853     case 3:
854         topic = e->params()[2];
855     case 2:
856         userCount = e->params()[1].toUInt();
857     case 1:
858         channelName = e->params()[0];
859     default:
860         break;
861     }
862     if (coreSession()->ircListHelper()->addChannel(e->networkId(), channelName, userCount, topic))
863         e->stop();  // consumed by IrcListHelper, so don't further process/show this event
864 }
865
866
867 /* RPL_LISTEND ":End of LIST" */
868 void CoreSessionEventProcessor::processIrcEvent323(IrcEvent *e)
869 {
870     if (!checkParamCount(e, 1))
871         return;
872
873     if (coreSession()->ircListHelper()->endOfChannelList(e->networkId()))
874         e->stop();  // consumed by IrcListHelper, so don't further process/show this event
875 }
876
877
878 /* RPL_CHANNELMODEIS - "<channel> <mode> <mode params>" */
879 void CoreSessionEventProcessor::processIrcEvent324(IrcEvent *e)
880 {
881     processIrcEventMode(e);
882 }
883
884
885 /* RPL_NOTOPIC */
886 void CoreSessionEventProcessor::processIrcEvent331(IrcEvent *e)
887 {
888     if (!checkParamCount(e, 1))
889         return;
890
891     IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
892     if (chan)
893         chan->setTopic(QString());
894 }
895
896
897 /* RPL_TOPIC */
898 void CoreSessionEventProcessor::processIrcEvent332(IrcEvent *e)
899 {
900     if (!checkParamCount(e, 2))
901         return;
902
903     IrcChannel *chan = e->network()->ircChannel(e->params()[0]);
904     if (chan)
905         chan->setTopic(e->params()[1]);
906 }
907
908
909 /*  RPL_WHOREPLY: "<channel> <user> <host> <server> <nick>
910               ( "H" / "G" > ["*"] [ ( "@" / "+" ) ] :<hopcount> <real name>" */
911 void CoreSessionEventProcessor::processIrcEvent352(IrcEvent *e)
912 {
913     if (!checkParamCount(e, 6))
914         return;
915
916     QString channel = e->params()[0];
917     IrcUser *ircuser = e->network()->ircUser(e->params()[4]);
918     if (ircuser) {
919         ircuser->setUser(e->params()[1]);
920         ircuser->setHost(e->params()[2]);
921
922         bool away = e->params()[5].contains("G", Qt::CaseInsensitive);
923         ircuser->setAway(away);
924         ircuser->setServer(e->params()[3]);
925         ircuser->setRealName(e->params().last().section(" ", 1));
926
927         if (coreNetwork(e)->useCapMultiPrefix()) {
928             // If multi-prefix is enabled, all modes will be sent in WHO replies.
929             // :kenny.chatspike.net 352 guest #test grawity broken.symlink *.chatspike.net grawity H@%+ :0 Mantas M.
930             // See: http://ircv3.net/specs/extensions/multi-prefix-3.1.html
931             QString uncheckedModes = e->params()[5];
932             QString validModes = QString();
933             while (!uncheckedModes.isEmpty()) {
934                 // Mode found in 1 left-most character, add it to the list
935                 if (e->network()->prefixes().contains(uncheckedModes[0])) {
936                     validModes.append(e->network()->prefixToMode(uncheckedModes[0]));
937                 }
938                 // Remove this mode from the list of unchecked modes
939                 uncheckedModes = uncheckedModes.remove(0, 1);
940             }
941
942             // Some IRC servers decide to not follow the spec, returning only -some- of the user
943             // modes in WHO despite listing them all in NAMES.  For now, assume it can only add
944             // and not take away.  *sigh*
945             if (!validModes.isEmpty())
946                 ircuser->addUserModes(validModes);
947         }
948     }
949
950     // Check if channel name has a who in progress.
951     // If not, then check if user nick exists and has a who in progress.
952     if (coreNetwork(e)->isAutoWhoInProgress(channel) ||
953         (ircuser && coreNetwork(e)->isAutoWhoInProgress(ircuser->nick()))) {
954         e->setFlag(EventManager::Silent);
955     }
956 }
957
958
959 /* RPL_NAMREPLY */
960 void CoreSessionEventProcessor::processIrcEvent353(IrcEvent *e)
961 {
962     if (!checkParamCount(e, 3))
963         return;
964
965     // param[0] is either "=", "*" or "@" indicating a public, private or secret channel
966     // we don't use this information at the time beeing
967     QString channelname = e->params()[1];
968
969     IrcChannel *channel = e->network()->ircChannel(channelname);
970     if (!channel) {
971         qWarning() << Q_FUNC_INFO << "Received unknown target channel:" << channelname;
972         return;
973     }
974
975     QStringList nicks;
976     QStringList modes;
977
978     // Cache result of multi-prefix to avoid unneeded casts and lookups with each iteration.
979     bool _useCapMultiPrefix = coreNetwork(e)->useCapMultiPrefix();
980
981     foreach(QString nick, e->params()[2].split(' ', QString::SkipEmptyParts)) {
982         QString mode;
983
984         if (_useCapMultiPrefix) {
985             // If multi-prefix is enabled, all modes will be sent in NAMES replies.
986             // :hades.arpa 353 guest = #tethys :~&@%+aji &@Attila @+alyx +KindOne Argure
987             // See: http://ircv3.net/specs/extensions/multi-prefix-3.1.html
988             while (e->network()->prefixes().contains(nick[0])) {
989                 // Mode found in 1 left-most character, add it to the list.
990                 // Note: sending multiple modes may cause a warning in older clients.
991                 // In testing, the clients still seemed to function fine.
992                 mode.append(e->network()->prefixToMode(nick[0]));
993                 // Remove this mode from the nick
994                 nick = nick.remove(0, 1);
995             }
996         } else if (e->network()->prefixes().contains(nick[0])) {
997             // Multi-prefix is disabled and a mode prefix was found.
998             mode = e->network()->prefixToMode(nick[0]);
999             nick = nick.mid(1);
1000         }
1001
1002         // If userhost-in-names capability is enabled, the following will be
1003         // in the form "nick!user@host" rather than "nick".  This works without
1004         // special handling as the following use nickFromHost() as needed.
1005         // See: http://ircv3.net/specs/extensions/userhost-in-names-3.2.html
1006
1007         nicks << nick;
1008         modes << mode;
1009     }
1010
1011     channel->joinIrcUsers(nicks, modes);
1012 }
1013
1014
1015 /* ERR_ERRONEUSNICKNAME */
1016 void CoreSessionEventProcessor::processIrcEvent432(IrcEventNumeric *e)
1017 {
1018     if (!checkParamCount(e, 1))
1019         return;
1020
1021     QString errnick;
1022     if (e->params().count() < 2) {
1023         // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
1024         // nick @@@
1025         // :irc.scortum.moep.net 432  @@@ :Erroneous Nickname: Illegal characters
1026         // correct server reply:
1027         // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
1028         e->params().prepend(e->target());
1029         e->setTarget("*");
1030     }
1031     errnick = e->params()[0];
1032
1033     tryNextNick(e, errnick, true /* erroneus */);
1034 }
1035
1036
1037 /* ERR_NICKNAMEINUSE */
1038 void CoreSessionEventProcessor::processIrcEvent433(IrcEventNumeric *e)
1039 {
1040     if (!checkParamCount(e, 1))
1041         return;
1042
1043     QString errnick = e->params().first();
1044
1045     // if there is a problem while connecting to the server -> we handle it
1046     // but only if our connection has not been finished yet...
1047     if (!e->network()->currentServer().isEmpty())
1048         return;
1049
1050     tryNextNick(e, errnick);
1051 }
1052
1053
1054 /* ERR_UNAVAILRESOURCE */
1055 void CoreSessionEventProcessor::processIrcEvent437(IrcEventNumeric *e)
1056 {
1057     if (!checkParamCount(e, 1))
1058         return;
1059
1060     QString errnick = e->params().first();
1061
1062     // if there is a problem while connecting to the server -> we handle it
1063     // but only if our connection has not been finished yet...
1064     if (!e->network()->currentServer().isEmpty())
1065         return;
1066
1067     if (!e->network()->isChannelName(errnick))
1068         tryNextNick(e, errnick);
1069 }
1070
1071
1072 /* template
1073 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
1074   if(!checkParamCount(e, 1))
1075     return;
1076
1077 }
1078 */
1079
1080 /* Handle signals from Netsplit objects  */
1081
1082 void CoreSessionEventProcessor::handleNetsplitJoin(Network *net,
1083     const QString &channel,
1084     const QStringList &users,
1085     const QStringList &modes,
1086     const QString &quitMessage)
1087 {
1088     IrcChannel *ircChannel = net->ircChannel(channel);
1089     if (!ircChannel) {
1090         return;
1091     }
1092     QList<IrcUser *> ircUsers;
1093     QStringList newModes = modes;
1094     QStringList newUsers = users;
1095
1096     foreach(const QString &user, users) {
1097         IrcUser *iu = net->ircUser(nickFromMask(user));
1098         if (iu)
1099             ircUsers.append(iu);
1100         else { // the user already quit
1101             int idx = users.indexOf(user);
1102             newUsers.removeAt(idx);
1103             newModes.removeAt(idx);
1104         }
1105     }
1106
1107     ircChannel->joinIrcUsers(ircUsers, newModes);
1108     NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitJoin, net, channel, newUsers, quitMessage);
1109     emit newEvent(event);
1110 }
1111
1112
1113 void CoreSessionEventProcessor::handleNetsplitQuit(Network *net, const QString &channel, const QStringList &users, const QString &quitMessage)
1114 {
1115     NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitQuit, net, channel, users, quitMessage);
1116     emit newEvent(event);
1117     foreach(QString user, users) {
1118         IrcUser *iu = net->ircUser(nickFromMask(user));
1119         if (iu)
1120             iu->quit();
1121     }
1122 }
1123
1124
1125 void CoreSessionEventProcessor::handleEarlyNetsplitJoin(Network *net, const QString &channel, const QStringList &users, const QStringList &modes)
1126 {
1127     IrcChannel *ircChannel = net->ircChannel(channel);
1128     if (!ircChannel) {
1129         qDebug() << "handleEarlyNetsplitJoin(): channel " << channel << " invalid";
1130         return;
1131     }
1132     QList<NetworkEvent *> events;
1133     QList<IrcUser *> ircUsers;
1134     QStringList newModes = modes;
1135
1136     foreach(QString user, users) {
1137         IrcUser *iu = net->updateNickFromMask(user);
1138         if (iu) {
1139             ircUsers.append(iu);
1140             // fake event for scripts that consume join events
1141             events << new IrcEvent(EventManager::IrcEventJoin, net, iu->hostmask(), QStringList() << channel);
1142         }
1143         else {
1144             newModes.removeAt(users.indexOf(user));
1145         }
1146     }
1147     ircChannel->joinIrcUsers(ircUsers, newModes);
1148     foreach(NetworkEvent *event, events) {
1149         event->setFlag(EventManager::Fake); // ignore this in here!
1150         emit newEvent(event);
1151     }
1152 }
1153
1154
1155 void CoreSessionEventProcessor::handleNetsplitFinished()
1156 {
1157     Netsplit *n = qobject_cast<Netsplit *>(sender());
1158     Q_ASSERT(n);
1159     QHash<QString, Netsplit *> splithash  = _netsplits.take(n->network());
1160     splithash.remove(splithash.key(n));
1161     if (splithash.count())
1162         _netsplits[n->network()] = splithash;
1163     n->deleteLater();
1164 }
1165
1166
1167 void CoreSessionEventProcessor::destroyNetsplits(NetworkId netId)
1168 {
1169     Network *net = coreSession()->network(netId);
1170     if (!net)
1171         return;
1172
1173     QHash<QString, Netsplit *> splits = _netsplits.take(net);
1174     qDeleteAll(splits);
1175 }
1176
1177
1178 /*******************************/
1179 /******** CTCP HANDLING ********/
1180 /*******************************/
1181
1182 void CoreSessionEventProcessor::processCtcpEvent(CtcpEvent *e)
1183 {
1184     if (e->testFlag(EventManager::Self))
1185         return;  // ignore ctcp events generated by user input
1186
1187     if (e->type() != EventManager::CtcpEvent || e->ctcpType() != CtcpEvent::Query)
1188         return;
1189
1190     handle(e->ctcpCmd(), Q_ARG(CtcpEvent *, e));
1191 }
1192
1193
1194 void CoreSessionEventProcessor::defaultHandler(const QString &ctcpCmd, CtcpEvent *e)
1195 {
1196     // This handler is only there to avoid warnings for unknown CTCPs
1197     Q_UNUSED(e);
1198     Q_UNUSED(ctcpCmd);
1199 }
1200
1201
1202 void CoreSessionEventProcessor::handleCtcpAction(CtcpEvent *e)
1203 {
1204     // This handler is only there to feed CLIENTINFO
1205     Q_UNUSED(e);
1206 }
1207
1208
1209 void CoreSessionEventProcessor::handleCtcpClientinfo(CtcpEvent *e)
1210 {
1211     QStringList supportedHandlers;
1212     foreach(QString handler, providesHandlers())
1213     supportedHandlers << handler.toUpper();
1214     qSort(supportedHandlers);
1215     e->setReply(supportedHandlers.join(" "));
1216 }
1217
1218
1219 // http://www.irchelp.org/irchelp/rfc/ctcpspec.html
1220 // http://en.wikipedia.org/wiki/Direct_Client-to-Client
1221 void CoreSessionEventProcessor::handleCtcpDcc(CtcpEvent *e)
1222 {
1223     // DCC support is unfinished, experimental and potentially dangerous, so make it opt-in
1224     if (!Quassel::isOptionSet("enable-experimental-dcc")) {
1225         quInfo() << "DCC disabled, start core with --enable-experimental-dcc if you really want to try it out";
1226         return;
1227     }
1228
1229     // normal:  SEND <filename> <ip> <port> [<filesize>]
1230     // reverse: SEND <filename> <ip> 0 <filesize> <token>
1231     QStringList params = e->param().split(' ');
1232     if (params.count()) {
1233         QString cmd = params[0].toUpper();
1234         if (cmd == "SEND") {
1235             if (params.count() < 4) {
1236                 qWarning() << "Invalid DCC SEND request:" << e;  // TODO emit proper error to client
1237                 return;
1238             }
1239             QString filename = params[1];
1240             QHostAddress address;
1241             quint16 port = params[3].toUShort();
1242             quint64 size = 0;
1243             QString numIp = params[2]; // this is either IPv4 as a 32 bit value, or IPv6 (which always contains a colon)
1244             if (numIp.contains(':')) { // IPv6
1245                 if (!address.setAddress(numIp)) {
1246                     qWarning() << "Invalid IPv6:" << numIp;
1247                     return;
1248                 }
1249             }
1250             else {
1251                 address.setAddress(numIp.toUInt());
1252             }
1253
1254             if (port == 0) { // Reverse DCC is indicated by a 0 port
1255                 emit newEvent(new MessageEvent(Message::Error, e->network(), tr("Reverse DCC SEND not supported"), e->prefix(), e->target(), Message::None, e->timestamp()));
1256                 return;
1257             }
1258             if (port < 1024) {
1259                 qWarning() << "Privileged port requested:" << port; // FIXME ask user if this is ok
1260             }
1261
1262
1263             if (params.count() > 4) { // filesize is optional
1264                 size = params[4].toULong();
1265             }
1266
1267             // TODO: check if target is the right thing to use for the partner
1268             CoreTransfer *transfer = new CoreTransfer(Transfer::Receive, e->target(), filename, address, port, size, this);
1269             coreSession()->signalProxy()->synchronize(transfer);
1270             coreSession()->transferManager()->addTransfer(transfer);
1271         }
1272         else {
1273             emit newEvent(new MessageEvent(Message::Error, e->network(), tr("DCC %1 not supported").arg(cmd), e->prefix(), e->target(), Message::None, e->timestamp()));
1274             return;
1275         }
1276     }
1277 }
1278
1279
1280 void CoreSessionEventProcessor::handleCtcpPing(CtcpEvent *e)
1281 {
1282     e->setReply(e->param().isNull() ? "" : e->param());
1283 }
1284
1285
1286 void CoreSessionEventProcessor::handleCtcpTime(CtcpEvent *e)
1287 {
1288     e->setReply(QDateTime::currentDateTime().toString());
1289 }
1290
1291
1292 void CoreSessionEventProcessor::handleCtcpVersion(CtcpEvent *e)
1293 {
1294     e->setReply(QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
1295         .arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate));
1296 }