Exemplo n.º 1
0
PlayersWindow::PlayersWindow(QWidget *parent, int expireDays)
    : QWidget (parent)
{
    setAttribute(Qt::WA_DeleteOnClose, true);
    resize(726, this->height());

    QGridLayout *mylayout = new QGridLayout(this);

    const auto &members = SecurityManager::getMembers();

    mytable = new QCompactTable(members.size(),7);

    mytable->setShowGrid(true);
    mylayout->addWidget(mytable,0,0,1,6);

    QMap<int, QString> authgrade;
    authgrade[0] = "User";
    authgrade[1] = "Mod";
    authgrade[2] = "Admin";
    authgrade[3] = "Owner";

    QStringList headers;
    headers << "Player" << "Authority" << "Banned Status" << "Registered" << "IP" << "Last Appearance" << "Expires In";
    mytable->setHorizontalHeaderLabels(headers);

    int i = 0;

    for (auto it = members.begin(); it != members.end(); ++it) {
        const SecurityManager::Member &m = it->second;

        QTableWidgetItem *witem = new QTableWidgetItem(m.name);
        mytable->setItem(i, 0, witem);

        witem = new QTableWidgetItem(authgrade[m.authority()]);
        mytable->setItem(i, 1, witem);

        QString bannedString = "Banned";
        int expiration = m.ban_expire_time - QDateTime::currentDateTimeUtc().toTime_t();
        if(expiration < 0) {
            if (m.ban_expire_time != 0)
            bannedString = "Expires on Login";
        } else {
            if(expiration < 60) {
                if(expiration == 1) {
                    bannedString.append(QString(" (%1 second)").arg(expiration));
                } else {
                    bannedString.append(QString(" (%2 seconds)").arg(expiration));
                }
            } else {
                if(expiration >= 60) {
                    expiration = expiration / 60;
                    if(expiration == 1) {
                        bannedString.append(QString(" (%1 minute)").arg(expiration));
                    } else {
                        bannedString.append(QString(" (%2 minutes)").arg(expiration));
                    }
                }
            }
        }
        witem = new QTableWidgetItem(m.banned ? bannedString : "Fine");
        mytable->setItem(i, 2, witem);

        witem = new QTableWidgetItem(m.isProtected() > 0 ? "Yes" : "No");
        mytable->setItem(i, 3, witem);

        witem = new QTableWidgetItem(m.ip);
        mytable->setItem(i, 4, witem);

        witem = new QTableWidgetItem(m.date);
        mytable->setItem(i, 5, witem);

        witem = new QTableWidgetItem(QString::number(expireDays - QDate::fromString(m.date, Qt::ISODate).daysTo(QDate::currentDate())) + " Days");
        mytable->setItem(i, 6, witem);

        i++;
    }

    //mytable->sortByColumn(0, Qt::AscendingOrder);

    //mytable->setSortingEnabled(true);

    QPushButton *_authority = new QPushButton(tr("&Authority"));
    QMenu *m = new QMenu(_authority);
    m->addAction(tr("User"), this, SLOT(user()));
    m->addAction(tr("Moderator"), this, SLOT(mod()));
    m->addAction(tr("Administrator"), this, SLOT(admin()));
    m->addAction(tr("Owner"), this, SLOT(owner()));
    _authority->setMenu(m);

    QPushButton *_ban = new QPushButton(tr("&Ban"));
    QPushButton *_unban = new QPushButton(tr("U&nban"));
    QPushButton *_clpass = new QPushButton(tr("&Clear Password"));
    QCheckBox *enableSorting = new QCheckBox(tr("&Enable sorting"));

    mylayout->addWidget(_authority,1,0);
    mylayout->addWidget(_ban,1,2);
    mylayout->addWidget(_unban,1,3);
    mylayout->addWidget(_clpass,1,4);
    mylayout->addWidget(enableSorting, 1, 5);

    if (mytable->rowCount() == 0)
        return;

    connect(_ban,SIGNAL(clicked()),SLOT(ban()));
    connect(_unban,SIGNAL(clicked()),SLOT(unban()));
    connect(_clpass,SIGNAL(clicked()),SLOT(clpass()));
    connect(enableSorting, SIGNAL(toggled(bool)), SLOT(enableSorting(bool)));
}
Exemplo n.º 2
0
PlayersWindow::PlayersWindow(QWidget *parent, int expireDays)
    : QWidget (parent)
{
    setAttribute(Qt::WA_DeleteOnClose, true);
    resize(726, this->height());

    QGridLayout *mylayout = new QGridLayout(this);

    mytable = new QCompactTable(0,7);

    mytable->setShowGrid(true);
    mylayout->addWidget(mytable,0,0,1,6);

    QMap<int, QString> authgrade;
    authgrade[0] = "User";
    authgrade[1] = "Mod";
    authgrade[2] = "Admin";
    authgrade[3] = "Owner";

    QStringList headers;
    headers << "Player" << "Authority" << "Banned Status" << "Registered" << "IP" << "Last Appearance" << "Expires In";
    mytable->setHorizontalHeaderLabels(headers);

    QSqlQuery q;
    q.setForwardOnly(true);

    q.exec("select count(*) from trainers");

    if (q.next()) {
        mytable->setRowCount(q.value(0).toInt());
    }

    q.exec("select name, auth, banned, hash, ip, laston, ban_expire_time from trainers order by name asc");

    int i = 0;

    while(q.next()) {
        QTableWidgetItem *witem = new QTableWidgetItem(q.value(0).toString());
        mytable->setItem(i, 0, witem);

        witem = new QTableWidgetItem(authgrade[q.value(1).toInt()]);
        mytable->setItem(i, 1, witem);

        QString bannedString = "Banned";
        int expiration = q.value(6).toInt() - QDateTime::currentDateTimeUtc().toTime_t();
        if(expiration < 0) {
            if (q.value(6).toInt() != 0)
            bannedString = "Expires on Login";
        } else {
            if(expiration < 60) {
                if(expiration == 1) {
                    bannedString.append(QString(" (%1 second)").arg(expiration));
                } else {
                    bannedString.append(QString(" (%2 seconds)").arg(expiration));
                }
            } else {
                if(expiration >= 60) {
                    expiration = expiration / 60;
                    if(expiration == 1) {
                        bannedString.append(QString(" (%1 minute)").arg(expiration));
                    } else {
                        bannedString.append(QString(" (%2 minutes)").arg(expiration));
                    }
                }
            }
        }
        witem = new QTableWidgetItem(q.value(2).toBool() ? bannedString : "Fine");
        mytable->setItem(i, 2, witem);

        witem = new QTableWidgetItem(q.value(3).toString().length() > 0 ? "Yes" : "No");
        mytable->setItem(i, 3, witem);

        witem = new QTableWidgetItem(q.value(4).toString());
        mytable->setItem(i, 4, witem);

        witem = new QTableWidgetItem(q.value(5).toString());
        mytable->setItem(i, 5, witem);

        witem = new QTableWidgetItem(QString::number(expireDays - QDate::fromString(q.value(5).toString(), "yyyy-MM-dd").daysTo(QDate::currentDate())) + " Days");
        mytable->setItem(i, 6, witem);

        i++;
    }

    mytable->sortByColumn(0, Qt::AscendingOrder);

    mytable->setSortingEnabled(true);

    QPushButton *_authority = new QPushButton(tr("&Authority"));
    QMenu *m = new QMenu(_authority);
    m->addAction(tr("User"), this, SLOT(user()));
    m->addAction(tr("Moderator"), this, SLOT(mod()));
    m->addAction(tr("Administrator"), this, SLOT(admin()));
    m->addAction(tr("Owner"), this, SLOT(owner()));
    _authority->setMenu(m);

    QPushButton *_ban = new QPushButton(tr("&Ban"));
    QPushButton *_unban = new QPushButton(tr("U&nban"));
    QPushButton *_clpass = new QPushButton(tr("&Clear Password"));

    mylayout->addWidget(_authority,1,0);
    mylayout->addWidget(_ban,1,2);
    mylayout->addWidget(_unban,1,3);
    mylayout->addWidget(_clpass,1,4);

    if (mytable->rowCount() == 0)
        return;

    connect(_ban,SIGNAL(clicked()),SLOT(ban()));
    connect(_unban,SIGNAL(clicked()),SLOT(unban()));
    connect(_clpass,SIGNAL(clicked()),SLOT(clpass()));
}