Esempio n. 1
0
void IrcSessionPrivate::receiveMessage(IrcMessage* msg)
{
    Q_Q(IrcSession);
    switch (msg->type()) {
        case IrcMessage::Numeric: {
            IrcNumericMessage* numeric = static_cast<IrcNumericMessage*>(msg);
            if (numeric->code() == Irc::RPL_WELCOME) {
                setNick(msg->parameters().value(0));
                setConnected(true);
            } else if (numeric->code() == Irc::RPL_ISUPPORT) {
                foreach (const QString& param, msg->parameters().mid(1)) {
                    QStringList keyValue = param.split("=", QString::SkipEmptyParts);
                    info.insert(keyValue.value(0), keyValue.value(1));
                }
                emit q->sessionInfoReceived(IrcSessionInfo(q));
            }
            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->flags() & IrcMessage::Own)
                setNick(static_cast<IrcNickMessage*>(msg)->nick());
            break;
        case IrcMessage::Capability: {
            IrcCapabilityMessage* capMsg = static_cast<IrcCapabilityMessage*>(msg);
            QString subCommand = capMsg->subCommand();
            if (subCommand == "LS") {
                foreach (const QString& cap, capMsg->capabilities())
                    handleCapability(&availableCaps, cap);

                if (!connected) {
                    QStringList params = capMsg->parameters();
                    if (params.value(params.count() - 1) != QLatin1String("*")) {
                        QStringList request;
                        emit q->capabilities(availableCaps.toList(), &request);
                        if (!request.isEmpty())
                            q->sendCommand(IrcCommand::createCapability("REQ", request));
                        else
                            q->sendData("CAP END");
                    }
                }
            } else if (subCommand == "ACK" || subCommand == "NAK") {
Esempio n. 2
0
void MyIrcSession::on_numericMessageReceived(IrcMessage *message) {
	QString channel;
	QStringList members;

	IrcNumericMessage *m = (IrcNumericMessage *) message;
	switch (m->code()) {
		case 332:
			m_topicData = TO_UTF8(m->parameters().value(2));
			break;
		case 333:
			 np->handleSubject(user, TO_UTF8(m->parameters().value(1)) + suffix, m_topicData, TO_UTF8(m->parameters().value(2)));
			break;
		case 353:
			channel = m->parameters().value(2);
			members = m->parameters().value(3).split(" ");

			for (int i = 0; i < members.size(); i++) {
				bool flags = 0;
				std::string nickname = TO_UTF8(members.at(i));
				flags = correctNickname(nickname);
				m_modes[TO_UTF8(channel) + nickname] = flags;
				np->handleParticipantChanged(user, nickname, TO_UTF8(channel) + suffix,(int) flags, pbnetwork::STATUS_ONLINE);
			}
			break;
		case 432:
			if (m_connected) {
				np->handleDisconnected(user, pbnetwork::CONNECTION_ERROR_INVALID_USERNAME, "Erroneous Nickname");
			}
			break;
		default:
			break;
	}

	//qDebug() << "numeric message received:" << receiver() << origin << code << params;
}
Esempio n. 3
0
void SessionChildItem::receiveMessage(IrcMessage* message)
{
    AbstractSessionItem::receiveMessage(message);
    if (message->type() == IrcMessage::Private)
    {
        IrcPrivateMessage* privMsg = static_cast<IrcPrivateMessage*>(message);

        QString alertText;
        if (isChannel())
        {
            if (privMsg->message().contains(m_parent->session()->nickName(), Qt::CaseInsensitive))
            {
                setHighlighted(true);
                if (!isCurrent())
                    alertText = tr("%1 on %2:\n%3").arg(privMsg->sender().name()).arg(title()).arg(privMsg->message());
            }
        }
        else
        {
            setHighlighted(true);
            if (!isCurrent())
                alertText = tr("%1 in private:\n%2").arg(privMsg->sender().name()).arg(privMsg->message());
        }

        if (!alertText.isEmpty())
        {
            setAlertText(alertText);
            emit alert(this);
        }

        if (!isCurrent())
            setUnreadCount(unreadCount() + 1);
    }
    else if (message->type() == IrcMessage::Numeric)
    {
        IrcNumericMessage* numMsg = static_cast<IrcNumericMessage*>(message);
        if (isChannel() && numMsg->code() == Irc::RPL_TOPIC)
            setSubtitle(numMsg->parameters().value(2));
        else if (!isChannel() && numMsg->code() == Irc::RPL_WHOISUSER)
            setSubtitle(numMsg->parameters().value(5));
    }
}
Esempio n. 4
0
void dlgIRC::onMessageReceived( IrcMessage* msg )
{
    switch( msg->type() )
    {
    case IrcMessage::Type::Join: {
        IrcJoinMessage *rmsg = static_cast<IrcJoinMessage*>(msg);
        slot_joined( rmsg->sender().name(), rmsg->channel() );
        break;
        }
    case IrcMessage::Type::Notice: {
        IrcNoticeMessage *rmsg = static_cast<IrcNoticeMessage*>(msg);
        irc_gotMsg( rmsg->sender().name(), rmsg->target(), rmsg->message() );
        break;
        }
    case IrcMessage::Type::Private: {
        IrcPrivateMessage *rmsg = static_cast<IrcPrivateMessage*>(msg);
        irc_gotMsg( rmsg->sender().name(), rmsg->target(), rmsg->message() );
        break;
        }
    case IrcMessage::Type::Numeric: {
        IrcNumericMessage *rmsg = static_cast<IrcNumericMessage*>(msg);
        irc_gotMsg3( rmsg->sender().name(), rmsg->code(), rmsg->parameters() );
        break;
        }
    case IrcMessage::Type::Part: {
        IrcPartMessage *rmsg = static_cast<IrcPartMessage*>(msg);
        slot_parted( rmsg->sender().name(), rmsg->channel(), rmsg->reason() );
        break;
        }
    case IrcMessage::Type::Unknown:
        irc_gotMsg2( msg->sender().name(), msg->parameters() );
        break;
    }
    /*
    Nick 	IrcNickMessage
    Quit 	IrcQuitMessage
    Topic 	IrcTopicMessage
    Invite 	IrcInviteMessage
    Kick 	IrcKickMessage
    Mode 	IrcModeMessage
    Ping 	IrcPingMessage
    Pong 	IrcPongMessage
    Error 	IrcErrorMessage
    */
}
Esempio n. 5
0
void tst_IrcMessage::testNumericMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(int, code);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Numeric);
    QVERIFY(message->command().toInt() > 0);
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("code").toInt(), code);

    IrcNumericMessage* numericMessage = qobject_cast<IrcNumericMessage*>(message);
    QVERIFY(numericMessage);
    QCOMPARE(numericMessage->isValid(), valid);
    QCOMPARE(numericMessage->code(), code);
}
Esempio n. 6
0
void SessionChildItem::receiveMessage(IrcMessage* message)
{
    if (m_usermodel)
        m_usermodel->processMessage(message);

    if (message->type() == IrcMessage::Numeric) {
        IrcNumericMessage* numeric = static_cast<IrcNumericMessage*>(message);
        switch (numeric->code()) {
            case Irc::RPL_NAMREPLY:
                if (m_sent.contains(IrcCommand::Names))
                    return;
                break;
            case Irc::RPL_ENDOFNAMES:
                if (m_sent.contains(IrcCommand::Names)) {
                    emit namesReceived(m_usermodel->users());
                    m_sent.remove(IrcCommand::Names);
                    return;
                }
                break;
            case Irc::RPL_TOPIC:
                if (isChannel()) {
                    setSubtitle(message->parameters().value(2));
                    setDescription(IrcUtil::messageToHtml(subtitle()));
                }
                break;
            case Irc::RPL_WHOISUSER:
                if (!isChannel()) {
                    setSubtitle(message->parameters().value(5));
                    setDescription(IrcUtil::messageToHtml(subtitle()));
                }
                if (m_sent.contains(IrcCommand::Whois)) {
                    m_whois.append(tr("Ident: %1").arg(message->parameters().value(2)));
                    m_whois.append(tr("Host: %1").arg(message->parameters().value(3)));
                    m_whois.append(tr("Name: %1").arg(message->parameters().value(5)));
                    return;
                }
                break;
            case Irc::RPL_WHOISSERVER:
                if (m_sent.contains(IrcCommand::Whois)) {
                    m_whois.append(tr("Server: %1 (%2)").arg(message->parameters().value(2), message->parameters().value(3)));
                    return;
                }
                break;
            case Irc::RPL_WHOISOPERATOR:
                if (m_sent.contains(IrcCommand::Whois)) {
                    m_whois.append(tr("IRC operator"));
                    return;
                }
                break;
            case Irc::RPL_WHOISACCOUNT:
                if (m_sent.contains(IrcCommand::Whois)) {
                    m_whois.append(tr("Logged in as: %1").arg(message->parameters().value(2)));
                    return;
                }
                break;
            case Irc::RPL_WHOISREGNICK:
                if (m_sent.contains(IrcCommand::Whois)) {
                    m_whois.append(tr("Registered nick"));
                    return;
                }
                break;
            case Irc::RPL_WHOISSECURE:
                if (m_sent.contains(IrcCommand::Whois)) {
                    m_whois.append(tr("Secure connection"));
                    return;
                }
                break;
            case Irc::RPL_WHOISIDLE:
                if (m_sent.contains(IrcCommand::Whois)) {
                    QDateTime signon = QDateTime::fromTime_t(message->parameters().value(3).toInt());
                    QTime idle = QTime().addSecs(message->parameters().value(2).toInt());
                    m_whois.append(tr("Connected: %1").arg(signon.toString()));
                    m_whois.append(tr("Idle: %1").arg(idle.toString()));
                    return;
                }
                break;
            case Irc::RPL_WHOISCHANNELS:
                if (m_sent.contains(IrcCommand::Whois)) {
                    m_whois.append(tr("Channels: %1").arg(message->parameters().value(2)));
                    return;
                }
                break;
            case Irc::RPL_WHOISHOST:
            case Irc::RPL_WHOISMODES:
                if (m_sent.contains(IrcCommand::Whois)) {
                    return;
                }
                break;
            case Irc::RPL_ENDOFWHOIS:
                if (m_sent.contains(IrcCommand::Whois)) {
                    emit whoisReceived(m_whois);
                    m_sent.remove(IrcCommand::Whois);
                    m_whois.clear();
                }
            case Irc::RPL_WHOISHELPOP:
            case Irc::RPL_WHOISSPECIAL:
                return;
            default:
                break;
        }
    }

    if (message->type() == IrcMessage::Private) {
        IrcPrivateMessage* privMsg = static_cast<IrcPrivateMessage*>(message);

        QString alertText;
        if (isChannel()) {
            if (privMsg->message().contains(m_parent->session()->nickName(), Qt::CaseInsensitive)) {
                setHighlighted(true);
                if (!isCurrent())
                    alertText = tr("%1 on %2:\n%3").arg(privMsg->sender().name()).arg(title()).arg(privMsg->message());
            }
        } else {
            setHighlighted(true);
            if (!isCurrent())
                alertText = tr("%1 in private:\n%2").arg(privMsg->sender().name()).arg(privMsg->message());
        }

        if (!alertText.isEmpty())
            emit alerted(alertText);

        if (!isCurrent())
            setUnreadCount(unreadCount() + 1);
    }

    const QString formatted = messageFormatter()->formatMessage(message, m_usermodel);
    if (!formatted.isEmpty())
        appendMessage(formatted);
}
Esempio n. 7
0
void MyIrcSession::on_numericMessageReceived(IrcMessage *message) {
	QString channel;
	QStringList members;
	std::string nick;

	IrcNumericMessage *m = (IrcNumericMessage *) message;
	QStringList parameters = m->parameters();
	switch (m->code()) {
		case 301:
			break;
		case 315:
			LOG4CXX_INFO(logger, "End of /who request " << TO_UTF8(parameters[1]));
			break;
		case 332:
			m_topicData = TO_UTF8(parameters[2]);
			break;
		case 333:
			nick = TO_UTF8(parameters[2]);
			if (nick.find("!") != std::string::npos) {
				nick = nick.substr(0, nick.find("!"));
			}
			if (nick.find("/") != std::string::npos) {
				nick = nick.substr(0, nick.find("/"));
			}
			np->handleSubject(user, TO_UTF8(parameters[1].toLower()) + suffix, m_topicData, nick);
			break;
		case 352: {
			channel = parameters[1].toLower();
			nick = TO_UTF8(parameters[5]);
			IRCBuddy &buddy = getIRCBuddy(TO_UTF8(channel), nick);

			if (parameters[6].toUpper().startsWith("G")) {
				if (!buddy.isAway()) {
					buddy.setAway(true);
					np->handleParticipantChanged(user, nick, TO_UTF8(channel) + suffix, buddy.isOp(), pbnetwork::STATUS_AWAY);
				}
			}
			else if (buddy.isAway()) {
				buddy.setAway(false);
				np->handleParticipantChanged(user, nick, TO_UTF8(channel) + suffix, buddy.isOp(), pbnetwork::STATUS_ONLINE);
			}
			break;
		}
		case 353:
			channel = parameters[2].toLower();
			members = parameters[3].split(" ");

			LOG4CXX_INFO(logger, user << ": Received members for " << TO_UTF8(channel) << suffix);
			for (int i = 0; i < members.size(); i++) {
				bool op = 0;
				std::string nickname = TO_UTF8(members.at(i));
				op = correctNickname(nickname);
				IRCBuddy &buddy = getIRCBuddy(TO_UTF8(channel), nickname);
				buddy.setOp(op);
				np->handleParticipantChanged(user, nickname, TO_UTF8(channel) + suffix, buddy.isOp(), pbnetwork::STATUS_ONLINE);
			}

			break;
		case 366:
			// ask /who to get away states
			channel = parameters[1].toLower();
			LOG4CXX_INFO(logger, user << "Asking /who for channel " << TO_UTF8(channel));
			sendCommand(IrcCommand::createWho(channel));
			break;
		case 432:
			np->handleDisconnected(user, pbnetwork::CONNECTION_ERROR_INVALID_USERNAME, "Erroneous Nickname");
			break;
		case 433:
			for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
				np->handleParticipantChanged(user, TO_UTF8(nickName()), it->second->getChannel() + suffix, pbnetwork::PARTICIPANT_FLAG_CONFLICT);
			}
			if (suffix.empty()) {
				np->handleDisconnected(user, pbnetwork::CONNECTION_ERROR_INVALID_USERNAME, "Nickname is already in use");
			}
			break;
		case 436:
			for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
				np->handleParticipantChanged(user, TO_UTF8(nickName()), it->second->getChannel() + suffix, pbnetwork::PARTICIPANT_FLAG_CONFLICT);
			}
			np->handleDisconnected(user, pbnetwork::CONNECTION_ERROR_INVALID_USERNAME, "Nickname collision KILL");
		case 464:
			for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) {
				np->handleParticipantChanged(user, TO_UTF8(nickName()), it->second->getChannel() + suffix, pbnetwork::PARTICIPANT_FLAG_NOT_AUTHORIZED);
			}
			if (suffix.empty()) {
				np->handleDisconnected(user, pbnetwork::CONNECTION_ERROR_INVALID_USERNAME, "Password incorrect");
			}
		case 321:
			m_rooms.clear();
			m_names.clear();
			break;
		case 322:
			m_rooms.push_back(TO_UTF8(parameters[1]));
			m_names.push_back(TO_UTF8(parameters[1]));
			break;
		case 323:
			np->handleRoomList("", m_rooms, m_names);
			break;
		default:
			break;
	}

	if (m->code() >= 400 && m->code() < 500) {
			LOG4CXX_INFO(logger, user << ": Error message received: " << message->toData().data());
	}
}
Esempio n. 8
0
void MyIrcSession::on_numericMessageReceived(IrcMessage *message) {
	QString channel;
	QStringList members;
	std::string nick;

	IrcNumericMessage *m = (IrcNumericMessage *) message;
	QStringList parameters = m->parameters();
	switch (m->code()) {
		case 301:
			break;
		case 315:
			LOG4CXX_INFO(logger, "End of /who request " << TO_UTF8(parameters[1]));
			break;
		case 332:
			m_topicData = TO_UTF8(parameters[2]);
			break;
		case 333:
			nick = TO_UTF8(parameters[2]);
			if (nick.find("!") != std::string::npos) {
				nick = nick.substr(0, nick.find("!"));
			}
			if (nick.find("/") != std::string::npos) {
				nick = nick.substr(0, nick.find("/"));
			}
			np->handleSubject(user, TO_UTF8(parameters[1]) + suffix, m_topicData, nick);
			break;
		case 352: {
			channel = parameters[1];
			nick = TO_UTF8(parameters[5]);
			IRCBuddy &buddy = getIRCBuddy(TO_UTF8(channel), nick);

			if (parameters[6].toUpper().startsWith("G")) {
				if (!buddy.isAway()) {
					buddy.setAway(true);
					np->handleParticipantChanged(user, nick, TO_UTF8(channel) + suffix, buddy.isOp(), pbnetwork::STATUS_AWAY);
				}
			}
			else if (buddy.isAway()) {
				buddy.setAway(false);
				np->handleParticipantChanged(user, nick, TO_UTF8(channel) + suffix, buddy.isOp(), pbnetwork::STATUS_ONLINE);
			}
			break;
		}
		case 353:
			channel = parameters[2];
			members = parameters[3].split(" ");

			LOG4CXX_INFO(logger, user << ": Received members for " << TO_UTF8(channel) << suffix);
			for (int i = 0; i < members.size(); i++) {
				bool op = 0;
				std::string nickname = TO_UTF8(members.at(i));
				op = correctNickname(nickname);
				IRCBuddy &buddy = getIRCBuddy(TO_UTF8(channel), nickname);
				buddy.setOp(op);
				np->handleParticipantChanged(user, nickname, TO_UTF8(channel) + suffix, buddy.isOp(), pbnetwork::STATUS_ONLINE);
			}

			break;
		case 366:
			// ask /who to get away states
			channel = parameters[1];
			LOG4CXX_INFO(logger, user << "Asking /who for channel " << TO_UTF8(channel));
			sendCommand(IrcCommand::createWho(channel));
			break;
		case 432:
			np->handleDisconnected(user, pbnetwork::CONNECTION_ERROR_INVALID_USERNAME, "Erroneous Nickname");
			break;
		case 321:
			m_rooms.clear();
			m_names.clear();
			break;
		case 322:
			m_rooms.push_back(TO_UTF8(parameters[1]));
			m_names.push_back(TO_UTF8(parameters[1]));
			break;
		case 323:
			np->handleRoomList("", m_rooms, m_names);
			break;
		default:
			break;
	}

	//qDebug() << "numeric message received:" << receiver() << origin << code << params;
}