void IrcSessionPrivate::processLine(const QByteArray& line) { Q_Q(IrcSession); QString encoded = encoder.encode(line); static bool dbg = qgetenv("COMMUNI_DEBUG").toInt(); if (dbg) qDebug() << encoded; IrcMessage* msg = IrcMessage::fromString(encoded); if (msg) { switch (msg->type()) { case IrcMessage::Numeric: if (static_cast<IrcNumericMessage*>(msg)->code() == Irc::RPL_WELCOME) { setNick(msg->parameters().value(0)); connected = true; emit q->connected(); emit q->connectedChanged(true); } else if (static_cast<IrcNumericMessage*>(msg)->code() == Irc::RPL_ISUPPORT) { foreach (const QString& param, msg->parameters().mid(1)) { const QStringList keyValue = param.split("=", QString::SkipEmptyParts); info.insert(keyValue.value(0), keyValue.value(1)); } } break; case IrcMessage::Ping: q->sendRaw("PONG " + static_cast<IrcPingMessage*>(msg)->argument()); break; case IrcMessage::Private: { IrcPrivateMessage* privMsg = static_cast<IrcPrivateMessage*>(msg); if (privMsg->isRequest()) { QString reply; QString request = privMsg->message().split(" ", QString::SkipEmptyParts).value(0).toUpper(); if (request == "PING") reply = privMsg->message(); else if (request == "TIME") reply = "TIME " + QLocale().toString(QDateTime::currentDateTime(), QLocale::ShortFormat); else if (request == "VERSION") reply = QString("VERSION Communi ") + Irc::version(); if (!reply.isNull()) q->sendCommand(IrcCommand::createCtcpReply(msg->sender().name(), reply)); } break; } case IrcMessage::Nick: if (msg->sender().name() == nickName) setNick(static_cast<IrcNickMessage*>(msg)->nick()); break; default: break; } emit q->messageReceived(msg); msg->deleteLater(); }
void IrcSessionPrivate::processLine(const QByteArray& line) { Q_Q(IrcSession); static bool dbg = qgetenv("COMMUNI_DEBUG").toInt(); if (dbg) qDebug() << line; IrcMessage* msg = IrcMessage::fromData(line, encoding, q); if (msg) { switch (msg->type()) { case IrcMessage::Numeric: if (static_cast<IrcNumericMessage*>(msg)->code() == Irc::RPL_WELCOME) { setNick(msg->parameters().value(0)); setConnected(true); } break; case IrcMessage::Ping: q->sendRaw("PONG " + static_cast<IrcPingMessage*>(msg)->argument()); break; case IrcMessage::Private: { IrcPrivateMessage* privMsg = static_cast<IrcPrivateMessage*>(msg); if (privMsg->isRequest()) { IrcCommand* reply = q->createCtcpReply(privMsg); if (reply) q->sendCommand(reply); } break; } case IrcMessage::Nick: if (msg->isOwn()) setNick(static_cast<IrcNickMessage*>(msg)->nick()); break; case IrcMessage::Capability: if (!connected) { IrcCapabilityMessage* capMsg = static_cast<IrcCapabilityMessage*>(msg); QString subCommand = capMsg->subCommand(); if (subCommand == "LS") { foreach (const QString& cap, capMsg->capabilities()) capabilities.insert(cap); QStringList params = capMsg->parameters(); if (params.value(params.count() - 1) != QLatin1String("*")) { QStringList request; emit q->capabilities(capabilities.toList(), &request); if (!request.isEmpty()) q->sendCommand(IrcCommand::createCapability("REQ", request)); else q->sendData("CAP END"); } } else if (subCommand == "ACK" || subCommand == "NAK") { q->sendData("CAP END"); } }