示例#1
0
void CBDS::parseViewerData(const QVariantList &data)
{
    Viewer def("def");
    QList<Viewer*> list;
    bool ownerset = false;
    for (auto i = data.constBegin(); i != data.constEnd(); ++i)
    {
        QVariantMap o = (*i).toMap();
        Viewer *v = new Viewer(o.value("name").toString(), o.value("tipped", def.getTipped()).toInt(), o.value("fanclub", def.isFanclubmember()).toBool(), o.value("mod", def.isModerator()).toBool(), o.value("hastokens", def.hasTokens()).toBool(), o.value("gender", def.getGender()).toString().at(0).toLatin1());
        if (o.value("roomowner", false).toBool())
        {
            if (!ownerset)
            {
                v->setRoomOwner(true);
                setRoomOwner(v->getName());
                ownerset = true;
            }
            else
                emit error(QString("Can't have more than 1 room owner. Owner: \"%1\" second: \"%2\"").arg(m_roomowner, v->getName()));
        }
        list << v;
    }

    if (!ownerset && !list.isEmpty())
    {
        list.first()->setRoomOwner(true);
        setRoomOwner(list.first()->getName());
        emit error("No Viewer is set as the room owner. Automatically set \"" + list.first()->getName() + "\" as the owner.");
    }

    m_viewers.populate(list);
    for (auto i = list.constBegin(); i != list.constEnd(); ++i)
    {
        if ((*i)->parent())
            connectViewer((*i));
        else
        {
            emit error("Can't add \"" + (*i)->getName() + "\". Name already exists or is reserved.");
            (*i)->deleteLater();
        }
    }
}
示例#2
0
void CBDS::onTip(const int &amount, const QString &message)
{
    Viewer *v = qobject_cast<Viewer *>(sender());
    if (v)
    {
        m_chat.addLine(new ChatLine(message, v, "#000000", "#FFFF33", amount));
        QScriptValue e = m_engine.newObject();
        QScriptValue::PropertyFlags flag = QScriptValue::ReadOnly | QScriptValue::Undeletable;
        e.setProperty("amount", amount, flag);
        e.setProperty("message", message, flag);
        e.setProperty("from_user", v->getName(), flag);
        e.setProperty("from_user_in_fanclub", v->isFanclubmember(), flag);
        e.setProperty("from_user_has_tokens", v->hasTokens(), flag);
        e.setProperty("from_user_is_mod", v->isModerator(), flag);
        e.setProperty("from_user_tipped_recently", v->getTipped() >= Viewer::TIPPED_RECENTLY ? true : false, flag);
        e.setProperty("from_user_tipped_alot_recently", v->getTipped() >= Viewer::TIPPED_ALOT ? true : false, flag);
        e.setProperty("from_user_tipped_tons_recently", v->getTipped() >= Viewer::TIPPED_TONS ? true : false, flag);
        e.setProperty("from_user_gender", v->getGender(), flag);
        m_cbo->callTipFunction(e);
    }
}
示例#3
0
void CBDS::onChat(const QString &message)
{
    Viewer *v = qobject_cast<Viewer *>(sender());
    if (v)
    {
        if (message == "/debug")
        {
            v->setDebugReadable(!v->getDebugReadable());
            m_chat.addLine(new ChatLine(v->getDebugReadable() ? "Debug mode enabled. Type /debug again to disable." : "Debug mode disabled.", Q_NULLPTR, "#000000", "#FFFFFF", 0, v->getName()));
            return;
        }
        QScriptValue e = createViewerValue(v);
        e.setProperty("c", v->getTextcolor());
        e.setProperty("m", message);
        e.setProperty("f", v->getFont());
        if (m_cbo->callMessageFunction(e) && !e.property("X-Spam").toBool())
        {
            //There is an example for changing the background in the API docs. I'd prefer proper documentation.
            QString background = "#FFFFFF";
            if (e.property("background").isValid())
            {
                background = e.property("background").toString().toUpper();
                if (!QRegExp("#([0-9A-F|]{3}|[0-9A-F]{6})").exactMatch(background))
                {
                    emit m_cbo->warning("CSS message background hacks aren't supported since there is no browser support guarantee. If you feel i should add support let me know. IMHO CB should make stuff like this a viable option here and for notices and ensure browser support.");
                    background = "#FFFFFF";
                }
            }
            m_chat.addLine(new ChatLine(e.property("m").toString(), v, e.property("c").toString(), background));
        }
    }
}