mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-12 04:50:01 -08:00
Compare commits
7 commits
b4acbcc0cf
...
dab2b38bf5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dab2b38bf5 | ||
|
|
b054ef8c40 | ||
|
|
b7f04bbb6e | ||
|
|
2b7ddfd968 | ||
|
|
7495703c02 | ||
|
|
803e1e9ec3 | ||
|
|
4d645e7513 |
20 changed files with 572 additions and 93 deletions
|
|
@ -287,8 +287,12 @@ set(cockatrice_SOURCES
|
||||||
src/interface/widgets/utility/custom_line_edit.cpp
|
src/interface/widgets/utility/custom_line_edit.cpp
|
||||||
src/interface/widgets/utility/epoch_format.h
|
src/interface/widgets/utility/epoch_format.h
|
||||||
src/interface/widgets/utility/get_text_with_max.cpp
|
src/interface/widgets/utility/get_text_with_max.cpp
|
||||||
|
src/interface/widgets/utility/pill_painter.cpp
|
||||||
|
src/interface/widgets/utility/pill_painter.h
|
||||||
src/interface/widgets/utility/report_utils.cpp
|
src/interface/widgets/utility/report_utils.cpp
|
||||||
src/interface/widgets/utility/report_utils.h
|
src/interface/widgets/utility/report_utils.h
|
||||||
|
src/interface/widgets/utility/table_activation.cpp
|
||||||
|
src/interface/widgets/utility/table_activation.h
|
||||||
src/interface/widgets/utility/sequence_edit.cpp
|
src/interface/widgets/utility/sequence_edit.cpp
|
||||||
src/interface/widgets/utility/visibility_change_listener.cpp
|
src/interface/widgets/utility/visibility_change_listener.cpp
|
||||||
src/interface/widgets/utility/visibility_change_listener.h
|
src/interface/widgets/utility/visibility_change_listener.h
|
||||||
|
|
@ -376,6 +380,7 @@ set(cockatrice_SOURCES
|
||||||
src/interface/widgets/tabs/api/edhrec/display/top_tags/edhrec_top_tags_api_response_display_widget.cpp
|
src/interface/widgets/tabs/api/edhrec/display/top_tags/edhrec_top_tags_api_response_display_widget.cpp
|
||||||
src/interface/widgets/tabs/api/edhrec/tab_edhrec.cpp
|
src/interface/widgets/tabs/api/edhrec/tab_edhrec.cpp
|
||||||
src/interface/widgets/tabs/api/edhrec/tab_edhrec_main.cpp
|
src/interface/widgets/tabs/api/edhrec/tab_edhrec_main.cpp
|
||||||
|
src/interface/widgets/tabs/alt_table_delegate.cpp
|
||||||
src/interface/widgets/tabs/report_status_delegate.cpp
|
src/interface/widgets/tabs/report_status_delegate.cpp
|
||||||
src/interface/widgets/tabs/tab.cpp
|
src/interface/widgets/tabs/tab.cpp
|
||||||
src/interface/widgets/tabs/tab_account.cpp
|
src/interface/widgets/tabs/tab_account.cpp
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,8 @@ void DlgMyReports::onSelectionChanged()
|
||||||
connect(pend, &PendingCommand::finished, this, &DlgMyReports::reportDetailsResponse);
|
connect(pend, &PendingCommand::finished, this, &DlgMyReports::reportDetailsResponse);
|
||||||
client->sendCommand(pend);
|
client->sendCommand(pend);
|
||||||
|
|
||||||
QString status = table->item(row, COL_STATUS)->text();
|
// The cell text is the translated label; the raw status lives in UserRole.
|
||||||
|
const QString status = table->item(row, COL_STATUS)->data(Qt::UserRole).toString();
|
||||||
bool canComment = (status == "open" || status == "assigned");
|
bool canComment = (status == "open" || status == "assigned");
|
||||||
commentButton->setEnabled(canComment);
|
commentButton->setEnabled(canComment);
|
||||||
commentInput->setEnabled(canComment);
|
commentInput->setEnabled(canComment);
|
||||||
|
|
|
||||||
111
cockatrice/src/interface/widgets/tabs/alt_table_delegate.cpp
Normal file
111
cockatrice/src/interface/widgets/tabs/alt_table_delegate.cpp
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
#include "alt_table_delegate.h"
|
||||||
|
|
||||||
|
#include "../utility/pill_painter.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QModelIndex>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPalette>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOptionViewItem>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr int ICON_TEXT_GAP = 4;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
AltTableDelegate::AltTableDelegate(int viaColumn,
|
||||||
|
int warnsColumn,
|
||||||
|
int bansColumn,
|
||||||
|
int sharedColumn,
|
||||||
|
int activeColumn,
|
||||||
|
QObject *parent)
|
||||||
|
: QStyledItemDelegate(parent), viaColumn(viaColumn), warnsColumn(warnsColumn), bansColumn(bansColumn),
|
||||||
|
sharedColumn(sharedColumn), activeColumn(activeColumn)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void AltTableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
const bool selected = (option.state & QStyle::State_Selected) != 0;
|
||||||
|
|
||||||
|
QStyleOptionViewItem opt(option);
|
||||||
|
initStyleOption(&opt, index);
|
||||||
|
painter->setFont(opt.font);
|
||||||
|
QStyle *style = opt.widget != nullptr ? opt.widget->style() : QApplication::style();
|
||||||
|
const QString text = index.data(Qt::DisplayRole).toString();
|
||||||
|
const QPalette::ColorRole emphasisRole = selected ? QPalette::HighlightedText : QPalette::WindowText;
|
||||||
|
|
||||||
|
if (index.column() == viaColumn) {
|
||||||
|
bool sharedOk = false;
|
||||||
|
const unsigned shared = index.sibling(index.row(), sharedColumn).data(Qt::DisplayRole).toUInt(&sharedOk);
|
||||||
|
const bool ipMatch = text.startsWith(QStringLiteral("ip:"));
|
||||||
|
// shared_count for an IP match already includes the investigated account,
|
||||||
|
// so anything above 2 means the address is shared beyond that pair.
|
||||||
|
const bool dimmed = sharedOk && ipMatch && shared > 2;
|
||||||
|
const QPalette::ColorRole textRole = (dimmed && !selected) ? QPalette::PlaceholderText : emphasisRole;
|
||||||
|
|
||||||
|
QPalette::ColorRole tintRole = QPalette::NoRole;
|
||||||
|
if (text == QStringLiteral("email")) {
|
||||||
|
tintRole = QPalette::Link;
|
||||||
|
} else if (text.startsWith(QStringLiteral("clientid:"))) {
|
||||||
|
tintRole = QPalette::Highlight;
|
||||||
|
} else if (ipMatch) {
|
||||||
|
tintRole = QPalette::PlaceholderText;
|
||||||
|
}
|
||||||
|
if (tintRole != QPalette::NoRole) {
|
||||||
|
if (!pill_painter::paint(painter, opt, tintRole, textRole, text)) {
|
||||||
|
QStyledItemDelegate::paint(painter, opt, index);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QStyledItemDelegate::paint(painter, opt, index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index.column() == warnsColumn || index.column() == bansColumn) {
|
||||||
|
bool countOk = false;
|
||||||
|
const int count = text.toInt(&countOk);
|
||||||
|
if (countOk && count > 0 && !selected) {
|
||||||
|
const QIcon icon = style->standardIcon(index.column() == bansColumn ? QStyle::SP_MessageBoxCritical
|
||||||
|
: QStyle::SP_MessageBoxWarning);
|
||||||
|
const int iconSize = qMax(0, opt.rect.height() - 2 * ICON_TEXT_GAP);
|
||||||
|
QRect textRect = opt.rect;
|
||||||
|
if (!icon.isNull() && iconSize > 0) {
|
||||||
|
const QRect iconRect(opt.rect.left() + ICON_TEXT_GAP, opt.rect.top() + ICON_TEXT_GAP, iconSize,
|
||||||
|
iconSize);
|
||||||
|
icon.paint(painter, iconRect);
|
||||||
|
textRect.setLeft(iconRect.right() + ICON_TEXT_GAP);
|
||||||
|
}
|
||||||
|
const QString elided = opt.fontMetrics.elidedText(text, opt.textElideMode, textRect.width());
|
||||||
|
style->drawItemText(painter, textRect, Qt::AlignLeft | Qt::AlignVCenter, opt.palette, true, elided,
|
||||||
|
emphasisRole);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index.column() == activeColumn) {
|
||||||
|
const QVariant activeData = index.data(Qt::UserRole);
|
||||||
|
const bool active =
|
||||||
|
activeData.isValid() ? activeData.toBool() : text.compare(QStringLiteral("yes"), Qt::CaseInsensitive) == 0;
|
||||||
|
const QPalette::ColorRole tintRole = active ? QPalette::Highlight : QPalette::PlaceholderText;
|
||||||
|
if (!pill_painter::paint(painter, opt, tintRole, emphasisRole, text)) {
|
||||||
|
QStyledItemDelegate::paint(painter, opt, index);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStyledItemDelegate::paint(painter, opt, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize AltTableDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
const QSize hint = QStyledItemDelegate::sizeHint(option, index);
|
||||||
|
if (index.column() == viaColumn || index.column() == activeColumn) {
|
||||||
|
return hint + QSize(pill_painter::PAD_X + 2 * ICON_TEXT_GAP, pill_painter::PAD_Y);
|
||||||
|
}
|
||||||
|
if (index.column() == warnsColumn || index.column() == bansColumn) {
|
||||||
|
return hint + QSize(2 * ICON_TEXT_GAP, 0);
|
||||||
|
}
|
||||||
|
return hint;
|
||||||
|
}
|
||||||
37
cockatrice/src/interface/widgets/tabs/alt_table_delegate.h
Normal file
37
cockatrice/src/interface/widgets/tabs/alt_table_delegate.h
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#ifndef ALT_TABLE_DELEGATE_H
|
||||||
|
#define ALT_TABLE_DELEGATE_H
|
||||||
|
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
#include <qtmetamacros.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Badge + icon painting for the User Alts table. The match-evidence column
|
||||||
|
* renders as a palette-tinted pill per match type (email / client id / IP), and
|
||||||
|
* an IP shared by more than one other account is dimmed. Warn/ban counts gain
|
||||||
|
* the style's warning/critical icons when nonzero. The active column renders as
|
||||||
|
* a palette-tinted pill (Highlight when active, PlaceholderText when inactive,
|
||||||
|
* from Qt::UserRole). Selected rows and unknown content fall back to default
|
||||||
|
* painting.
|
||||||
|
*/
|
||||||
|
class AltTableDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit AltTableDelegate(int viaColumn,
|
||||||
|
int warnsColumn,
|
||||||
|
int bansColumn,
|
||||||
|
int sharedColumn,
|
||||||
|
int activeColumn,
|
||||||
|
QObject *parent = nullptr);
|
||||||
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
|
[[nodiscard]] QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int viaColumn;
|
||||||
|
int warnsColumn;
|
||||||
|
int bansColumn;
|
||||||
|
int sharedColumn;
|
||||||
|
int activeColumn;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ALT_TABLE_DELEGATE_H
|
||||||
|
|
@ -1,18 +1,13 @@
|
||||||
#include "report_status_delegate.h"
|
#include "report_status_delegate.h"
|
||||||
|
|
||||||
|
#include "../utility/pill_painter.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QStyleOptionViewItem>
|
#include <QStyleOptionViewItem>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
constexpr qreal PILL_ALPHA = 0.30;
|
|
||||||
constexpr int PILL_PAD_X = 10;
|
|
||||||
constexpr int PILL_PAD_Y = 4;
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
ReportStatusDelegate::ReportStatusDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
ReportStatusDelegate::ReportStatusDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +25,7 @@ void ReportStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
tintRole = QPalette::Highlight;
|
tintRole = QPalette::Highlight;
|
||||||
} else if (status == QStringLiteral("assigned")) {
|
} else if (status == QStringLiteral("assigned")) {
|
||||||
tintRole = QPalette::Link;
|
tintRole = QPalette::Link;
|
||||||
} else if (status == QStringLiteral("resolved")) {
|
} else if (status == QStringLiteral("resolved") || status == QStringLiteral("dismissed")) {
|
||||||
tintRole = QPalette::PlaceholderText;
|
tintRole = QPalette::PlaceholderText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,32 +41,14 @@ void ReportStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QRect pillRect = opt.rect.adjusted(PILL_PAD_X / 2, PILL_PAD_Y / 2, -PILL_PAD_X / 2, -PILL_PAD_Y / 2);
|
|
||||||
if (pillRect.width() <= 0 || pillRect.height() <= 0) {
|
|
||||||
QStyledItemDelegate::paint(painter, opt, index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!selected) {
|
|
||||||
painter->save();
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
|
||||||
QColor pill = opt.palette.color(tintRole);
|
|
||||||
pill.setAlphaF(PILL_ALPHA);
|
|
||||||
painter->setPen(Qt::NoPen);
|
|
||||||
painter->setBrush(pill);
|
|
||||||
painter->drawRoundedRect(pillRect, pillRect.height() / 2.0, pillRect.height() / 2.0);
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString elided =
|
|
||||||
opt.fontMetrics.elidedText(opt.text.isEmpty() ? status : opt.text, opt.textElideMode, pillRect.width());
|
|
||||||
const QPalette::ColorRole textRole = selected ? QPalette::HighlightedText : QPalette::WindowText;
|
const QPalette::ColorRole textRole = selected ? QPalette::HighlightedText : QPalette::WindowText;
|
||||||
QStyle *style = opt.widget != nullptr ? opt.widget->style() : QApplication::style();
|
if (!pill_painter::paint(painter, opt, tintRole, textRole, opt.text.isEmpty() ? status : opt.text)) {
|
||||||
style->drawItemText(painter, pillRect, Qt::AlignCenter, opt.palette, true, elided, textRole);
|
QStyledItemDelegate::paint(painter, opt, index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize ReportStatusDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
QSize ReportStatusDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
const QSize hint = QStyledItemDelegate::sizeHint(option, index);
|
const QSize hint = QStyledItemDelegate::sizeHint(option, index);
|
||||||
return hint + QSize(PILL_PAD_X, PILL_PAD_Y);
|
return hint + QSize(pill_painter::PAD_X, pill_painter::PAD_Y);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status pill for the report queue table. Paints the status text on a
|
* Status pill for the report queue table. Paints the status text on a
|
||||||
* translucent badge tinted with a palette role per status, so the colors
|
* translucent badge tinted with a palette role per status (open, assigned,
|
||||||
* always follow the active theme. Falls back to default painting for
|
* resolved, dismissed), so the colors always follow the active theme.
|
||||||
* selected rows and unknown statuses.
|
* Falls back to default painting for selected rows and unknown statuses.
|
||||||
*/
|
*/
|
||||||
class ReportStatusDelegate : public QStyledItemDelegate
|
class ReportStatusDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
#include "tab_alts.h"
|
#include "tab_alts.h"
|
||||||
|
|
||||||
#include "../utility/epoch_format.h"
|
#include "../utility/epoch_format.h"
|
||||||
|
#include "../utility/table_activation.h"
|
||||||
#include "abstract_client.h"
|
#include "abstract_client.h"
|
||||||
|
#include "alt_table_delegate.h"
|
||||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/response_user_alts.pb.h"
|
#include "libcockatrice/protocol/pb/response_user_alts.pb.h"
|
||||||
|
|
||||||
|
|
@ -40,14 +42,15 @@ constexpr int COL_ALTS_USER = 0;
|
||||||
constexpr int COL_ALTS_VIA = 1;
|
constexpr int COL_ALTS_VIA = 1;
|
||||||
constexpr int COL_ALTS_DEPTH = 2;
|
constexpr int COL_ALTS_DEPTH = 2;
|
||||||
constexpr int COL_ALTS_SHARED = 3;
|
constexpr int COL_ALTS_SHARED = 3;
|
||||||
constexpr int COL_ALTS_EMAIL = 4;
|
constexpr int COL_ALTS_IPS = 4;
|
||||||
constexpr int COL_ALTS_CLIENTID = 5;
|
constexpr int COL_ALTS_EMAIL = 5;
|
||||||
constexpr int COL_ALTS_REGISTERED = 6;
|
constexpr int COL_ALTS_CLIENTID = 6;
|
||||||
constexpr int COL_ALTS_LAST_LOGIN = 7;
|
constexpr int COL_ALTS_REGISTERED = 7;
|
||||||
constexpr int COL_ALTS_WARNS = 8;
|
constexpr int COL_ALTS_LAST_LOGIN = 8;
|
||||||
constexpr int COL_ALTS_BANS = 9;
|
constexpr int COL_ALTS_WARNS = 9;
|
||||||
constexpr int COL_ALTS_ACTIVE = 10;
|
constexpr int COL_ALTS_BANS = 10;
|
||||||
constexpr int COL_ALTS_COUNT = 11;
|
constexpr int COL_ALTS_ACTIVE = 11;
|
||||||
|
constexpr int COL_ALTS_COUNT = 12;
|
||||||
|
|
||||||
constexpr int COL_WARNS_TIME = 0;
|
constexpr int COL_WARNS_TIME = 0;
|
||||||
constexpr int COL_WARNS_MODERATOR = 1;
|
constexpr int COL_WARNS_MODERATOR = 1;
|
||||||
|
|
@ -92,6 +95,8 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
depthSpin->setMinimum(1);
|
depthSpin->setMinimum(1);
|
||||||
depthSpin->setMaximum(MAX_ALT_DEPTH);
|
depthSpin->setMaximum(MAX_ALT_DEPTH);
|
||||||
depthSpin->setValue(1);
|
depthSpin->setValue(1);
|
||||||
|
depthSpin->setKeyboardTracking(false);
|
||||||
|
connect(depthSpin, &QSpinBox::valueChanged, this, &TabAlts::onSearchFilterChanged);
|
||||||
|
|
||||||
investigateButton = new QPushButton;
|
investigateButton = new QPushButton;
|
||||||
connect(investigateButton, &QPushButton::clicked, this, &TabAlts::investigateUser);
|
connect(investigateButton, &QPushButton::clicked, this, &TabAlts::investigateUser);
|
||||||
|
|
@ -101,6 +106,18 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
connect(backButton, &QPushButton::clicked, this, &TabAlts::goBack);
|
connect(backButton, &QPushButton::clicked, this, &TabAlts::goBack);
|
||||||
|
|
||||||
statusLabel = new QLabel;
|
statusLabel = new QLabel;
|
||||||
|
trailLabel = new QLabel;
|
||||||
|
trailLabel->setTextFormat(Qt::RichText);
|
||||||
|
trailLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||||
|
trailLabel->setOpenExternalLinks(false);
|
||||||
|
// The trail grows with every hop, so let it wrap instead of forcing the tab
|
||||||
|
// wider than the window.
|
||||||
|
trailLabel->setWordWrap(true);
|
||||||
|
connect(trailLabel, &QLabel::linkActivated, this, [this](const QString &userName) {
|
||||||
|
if (!userName.isEmpty() && userName != currentUser) {
|
||||||
|
goToTrailEntry(userName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
auto *topBar = new QHBoxLayout;
|
auto *topBar = new QHBoxLayout;
|
||||||
topBar->addWidget(backButton);
|
topBar->addWidget(backButton);
|
||||||
|
|
@ -112,7 +129,7 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
auto *chip = new QPushButton(text);
|
auto *chip = new QPushButton(text);
|
||||||
chip->setCheckable(true);
|
chip->setCheckable(true);
|
||||||
chip->setChecked(true);
|
chip->setChecked(true);
|
||||||
connect(chip, &QPushButton::toggled, this, &TabAlts::onFilterChanged);
|
connect(chip, &QPushButton::toggled, this, &TabAlts::onSearchFilterChanged);
|
||||||
return chip;
|
return chip;
|
||||||
};
|
};
|
||||||
emailChip = makeChip(QString());
|
emailChip = makeChip(QString());
|
||||||
|
|
@ -123,7 +140,14 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
vpnSpin->setMinimum(1);
|
vpnSpin->setMinimum(1);
|
||||||
vpnSpin->setMaximum(100000);
|
vpnSpin->setMaximum(100000);
|
||||||
vpnSpin->setValue(DEFAULT_VPN_THRESHOLD);
|
vpnSpin->setValue(DEFAULT_VPN_THRESHOLD);
|
||||||
connect(vpnSpin, &QSpinBox::valueChanged, this, &TabAlts::onFilterChanged);
|
connect(vpnSpin, &QSpinBox::valueChanged, this, &TabAlts::onDisplayFilterChanged);
|
||||||
|
windowLabel = new QLabel;
|
||||||
|
monthsSpin = new QSpinBox;
|
||||||
|
monthsSpin->setMinimum(1);
|
||||||
|
monthsSpin->setMaximum(24);
|
||||||
|
monthsSpin->setValue(6);
|
||||||
|
monthsSpin->setKeyboardTracking(false);
|
||||||
|
connect(monthsSpin, &QSpinBox::valueChanged, this, &TabAlts::onSearchFilterChanged);
|
||||||
|
|
||||||
auto *filterBar = new QHBoxLayout;
|
auto *filterBar = new QHBoxLayout;
|
||||||
filterBar->addWidget(emailChip);
|
filterBar->addWidget(emailChip);
|
||||||
|
|
@ -131,11 +155,19 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
filterBar->addWidget(ipChip);
|
filterBar->addWidget(ipChip);
|
||||||
filterBar->addWidget(vpnLabel);
|
filterBar->addWidget(vpnLabel);
|
||||||
filterBar->addWidget(vpnSpin);
|
filterBar->addWidget(vpnSpin);
|
||||||
|
filterBar->addWidget(windowLabel);
|
||||||
|
filterBar->addWidget(monthsSpin);
|
||||||
filterBar->addStretch();
|
filterBar->addStretch();
|
||||||
|
|
||||||
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
|
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
|
||||||
configureAltTable(altsTable);
|
configureAltTable(altsTable);
|
||||||
connect(altsTable, &QTableWidget::activated, this, [this](const QModelIndex &index) {
|
altsDelegate =
|
||||||
|
new AltTableDelegate(COL_ALTS_VIA, COL_ALTS_WARNS, COL_ALTS_BANS, COL_ALTS_SHARED, COL_ALTS_ACTIVE, altsTable);
|
||||||
|
altsTable->setItemDelegateForColumn(COL_ALTS_VIA, altsDelegate);
|
||||||
|
altsTable->setItemDelegateForColumn(COL_ALTS_WARNS, altsDelegate);
|
||||||
|
altsTable->setItemDelegateForColumn(COL_ALTS_BANS, altsDelegate);
|
||||||
|
altsTable->setItemDelegateForColumn(COL_ALTS_ACTIVE, altsDelegate);
|
||||||
|
connectTableActivation(altsTable, this, [this](const QModelIndex &index) {
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -173,6 +205,10 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
detailsLayout->addLayout(detailGrid);
|
detailsLayout->addLayout(detailGrid);
|
||||||
detailsLayout->addWidget(warnsTable, 1);
|
detailsLayout->addWidget(warnsTable, 1);
|
||||||
detailsLayout->addWidget(bansTable, 1);
|
detailsLayout->addWidget(bansTable, 1);
|
||||||
|
investigateSelectedButton = new QPushButton;
|
||||||
|
investigateSelectedButton->setEnabled(false);
|
||||||
|
connect(investigateSelectedButton, &QPushButton::clicked, this, &TabAlts::investigateSelected);
|
||||||
|
detailsLayout->addWidget(investigateSelectedButton);
|
||||||
|
|
||||||
auto *contentSplitter = new QSplitter(Qt::Horizontal);
|
auto *contentSplitter = new QSplitter(Qt::Horizontal);
|
||||||
contentSplitter->addWidget(altsTable);
|
contentSplitter->addWidget(altsTable);
|
||||||
|
|
@ -185,6 +221,7 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
||||||
mainLayout->addLayout(topBar);
|
mainLayout->addLayout(topBar);
|
||||||
mainLayout->addLayout(filterBar);
|
mainLayout->addLayout(filterBar);
|
||||||
mainLayout->addWidget(statusLabel);
|
mainLayout->addWidget(statusLabel);
|
||||||
|
mainLayout->addWidget(trailLabel);
|
||||||
mainLayout->addWidget(contentSplitter, 1);
|
mainLayout->addWidget(contentSplitter, 1);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
|
@ -212,8 +249,11 @@ void TabAlts::retranslateUi()
|
||||||
ipChip->setToolTip(tr("Show or hide IP address matches"));
|
ipChip->setToolTip(tr("Show or hide IP address matches"));
|
||||||
vpnLabel->setText(tr("Hide IPs shared by more than"));
|
vpnLabel->setText(tr("Hide IPs shared by more than"));
|
||||||
vpnSpin->setSuffix(tr(" users"));
|
vpnSpin->setSuffix(tr(" users"));
|
||||||
|
windowLabel->setText(tr("Session window"));
|
||||||
|
monthsSpin->setSuffix(tr(" months"));
|
||||||
|
monthsSpin->setToolTip(tr("How far back session IPs and client IDs are considered."));
|
||||||
|
|
||||||
altsTable->setHorizontalHeaderLabels({tr("User"), tr("Via"), tr("Depth"), tr("Shared"), tr("eMail"),
|
altsTable->setHorizontalHeaderLabels({tr("User"), tr("Via"), tr("Depth"), tr("Shared"), tr("IPs"), tr("eMail"),
|
||||||
tr("Client ID"), tr("Registered"), tr("Last login"), tr("Warns"), tr("Bans"),
|
tr("Client ID"), tr("Registered"), tr("Last login"), tr("Warns"), tr("Bans"),
|
||||||
tr("Active")});
|
tr("Active")});
|
||||||
altsTable->setToolTip(tr("Double-click or press Enter on a row to investigate that account"));
|
altsTable->setToolTip(tr("Double-click or press Enter on a row to investigate that account"));
|
||||||
|
|
@ -224,6 +264,8 @@ void TabAlts::retranslateUi()
|
||||||
detailNameLabel->setText(tr("Name:"));
|
detailNameLabel->setText(tr("Name:"));
|
||||||
detailCountsLabel->setText(tr("Counts:"));
|
detailCountsLabel->setText(tr("Counts:"));
|
||||||
detailNotesLabel->setText(tr("Admin notes:"));
|
detailNotesLabel->setText(tr("Admin notes:"));
|
||||||
|
investigateSelectedButton->setText(tr("Investigate this user"));
|
||||||
|
investigateSelectedButton->setToolTip(tr("Open the selected account as a new investigation"));
|
||||||
|
|
||||||
if (!lastAlts.isEmpty()) {
|
if (!lastAlts.isEmpty()) {
|
||||||
renderTable();
|
renderTable();
|
||||||
|
|
@ -240,6 +282,13 @@ void TabAlts::investigate(const QString &userName)
|
||||||
if (userName.isEmpty() || userName == currentUser) {
|
if (userName.isEmpty() || userName == currentUser) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Alt matches are symmetric, so revisiting an earlier account is a normal
|
||||||
|
// double-click. Truncate there instead of pushing it again, so the trail
|
||||||
|
// stays a single path.
|
||||||
|
if (backStack.contains(userName)) {
|
||||||
|
goToTrailEntry(userName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!currentUser.isEmpty()) {
|
if (!currentUser.isEmpty()) {
|
||||||
backStack << currentUser;
|
backStack << currentUser;
|
||||||
backButton->setEnabled(true);
|
backButton->setEnabled(true);
|
||||||
|
|
@ -247,6 +296,20 @@ void TabAlts::investigate(const QString &userName)
|
||||||
loadUser(userName);
|
loadUser(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabAlts::goToTrailEntry(const QString &userName)
|
||||||
|
{
|
||||||
|
const int index = backStack.indexOf(userName);
|
||||||
|
if (index < 0) {
|
||||||
|
investigate(userName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Clicking an earlier crumb truncates the history there instead of pushing
|
||||||
|
// another entry, so the trail keeps a single path and Back still works.
|
||||||
|
backStack.erase(backStack.begin() + index, backStack.end());
|
||||||
|
backButton->setEnabled(!backStack.isEmpty());
|
||||||
|
loadUser(userName);
|
||||||
|
}
|
||||||
|
|
||||||
void TabAlts::goBack()
|
void TabAlts::goBack()
|
||||||
{
|
{
|
||||||
if (backStack.isEmpty()) {
|
if (backStack.isEmpty()) {
|
||||||
|
|
@ -261,22 +324,52 @@ void TabAlts::loadUser(const QString &userName)
|
||||||
{
|
{
|
||||||
currentUser = userName;
|
currentUser = userName;
|
||||||
searchEdit->setText(userName);
|
searchEdit->setText(userName);
|
||||||
|
updateTrail();
|
||||||
investigateUser();
|
investigateUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabAlts::updateTrail()
|
||||||
|
{
|
||||||
|
QStringList trail = backStack;
|
||||||
|
trail << currentUser;
|
||||||
|
trail.removeAll(QString());
|
||||||
|
QStringList links;
|
||||||
|
for (const QString &name : trail) {
|
||||||
|
const QString safeName = name.toHtmlEscaped();
|
||||||
|
if (name == currentUser) {
|
||||||
|
links << QStringLiteral("<b>") + safeName + QStringLiteral("</b>");
|
||||||
|
} else {
|
||||||
|
links << QStringLiteral("<a href=\"") + safeName + QStringLiteral("\">") + safeName +
|
||||||
|
QStringLiteral("</a>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trailLabel->setText(links.join(QStringLiteral(" › ")));
|
||||||
|
trailLabel->setVisible(!links.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
void TabAlts::investigateUser()
|
void TabAlts::investigateUser()
|
||||||
{
|
{
|
||||||
const QString userName = searchEdit->text().simplified();
|
const QString userName = searchEdit->text().simplified();
|
||||||
if (userName.isEmpty()) {
|
if (userName.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (userName != currentUser && !currentUser.isEmpty()) {
|
||||||
|
backStack << currentUser;
|
||||||
|
backButton->setEnabled(true);
|
||||||
|
}
|
||||||
currentUser = userName;
|
currentUser = userName;
|
||||||
|
updateTrail();
|
||||||
|
reloadCurrentUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::reloadCurrentUser()
|
||||||
|
{
|
||||||
lastAlts.clear();
|
lastAlts.clear();
|
||||||
selectedUser.clear();
|
selectedUser.clear();
|
||||||
clearDetails();
|
clearDetails();
|
||||||
altsTable->setRowCount(0);
|
altsTable->setRowCount(0);
|
||||||
statusLabel->setText(tr("Loading alts for %1...").arg(currentUser));
|
statusLabel->setText(tr("Loading alts for %1...").arg(currentUser));
|
||||||
requestAlts(userName, depthSpin->value());
|
requestAlts(currentUser, depthSpin->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabAlts::requestAlts(const QString &userName, int depth)
|
void TabAlts::requestAlts(const QString &userName, int depth)
|
||||||
|
|
@ -284,6 +377,10 @@ void TabAlts::requestAlts(const QString &userName, int depth)
|
||||||
Command_GetUserAlts cmd;
|
Command_GetUserAlts cmd;
|
||||||
cmd.set_user_name(userName.toStdString());
|
cmd.set_user_name(userName.toStdString());
|
||||||
cmd.set_depth(static_cast<google::protobuf::uint32>(depth));
|
cmd.set_depth(static_cast<google::protobuf::uint32>(depth));
|
||||||
|
cmd.set_include_email(emailChip->isChecked());
|
||||||
|
cmd.set_include_clientid(clientIdChip->isChecked());
|
||||||
|
cmd.set_include_ip(ipChip->isChecked());
|
||||||
|
cmd.set_session_months(static_cast<google::protobuf::uint32>(monthsSpin->value()));
|
||||||
PendingCommand *pend = client->prepareModeratorCommand(cmd);
|
PendingCommand *pend = client->prepareModeratorCommand(cmd);
|
||||||
connect(pend, &PendingCommand::finished, this, [this, userName](const Response &response) {
|
connect(pend, &PendingCommand::finished, this, [this, userName](const Response &response) {
|
||||||
if (userName == currentUser) {
|
if (userName == currentUser) {
|
||||||
|
|
@ -357,9 +454,17 @@ void TabAlts::renderTable()
|
||||||
++ipCount;
|
++ipCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emailChip->setText(tr("Email (%1)").arg(emailCount));
|
// The server omits unchecked match types, so keep the last count while a
|
||||||
clientIdChip->setText(tr("Client ID (%1)").arg(clientIdCount));
|
// chip is off instead of relabelling it "(0)".
|
||||||
ipChip->setText(tr("IP (%1)").arg(ipCount));
|
if (emailChip->isChecked()) {
|
||||||
|
emailChip->setText(tr("Email (%1)").arg(emailCount));
|
||||||
|
}
|
||||||
|
if (clientIdChip->isChecked()) {
|
||||||
|
clientIdChip->setText(tr("Client ID (%1)").arg(clientIdCount));
|
||||||
|
}
|
||||||
|
if (ipChip->isChecked()) {
|
||||||
|
ipChip->setText(tr("IP (%1)").arg(ipCount));
|
||||||
|
}
|
||||||
|
|
||||||
QFont userFont = altsTable->font();
|
QFont userFont = altsTable->font();
|
||||||
userFont.setBold(true);
|
userFont.setBold(true);
|
||||||
|
|
@ -385,16 +490,26 @@ void TabAlts::renderTable()
|
||||||
altsTable->setItem(
|
altsTable->setItem(
|
||||||
row, COL_ALTS_SHARED,
|
row, COL_ALTS_SHARED,
|
||||||
new QTableWidgetItem(alt.has_shared_count() ? QString::number(alt.shared_count()) : QStringLiteral("-")));
|
new QTableWidgetItem(alt.has_shared_count() ? QString::number(alt.shared_count()) : QStringLiteral("-")));
|
||||||
|
altsTable->setItem(
|
||||||
|
row, COL_ALTS_IPS,
|
||||||
|
new QTableWidgetItem(alt.has_ip_count() ? QString::number(alt.ip_count()) : QStringLiteral("-")));
|
||||||
altsTable->setItem(row, COL_ALTS_EMAIL, new QTableWidgetItem(QString::fromStdString(alt.email())));
|
altsTable->setItem(row, COL_ALTS_EMAIL, new QTableWidgetItem(QString::fromStdString(alt.email())));
|
||||||
altsTable->setItem(row, COL_ALTS_CLIENTID, new QTableWidgetItem(QString::fromStdString(alt.clientid())));
|
altsTable->setItem(row, COL_ALTS_CLIENTID, new QTableWidgetItem(QString::fromStdString(alt.clientid())));
|
||||||
altsTable->setItem(row, COL_ALTS_REGISTERED, new QTableWidgetItem(formatEpoch(alt.registration_time())));
|
altsTable->setItem(row, COL_ALTS_REGISTERED, new QTableWidgetItem(formatEpoch(alt.registration_time())));
|
||||||
altsTable->setItem(row, COL_ALTS_LAST_LOGIN, new QTableWidgetItem(formatEpoch(alt.last_login())));
|
altsTable->setItem(row, COL_ALTS_LAST_LOGIN, new QTableWidgetItem(formatEpoch(alt.last_login())));
|
||||||
altsTable->setItem(row, COL_ALTS_WARNS, new QTableWidgetItem(QString::number(alt.warn_count())));
|
altsTable->setItem(row, COL_ALTS_WARNS, new QTableWidgetItem(QString::number(alt.warn_count())));
|
||||||
altsTable->setItem(row, COL_ALTS_BANS, new QTableWidgetItem(QString::number(alt.ban_count())));
|
altsTable->setItem(row, COL_ALTS_BANS, new QTableWidgetItem(QString::number(alt.ban_count())));
|
||||||
altsTable->setItem(row, COL_ALTS_ACTIVE, new QTableWidgetItem(alt.is_active() ? tr("yes") : tr("no")));
|
auto *activeItem = new QTableWidgetItem(alt.is_active() ? tr("yes") : tr("no"));
|
||||||
|
activeItem->setData(Qt::UserRole, alt.is_active());
|
||||||
|
altsTable->setItem(row, COL_ALTS_ACTIVE, activeItem);
|
||||||
|
// shared_count already includes the investigated account, so anything
|
||||||
|
// above 2 means the address is shared beyond that pair.
|
||||||
if (QString::fromStdString(alt.match_reason()).startsWith(QStringLiteral("ip:")) && alt.has_shared_count() &&
|
if (QString::fromStdString(alt.match_reason()).startsWith(QStringLiteral("ip:")) && alt.has_shared_count() &&
|
||||||
alt.shared_count() > 1) {
|
alt.shared_count() > 2) {
|
||||||
for (int col = 0; col < COL_ALTS_COUNT; ++col) {
|
for (int col = 0; col < COL_ALTS_COUNT; ++col) {
|
||||||
|
if (col == COL_ALTS_VIA) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (auto *item = altsTable->item(row, col)) {
|
if (auto *item = altsTable->item(row, col)) {
|
||||||
item->setForeground(dimColor);
|
item->setForeground(dimColor);
|
||||||
}
|
}
|
||||||
|
|
@ -437,7 +552,17 @@ void TabAlts::renderTable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabAlts::onFilterChanged()
|
void TabAlts::onSearchFilterChanged()
|
||||||
|
{
|
||||||
|
if (currentUser.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// A filter change reloads the user being investigated; it must not switch
|
||||||
|
// to a name that was typed into the search box but never submitted.
|
||||||
|
reloadCurrentUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::onDisplayFilterChanged()
|
||||||
{
|
{
|
||||||
if (lastAlts.isEmpty()) {
|
if (lastAlts.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -445,6 +570,13 @@ void TabAlts::onFilterChanged()
|
||||||
renderTable();
|
renderTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabAlts::investigateSelected()
|
||||||
|
{
|
||||||
|
if (!selectedUser.isEmpty() && selectedUser != currentUser) {
|
||||||
|
investigate(selectedUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TabAlts::onAltSelected()
|
void TabAlts::onAltSelected()
|
||||||
{
|
{
|
||||||
const auto selected = altsTable->selectedItems();
|
const auto selected = altsTable->selectedItems();
|
||||||
|
|
@ -468,6 +600,7 @@ void TabAlts::requestDetails(const QString &userName)
|
||||||
detailNotesEdit->clear();
|
detailNotesEdit->clear();
|
||||||
warnsTable->setRowCount(0);
|
warnsTable->setRowCount(0);
|
||||||
bansTable->setRowCount(0);
|
bansTable->setRowCount(0);
|
||||||
|
investigateSelectedButton->setEnabled(userName != currentUser);
|
||||||
|
|
||||||
Command_ReportUserInfo infoCmd;
|
Command_ReportUserInfo infoCmd;
|
||||||
infoCmd.set_user_name(userName.toStdString());
|
infoCmd.set_user_name(userName.toStdString());
|
||||||
|
|
@ -507,6 +640,7 @@ void TabAlts::clearDetails()
|
||||||
detailNotesEdit->clear();
|
detailNotesEdit->clear();
|
||||||
warnsTable->setRowCount(0);
|
warnsTable->setRowCount(0);
|
||||||
bansTable->setRowCount(0);
|
bansTable->setRowCount(0);
|
||||||
|
investigateSelectedButton->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabAlts::userDetailsResponse(const Response &response)
|
void TabAlts::userDetailsResponse(const Response &response)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <qtmetamacros.h>
|
#include <qtmetamacros.h>
|
||||||
|
|
||||||
class AbstractClient;
|
class AbstractClient;
|
||||||
|
class AltTableDelegate;
|
||||||
class QGroupBox;
|
class QGroupBox;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
|
@ -41,8 +42,10 @@ public:
|
||||||
private slots:
|
private slots:
|
||||||
void investigateUser();
|
void investigateUser();
|
||||||
void goBack();
|
void goBack();
|
||||||
|
void investigateSelected();
|
||||||
void altsResponse(const Response &response);
|
void altsResponse(const Response &response);
|
||||||
void onFilterChanged();
|
void onSearchFilterChanged();
|
||||||
|
void onDisplayFilterChanged();
|
||||||
void onAltSelected();
|
void onAltSelected();
|
||||||
void userDetailsResponse(const Response &response);
|
void userDetailsResponse(const Response &response);
|
||||||
void warnHistoryResponse(const Response &response);
|
void warnHistoryResponse(const Response &response);
|
||||||
|
|
@ -50,6 +53,9 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadUser(const QString &userName);
|
void loadUser(const QString &userName);
|
||||||
|
void goToTrailEntry(const QString &userName);
|
||||||
|
void updateTrail();
|
||||||
|
void reloadCurrentUser();
|
||||||
void requestAlts(const QString &userName, int depth);
|
void requestAlts(const QString &userName, int depth);
|
||||||
void requestDetails(const QString &userName);
|
void requestDetails(const QString &userName);
|
||||||
void clearDetails();
|
void clearDetails();
|
||||||
|
|
@ -67,14 +73,19 @@ private:
|
||||||
QSpinBox *depthSpin;
|
QSpinBox *depthSpin;
|
||||||
QPushButton *investigateButton;
|
QPushButton *investigateButton;
|
||||||
QPushButton *backButton;
|
QPushButton *backButton;
|
||||||
|
QPushButton *investigateSelectedButton;
|
||||||
|
QLabel *trailLabel;
|
||||||
QLabel *statusLabel;
|
QLabel *statusLabel;
|
||||||
QTableWidget *altsTable;
|
QTableWidget *altsTable;
|
||||||
|
AltTableDelegate *altsDelegate;
|
||||||
|
|
||||||
QPushButton *emailChip;
|
QPushButton *emailChip;
|
||||||
QPushButton *clientIdChip;
|
QPushButton *clientIdChip;
|
||||||
QPushButton *ipChip;
|
QPushButton *ipChip;
|
||||||
QLabel *vpnLabel;
|
QLabel *vpnLabel;
|
||||||
QSpinBox *vpnSpin;
|
QSpinBox *vpnSpin;
|
||||||
|
QLabel *windowLabel;
|
||||||
|
QSpinBox *monthsSpin;
|
||||||
|
|
||||||
QLabel *detailNameValue;
|
QLabel *detailNameValue;
|
||||||
QLabel *detailCountsValue;
|
QLabel *detailCountsValue;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "tab_moderation.h"
|
#include "tab_moderation.h"
|
||||||
|
|
||||||
#include "../utility/epoch_format.h"
|
#include "../utility/epoch_format.h"
|
||||||
|
#include "../utility/table_activation.h"
|
||||||
#include "abstract_client.h"
|
#include "abstract_client.h"
|
||||||
#include "libcockatrice/protocol/pb/admin_commands.pb.h"
|
#include "libcockatrice/protocol/pb/admin_commands.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||||
|
|
@ -176,7 +177,7 @@ TabModeration::TabModeration(TabSupervisor *_tabSupervisor, AbstractClient *_cli
|
||||||
|
|
||||||
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
|
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
|
||||||
configureTable(altsTable);
|
configureTable(altsTable);
|
||||||
connect(altsTable, &QTableWidget::activated, this, [this](const QModelIndex &index) {
|
connectTableActivation(altsTable, this, [this](const QModelIndex &index) {
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -456,7 +457,14 @@ void TabModeration::altsResponse(const Response &response)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Response_UserAlts &resp = response.GetExtension(Response_UserAlts::ext);
|
const Response_UserAlts &resp = response.GetExtension(Response_UserAlts::ext);
|
||||||
cachedAltsCount = resp.alts_size();
|
// The server always includes the frontier user as a depth-0 seed row.
|
||||||
|
int relatedCount = 0;
|
||||||
|
for (int i = 0; i < resp.alts_size(); ++i) {
|
||||||
|
if (!resp.alts(i).has_depth() || resp.alts(i).depth() > 0) {
|
||||||
|
++relatedCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cachedAltsCount = relatedCount;
|
||||||
applyAltsCount();
|
applyAltsCount();
|
||||||
altsTable->setRowCount(resp.alts_size());
|
altsTable->setRowCount(resp.alts_size());
|
||||||
for (int i = 0; i < resp.alts_size(); ++i) {
|
for (int i = 0; i < resp.alts_size(); ++i) {
|
||||||
|
|
|
||||||
|
|
@ -463,6 +463,9 @@ void TabReport::applyFilters()
|
||||||
table->setSortingEnabled(false);
|
table->setSortingEnabled(false);
|
||||||
table->setRowCount(filteredReports.size());
|
table->setRowCount(filteredReports.size());
|
||||||
|
|
||||||
|
QFont reportedFont = table->font();
|
||||||
|
reportedFont.setBold(true);
|
||||||
|
|
||||||
for (int row = 0; row < filteredReports.size(); ++row) {
|
for (int row = 0; row < filteredReports.size(); ++row) {
|
||||||
const ServerInfo_Report &r = filteredReports[row];
|
const ServerInfo_Report &r = filteredReports[row];
|
||||||
|
|
||||||
|
|
@ -476,11 +479,7 @@ void TabReport::applyFilters()
|
||||||
|
|
||||||
table->setItem(row, COL_ROOM,
|
table->setItem(row, COL_ROOM,
|
||||||
new QTableWidgetItem(r.has_room_id() && r.room_id() > 0 ? QString::number(r.room_id()) : ""));
|
new QTableWidgetItem(r.has_room_id() && r.room_id() > 0 ? QString::number(r.room_id()) : ""));
|
||||||
}
|
|
||||||
|
|
||||||
QFont reportedFont = table->font();
|
|
||||||
reportedFont.setBold(true);
|
|
||||||
for (int row = 0; row < filteredReports.size(); ++row) {
|
|
||||||
if (auto *reportedItem = table->item(row, COL_REPORTED)) {
|
if (auto *reportedItem = table->item(row, COL_REPORTED)) {
|
||||||
reportedItem->setFont(reportedFont);
|
reportedItem->setFont(reportedFont);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
41
cockatrice/src/interface/widgets/utility/pill_painter.cpp
Normal file
41
cockatrice/src/interface/widgets/utility/pill_painter.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include "pill_painter.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QFontMetrics>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QRect>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOptionViewItem>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr qreal PILL_ALPHA = 0.30;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
bool pill_painter::paint(QPainter *painter,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
QPalette::ColorRole tintRole,
|
||||||
|
QPalette::ColorRole textRole,
|
||||||
|
const QString &text)
|
||||||
|
{
|
||||||
|
const QRect pillRect = option.rect.adjusted(PAD_X / 2, PAD_Y / 2, -PAD_X / 2, -PAD_Y / 2);
|
||||||
|
if (pillRect.width() <= 0 || pillRect.height() <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((option.state & QStyle::State_Selected) == 0) {
|
||||||
|
painter->save();
|
||||||
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
QColor pill = option.palette.color(tintRole);
|
||||||
|
pill.setAlphaF(PILL_ALPHA);
|
||||||
|
painter->setPen(Qt::NoPen);
|
||||||
|
painter->setBrush(pill);
|
||||||
|
painter->drawRoundedRect(pillRect, pillRect.height() / 2.0, pillRect.height() / 2.0);
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStyle *style = option.widget != nullptr ? option.widget->style() : QApplication::style();
|
||||||
|
const QString elided = option.fontMetrics.elidedText(text, option.textElideMode, pillRect.width());
|
||||||
|
style->drawItemText(painter, pillRect, Qt::AlignCenter, option.palette, true, elided, textRole);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
29
cockatrice/src/interface/widgets/utility/pill_painter.h
Normal file
29
cockatrice/src/interface/widgets/utility/pill_painter.h
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef PILL_PAINTER_H
|
||||||
|
#define PILL_PAINTER_H
|
||||||
|
|
||||||
|
#include <QPalette>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class QPainter;
|
||||||
|
class QStyleOptionViewItem;
|
||||||
|
|
||||||
|
namespace pill_painter
|
||||||
|
{
|
||||||
|
constexpr int PAD_X = 10;
|
||||||
|
constexpr int PAD_Y = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a translucent, palette-tinted rounded pill inside the option's rect and
|
||||||
|
* paints the text elided and centred on it, so badges follow the active theme.
|
||||||
|
* Returns false when the cell is too small to hold a pill, leaving the caller to
|
||||||
|
* fall back to default painting.
|
||||||
|
*/
|
||||||
|
bool paint(QPainter *painter,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
QPalette::ColorRole tintRole,
|
||||||
|
QPalette::ColorRole textRole,
|
||||||
|
const QString &text);
|
||||||
|
|
||||||
|
} // namespace pill_painter
|
||||||
|
|
||||||
|
#endif // PILL_PAINTER_H
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
#include "table_activation.h"
|
||||||
|
|
||||||
|
#include <QKeySequence>
|
||||||
|
#include <QShortcut>
|
||||||
|
#include <QTableWidget>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
void addActivationShortcut(QTableWidget *table,
|
||||||
|
QObject *context,
|
||||||
|
int key,
|
||||||
|
const std::function<void(const QModelIndex &)> &handler)
|
||||||
|
{
|
||||||
|
auto *shortcut = new QShortcut(QKeySequence(key), table);
|
||||||
|
// The table's viewport takes focus, so match children as well.
|
||||||
|
shortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
||||||
|
QObject::connect(shortcut, &QShortcut::activated, context, [table, handler] { handler(table->currentIndex()); });
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void connectTableActivation(QTableWidget *table,
|
||||||
|
QObject *context,
|
||||||
|
const std::function<void(const QModelIndex &)> &handler)
|
||||||
|
{
|
||||||
|
QObject::connect(table, &QTableWidget::doubleClicked, context, handler);
|
||||||
|
addActivationShortcut(table, context, Qt::Key_Return, handler);
|
||||||
|
addActivationShortcut(table, context, Qt::Key_Enter, handler);
|
||||||
|
}
|
||||||
32
cockatrice/src/interface/widgets/utility/table_activation.h
Normal file
32
cockatrice/src/interface/widgets/utility/table_activation.h
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/**
|
||||||
|
* @file table_activation.h
|
||||||
|
* @brief Row activation for tables that must not navigate on a single click.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TABLE_ACTIVATION_H
|
||||||
|
#define TABLE_ACTIVATION_H
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
class QModelIndex;
|
||||||
|
class QObject;
|
||||||
|
class QTableWidget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Call @p handler on double-click or Enter, never on a single click.
|
||||||
|
*
|
||||||
|
* QAbstractItemView::activated fires on a single click on platforms where
|
||||||
|
* SH_ItemView_ActivateItemOnSingleClick is set, so navigation actions must not
|
||||||
|
* use it. This connects doubleClicked and installs Return/Enter shortcuts that
|
||||||
|
* forward the current index.
|
||||||
|
*
|
||||||
|
* @param table The table whose rows activate.
|
||||||
|
* @param context Object that owns the connections; the handler is disconnected
|
||||||
|
* with it.
|
||||||
|
* @param handler Receives the activated row's index, which may be invalid.
|
||||||
|
*/
|
||||||
|
void connectTableActivation(QTableWidget *table,
|
||||||
|
QObject *context,
|
||||||
|
const std::function<void(const QModelIndex &)> &handler);
|
||||||
|
|
||||||
|
#endif // TABLE_ACTIVATION_H
|
||||||
|
|
@ -170,6 +170,10 @@ message Command_GetUserAlts {
|
||||||
}
|
}
|
||||||
optional string user_name = 1;
|
optional string user_name = 1;
|
||||||
optional uint32 depth = 2 [default = 1]; // BFS depth: 1 = direct matches only, up to 3 for transitive alts-of-alts
|
optional uint32 depth = 2 [default = 1]; // BFS depth: 1 = direct matches only, up to 3 for transitive alts-of-alts
|
||||||
|
optional bool include_email = 3 [default = true]; // match and expand over registration email
|
||||||
|
optional bool include_clientid = 4 [default = true]; // match and expand over current and historic client ids
|
||||||
|
optional bool include_ip = 5 [default = true]; // match and expand over recent session IPs
|
||||||
|
optional uint32 session_months = 6 [default = 6]; // session lookback window in months, 1-24
|
||||||
}
|
}
|
||||||
|
|
||||||
message Command_GetModeratorLastLogins {
|
message Command_GetModeratorLastLogins {
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,5 @@ message ServerInfo_UserAlt {
|
||||||
optional uint32 depth = 10; // BFS distance from investigated account; 1 = direct, 2+ = alt-of-alt
|
optional uint32 depth = 10; // BFS distance from investigated account; 1 = direct, 2+ = alt-of-alt
|
||||||
optional uint32 shared_count =
|
optional uint32 shared_count =
|
||||||
11; // distinct users sharing the matched identifier; high values suggest VPN/shared network
|
11; // distinct users sharing the matched identifier; high values suggest VPN/shared network
|
||||||
|
optional uint32 ip_count = 12; // distinct recent session IPs of this account in the search window
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1987,6 +1987,8 @@ constexpr int MAX_USER_ALTS_PER_LEVEL = 200;
|
||||||
// Identifier-heavy frontiers, e.g. VPN users with hundreds of recent IPs, are
|
// Identifier-heavy frontiers, e.g. VPN users with hundreds of recent IPs, are
|
||||||
// truncated: this tool is deliberately a first-pass sweep, not an audit.
|
// truncated: this tool is deliberately a first-pass sweep, not an audit.
|
||||||
constexpr int MAX_USER_ALT_IDENTIFIERS = 200;
|
constexpr int MAX_USER_ALT_IDENTIFIERS = 200;
|
||||||
|
constexpr int MIN_USER_ALT_MONTHS = 1;
|
||||||
|
constexpr int MAX_USER_ALT_MONTHS = 24;
|
||||||
|
|
||||||
QString altInClause(const QString &prefix, const QList<QString> &values)
|
QString altInClause(const QString &prefix, const QList<QString> &values)
|
||||||
{
|
{
|
||||||
|
|
@ -2037,7 +2039,12 @@ QList<QString> cappedIdentifiers(const QList<QString> &values)
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QString &userName, int depth)
|
QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QString &userName,
|
||||||
|
int depth,
|
||||||
|
bool useEmail,
|
||||||
|
bool useClientId,
|
||||||
|
bool useIp,
|
||||||
|
int sessionMonths)
|
||||||
{
|
{
|
||||||
QList<ServerInfo_UserAlt> results;
|
QList<ServerInfo_UserAlt> results;
|
||||||
|
|
||||||
|
|
@ -2050,6 +2057,16 @@ QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QStrin
|
||||||
} else if (depth > MAX_USER_ALT_DEPTH) {
|
} else if (depth > MAX_USER_ALT_DEPTH) {
|
||||||
depth = MAX_USER_ALT_DEPTH;
|
depth = MAX_USER_ALT_DEPTH;
|
||||||
}
|
}
|
||||||
|
if (sessionMonths < MIN_USER_ALT_MONTHS) {
|
||||||
|
sessionMonths = MIN_USER_ALT_MONTHS;
|
||||||
|
} else if (sessionMonths > MAX_USER_ALT_MONTHS) {
|
||||||
|
sessionMonths = MAX_USER_ALT_MONTHS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interpolated, not bound: placeholders are not allowed in INTERVAL
|
||||||
|
// expressions, and the clamped integer cannot inject SQL.
|
||||||
|
const QString sessionWindow = QStringLiteral(" AND start_time >= DATE_SUB(NOW(), INTERVAL ") +
|
||||||
|
QString::number(sessionMonths) + QStringLiteral(" MONTH)");
|
||||||
|
|
||||||
// Seed must exist; its row anchors the result at depth 0.
|
// Seed must exist; its row anchors the result at depth 0.
|
||||||
QSqlQuery *seedQuery = prepareQuery("SELECT u.name, u.email, u.clientid, UNIX_TIMESTAMP(u.registrationDate), "
|
QSqlQuery *seedQuery = prepareQuery("SELECT u.name, u.email, u.clientid, UNIX_TIMESTAMP(u.registrationDate), "
|
||||||
|
|
@ -2122,32 +2139,46 @@ QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QStrin
|
||||||
QSet<QString> clientIdKeys;
|
QSet<QString> clientIdKeys;
|
||||||
QSet<QString> ipKeys;
|
QSet<QString> ipKeys;
|
||||||
|
|
||||||
QSqlQuery frontierQuery(sqlDatabase);
|
if (useEmail || useClientId) {
|
||||||
prepareDynamicQuery(frontierQuery, QStringLiteral("SELECT email, clientid FROM {prefix}_users WHERE name IN ") +
|
QSqlQuery frontierQuery(sqlDatabase);
|
||||||
frontierClause);
|
prepareDynamicQuery(frontierQuery,
|
||||||
altBindValues(&frontierQuery, QStringLiteral(":alt_name"), frontier);
|
QStringLiteral("SELECT email, clientid FROM {prefix}_users WHERE name IN ") +
|
||||||
if (execSqlQuery(&frontierQuery)) {
|
frontierClause);
|
||||||
while (frontierQuery.next()) {
|
altBindValues(&frontierQuery, QStringLiteral(":alt_name"), frontier);
|
||||||
// Email comparison is case-insensitive in SQL, so normalise the
|
if (execSqlQuery(&frontierQuery)) {
|
||||||
// keys too or the membership tests below miss real matches.
|
while (frontierQuery.next()) {
|
||||||
appendIdentifier(emails, emailKeys, frontierQuery.value(0).toString().toLower());
|
// Email comparison is case-insensitive in SQL, so normalise the
|
||||||
appendIdentifier(clientIds, clientIdKeys, frontierQuery.value(1).toString());
|
// keys too or the membership tests below miss real matches.
|
||||||
|
if (useEmail) {
|
||||||
|
appendIdentifier(emails, emailKeys, frontierQuery.value(0).toString().toLower());
|
||||||
|
}
|
||||||
|
if (useClientId) {
|
||||||
|
appendIdentifier(clientIds, clientIdKeys, frontierQuery.value(1).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recent session identifiers: IPs plus historic client ids, most recent
|
// Recent session identifiers: IPs plus historic client ids, most recent
|
||||||
// first so a capped list keeps what the account actually used lately.
|
// first so a capped list keeps what the account actually used lately.
|
||||||
QSqlQuery sessionQuery(sqlDatabase);
|
if (useIp || useClientId) {
|
||||||
prepareDynamicQuery(sessionQuery, QStringLiteral("SELECT ip_address, clientid, MAX(start_time) AS last_seen "
|
QSqlQuery sessionQuery(sqlDatabase);
|
||||||
"FROM {prefix}_sessions WHERE user_name IN ") +
|
prepareDynamicQuery(sessionQuery,
|
||||||
frontierClause +
|
QStringLiteral("SELECT ip_address, clientid, MAX(start_time) AS last_seen "
|
||||||
QStringLiteral(" AND start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH) "
|
"FROM {prefix}_sessions WHERE user_name IN ") +
|
||||||
"GROUP BY ip_address, clientid ORDER BY last_seen DESC"));
|
frontierClause + sessionWindow +
|
||||||
altBindValues(&sessionQuery, QStringLiteral(":alt_name"), frontier);
|
QStringLiteral(" GROUP BY ip_address, clientid "
|
||||||
if (execSqlQuery(&sessionQuery)) {
|
"ORDER BY last_seen DESC"));
|
||||||
while (sessionQuery.next()) {
|
altBindValues(&sessionQuery, QStringLiteral(":alt_name"), frontier);
|
||||||
appendIdentifier(ips, ipKeys, sessionQuery.value(0).toString());
|
if (execSqlQuery(&sessionQuery)) {
|
||||||
appendIdentifier(clientIds, clientIdKeys, sessionQuery.value(1).toString());
|
while (sessionQuery.next()) {
|
||||||
|
if (useIp) {
|
||||||
|
appendIdentifier(ips, ipKeys, sessionQuery.value(0).toString());
|
||||||
|
}
|
||||||
|
if (useClientId) {
|
||||||
|
appendIdentifier(clientIds, clientIdKeys, sessionQuery.value(1).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2179,14 +2210,13 @@ QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QStrin
|
||||||
if (!ipList.isEmpty()) {
|
if (!ipList.isEmpty()) {
|
||||||
conditions << QStringLiteral("u.name IN (SELECT DISTINCT s.user_name FROM {prefix}_sessions s WHERE "
|
conditions << QStringLiteral("u.name IN (SELECT DISTINCT s.user_name FROM {prefix}_sessions s WHERE "
|
||||||
"s.ip_address IN ") +
|
"s.ip_address IN ") +
|
||||||
altInClause(QStringLiteral(":alt_ip"), ipList) +
|
altInClause(QStringLiteral(":alt_ip"), ipList) + sessionWindow + QStringLiteral(")");
|
||||||
QStringLiteral(" AND s.start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH))");
|
|
||||||
}
|
}
|
||||||
if (!clientIdList.isEmpty()) {
|
if (!clientIdList.isEmpty()) {
|
||||||
conditions << QStringLiteral("u.name IN (SELECT DISTINCT s.user_name FROM {prefix}_sessions s WHERE "
|
conditions << QStringLiteral("u.name IN (SELECT DISTINCT s.user_name FROM {prefix}_sessions s WHERE "
|
||||||
"s.clientid IN ") +
|
"s.clientid IN ") +
|
||||||
altInClause(QStringLiteral(":alt_hcid"), clientIdList) +
|
altInClause(QStringLiteral(":alt_hcid"), clientIdList) + sessionWindow +
|
||||||
QStringLiteral(" AND s.start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH))");
|
QStringLiteral(")");
|
||||||
}
|
}
|
||||||
candidateString += conditions.join(QStringLiteral(" OR "));
|
candidateString += conditions.join(QStringLiteral(" OR "));
|
||||||
// Already-visited accounts match their own identifiers at every level and
|
// Already-visited accounts match their own identifiers at every level and
|
||||||
|
|
@ -2251,7 +2281,7 @@ QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QStrin
|
||||||
altInClause(QStringLiteral(":alt_ecid"), clientIdList);
|
altInClause(QStringLiteral(":alt_ecid"), clientIdList);
|
||||||
}
|
}
|
||||||
evidenceString += evidenceConditions.join(QStringLiteral(" OR "));
|
evidenceString += evidenceConditions.join(QStringLiteral(" OR "));
|
||||||
evidenceString += QStringLiteral(") AND start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH)");
|
evidenceString += QStringLiteral(")") + sessionWindow;
|
||||||
|
|
||||||
QSqlQuery evidenceQuery(sqlDatabase);
|
QSqlQuery evidenceQuery(sqlDatabase);
|
||||||
prepareDynamicQuery(evidenceQuery, evidenceString);
|
prepareDynamicQuery(evidenceQuery, evidenceString);
|
||||||
|
|
@ -2346,9 +2376,8 @@ QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QStrin
|
||||||
prepareDynamicQuery(countQuery,
|
prepareDynamicQuery(countQuery,
|
||||||
QStringLiteral("SELECT ip_address, COUNT(DISTINCT user_name) FROM {prefix}_sessions "
|
QStringLiteral("SELECT ip_address, COUNT(DISTINCT user_name) FROM {prefix}_sessions "
|
||||||
"WHERE ip_address IN ") +
|
"WHERE ip_address IN ") +
|
||||||
altInClause(QStringLiteral(":alt_ci"), neededIpList) +
|
altInClause(QStringLiteral(":alt_ci"), neededIpList) + sessionWindow +
|
||||||
QStringLiteral(" AND start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH) "
|
QStringLiteral(" GROUP BY ip_address"));
|
||||||
"GROUP BY ip_address"));
|
|
||||||
altBindValues(&countQuery, QStringLiteral(":alt_ci"), neededIpList);
|
altBindValues(&countQuery, QStringLiteral(":alt_ci"), neededIpList);
|
||||||
if (execSqlQuery(&countQuery)) {
|
if (execSqlQuery(&countQuery)) {
|
||||||
while (countQuery.next()) {
|
while (countQuery.next()) {
|
||||||
|
|
@ -2385,6 +2414,31 @@ QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QStrin
|
||||||
frontier = nextFrontier;
|
frontier = nextFrontier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Distinct recent IP counts per account: cheap group signal without
|
||||||
|
// shipping full address histories to the client.
|
||||||
|
if (!results.isEmpty()) {
|
||||||
|
QList<QString> resultNames;
|
||||||
|
resultNames.reserve(results.size());
|
||||||
|
for (const ServerInfo_UserAlt &alt : results) {
|
||||||
|
resultNames << QString::fromStdString(alt.user_name());
|
||||||
|
}
|
||||||
|
QSqlQuery *ipCountQuery = prepareQuery(
|
||||||
|
QStringLiteral("SELECT user_name, COUNT(DISTINCT ip_address) FROM {prefix}_sessions WHERE user_name IN ") +
|
||||||
|
altInClause(QStringLiteral(":alt_ic"), resultNames) + sessionWindow +
|
||||||
|
QStringLiteral(" GROUP BY user_name"));
|
||||||
|
altBindValues(ipCountQuery, QStringLiteral(":alt_ic"), resultNames);
|
||||||
|
QMap<QString, int> ipCountsByUser;
|
||||||
|
if (execSqlQuery(ipCountQuery)) {
|
||||||
|
while (ipCountQuery->next()) {
|
||||||
|
ipCountsByUser.insert(ipCountQuery->value(0).toString(), ipCountQuery->value(1).toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (ServerInfo_UserAlt &alt : results) {
|
||||||
|
alt.set_ip_count(static_cast<google::protobuf::uint32>(
|
||||||
|
ipCountsByUser.value(QString::fromStdString(alt.user_name()), 0)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,12 @@ public:
|
||||||
const QString &beforeTime = QString(),
|
const QString &beforeTime = QString(),
|
||||||
bool *hasMore = nullptr);
|
bool *hasMore = nullptr);
|
||||||
QList<ServerInfo_UserSession> getUserSessions(const QString &userName, int limit);
|
QList<ServerInfo_UserSession> getUserSessions(const QString &userName, int limit);
|
||||||
QList<ServerInfo_UserAlt> getUserAlts(const QString &userName, int depth = 1);
|
QList<ServerInfo_UserAlt> getUserAlts(const QString &userName,
|
||||||
|
int depth = 1,
|
||||||
|
bool useEmail = true,
|
||||||
|
bool useClientId = true,
|
||||||
|
bool useIp = true,
|
||||||
|
int sessionMonths = 6);
|
||||||
QList<ServerInfo_ModeratorLogin> getModeratorLastLogins();
|
QList<ServerInfo_ModeratorLogin> getModeratorLastLogins();
|
||||||
|
|
||||||
// Uptime snapshot as recorded by Servatrice::statusUpdate() into the
|
// Uptime snapshot as recorded by Servatrice::statusUpdate() into the
|
||||||
|
|
|
||||||
|
|
@ -2596,7 +2596,9 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetUserAlts(const Comma
|
||||||
|
|
||||||
Response_UserAlts *re = new Response_UserAlts;
|
Response_UserAlts *re = new Response_UserAlts;
|
||||||
const int depth = cmd.has_depth() ? static_cast<int>(cmd.depth()) : 1;
|
const int depth = cmd.has_depth() ? static_cast<int>(cmd.depth()) : 1;
|
||||||
const QList<ServerInfo_UserAlt> alts = sqlInterface->getUserAlts(userName, depth);
|
const int sessionMonths = cmd.has_session_months() ? static_cast<int>(cmd.session_months()) : 6;
|
||||||
|
const QList<ServerInfo_UserAlt> alts = sqlInterface->getUserAlts(
|
||||||
|
userName, depth, cmd.include_email(), cmd.include_clientid(), cmd.include_ip(), sessionMonths);
|
||||||
for (const ServerInfo_UserAlt &alt : alts) {
|
for (const ServerInfo_UserAlt &alt : alts) {
|
||||||
re->add_alts()->CopyFrom(alt);
|
re->add_alts()->CopyFrom(alt);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
vcpkg
2
vcpkg
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9eec002df1cd109f8f104cd966a763daf9751489
|
Subproject commit 9e593bb18ea69cc5095e012465dcd675a822ed0d
|
||||||
Loading…
Add table
Add a link
Reference in a new issue