Example #1
0
void Session::handleMessage(IrcMessage* message)
{
    // 20s delay since the last message was received
    setPingInterval(20);

    if (message->type() == IrcMessage::Join)
    {
        if (message->isOwn())
            addChannel(static_cast<IrcJoinMessage*>(message)->channel());
    }
    else if (message->type() == IrcMessage::Part)
    {
        if (message->isOwn())
            removeChannel(static_cast<IrcPartMessage*>(message)->channel());
    }
    else if (message->type() == IrcMessage::Pong)
    {
        if (message->parameters().contains("_C_o_m_m_u_n_i_"))
        {
            // slow down to 60s intervals
            setPingInterval(60);

            updateLag(static_cast<int>(m_lagTimer.elapsed()));
            m_lagTimer.invalidate();
        }
    }
    else if (message->type() == IrcMessage::Numeric)
    {
        int code = static_cast<IrcNumericMessage*>(message)->code();
        if (code == Irc::RPL_ISUPPORT)
        {
            foreach (const QString& param, message->parameters().mid(1))
            {
                QStringList keyValue = param.split("=", QString::SkipEmptyParts);
                m_info.insert(keyValue.value(0), keyValue.value(1));
            }
            if (m_info.contains("NETWORK"))
                emit networkChanged(network());
            emit serverInfoReceived();
        }
Example #2
0
bool PresenceConfig::parseCmdLine(const QStringList &args)
{
    for (int i = 1; i < args.length(); i += 2)
    {
        if (args[i] == "-n")
        {
            if ( ! setNodeName(args[i+1].toAscii()) )
            {
                printf("Invalid node name given.\n");
                return false;
            }
        }
        else if (args[i] == "-p")
        {
            if ( ! setAnnouncementPort(args[i+1].toInt()))
            {
                printf("Invalid announcement port given.\n");
                return false;
            }
        }
        else if (args[i] == "-c")
        {
            if ( ! setClientPort(args[i+1].toInt()))
            {
                printf("Invalid client port given.\n");
                return false;
            }
        }
        else if (args[i] == "-i")
        {
            if ( ! setPingInterval(args[i+1].toInt()))
            {
                printf("Invalid ping interval given.\n");
                return false;
            }
        }
        else
        {
            return false;
        }
    }

    return true;
}