+
+/* Handle signals from Netsplit objects */
+
+void CoreSessionEventProcessor::handleNetsplitJoin(Network *net,
+ const QString &channel,
+ const QStringList &users,
+ const QStringList &modes,
+ const QString &quitMessage)
+{
+ IrcChannel *ircChannel = net->ircChannel(channel);
+ if (!ircChannel) {
+ return;
+ }
+ QList<IrcUser *> ircUsers;
+ QStringList newModes = modes;
+ QStringList newUsers = users;
+
+ foreach(const QString &user, users) {
+ IrcUser *iu = net->ircUser(nickFromMask(user));
+ if (iu)
+ ircUsers.append(iu);
+ else { // the user already quit
+ int idx = users.indexOf(user);
+ newUsers.removeAt(idx);
+ newModes.removeAt(idx);
+ }
+ }
+
+ ircChannel->joinIrcUsers(ircUsers, newModes);
+ NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitJoin, net, channel, newUsers, quitMessage);
+ emit newEvent(event);
+}
+
+
+void CoreSessionEventProcessor::handleNetsplitQuit(Network *net, const QString &channel, const QStringList &users, const QString &quitMessage)
+{
+ NetworkSplitEvent *event = new NetworkSplitEvent(EventManager::NetworkSplitQuit, net, channel, users, quitMessage);
+ emit newEvent(event);
+ foreach(QString user, users) {
+ IrcUser *iu = net->ircUser(nickFromMask(user));
+ if (iu)
+ iu->quit();
+ }
+}
+
+
+void CoreSessionEventProcessor::handleEarlyNetsplitJoin(Network *net, const QString &channel, const QStringList &users, const QStringList &modes)
+{
+ IrcChannel *ircChannel = net->ircChannel(channel);
+ if (!ircChannel) {
+ qDebug() << "handleEarlyNetsplitJoin(): channel " << channel << " invalid";
+ return;
+ }
+ QList<NetworkEvent *> events;
+ QList<IrcUser *> ircUsers;
+ QStringList newModes = modes;
+
+ foreach(QString user, users) {
+ IrcUser *iu = net->updateNickFromMask(user);
+ if (iu) {
+ ircUsers.append(iu);
+ // fake event for scripts that consume join events
+ events << new IrcEvent(EventManager::IrcEventJoin, net, iu->hostmask(), QStringList() << channel);
+ }
+ else {
+ newModes.removeAt(users.indexOf(user));
+ }
+ }
+ ircChannel->joinIrcUsers(ircUsers, newModes);
+ foreach(NetworkEvent *event, events) {
+ event->setFlag(EventManager::Fake); // ignore this in here!
+ emit newEvent(event);
+ }
+}
+
+
+void CoreSessionEventProcessor::handleNetsplitFinished()
+{
+ Netsplit *n = qobject_cast<Netsplit *>(sender());
+ Q_ASSERT(n);
+ QHash<QString, Netsplit *> splithash = _netsplits.take(n->network());
+ splithash.remove(splithash.key(n));
+ if (splithash.count())
+ _netsplits[n->network()] = splithash;
+ n->deleteLater();
+}
+
+
+void CoreSessionEventProcessor::destroyNetsplits(NetworkId netId)
+{
+ Network *net = coreSession()->network(netId);
+ if (!net)
+ return;
+
+ QHash<QString, Netsplit *> splits = _netsplits.take(net);
+ qDeleteAll(splits);
+}
+
+
+/*******************************/
+/******** CTCP HANDLING ********/
+/*******************************/
+
+void CoreSessionEventProcessor::processCtcpEvent(CtcpEvent *e)
+{
+ if (e->testFlag(EventManager::Self))
+ return; // ignore ctcp events generated by user input
+
+ if (e->type() != EventManager::CtcpEvent || e->ctcpType() != CtcpEvent::Query)
+ return;
+
+ handle(e->ctcpCmd(), Q_ARG(CtcpEvent *, e));
+}
+
+
+void CoreSessionEventProcessor::defaultHandler(const QString &ctcpCmd, CtcpEvent *e)
+{
+ // This handler is only there to avoid warnings for unknown CTCPs
+ Q_UNUSED(e);
+ Q_UNUSED(ctcpCmd);
+}
+
+
+void CoreSessionEventProcessor::handleCtcpAction(CtcpEvent *e)
+{
+ // This handler is only there to feed CLIENTINFO
+ Q_UNUSED(e);
+}
+
+
+void CoreSessionEventProcessor::handleCtcpClientinfo(CtcpEvent *e)
+{
+ QStringList supportedHandlers;
+ foreach(QString handler, providesHandlers())
+ supportedHandlers << handler.toUpper();
+ qSort(supportedHandlers);
+ e->setReply(supportedHandlers.join(" "));
+}
+
+
+// http://www.irchelp.org/irchelp/rfc/ctcpspec.html
+// http://en.wikipedia.org/wiki/Direct_Client-to-Client
+void CoreSessionEventProcessor::handleCtcpDcc(CtcpEvent *e)
+{
+ // DCC support is unfinished, experimental and potentially dangerous, so make it opt-in
+ if (!Quassel::isOptionSet("enable-experimental-dcc")) {
+ quInfo() << "DCC disabled, start core with --enable-experimental-dcc if you really want to try it out";
+ return;
+ }
+
+ // normal: SEND <filename> <ip> <port> [<filesize>]
+ // reverse: SEND <filename> <ip> 0 <filesize> <token>
+ QStringList params = e->param().split(' ');
+ if (params.count()) {
+ QString cmd = params[0].toUpper();
+ if (cmd == "SEND") {
+ if (params.count() < 4) {
+ qWarning() << "Invalid DCC SEND request:" << e; // TODO emit proper error to client
+ return;
+ }
+ QString filename = params[1];
+ QHostAddress address;
+ quint16 port = params[3].toUShort();
+ quint64 size = 0;
+ QString numIp = params[2]; // this is either IPv4 as a 32 bit value, or IPv6 (which always contains a colon)
+ if (numIp.contains(':')) { // IPv6
+ if (!address.setAddress(numIp)) {
+ qWarning() << "Invalid IPv6:" << numIp;
+ return;
+ }
+ }
+ else {
+ address.setAddress(numIp.toUInt());
+ }
+
+ if (port == 0) { // Reverse DCC is indicated by a 0 port
+ emit newEvent(new MessageEvent(Message::Error, e->network(), tr("Reverse DCC SEND not supported"), e->prefix(), e->target(), Message::None, e->timestamp()));
+ return;
+ }
+ if (port < 1024) {
+ qWarning() << "Privileged port requested:" << port; // FIXME ask user if this is ok
+ }
+
+
+ if (params.count() > 4) { // filesize is optional
+ size = params[4].toULong();
+ }
+
+ // TODO: check if target is the right thing to use for the partner
+ CoreTransfer *transfer = new CoreTransfer(Transfer::Receive, e->target(), filename, address, port, size, this);
+ coreSession()->signalProxy()->synchronize(transfer);
+ coreSession()->transferManager()->addTransfer(transfer);
+ }
+ else {
+ emit newEvent(new MessageEvent(Message::Error, e->network(), tr("DCC %1 not supported").arg(cmd), e->prefix(), e->target(), Message::None, e->timestamp()));
+ return;
+ }
+ }
+}
+
+
+void CoreSessionEventProcessor::handleCtcpPing(CtcpEvent *e)
+{
+ e->setReply(e->param().isNull() ? "" : e->param());
+}
+
+
+void CoreSessionEventProcessor::handleCtcpTime(CtcpEvent *e)
+{
+ e->setReply(QDateTime::currentDateTime().toString());
+}
+
+
+void CoreSessionEventProcessor::handleCtcpVersion(CtcpEvent *e)
+{
+ e->setReply(QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
+ .arg(Quassel::buildInfo().plainVersionString).arg(Quassel::buildInfo().buildDate));
+}