mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
Compare commits
11 commits
2b7ddfd968
...
fbf11acddc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbf11acddc | ||
|
|
13e0608662 | ||
|
|
89789dc317 | ||
|
|
360dd0ee2a | ||
|
|
925234ebbb | ||
|
|
459c61933b | ||
|
|
e36b59c2f5 | ||
|
|
3823dfa087 | ||
|
|
f468315826 | ||
|
|
3113289dbe | ||
|
|
a7fa3f0852 |
27 changed files with 1810 additions and 170 deletions
|
|
@ -303,8 +303,12 @@ set(cockatrice_SOURCES
|
||||||
src/interface/widgets/settings_page/user_interface_settings_page.cpp
|
src/interface/widgets/settings_page/user_interface_settings_page.cpp
|
||||||
src/interface/widgets/utility/custom_line_edit.cpp
|
src/interface/widgets/utility/custom_line_edit.cpp
|
||||||
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
|
||||||
|
|
@ -390,9 +394,12 @@ 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/tab.cpp
|
src/interface/widgets/tabs/tab.cpp
|
||||||
src/interface/widgets/tabs/tab_account.cpp
|
src/interface/widgets/tabs/tab_account.cpp
|
||||||
src/interface/widgets/tabs/tab_admin.cpp
|
src/interface/widgets/tabs/tab_admin.cpp
|
||||||
|
src/interface/widgets/tabs/tab_alts.cpp
|
||||||
src/interface/widgets/tabs/tab_card_art_rules.cpp
|
src/interface/widgets/tabs/tab_card_art_rules.cpp
|
||||||
src/interface/widgets/tabs/tab_deck_editor.cpp
|
src/interface/widgets/tabs/tab_deck_editor.cpp
|
||||||
src/interface/widgets/tabs/tab_deck_storage.cpp
|
src/interface/widgets/tabs/tab_deck_storage.cpp
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,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);
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ UserContextMenu::UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *parent,
|
||||||
aDemoteFromDeveloper = new QAction(QString(), this);
|
aDemoteFromDeveloper = new QAction(QString(), this);
|
||||||
aGetAdminNotes = new QAction(QString(), this);
|
aGetAdminNotes = new QAction(QString(), this);
|
||||||
aInvestigateUser = new QAction(QString(), this);
|
aInvestigateUser = new QAction(QString(), this);
|
||||||
|
aInvestigateAlts = new QAction(QString(), this);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
@ -110,6 +111,7 @@ void UserContextMenu::retranslateUi()
|
||||||
aDemoteFromDeveloper->setText(tr("Demote user from de&veloper"));
|
aDemoteFromDeveloper->setText(tr("Demote user from de&veloper"));
|
||||||
aGetAdminNotes->setText(tr("View admin notes"));
|
aGetAdminNotes->setText(tr("View admin notes"));
|
||||||
aInvestigateUser->setText(tr("Investigate user"));
|
aInvestigateUser->setText(tr("Investigate user"));
|
||||||
|
aInvestigateAlts->setText(tr("Investigate &alts"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserContextMenu::gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer)
|
void UserContextMenu::gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer)
|
||||||
|
|
@ -453,6 +455,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos,
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
menu->addAction(aGetAdminNotes);
|
menu->addAction(aGetAdminNotes);
|
||||||
menu->addAction(aInvestigateUser);
|
menu->addAction(aInvestigateUser);
|
||||||
|
menu->addAction(aInvestigateAlts);
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
if (userLevel.testFlag(ServerInfo_User::IsModerator) &&
|
if (userLevel.testFlag(ServerInfo_User::IsModerator) &&
|
||||||
|
|
@ -498,6 +501,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos,
|
||||||
aBanHistory->setEnabled(anotherUser);
|
aBanHistory->setEnabled(anotherUser);
|
||||||
aGetAdminNotes->setEnabled(anotherUser);
|
aGetAdminNotes->setEnabled(anotherUser);
|
||||||
aInvestigateUser->setEnabled(anotherUser);
|
aInvestigateUser->setEnabled(anotherUser);
|
||||||
|
aInvestigateAlts->setEnabled(anotherUser);
|
||||||
aPromoteToMod->setEnabled(anotherUser);
|
aPromoteToMod->setEnabled(anotherUser);
|
||||||
aDemoteFromMod->setEnabled(anotherUser);
|
aDemoteFromMod->setEnabled(anotherUser);
|
||||||
aPromoteToJudge->setEnabled(anotherUser);
|
aPromoteToJudge->setEnabled(anotherUser);
|
||||||
|
|
@ -552,6 +556,8 @@ void UserContextMenu::showContextMenu(const QPoint &pos,
|
||||||
execAdminNotes(userName);
|
execAdminNotes(userName);
|
||||||
} else if (actionClicked == aInvestigateUser) {
|
} else if (actionClicked == aInvestigateUser) {
|
||||||
execInvestigateUser(userName);
|
execInvestigateUser(userName);
|
||||||
|
} else if (actionClicked == aInvestigateAlts) {
|
||||||
|
execInvestigateAlts(userName);
|
||||||
} else if (actionClicked == aCopyToClipBoard) {
|
} else if (actionClicked == aCopyToClipBoard) {
|
||||||
QClipboard *clipboard = QGuiApplication::clipboard();
|
QClipboard *clipboard = QGuiApplication::clipboard();
|
||||||
clipboard->setText(deckHash);
|
clipboard->setText(deckHash);
|
||||||
|
|
@ -746,6 +752,11 @@ void UserContextMenu::execInvestigateUser(const QString &userName)
|
||||||
tabSupervisor->openTabModeration(userName);
|
tabSupervisor->openTabModeration(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UserContextMenu::execInvestigateAlts(const QString &userName)
|
||||||
|
{
|
||||||
|
tabSupervisor->openTabAlts(userName);
|
||||||
|
}
|
||||||
|
|
||||||
void UserContextMenu::execAdjustMod(const QString &userName, bool shouldBeMod)
|
void UserContextMenu::execAdjustMod(const QString &userName, bool shouldBeMod)
|
||||||
{
|
{
|
||||||
Command_AdjustMod cmd;
|
Command_AdjustMod cmd;
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ private:
|
||||||
QAction *aGetAdminNotes;
|
QAction *aGetAdminNotes;
|
||||||
std::function<QList<GameInviteOption>()> gameInviteLinkProvider;
|
std::function<QList<GameInviteOption>()> gameInviteLinkProvider;
|
||||||
QAction *aInvestigateUser;
|
QAction *aInvestigateUser;
|
||||||
|
QAction *aInvestigateAlts;
|
||||||
signals:
|
signals:
|
||||||
void openMessageDialog(const QString &userName, bool focus);
|
void openMessageDialog(const QString &userName, bool focus);
|
||||||
private slots:
|
private slots:
|
||||||
|
|
@ -127,6 +128,7 @@ public:
|
||||||
void execWarnHistory(const QString &userName);
|
void execWarnHistory(const QString &userName);
|
||||||
void execAdminNotes(const QString &userName);
|
void execAdminNotes(const QString &userName);
|
||||||
void execInvestigateUser(const QString &userName);
|
void execInvestigateUser(const QString &userName);
|
||||||
|
void execInvestigateAlts(const QString &userName);
|
||||||
void execAdjustMod(const QString &userName, bool shouldBeMod);
|
void execAdjustMod(const QString &userName, bool shouldBeMod);
|
||||||
void execAdjustJudge(const QString &userName, bool shouldBeJudge);
|
void execAdjustJudge(const QString &userName, bool shouldBeJudge);
|
||||||
void execAdjustDeveloper(const QString &userName, bool shouldBeDeveloper);
|
void execAdjustDeveloper(const QString &userName, bool shouldBeDeveloper);
|
||||||
|
|
|
||||||
95
cockatrice/src/interface/widgets/tabs/alt_table_delegate.cpp
Normal file
95
cockatrice/src/interface/widgets/tabs/alt_table_delegate.cpp
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
#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, QObject *parent)
|
||||||
|
: QStyledItemDelegate(parent), viaColumn(viaColumn), warnsColumn(warnsColumn), bansColumn(bansColumn),
|
||||||
|
sharedColumn(sharedColumn)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
33
cockatrice/src/interface/widgets/tabs/alt_table_delegate.h
Normal file
33
cockatrice/src/interface/widgets/tabs/alt_table_delegate.h
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#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. 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,
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ALT_TABLE_DELEGATE_H
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
#include "report_status_delegate.h"
|
||||||
|
|
||||||
|
#include "../utility/pill_painter.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPalette>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOptionViewItem>
|
||||||
|
|
||||||
|
ReportStatusDelegate::ReportStatusDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
const bool selected = (option.state & QStyle::State_Selected) != 0;
|
||||||
|
QString status = index.data(Qt::UserRole).toString();
|
||||||
|
if (status.isEmpty()) {
|
||||||
|
status = index.data(Qt::DisplayRole).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QPalette::ColorRole tintRole = QPalette::NoRole;
|
||||||
|
if (status == QStringLiteral("open")) {
|
||||||
|
tintRole = QPalette::Highlight;
|
||||||
|
} else if (status == QStringLiteral("assigned")) {
|
||||||
|
tintRole = QPalette::Link;
|
||||||
|
} else if (status == QStringLiteral("resolved")) {
|
||||||
|
tintRole = QPalette::PlaceholderText;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStyleOptionViewItem opt(option);
|
||||||
|
initStyleOption(&opt, index);
|
||||||
|
painter->setFont(opt.font);
|
||||||
|
|
||||||
|
if (tintRole == QPalette::NoRole) {
|
||||||
|
const QPalette::ColorRole textRole = selected ? QPalette::HighlightedText : QPalette::PlaceholderText;
|
||||||
|
QStyle *fallbackStyle = opt.widget != nullptr ? opt.widget->style() : QApplication::style();
|
||||||
|
fallbackStyle->drawItemText(painter, opt.rect, Qt::AlignLeft | Qt::AlignVCenter, opt.palette, true, opt.text,
|
||||||
|
textRole);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QPalette::ColorRole textRole = selected ? QPalette::HighlightedText : QPalette::WindowText;
|
||||||
|
if (!pill_painter::paint(painter, opt, tintRole, textRole, opt.text.isEmpty() ? status : opt.text)) {
|
||||||
|
QStyledItemDelegate::paint(painter, opt, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize ReportStatusDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
const QSize hint = QStyledItemDelegate::sizeHint(option, index);
|
||||||
|
return hint + QSize(pill_painter::PAD_X, pill_painter::PAD_Y);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef REPORT_STATUS_DELEGATE_H
|
||||||
|
#define REPORT_STATUS_DELEGATE_H
|
||||||
|
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
#include <qtmetamacros.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* always follow the active theme. Falls back to default painting for
|
||||||
|
* selected rows and unknown statuses.
|
||||||
|
*/
|
||||||
|
class ReportStatusDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ReportStatusDelegate(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;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // REPORT_STATUS_DELEGATE_H
|
||||||
639
cockatrice/src/interface/widgets/tabs/tab_alts.cpp
Normal file
639
cockatrice/src/interface/widgets/tabs/tab_alts.cpp
Normal file
|
|
@ -0,0 +1,639 @@
|
||||||
|
#include "tab_alts.h"
|
||||||
|
|
||||||
|
#include "../utility/table_activation.h"
|
||||||
|
#include "abstract_client.h"
|
||||||
|
#include "alt_table_delegate.h"
|
||||||
|
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||||
|
#include "libcockatrice/protocol/pb/response_user_alts.pb.h"
|
||||||
|
|
||||||
|
#include <QAbstractItemView>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QItemSelectionModel>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QList>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QSignalBlocker>
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QSplitter>
|
||||||
|
#include <QTableWidget>
|
||||||
|
#include <QTableWidgetItem>
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <libcockatrice/protocol/pb/command_report_user_info.pb.h>
|
||||||
|
#include <libcockatrice/protocol/pb/moderator_commands.pb.h>
|
||||||
|
#include <libcockatrice/protocol/pb/response_ban_history.pb.h>
|
||||||
|
#include <libcockatrice/protocol/pb/response_report_user_info.pb.h>
|
||||||
|
#include <libcockatrice/protocol/pb/response_warn_history.pb.h>
|
||||||
|
#include <libcockatrice/protocol/pb/serverinfo_ban.pb.h>
|
||||||
|
#include <libcockatrice/protocol/pb/serverinfo_warning.pb.h>
|
||||||
|
#include <libcockatrice/protocol/pending_command.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr int COL_ALTS_USER = 0;
|
||||||
|
constexpr int COL_ALTS_VIA = 1;
|
||||||
|
constexpr int COL_ALTS_DEPTH = 2;
|
||||||
|
constexpr int COL_ALTS_SHARED = 3;
|
||||||
|
constexpr int COL_ALTS_EMAIL = 4;
|
||||||
|
constexpr int COL_ALTS_CLIENTID = 5;
|
||||||
|
constexpr int COL_ALTS_REGISTERED = 6;
|
||||||
|
constexpr int COL_ALTS_LAST_LOGIN = 7;
|
||||||
|
constexpr int COL_ALTS_WARNS = 8;
|
||||||
|
constexpr int COL_ALTS_BANS = 9;
|
||||||
|
constexpr int COL_ALTS_ACTIVE = 10;
|
||||||
|
constexpr int COL_ALTS_COUNT = 11;
|
||||||
|
|
||||||
|
constexpr int COL_WARNS_TIME = 0;
|
||||||
|
constexpr int COL_WARNS_MODERATOR = 1;
|
||||||
|
constexpr int COL_WARNS_REASON = 2;
|
||||||
|
constexpr int COL_WARNS_COUNT = 3;
|
||||||
|
|
||||||
|
constexpr int COL_BANS_TIME = 0;
|
||||||
|
constexpr int COL_BANS_MODERATOR = 1;
|
||||||
|
constexpr int COL_BANS_LENGTH = 2;
|
||||||
|
constexpr int COL_BANS_REASON = 3;
|
||||||
|
constexpr int COL_BANS_COUNT = 4;
|
||||||
|
|
||||||
|
constexpr int MAX_ALT_DEPTH = 3;
|
||||||
|
// Starting default only (adjustable 1-100000): shared VPN exits routinely
|
||||||
|
// cover dozens of users, so 10 hides the obvious VPN noise but keeps
|
||||||
|
// small shared networks visible.
|
||||||
|
constexpr int DEFAULT_VPN_THRESHOLD = 10;
|
||||||
|
|
||||||
|
void configureAltTable(QTableWidget *table)
|
||||||
|
{
|
||||||
|
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
table->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
table->verticalHeader()->setVisible(false);
|
||||||
|
table->setAlternatingRowColors(true);
|
||||||
|
table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
|
table->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &initialUser)
|
||||||
|
: Tab(_tabSupervisor), client(_client)
|
||||||
|
{
|
||||||
|
auto *centralWidget = new QWidget(this);
|
||||||
|
setCentralWidget(centralWidget);
|
||||||
|
|
||||||
|
searchEdit = new QLineEdit;
|
||||||
|
searchEdit->setClearButtonEnabled(true);
|
||||||
|
connect(searchEdit, &QLineEdit::returnPressed, this, &TabAlts::investigateUser);
|
||||||
|
|
||||||
|
depthSpin = new QSpinBox;
|
||||||
|
depthSpin->setMinimum(1);
|
||||||
|
depthSpin->setMaximum(MAX_ALT_DEPTH);
|
||||||
|
depthSpin->setValue(1);
|
||||||
|
|
||||||
|
investigateButton = new QPushButton;
|
||||||
|
connect(investigateButton, &QPushButton::clicked, this, &TabAlts::investigateUser);
|
||||||
|
|
||||||
|
backButton = new QPushButton;
|
||||||
|
backButton->setEnabled(false);
|
||||||
|
connect(backButton, &QPushButton::clicked, this, &TabAlts::goBack);
|
||||||
|
|
||||||
|
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;
|
||||||
|
topBar->addWidget(backButton);
|
||||||
|
topBar->addWidget(searchEdit);
|
||||||
|
topBar->addWidget(depthSpin);
|
||||||
|
topBar->addWidget(investigateButton);
|
||||||
|
|
||||||
|
auto makeChip = [this](const QString &text) {
|
||||||
|
auto *chip = new QPushButton(text);
|
||||||
|
chip->setCheckable(true);
|
||||||
|
chip->setChecked(true);
|
||||||
|
connect(chip, &QPushButton::toggled, this, &TabAlts::onFilterChanged);
|
||||||
|
return chip;
|
||||||
|
};
|
||||||
|
emailChip = makeChip(QString());
|
||||||
|
clientIdChip = makeChip(QString());
|
||||||
|
ipChip = makeChip(QString());
|
||||||
|
vpnLabel = new QLabel;
|
||||||
|
vpnSpin = new QSpinBox;
|
||||||
|
vpnSpin->setMinimum(1);
|
||||||
|
vpnSpin->setMaximum(100000);
|
||||||
|
vpnSpin->setValue(DEFAULT_VPN_THRESHOLD);
|
||||||
|
connect(vpnSpin, &QSpinBox::valueChanged, this, &TabAlts::onFilterChanged);
|
||||||
|
|
||||||
|
auto *filterBar = new QHBoxLayout;
|
||||||
|
filterBar->addWidget(emailChip);
|
||||||
|
filterBar->addWidget(clientIdChip);
|
||||||
|
filterBar->addWidget(ipChip);
|
||||||
|
filterBar->addWidget(vpnLabel);
|
||||||
|
filterBar->addWidget(vpnSpin);
|
||||||
|
filterBar->addStretch();
|
||||||
|
|
||||||
|
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
|
||||||
|
configureAltTable(altsTable);
|
||||||
|
altsDelegate = new AltTableDelegate(COL_ALTS_VIA, COL_ALTS_WARNS, COL_ALTS_BANS, COL_ALTS_SHARED, altsTable);
|
||||||
|
altsTable->setItemDelegateForColumn(COL_ALTS_VIA, altsDelegate);
|
||||||
|
altsTable->setItemDelegateForColumn(COL_ALTS_WARNS, altsDelegate);
|
||||||
|
altsTable->setItemDelegateForColumn(COL_ALTS_BANS, altsDelegate);
|
||||||
|
connectTableActivation(altsTable, this, [this](const QModelIndex &index) {
|
||||||
|
if (!index.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto *userItem = altsTable->item(index.row(), COL_ALTS_USER);
|
||||||
|
if (userItem != nullptr && !userItem->text().isEmpty() && userItem->text() != currentUser) {
|
||||||
|
investigate(userItem->text());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connect(altsTable, &QTableWidget::itemSelectionChanged, this, &TabAlts::onAltSelected);
|
||||||
|
|
||||||
|
detailNameValue = new QLabel;
|
||||||
|
detailCountsValue = new QLabel;
|
||||||
|
detailNotesEdit = new QTextEdit;
|
||||||
|
detailNotesEdit->setReadOnly(true);
|
||||||
|
// Compact cap so the warn/ban tables stay visible without scrolling the tab.
|
||||||
|
detailNotesEdit->setMaximumHeight(60);
|
||||||
|
warnsTable = new QTableWidget(0, COL_WARNS_COUNT);
|
||||||
|
configureAltTable(warnsTable);
|
||||||
|
bansTable = new QTableWidget(0, COL_BANS_COUNT);
|
||||||
|
configureAltTable(bansTable);
|
||||||
|
|
||||||
|
auto *detailGrid = new QGridLayout;
|
||||||
|
detailNameLabel = new QLabel;
|
||||||
|
detailCountsLabel = new QLabel;
|
||||||
|
detailNotesLabel = new QLabel;
|
||||||
|
detailGrid->addWidget(detailNameLabel, 0, 0);
|
||||||
|
detailGrid->addWidget(detailNameValue, 0, 1);
|
||||||
|
detailGrid->addWidget(detailCountsLabel, 0, 2);
|
||||||
|
detailGrid->addWidget(detailCountsValue, 0, 3);
|
||||||
|
detailGrid->addWidget(detailNotesLabel, 1, 0);
|
||||||
|
detailGrid->addWidget(detailNotesEdit, 1, 1, 1, 3);
|
||||||
|
|
||||||
|
detailsGroup = new QGroupBox;
|
||||||
|
auto *detailsLayout = new QVBoxLayout(detailsGroup);
|
||||||
|
detailsLayout->addLayout(detailGrid);
|
||||||
|
detailsLayout->addWidget(warnsTable, 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);
|
||||||
|
contentSplitter->addWidget(altsTable);
|
||||||
|
contentSplitter->addWidget(detailsGroup);
|
||||||
|
contentSplitter->setStretchFactor(0, 3);
|
||||||
|
contentSplitter->setStretchFactor(1, 2);
|
||||||
|
detailsGroup->setMinimumWidth(260);
|
||||||
|
|
||||||
|
auto *mainLayout = new QVBoxLayout(centralWidget);
|
||||||
|
mainLayout->addLayout(topBar);
|
||||||
|
mainLayout->addLayout(filterBar);
|
||||||
|
mainLayout->addWidget(statusLabel);
|
||||||
|
mainLayout->addWidget(trailLabel);
|
||||||
|
mainLayout->addWidget(contentSplitter, 1);
|
||||||
|
|
||||||
|
retranslateUi();
|
||||||
|
clearDetails();
|
||||||
|
investigate(initialUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::retranslateUi()
|
||||||
|
{
|
||||||
|
searchEdit->setPlaceholderText(tr("User name"));
|
||||||
|
depthSpin->setPrefix(tr("Depth: "));
|
||||||
|
depthSpin->setToolTip(tr("Search depth: 1 finds direct matches, higher values follow alts of alts."));
|
||||||
|
investigateButton->setText(tr("Investigate"));
|
||||||
|
backButton->setText(tr("Back"));
|
||||||
|
backButton->setToolTip(tr("Back to the previously investigated user"));
|
||||||
|
if (currentUser.isEmpty()) {
|
||||||
|
statusLabel->setText(tr("Enter a user name to investigate."));
|
||||||
|
}
|
||||||
|
|
||||||
|
emailChip->setText(tr("Email"));
|
||||||
|
emailChip->setToolTip(tr("Show or hide email matches"));
|
||||||
|
clientIdChip->setText(tr("Client ID"));
|
||||||
|
clientIdChip->setToolTip(tr("Show or hide client ID matches"));
|
||||||
|
ipChip->setText(tr("IP"));
|
||||||
|
ipChip->setToolTip(tr("Show or hide IP address matches"));
|
||||||
|
vpnLabel->setText(tr("Hide IPs shared by more than"));
|
||||||
|
vpnSpin->setSuffix(tr(" users"));
|
||||||
|
|
||||||
|
altsTable->setHorizontalHeaderLabels({tr("User"), tr("Via"), tr("Depth"), tr("Shared"), tr("eMail"),
|
||||||
|
tr("Client ID"), tr("Registered"), tr("Last login"), tr("Warns"), tr("Bans"),
|
||||||
|
tr("Active")});
|
||||||
|
altsTable->setToolTip(tr("Double-click or press Enter on a row to investigate that account"));
|
||||||
|
warnsTable->setHorizontalHeaderLabels({tr("Warning time"), tr("Moderator"), tr("Reason")});
|
||||||
|
bansTable->setHorizontalHeaderLabels({tr("Ban time"), tr("Moderator"), tr("Length"), tr("Reason")});
|
||||||
|
|
||||||
|
detailsGroup->setTitle(tr("Selected user"));
|
||||||
|
detailNameLabel->setText(tr("Name:"));
|
||||||
|
detailCountsLabel->setText(tr("Counts:"));
|
||||||
|
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()) {
|
||||||
|
renderTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TabAlts::formatEpoch(quint64 ts) const
|
||||||
|
{
|
||||||
|
if (ts == 0) {
|
||||||
|
return tr("Unknown");
|
||||||
|
}
|
||||||
|
return QDateTime::fromSecsSinceEpoch(ts).toLocalTime().toString("yyyy-MM-dd HH:mm");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::investigate(const QString &userName)
|
||||||
|
{
|
||||||
|
if (userName.isEmpty() || userName == currentUser) {
|
||||||
|
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()) {
|
||||||
|
backStack << currentUser;
|
||||||
|
backButton->setEnabled(true);
|
||||||
|
}
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
if (backStack.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QString previousUser = backStack.takeLast();
|
||||||
|
backButton->setEnabled(!backStack.isEmpty());
|
||||||
|
loadUser(previousUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::loadUser(const QString &userName)
|
||||||
|
{
|
||||||
|
currentUser = userName;
|
||||||
|
searchEdit->setText(userName);
|
||||||
|
updateTrail();
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
const QString userName = searchEdit->text().simplified();
|
||||||
|
if (userName.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (userName != currentUser && !currentUser.isEmpty()) {
|
||||||
|
backStack << currentUser;
|
||||||
|
backButton->setEnabled(true);
|
||||||
|
}
|
||||||
|
currentUser = userName;
|
||||||
|
updateTrail();
|
||||||
|
lastAlts.clear();
|
||||||
|
selectedUser.clear();
|
||||||
|
clearDetails();
|
||||||
|
altsTable->setRowCount(0);
|
||||||
|
statusLabel->setText(tr("Loading alts for %1...").arg(currentUser));
|
||||||
|
requestAlts(userName, depthSpin->value());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::requestAlts(const QString &userName, int depth)
|
||||||
|
{
|
||||||
|
Command_GetUserAlts cmd;
|
||||||
|
cmd.set_user_name(userName.toStdString());
|
||||||
|
cmd.set_depth(static_cast<google::protobuf::uint32>(depth));
|
||||||
|
PendingCommand *pend = client->prepareModeratorCommand(cmd);
|
||||||
|
connect(pend, &PendingCommand::finished, this, [this, userName](const Response &response) {
|
||||||
|
if (userName == currentUser) {
|
||||||
|
altsResponse(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
client->sendCommand(pend);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::altsResponse(const Response &response)
|
||||||
|
{
|
||||||
|
lastAlts.clear();
|
||||||
|
if (response.response_code() != Response::RespOk) {
|
||||||
|
renderTable();
|
||||||
|
statusLabel->setText(tr("User %1 not found.").arg(currentUser));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Response_UserAlts &resp = response.GetExtension(Response_UserAlts::ext);
|
||||||
|
for (int i = 0; i < resp.alts_size(); ++i) {
|
||||||
|
lastAlts << resp.alts(i);
|
||||||
|
}
|
||||||
|
renderTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TabAlts::rowVisible(const ServerInfo_UserAlt &alt) const
|
||||||
|
{
|
||||||
|
const QString name = QString::fromStdString(alt.user_name());
|
||||||
|
if (name == currentUser) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!alt.has_match_reason() || alt.match_reason().empty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const QString reason = QString::fromStdString(alt.match_reason());
|
||||||
|
if (reason == QStringLiteral("email")) {
|
||||||
|
return emailChip->isChecked();
|
||||||
|
}
|
||||||
|
if (reason.startsWith(QStringLiteral("clientid:"))) {
|
||||||
|
return clientIdChip->isChecked();
|
||||||
|
}
|
||||||
|
if (reason.startsWith(QStringLiteral("ip:"))) {
|
||||||
|
return ipChip->isChecked() &&
|
||||||
|
(!alt.has_shared_count() || alt.shared_count() <= static_cast<unsigned>(vpnSpin->value()));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::renderTable()
|
||||||
|
{
|
||||||
|
// Blocked so the programmatic refill neither wipes the details panel
|
||||||
|
// (via the selection-cleared path) nor refetches them on restore.
|
||||||
|
const QSignalBlocker blocker(altsTable);
|
||||||
|
altsTable->setRowCount(0);
|
||||||
|
|
||||||
|
int emailCount = 0;
|
||||||
|
int clientIdCount = 0;
|
||||||
|
int ipCount = 0;
|
||||||
|
for (const ServerInfo_UserAlt &alt : lastAlts) {
|
||||||
|
const QString reason = QString::fromStdString(alt.match_reason());
|
||||||
|
if (reason == QStringLiteral("email")) {
|
||||||
|
++emailCount;
|
||||||
|
} else if (reason.startsWith(QStringLiteral("clientid:"))) {
|
||||||
|
++clientIdCount;
|
||||||
|
} else if (reason.startsWith(QStringLiteral("ip:"))) {
|
||||||
|
++ipCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emailChip->setText(tr("Email (%1)").arg(emailCount));
|
||||||
|
clientIdChip->setText(tr("Client ID (%1)").arg(clientIdCount));
|
||||||
|
ipChip->setText(tr("IP (%1)").arg(ipCount));
|
||||||
|
|
||||||
|
QFont userFont = altsTable->font();
|
||||||
|
userFont.setBold(true);
|
||||||
|
const QColor dimColor = palette().color(QPalette::Disabled, QPalette::Text);
|
||||||
|
|
||||||
|
int hidden = 0;
|
||||||
|
int row = 0;
|
||||||
|
for (const ServerInfo_UserAlt &alt : lastAlts) {
|
||||||
|
if (!rowVisible(alt)) {
|
||||||
|
++hidden;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
altsTable->insertRow(row);
|
||||||
|
auto *userItem = new QTableWidgetItem(QString::fromStdString(alt.user_name()));
|
||||||
|
userItem->setFont(userFont);
|
||||||
|
altsTable->setItem(row, COL_ALTS_USER, userItem);
|
||||||
|
altsTable->setItem(row, COL_ALTS_VIA,
|
||||||
|
new QTableWidgetItem(alt.has_match_reason() && !alt.match_reason().empty()
|
||||||
|
? QString::fromStdString(alt.match_reason())
|
||||||
|
: QStringLiteral("-")));
|
||||||
|
altsTable->setItem(row, COL_ALTS_DEPTH,
|
||||||
|
new QTableWidgetItem(alt.has_depth() ? QString::number(alt.depth()) : QStringLiteral("-")));
|
||||||
|
altsTable->setItem(
|
||||||
|
row, COL_ALTS_SHARED,
|
||||||
|
new QTableWidgetItem(alt.has_shared_count() ? QString::number(alt.shared_count()) : QStringLiteral("-")));
|
||||||
|
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_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_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_ACTIVE, new QTableWidgetItem(alt.is_active() ? tr("yes") : tr("no")));
|
||||||
|
// 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() &&
|
||||||
|
alt.shared_count() > 2) {
|
||||||
|
for (int col = 0; col < COL_ALTS_COUNT; ++col) {
|
||||||
|
if (col == COL_ALTS_VIA) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (auto *item = altsTable->item(row, col)) {
|
||||||
|
item->setForeground(dimColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++row;
|
||||||
|
}
|
||||||
|
if (hidden == 0) {
|
||||||
|
statusLabel->setText(tr("%1 account(s) related to %2.").arg(lastAlts.size()).arg(currentUser));
|
||||||
|
} else {
|
||||||
|
statusLabel->setText(tr("%1 shown, %2 hidden by filters (%3 total) related to %4.")
|
||||||
|
.arg(row)
|
||||||
|
.arg(hidden)
|
||||||
|
.arg(lastAlts.size())
|
||||||
|
.arg(currentUser));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!selectedUser.isEmpty()) {
|
||||||
|
bool restored = false;
|
||||||
|
for (int restoreRow = 0; restoreRow < altsTable->rowCount(); ++restoreRow) {
|
||||||
|
auto *userItem = altsTable->item(restoreRow, COL_ALTS_USER);
|
||||||
|
if (userItem != nullptr && userItem->text() == selectedUser) {
|
||||||
|
altsTable->setCurrentItem(userItem, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||||
|
restored = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!restored) {
|
||||||
|
selectedUser.clear();
|
||||||
|
clearDetails();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::onFilterChanged()
|
||||||
|
{
|
||||||
|
if (lastAlts.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
renderTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::investigateSelected()
|
||||||
|
{
|
||||||
|
if (!selectedUser.isEmpty() && selectedUser != currentUser) {
|
||||||
|
investigate(selectedUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::onAltSelected()
|
||||||
|
{
|
||||||
|
const auto selected = altsTable->selectedItems();
|
||||||
|
if (selected.isEmpty()) {
|
||||||
|
selectedUser.clear();
|
||||||
|
clearDetails();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto *userItem = altsTable->item(selected.first()->row(), COL_ALTS_USER);
|
||||||
|
if (userItem == nullptr || userItem->text().isEmpty() || userItem->text() == selectedUser) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectedUser = userItem->text();
|
||||||
|
requestDetails(selectedUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::requestDetails(const QString &userName)
|
||||||
|
{
|
||||||
|
detailNameValue->setText(userName);
|
||||||
|
detailCountsValue->setText(tr("Loading..."));
|
||||||
|
detailNotesEdit->clear();
|
||||||
|
warnsTable->setRowCount(0);
|
||||||
|
bansTable->setRowCount(0);
|
||||||
|
investigateSelectedButton->setEnabled(userName != currentUser);
|
||||||
|
|
||||||
|
Command_ReportUserInfo infoCmd;
|
||||||
|
infoCmd.set_user_name(userName.toStdString());
|
||||||
|
PendingCommand *infoPend = client->prepareModeratorCommand(infoCmd);
|
||||||
|
connect(infoPend, &PendingCommand::finished, this, [this, userName](const Response &response) {
|
||||||
|
if (userName == selectedUser) {
|
||||||
|
userDetailsResponse(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
client->sendCommand(infoPend);
|
||||||
|
|
||||||
|
Command_GetWarnHistory warnCmd;
|
||||||
|
warnCmd.set_user_name(userName.toStdString());
|
||||||
|
PendingCommand *warnPend = client->prepareModeratorCommand(warnCmd);
|
||||||
|
connect(warnPend, &PendingCommand::finished, this, [this, userName](const Response &response) {
|
||||||
|
if (userName == selectedUser) {
|
||||||
|
warnHistoryResponse(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
client->sendCommand(warnPend);
|
||||||
|
|
||||||
|
Command_GetBanHistory banCmd;
|
||||||
|
banCmd.set_user_name(userName.toStdString());
|
||||||
|
PendingCommand *banPend = client->prepareModeratorCommand(banCmd);
|
||||||
|
connect(banPend, &PendingCommand::finished, this, [this, userName](const Response &response) {
|
||||||
|
if (userName == selectedUser) {
|
||||||
|
banHistoryResponse(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
client->sendCommand(banPend);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::clearDetails()
|
||||||
|
{
|
||||||
|
detailNameValue->clear();
|
||||||
|
detailCountsValue->setText(tr("Select a row to inspect its history."));
|
||||||
|
detailNotesEdit->clear();
|
||||||
|
warnsTable->setRowCount(0);
|
||||||
|
bansTable->setRowCount(0);
|
||||||
|
investigateSelectedButton->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::userDetailsResponse(const Response &response)
|
||||||
|
{
|
||||||
|
if (response.response_code() != Response::RespOk) {
|
||||||
|
detailCountsValue->setText(tr("Error loading user info."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Response_ReportUserInfo &resp = response.GetExtension(Response_ReportUserInfo::ext);
|
||||||
|
detailCountsValue->setText(tr("Reports: %1 Bans: %2 Warnings: %3")
|
||||||
|
.arg(resp.total_reports())
|
||||||
|
.arg(resp.total_bans())
|
||||||
|
.arg(resp.total_warns()));
|
||||||
|
|
||||||
|
if (resp.has_admin_notes() && !resp.admin_notes().empty()) {
|
||||||
|
detailNotesEdit->setPlainText(QString::fromStdString(resp.admin_notes()));
|
||||||
|
} else {
|
||||||
|
detailNotesEdit->setPlainText(tr("(none)"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::warnHistoryResponse(const Response &response)
|
||||||
|
{
|
||||||
|
warnsTable->setRowCount(0);
|
||||||
|
if (response.response_code() != Response::RespOk) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Response_WarnHistory &resp = response.GetExtension(Response_WarnHistory::ext);
|
||||||
|
warnsTable->setRowCount(resp.warn_list_size());
|
||||||
|
for (int i = 0; i < resp.warn_list_size(); ++i) {
|
||||||
|
const ServerInfo_Warning &warn = resp.warn_list(i);
|
||||||
|
warnsTable->setItem(i, COL_WARNS_TIME, new QTableWidgetItem(QString::fromStdString(warn.time_of())));
|
||||||
|
warnsTable->setItem(i, COL_WARNS_MODERATOR, new QTableWidgetItem(QString::fromStdString(warn.admin_name())));
|
||||||
|
warnsTable->setItem(i, COL_WARNS_REASON, new QTableWidgetItem(QString::fromStdString(warn.reason())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabAlts::banHistoryResponse(const Response &response)
|
||||||
|
{
|
||||||
|
bansTable->setRowCount(0);
|
||||||
|
if (response.response_code() != Response::RespOk) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Response_BanHistory &resp = response.GetExtension(Response_BanHistory::ext);
|
||||||
|
bansTable->setRowCount(resp.ban_list_size());
|
||||||
|
for (int i = 0; i < resp.ban_list_size(); ++i) {
|
||||||
|
const ServerInfo_Ban &ban = resp.ban_list(i);
|
||||||
|
bansTable->setItem(i, COL_BANS_TIME, new QTableWidgetItem(QString::fromStdString(ban.ban_time())));
|
||||||
|
bansTable->setItem(i, COL_BANS_MODERATOR, new QTableWidgetItem(QString::fromStdString(ban.admin_name())));
|
||||||
|
bansTable->setItem(i, COL_BANS_LENGTH, new QTableWidgetItem(QString::fromStdString(ban.ban_length())));
|
||||||
|
bansTable->setItem(i, COL_BANS_REASON, new QTableWidgetItem(QString::fromStdString(ban.ban_reason())));
|
||||||
|
}
|
||||||
|
}
|
||||||
98
cockatrice/src/interface/widgets/tabs/tab_alts.h
Normal file
98
cockatrice/src/interface/widgets/tabs/tab_alts.h
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
#ifndef TAB_ALTS_H
|
||||||
|
#define TAB_ALTS_H
|
||||||
|
|
||||||
|
#include "tab.h"
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
#include <QString>
|
||||||
|
#include <QtGlobal>
|
||||||
|
#include <libcockatrice/protocol/pb/serverinfo_user_alt.pb.h>
|
||||||
|
#include <qtmetamacros.h>
|
||||||
|
|
||||||
|
class AbstractClient;
|
||||||
|
class AltTableDelegate;
|
||||||
|
class QGroupBox;
|
||||||
|
class QLabel;
|
||||||
|
class QLineEdit;
|
||||||
|
class QPushButton;
|
||||||
|
class QSpinBox;
|
||||||
|
class QTableWidget;
|
||||||
|
class QTextEdit;
|
||||||
|
class Response;
|
||||||
|
class TabSupervisor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Staff alt-graph investigation tool. Shows accounts related to the
|
||||||
|
* investigated user (shared email, client id, or recent IP address),
|
||||||
|
* including transitive alts-of-alts, with per-row match evidence.
|
||||||
|
* Selecting a row loads that account's warnings, bans, and admin notes.
|
||||||
|
*/
|
||||||
|
class TabAlts : public Tab
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &initialUser = {});
|
||||||
|
void retranslateUi() override;
|
||||||
|
[[nodiscard]] QString getTabText() const override
|
||||||
|
{
|
||||||
|
return tr("User Alts");
|
||||||
|
}
|
||||||
|
void investigate(const QString &userName);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void investigateUser();
|
||||||
|
void goBack();
|
||||||
|
void investigateSelected();
|
||||||
|
void altsResponse(const Response &response);
|
||||||
|
void onFilterChanged();
|
||||||
|
void onAltSelected();
|
||||||
|
void userDetailsResponse(const Response &response);
|
||||||
|
void warnHistoryResponse(const Response &response);
|
||||||
|
void banHistoryResponse(const Response &response);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void loadUser(const QString &userName);
|
||||||
|
void goToTrailEntry(const QString &userName);
|
||||||
|
void updateTrail();
|
||||||
|
void requestAlts(const QString &userName, int depth);
|
||||||
|
void requestDetails(const QString &userName);
|
||||||
|
void clearDetails();
|
||||||
|
void renderTable();
|
||||||
|
[[nodiscard]] bool rowVisible(const ServerInfo_UserAlt &alt) const;
|
||||||
|
[[nodiscard]] QString formatEpoch(quint64 ts) const;
|
||||||
|
|
||||||
|
AbstractClient *client;
|
||||||
|
QString currentUser;
|
||||||
|
QString selectedUser;
|
||||||
|
QList<QString> backStack;
|
||||||
|
QList<ServerInfo_UserAlt> lastAlts;
|
||||||
|
|
||||||
|
QLineEdit *searchEdit;
|
||||||
|
QSpinBox *depthSpin;
|
||||||
|
QPushButton *investigateButton;
|
||||||
|
QPushButton *backButton;
|
||||||
|
QPushButton *investigateSelectedButton;
|
||||||
|
QLabel *trailLabel;
|
||||||
|
QLabel *statusLabel;
|
||||||
|
QTableWidget *altsTable;
|
||||||
|
AltTableDelegate *altsDelegate;
|
||||||
|
|
||||||
|
QPushButton *emailChip;
|
||||||
|
QPushButton *clientIdChip;
|
||||||
|
QPushButton *ipChip;
|
||||||
|
QLabel *vpnLabel;
|
||||||
|
QSpinBox *vpnSpin;
|
||||||
|
|
||||||
|
QLabel *detailNameValue;
|
||||||
|
QLabel *detailCountsValue;
|
||||||
|
QTextEdit *detailNotesEdit;
|
||||||
|
QTableWidget *warnsTable;
|
||||||
|
QTableWidget *bansTable;
|
||||||
|
|
||||||
|
QGroupBox *detailsGroup;
|
||||||
|
QLabel *detailNameLabel;
|
||||||
|
QLabel *detailCountsLabel;
|
||||||
|
QLabel *detailNotesLabel;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TAB_ALTS_H
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
#include "tab_moderation.h"
|
#include "tab_moderation.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"
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_moderator_login.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_moderator_login.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_user_alt.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_user_alt.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_user_session.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_user_session.pb.h"
|
||||||
|
#include "tab_supervisor.h"
|
||||||
|
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
@ -21,6 +23,7 @@
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QTabWidget>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QTableWidgetItem>
|
#include <QTableWidgetItem>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
|
@ -93,38 +96,67 @@ TabModeration::TabModeration(TabSupervisor *_tabSupervisor, AbstractClient *_cli
|
||||||
topBar->addWidget(removeAvatarButton);
|
topBar->addWidget(removeAvatarButton);
|
||||||
|
|
||||||
userInfoGroup = new QGroupBox;
|
userInfoGroup = new QGroupBox;
|
||||||
userInfoNameLabel = new QLabel;
|
|
||||||
userInfoNameValue = new QLabel;
|
userInfoNameValue = new QLabel;
|
||||||
userInfoRegisteredLabel = new QLabel;
|
QFont displayFont = userInfoNameValue->font();
|
||||||
userInfoRegisteredValue = new QLabel;
|
displayFont.setPointSize(displayFont.pointSize() + 6);
|
||||||
userInfoLastLoginLabel = new QLabel;
|
displayFont.setBold(true);
|
||||||
userInfoLastLoginValue = new QLabel;
|
userInfoNameValue->setFont(displayFont);
|
||||||
userInfoStatusLabel = new QLabel;
|
|
||||||
userInfoStatusValue = new QLabel;
|
userInfoStatusValue = new QLabel;
|
||||||
userInfoCountsLabel = new QLabel;
|
QFont statusFont = userInfoStatusValue->font();
|
||||||
userInfoCountsValue = new QLabel;
|
statusFont.setBold(true);
|
||||||
|
userInfoStatusValue->setFont(statusFont);
|
||||||
|
sublineLabel = new QLabel;
|
||||||
|
|
||||||
|
auto makeCountCard = [](const QString &title, QLabel *&value) {
|
||||||
|
auto *card = new QGroupBox(title);
|
||||||
|
value = new QLabel(QStringLiteral("–"), card);
|
||||||
|
QFont cardFont = value->font();
|
||||||
|
cardFont.setPointSize(cardFont.pointSize() + 6);
|
||||||
|
cardFont.setBold(true);
|
||||||
|
value->setFont(cardFont);
|
||||||
|
value->setAlignment(Qt::AlignCenter);
|
||||||
|
auto *cardLayout = new QVBoxLayout(card);
|
||||||
|
cardLayout->addWidget(value);
|
||||||
|
return card;
|
||||||
|
};
|
||||||
|
cardReports = makeCountCard(QString(), cardReportsValue);
|
||||||
|
cardWarns = makeCountCard(QString(), cardWarnsValue);
|
||||||
|
cardBans = makeCountCard(QString(), cardBansValue);
|
||||||
|
|
||||||
|
altsCard = new QGroupBox;
|
||||||
|
altsCountValue = new QLabel(QStringLiteral("–"), altsCard);
|
||||||
|
QFont altsFont = altsCountValue->font();
|
||||||
|
altsFont.setPointSize(altsFont.pointSize() + 6);
|
||||||
|
altsFont.setBold(true);
|
||||||
|
altsCountValue->setFont(altsFont);
|
||||||
|
altsCountValue->setAlignment(Qt::AlignCenter);
|
||||||
|
openAltsButton = new QPushButton;
|
||||||
|
connect(openAltsButton, &QPushButton::clicked, this, &TabModeration::openAltsGraph);
|
||||||
|
auto *altsCardLayout = new QVBoxLayout(altsCard);
|
||||||
|
altsCardLayout->addWidget(altsCountValue);
|
||||||
|
altsCardLayout->addWidget(openAltsButton);
|
||||||
|
|
||||||
|
auto *cardsRow = new QHBoxLayout;
|
||||||
|
cardsRow->addWidget(cardReports);
|
||||||
|
cardsRow->addWidget(cardWarns);
|
||||||
|
cardsRow->addWidget(cardBans);
|
||||||
|
cardsRow->addWidget(altsCard);
|
||||||
|
|
||||||
userInfoNotesLabel = new QLabel;
|
userInfoNotesLabel = new QLabel;
|
||||||
userInfoNotesEdit = new QTextEdit;
|
userInfoNotesEdit = new QTextEdit;
|
||||||
userInfoNotesEdit->setReadOnly(true);
|
userInfoNotesEdit->setReadOnly(true);
|
||||||
|
|
||||||
auto *infoGrid = new QGridLayout;
|
auto *identityRow = new QHBoxLayout;
|
||||||
infoGrid->addWidget(userInfoNameLabel, 0, 0);
|
identityRow->addWidget(userInfoNameValue);
|
||||||
infoGrid->addWidget(userInfoNameValue, 0, 1);
|
identityRow->addStretch();
|
||||||
infoGrid->addWidget(userInfoRegisteredLabel, 0, 2);
|
identityRow->addWidget(userInfoStatusValue);
|
||||||
infoGrid->addWidget(userInfoRegisteredValue, 0, 3);
|
|
||||||
infoGrid->addWidget(userInfoLastLoginLabel, 1, 0);
|
|
||||||
infoGrid->addWidget(userInfoLastLoginValue, 1, 1);
|
|
||||||
infoGrid->addWidget(userInfoStatusLabel, 1, 2);
|
|
||||||
infoGrid->addWidget(userInfoStatusValue, 1, 3);
|
|
||||||
infoGrid->addWidget(userInfoCountsLabel, 2, 0);
|
|
||||||
infoGrid->addWidget(userInfoCountsValue, 2, 1, 1, 3);
|
|
||||||
infoGrid->addWidget(userInfoNotesLabel, 3, 0, Qt::AlignTop);
|
|
||||||
infoGrid->addWidget(userInfoNotesEdit, 3, 1, 1, 3);
|
|
||||||
infoGrid->setColumnStretch(1, 1);
|
|
||||||
infoGrid->setColumnStretch(3, 1);
|
|
||||||
|
|
||||||
auto *infoLayout = new QVBoxLayout(userInfoGroup);
|
auto *infoLayout = new QVBoxLayout(userInfoGroup);
|
||||||
infoLayout->addLayout(infoGrid);
|
infoLayout->addLayout(identityRow);
|
||||||
|
infoLayout->addWidget(sublineLabel);
|
||||||
|
infoLayout->addLayout(cardsRow);
|
||||||
|
infoLayout->addWidget(userInfoNotesLabel);
|
||||||
|
infoLayout->addWidget(userInfoNotesEdit);
|
||||||
|
|
||||||
auto configureTable = [](QTableWidget *table) {
|
auto configureTable = [](QTableWidget *table) {
|
||||||
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
|
@ -136,19 +168,27 @@ TabModeration::TabModeration(TabSupervisor *_tabSupervisor, AbstractClient *_cli
|
||||||
table->horizontalHeader()->setStretchLastSection(true);
|
table->horizontalHeader()->setStretchLastSection(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
altsGroup = new QGroupBox;
|
|
||||||
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
|
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
|
||||||
configureTable(altsTable);
|
configureTable(altsTable);
|
||||||
auto *altsLayout = new QVBoxLayout(altsGroup);
|
connectTableActivation(altsTable, this, [this](const QModelIndex &index) {
|
||||||
|
if (!index.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto *userItem = altsTable->item(index.row(), COL_ALTS_USER);
|
||||||
|
if (userItem != nullptr && !userItem->text().isEmpty()) {
|
||||||
|
getTabSupervisor()->openTabAlts(userItem->text());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
auto *altsPage = new QWidget;
|
||||||
|
auto *altsLayout = new QVBoxLayout(altsPage);
|
||||||
altsLayout->addWidget(altsTable);
|
altsLayout->addWidget(altsTable);
|
||||||
|
|
||||||
sessionsGroup = new QGroupBox;
|
|
||||||
sessionsTable = new QTableWidget(0, COL_SESSIONS_COUNT);
|
sessionsTable = new QTableWidget(0, COL_SESSIONS_COUNT);
|
||||||
configureTable(sessionsTable);
|
configureTable(sessionsTable);
|
||||||
auto *sessionsLayout = new QVBoxLayout(sessionsGroup);
|
auto *sessionsPage = new QWidget;
|
||||||
|
auto *sessionsLayout = new QVBoxLayout(sessionsPage);
|
||||||
sessionsLayout->addWidget(sessionsTable);
|
sessionsLayout->addWidget(sessionsTable);
|
||||||
|
|
||||||
staffGroup = new QGroupBox;
|
|
||||||
staffTable = new QTableWidget(0, COL_STAFF_COUNT);
|
staffTable = new QTableWidget(0, COL_STAFF_COUNT);
|
||||||
configureTable(staffTable);
|
configureTable(staffTable);
|
||||||
refreshStaffButton = new QPushButton;
|
refreshStaffButton = new QPushButton;
|
||||||
|
|
@ -156,19 +196,21 @@ TabModeration::TabModeration(TabSupervisor *_tabSupervisor, AbstractClient *_cli
|
||||||
auto *staffHeader = new QHBoxLayout;
|
auto *staffHeader = new QHBoxLayout;
|
||||||
staffHeader->addStretch();
|
staffHeader->addStretch();
|
||||||
staffHeader->addWidget(refreshStaffButton);
|
staffHeader->addWidget(refreshStaffButton);
|
||||||
auto *staffLayout = new QVBoxLayout(staffGroup);
|
auto *staffPage = new QWidget;
|
||||||
|
auto *staffLayout = new QVBoxLayout(staffPage);
|
||||||
staffLayout->addWidget(staffTable);
|
staffLayout->addWidget(staffTable);
|
||||||
staffLayout->addLayout(staffHeader);
|
staffLayout->addLayout(staffHeader);
|
||||||
|
|
||||||
|
sectionTabs = new QTabWidget;
|
||||||
|
sectionTabs->addTab(altsPage, QString());
|
||||||
|
sectionTabs->addTab(sessionsPage, QString());
|
||||||
|
sectionTabs->addTab(staffPage, QString());
|
||||||
|
|
||||||
auto *splitter = new QSplitter(Qt::Vertical);
|
auto *splitter = new QSplitter(Qt::Vertical);
|
||||||
splitter->addWidget(userInfoGroup);
|
splitter->addWidget(userInfoGroup);
|
||||||
splitter->addWidget(altsGroup);
|
splitter->addWidget(sectionTabs);
|
||||||
splitter->addWidget(sessionsGroup);
|
|
||||||
splitter->addWidget(staffGroup);
|
|
||||||
splitter->setStretchFactor(0, 1);
|
splitter->setStretchFactor(0, 1);
|
||||||
splitter->setStretchFactor(1, 2);
|
splitter->setStretchFactor(1, 2);
|
||||||
splitter->setStretchFactor(2, 2);
|
|
||||||
splitter->setStretchFactor(3, 1);
|
|
||||||
|
|
||||||
auto *mainLayout = new QVBoxLayout(centralWidget);
|
auto *mainLayout = new QVBoxLayout(centralWidget);
|
||||||
mainLayout->addLayout(topBar);
|
mainLayout->addLayout(topBar);
|
||||||
|
|
@ -189,19 +231,28 @@ void TabModeration::retranslateUi()
|
||||||
refreshStaffButton->setText(tr("Refresh"));
|
refreshStaffButton->setText(tr("Refresh"));
|
||||||
|
|
||||||
userInfoGroup->setTitle(tr("User Info"));
|
userInfoGroup->setTitle(tr("User Info"));
|
||||||
userInfoNameLabel->setText(tr("Name:"));
|
|
||||||
userInfoRegisteredLabel->setText(tr("Registered:"));
|
|
||||||
userInfoLastLoginLabel->setText(tr("Last login:"));
|
|
||||||
userInfoStatusLabel->setText(tr("Status:"));
|
|
||||||
userInfoCountsLabel->setText(tr("Counts:"));
|
|
||||||
userInfoNotesLabel->setText(tr("Admin notes:"));
|
userInfoNotesLabel->setText(tr("Admin notes:"));
|
||||||
|
cardReports->setTitle(tr("Reports"));
|
||||||
|
cardWarns->setTitle(tr("Warnings"));
|
||||||
|
cardBans->setTitle(tr("Bans"));
|
||||||
|
altsCard->setTitle(tr("Alts"));
|
||||||
|
openAltsButton->setText(tr("Open graph"));
|
||||||
|
openAltsButton->setToolTip(tr("Open this user in the User Alts tab"));
|
||||||
|
|
||||||
altsGroup->setTitle(tr("Alts"));
|
sectionTabs->setTabText(0, tr("Alts"));
|
||||||
sessionsGroup->setTitle(tr("Sessions"));
|
sectionTabs->setTabText(1, tr("Sessions"));
|
||||||
staffGroup->setTitle(tr("Staff Last Logins"));
|
sectionTabs->setTabText(2, tr("Staff Last Logins"));
|
||||||
|
|
||||||
|
if (cachedUserInfoValid) {
|
||||||
|
applyUserInfo();
|
||||||
|
}
|
||||||
|
if (cachedAltsCount >= 0) {
|
||||||
|
applyAltsCount();
|
||||||
|
}
|
||||||
|
|
||||||
altsTable->setHorizontalHeaderLabels({tr("User"), tr("eMail"), tr("Client ID"), tr("Registered"), tr("Last login"),
|
altsTable->setHorizontalHeaderLabels({tr("User"), tr("eMail"), tr("Client ID"), tr("Registered"), tr("Last login"),
|
||||||
tr("Warns"), tr("Bans"), tr("Active")});
|
tr("Warns"), tr("Bans"), tr("Active")});
|
||||||
|
altsTable->setToolTip(tr("Double-click or press Enter on a row to open it in the User Alts tab"));
|
||||||
sessionsTable->setHorizontalHeaderLabels({tr("IP"), tr("Client ID"), tr("Start"), tr("End"), tr("Type")});
|
sessionsTable->setHorizontalHeaderLabels({tr("IP"), tr("Client ID"), tr("Start"), tr("End"), tr("Type")});
|
||||||
staffTable->setHorizontalHeaderLabels({tr("User"), tr("Level"), tr("Last login")});
|
staffTable->setHorizontalHeaderLabels({tr("User"), tr("Level"), tr("Last login")});
|
||||||
}
|
}
|
||||||
|
|
@ -217,16 +268,21 @@ QString TabModeration::formatEpoch(quint64 ts) const
|
||||||
void TabModeration::clearUserData()
|
void TabModeration::clearUserData()
|
||||||
{
|
{
|
||||||
currentUser.clear();
|
currentUser.clear();
|
||||||
|
cachedUserInfoValid = false;
|
||||||
|
cachedAltsCount = -1;
|
||||||
userInfoNameValue->clear();
|
userInfoNameValue->clear();
|
||||||
userInfoRegisteredValue->clear();
|
|
||||||
userInfoLastLoginValue->clear();
|
|
||||||
userInfoStatusValue->clear();
|
userInfoStatusValue->clear();
|
||||||
userInfoCountsValue->clear();
|
sublineLabel->clear();
|
||||||
|
cardReportsValue->setText(QStringLiteral("–"));
|
||||||
|
cardWarnsValue->setText(QStringLiteral("–"));
|
||||||
|
cardBansValue->setText(QStringLiteral("–"));
|
||||||
|
altsCountValue->setText(QStringLiteral("–"));
|
||||||
userInfoNotesEdit->clear();
|
userInfoNotesEdit->clear();
|
||||||
altsTable->setRowCount(0);
|
altsTable->setRowCount(0);
|
||||||
sessionsTable->setRowCount(0);
|
sessionsTable->setRowCount(0);
|
||||||
resetPasswordButton->setEnabled(false);
|
resetPasswordButton->setEnabled(false);
|
||||||
removeAvatarButton->setEnabled(false);
|
removeAvatarButton->setEnabled(false);
|
||||||
|
openAltsButton->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabModeration::investigate(const QString &userName)
|
void TabModeration::investigate(const QString &userName)
|
||||||
|
|
@ -245,8 +301,12 @@ void TabModeration::investigateUser()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currentUser = userName;
|
currentUser = userName;
|
||||||
|
cachedUserInfoValid = false;
|
||||||
|
cachedAltsCount = -1;
|
||||||
resetPasswordButton->setEnabled(true);
|
resetPasswordButton->setEnabled(true);
|
||||||
removeAvatarButton->setEnabled(true);
|
removeAvatarButton->setEnabled(true);
|
||||||
|
openAltsButton->setEnabled(true);
|
||||||
|
altsCountValue->setText(QStringLiteral("…"));
|
||||||
altsTable->setRowCount(0);
|
altsTable->setRowCount(0);
|
||||||
sessionsTable->setRowCount(0);
|
sessionsTable->setRowCount(0);
|
||||||
requestUserInfo(userName);
|
requestUserInfo(userName);
|
||||||
|
|
@ -254,13 +314,22 @@ void TabModeration::investigateUser()
|
||||||
requestAlts(userName);
|
requestAlts(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabModeration::openAltsGraph()
|
||||||
|
{
|
||||||
|
if (currentUser.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
getTabSupervisor()->openTabAlts(currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
void TabModeration::requestUserInfo(const QString &userName)
|
void TabModeration::requestUserInfo(const QString &userName)
|
||||||
{
|
{
|
||||||
userInfoNameValue->setText(userName);
|
userInfoNameValue->setText(userName);
|
||||||
userInfoRegisteredValue->setText(tr("Loading..."));
|
sublineLabel->setText(tr("Loading..."));
|
||||||
userInfoLastLoginValue->setText(tr("Loading..."));
|
|
||||||
userInfoStatusValue->clear();
|
userInfoStatusValue->clear();
|
||||||
userInfoCountsValue->clear();
|
cardReportsValue->setText(QStringLiteral("…"));
|
||||||
|
cardWarnsValue->setText(QStringLiteral("…"));
|
||||||
|
cardBansValue->setText(QStringLiteral("…"));
|
||||||
userInfoNotesEdit->clear();
|
userInfoNotesEdit->clear();
|
||||||
|
|
||||||
Command_ReportUserInfo cmd;
|
Command_ReportUserInfo cmd;
|
||||||
|
|
@ -273,9 +342,12 @@ void TabModeration::requestUserInfo(const QString &userName)
|
||||||
void TabModeration::userInfoResponse(const Response &response)
|
void TabModeration::userInfoResponse(const Response &response)
|
||||||
{
|
{
|
||||||
if (response.response_code() != Response::RespOk) {
|
if (response.response_code() != Response::RespOk) {
|
||||||
userInfoRegisteredValue->clear();
|
cachedUserInfoValid = false;
|
||||||
userInfoLastLoginValue->clear();
|
sublineLabel->clear();
|
||||||
userInfoStatusValue->setText(tr("Error loading user info."));
|
userInfoStatusValue->setText(tr("Error loading user info."));
|
||||||
|
cardReportsValue->setText(QStringLiteral("–"));
|
||||||
|
cardWarnsValue->setText(QStringLiteral("–"));
|
||||||
|
cardBansValue->setText(QStringLiteral("–"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -284,20 +356,28 @@ void TabModeration::userInfoResponse(const Response &response)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
userInfoRegisteredValue->setText(formatEpoch(resp.registration_time()));
|
cachedUserInfo.CopyFrom(resp);
|
||||||
userInfoLastLoginValue->setText(formatEpoch(resp.last_login()));
|
cachedUserInfoValid = true;
|
||||||
|
applyUserInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabModeration::applyUserInfo()
|
||||||
|
{
|
||||||
|
const Response_ReportUserInfo &resp = cachedUserInfo;
|
||||||
|
sublineLabel->setText(tr("Registered %1 · Last login %2")
|
||||||
|
.arg(formatEpoch(resp.registration_time()))
|
||||||
|
.arg(formatEpoch(resp.last_login())));
|
||||||
|
|
||||||
QStringList statusParts;
|
QStringList statusParts;
|
||||||
statusParts << (resp.is_active() ? tr("active") : tr("inactive"));
|
statusParts << (resp.is_active() ? tr("active") : tr("inactive"));
|
||||||
if (resp.has_is_admin() && resp.is_admin()) {
|
if (resp.has_is_admin() && resp.is_admin()) {
|
||||||
statusParts << tr("admin");
|
statusParts << tr("admin");
|
||||||
}
|
}
|
||||||
userInfoStatusValue->setText(statusParts.join(", "));
|
userInfoStatusValue->setText(statusParts.join(QStringLiteral(", ")));
|
||||||
|
|
||||||
userInfoCountsValue->setText(tr("Reports: %1 Bans: %2 Warnings: %3")
|
cardReportsValue->setText(QString::number(resp.total_reports()));
|
||||||
.arg(resp.total_reports())
|
cardWarnsValue->setText(QString::number(resp.total_warns()));
|
||||||
.arg(resp.total_bans())
|
cardBansValue->setText(QString::number(resp.total_bans()));
|
||||||
.arg(resp.total_warns()));
|
|
||||||
|
|
||||||
if (resp.has_admin_notes() && !resp.admin_notes().empty()) {
|
if (resp.has_admin_notes() && !resp.admin_notes().empty()) {
|
||||||
userInfoNotesEdit->setPlainText(QString::fromStdString(resp.admin_notes()));
|
userInfoNotesEdit->setPlainText(QString::fromStdString(resp.admin_notes()));
|
||||||
|
|
@ -306,12 +386,21 @@ void TabModeration::userInfoResponse(const Response &response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabModeration::applyAltsCount()
|
||||||
|
{
|
||||||
|
altsCountValue->setText(tr("%1 related").arg(cachedAltsCount));
|
||||||
|
}
|
||||||
|
|
||||||
void TabModeration::requestSessions(const QString &userName)
|
void TabModeration::requestSessions(const QString &userName)
|
||||||
{
|
{
|
||||||
Command_GetUserSessions cmd;
|
Command_GetUserSessions cmd;
|
||||||
cmd.set_user_name(userName.toStdString());
|
cmd.set_user_name(userName.toStdString());
|
||||||
PendingCommand *pend = client->prepareModeratorCommand(cmd);
|
PendingCommand *pend = client->prepareModeratorCommand(cmd);
|
||||||
connect(pend, &PendingCommand::finished, this, &TabModeration::sessionsResponse);
|
connect(pend, &PendingCommand::finished, this, [this, userName](const Response &response) {
|
||||||
|
if (userName == currentUser) {
|
||||||
|
sessionsResponse(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
client->sendCommand(pend);
|
client->sendCommand(pend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -343,7 +432,11 @@ void TabModeration::requestAlts(const QString &userName)
|
||||||
Command_GetUserAlts cmd;
|
Command_GetUserAlts cmd;
|
||||||
cmd.set_user_name(userName.toStdString());
|
cmd.set_user_name(userName.toStdString());
|
||||||
PendingCommand *pend = client->prepareModeratorCommand(cmd);
|
PendingCommand *pend = client->prepareModeratorCommand(cmd);
|
||||||
connect(pend, &PendingCommand::finished, this, &TabModeration::altsResponse);
|
connect(pend, &PendingCommand::finished, this, [this, userName](const Response &response) {
|
||||||
|
if (userName == currentUser) {
|
||||||
|
altsResponse(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
client->sendCommand(pend);
|
client->sendCommand(pend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -351,10 +444,21 @@ void TabModeration::altsResponse(const Response &response)
|
||||||
{
|
{
|
||||||
altsTable->setRowCount(0);
|
altsTable->setRowCount(0);
|
||||||
if (response.response_code() != Response::RespOk) {
|
if (response.response_code() != Response::RespOk) {
|
||||||
|
cachedAltsCount = -1;
|
||||||
|
altsCountValue->setText(QStringLiteral("–"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Response_UserAlts &resp = response.GetExtension(Response_UserAlts::ext);
|
const Response_UserAlts &resp = response.GetExtension(Response_UserAlts::ext);
|
||||||
|
// 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();
|
||||||
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) {
|
||||||
const ServerInfo_UserAlt &alt = resp.alts(i);
|
const ServerInfo_UserAlt &alt = resp.alts(i);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <libcockatrice/protocol/pb/response_report_user_info.pb.h>
|
||||||
#include <qtmetamacros.h>
|
#include <qtmetamacros.h>
|
||||||
|
|
||||||
class AbstractClient;
|
class AbstractClient;
|
||||||
|
|
@ -13,6 +14,7 @@ class QLabel;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QTableWidget;
|
class QTableWidget;
|
||||||
|
class QTabWidget;
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
class Response;
|
class Response;
|
||||||
class TabSupervisor;
|
class TabSupervisor;
|
||||||
|
|
@ -36,6 +38,7 @@ public:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void investigateUser();
|
void investigateUser();
|
||||||
|
void openAltsGraph();
|
||||||
void userInfoResponse(const Response &response);
|
void userInfoResponse(const Response &response);
|
||||||
void sessionsResponse(const Response &response);
|
void sessionsResponse(const Response &response);
|
||||||
void altsResponse(const Response &response);
|
void altsResponse(const Response &response);
|
||||||
|
|
@ -51,10 +54,15 @@ private:
|
||||||
void requestAlts(const QString &userName);
|
void requestAlts(const QString &userName);
|
||||||
void requestModeratorLogins();
|
void requestModeratorLogins();
|
||||||
void clearUserData();
|
void clearUserData();
|
||||||
|
void applyUserInfo();
|
||||||
|
void applyAltsCount();
|
||||||
[[nodiscard]] QString formatEpoch(quint64 ts) const;
|
[[nodiscard]] QString formatEpoch(quint64 ts) const;
|
||||||
|
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
QString currentUser;
|
QString currentUser;
|
||||||
|
Response_ReportUserInfo cachedUserInfo;
|
||||||
|
bool cachedUserInfoValid = false;
|
||||||
|
int cachedAltsCount = -1;
|
||||||
|
|
||||||
QLineEdit *searchEdit;
|
QLineEdit *searchEdit;
|
||||||
QPushButton *investigateButton;
|
QPushButton *investigateButton;
|
||||||
|
|
@ -62,25 +70,25 @@ private:
|
||||||
QPushButton *removeAvatarButton;
|
QPushButton *removeAvatarButton;
|
||||||
|
|
||||||
QGroupBox *userInfoGroup;
|
QGroupBox *userInfoGroup;
|
||||||
QLabel *userInfoNameLabel;
|
|
||||||
QLabel *userInfoNameValue;
|
QLabel *userInfoNameValue;
|
||||||
QLabel *userInfoRegisteredLabel;
|
|
||||||
QLabel *userInfoRegisteredValue;
|
|
||||||
QLabel *userInfoLastLoginLabel;
|
|
||||||
QLabel *userInfoLastLoginValue;
|
|
||||||
QLabel *userInfoStatusLabel;
|
|
||||||
QLabel *userInfoStatusValue;
|
QLabel *userInfoStatusValue;
|
||||||
QLabel *userInfoCountsLabel;
|
QLabel *sublineLabel;
|
||||||
QLabel *userInfoCountsValue;
|
QGroupBox *cardReports;
|
||||||
|
QGroupBox *cardWarns;
|
||||||
|
QGroupBox *cardBans;
|
||||||
|
QGroupBox *altsCard;
|
||||||
|
QLabel *cardReportsValue;
|
||||||
|
QLabel *cardWarnsValue;
|
||||||
|
QLabel *cardBansValue;
|
||||||
|
QLabel *altsCountValue;
|
||||||
QLabel *userInfoNotesLabel;
|
QLabel *userInfoNotesLabel;
|
||||||
QTextEdit *userInfoNotesEdit;
|
QTextEdit *userInfoNotesEdit;
|
||||||
|
|
||||||
QGroupBox *altsGroup;
|
QTabWidget *sectionTabs;
|
||||||
QTableWidget *altsTable;
|
QTableWidget *altsTable;
|
||||||
QGroupBox *sessionsGroup;
|
|
||||||
QTableWidget *sessionsTable;
|
QTableWidget *sessionsTable;
|
||||||
QGroupBox *staffGroup;
|
|
||||||
QTableWidget *staffTable;
|
QTableWidget *staffTable;
|
||||||
|
QPushButton *openAltsButton;
|
||||||
QPushButton *refreshStaffButton;
|
QPushButton *refreshStaffButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "../utility/report_utils.h"
|
#include "../utility/report_utils.h"
|
||||||
#include "abstract_client.h"
|
#include "abstract_client.h"
|
||||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||||
|
#include "report_status_delegate.h"
|
||||||
#include "tab_supervisor.h"
|
#include "tab_supervisor.h"
|
||||||
|
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
|
|
@ -24,7 +25,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QSignalBlocker>
|
#include <QSignalBlocker>
|
||||||
#include <QSplitter>
|
#include <QTabWidget>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QTableWidgetItem>
|
#include <QTableWidgetItem>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
|
|
@ -125,17 +126,34 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
|
||||||
connect(table, &QTableWidget::itemSelectionChanged, this, &TabReport::onSelectionChanged);
|
connect(table, &QTableWidget::itemSelectionChanged, this, &TabReport::onSelectionChanged);
|
||||||
table->setContextMenuPolicy(Qt::CustomContextMenu);
|
table->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(table, &QTableWidget::customContextMenuRequested, this, &TabReport::showTableContextMenu);
|
connect(table, &QTableWidget::customContextMenuRequested, this, &TabReport::showTableContextMenu);
|
||||||
|
table->setItemDelegateForColumn(COL_STATUS, new ReportStatusDelegate(table));
|
||||||
userContextMenu = new UserContextMenu(tabSupervisor, this);
|
userContextMenu = new UserContextMenu(tabSupervisor, this);
|
||||||
connect(userContextMenu, &UserContextMenu::openMessageDialog, this, &TabReport::openMessageDialog);
|
connect(userContextMenu, &UserContextMenu::openMessageDialog, this, &TabReport::openMessageDialog);
|
||||||
|
|
||||||
descGroup = new QGroupBox;
|
reportHeaderName = new QLabel;
|
||||||
|
QFont displayFont = reportHeaderName->font();
|
||||||
|
displayFont.setPointSize(displayFont.pointSize() + 6);
|
||||||
|
displayFont.setBold(true);
|
||||||
|
reportHeaderName->setFont(displayFont);
|
||||||
|
reportHeaderStatus = new QLabel;
|
||||||
|
QFont statusFont = reportHeaderStatus->font();
|
||||||
|
statusFont.setBold(true);
|
||||||
|
reportHeaderStatus->setFont(statusFont);
|
||||||
|
reportHeaderSubline = new QLabel;
|
||||||
|
|
||||||
|
auto *reportIdentityRow = new QHBoxLayout;
|
||||||
|
reportIdentityRow->addWidget(reportHeaderName);
|
||||||
|
reportIdentityRow->addStretch();
|
||||||
|
reportIdentityRow->addWidget(reportHeaderStatus);
|
||||||
|
|
||||||
|
auto *descPage = new QWidget;
|
||||||
descriptionEdit = new QTextEdit;
|
descriptionEdit = new QTextEdit;
|
||||||
descriptionEdit->setReadOnly(true);
|
descriptionEdit->setReadOnly(true);
|
||||||
auto *descLayout = new QVBoxLayout(descGroup);
|
auto *descLayout = new QVBoxLayout(descPage);
|
||||||
descLayout->setContentsMargins(4, 4, 4, 4);
|
descLayout->setContentsMargins(4, 4, 4, 4);
|
||||||
descLayout->addWidget(descriptionEdit);
|
descLayout->addWidget(descriptionEdit);
|
||||||
|
|
||||||
chatGroup = new QGroupBox;
|
auto *chatPage = new QWidget;
|
||||||
chatLogEdit = new QTextEdit;
|
chatLogEdit = new QTextEdit;
|
||||||
chatLogEdit->setReadOnly(true);
|
chatLogEdit->setReadOnly(true);
|
||||||
QFont monoFont("monospace");
|
QFont monoFont("monospace");
|
||||||
|
|
@ -145,11 +163,11 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
|
||||||
monoFont.setPointSize(systemPointSize);
|
monoFont.setPointSize(systemPointSize);
|
||||||
}
|
}
|
||||||
chatLogEdit->setFont(monoFont);
|
chatLogEdit->setFont(monoFont);
|
||||||
auto *chatLayout = new QVBoxLayout(chatGroup);
|
auto *chatLayout = new QVBoxLayout(chatPage);
|
||||||
chatLayout->setContentsMargins(4, 4, 4, 4);
|
chatLayout->setContentsMargins(4, 4, 4, 4);
|
||||||
chatLayout->addWidget(chatLogEdit);
|
chatLayout->addWidget(chatLogEdit);
|
||||||
|
|
||||||
commentsGroup = new QGroupBox;
|
auto *commentsPage = new QWidget;
|
||||||
commentsEdit = new QTextEdit;
|
commentsEdit = new QTextEdit;
|
||||||
commentsEdit->setReadOnly(true);
|
commentsEdit->setReadOnly(true);
|
||||||
auto *commentInputRow = new QHBoxLayout;
|
auto *commentInputRow = new QHBoxLayout;
|
||||||
|
|
@ -160,12 +178,12 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
|
||||||
connect(commentInput, &QLineEdit::returnPressed, this, &TabReport::addComment);
|
connect(commentInput, &QLineEdit::returnPressed, this, &TabReport::addComment);
|
||||||
commentInputRow->addWidget(commentInput);
|
commentInputRow->addWidget(commentInput);
|
||||||
commentInputRow->addWidget(commentButton);
|
commentInputRow->addWidget(commentButton);
|
||||||
auto *commentsLayout = new QVBoxLayout(commentsGroup);
|
auto *commentsLayout = new QVBoxLayout(commentsPage);
|
||||||
commentsLayout->setContentsMargins(4, 4, 4, 4);
|
commentsLayout->setContentsMargins(4, 4, 4, 4);
|
||||||
commentsLayout->addWidget(commentsEdit);
|
commentsLayout->addWidget(commentsEdit);
|
||||||
commentsLayout->addLayout(commentInputRow);
|
commentsLayout->addLayout(commentInputRow);
|
||||||
|
|
||||||
userContextGroup = new QGroupBox;
|
auto *userPage = new QWidget;
|
||||||
userContextName = new QLabel;
|
userContextName = new QLabel;
|
||||||
userContextAccountAge = new QLabel;
|
userContextAccountAge = new QLabel;
|
||||||
userContextReports = new QLabel;
|
userContextReports = new QLabel;
|
||||||
|
|
@ -184,7 +202,7 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
|
||||||
userContextWarnsLabel = new QLabel;
|
userContextWarnsLabel = new QLabel;
|
||||||
userContextNotesLabel = new QLabel;
|
userContextNotesLabel = new QLabel;
|
||||||
userContextRecentReportsLabel = new QLabel;
|
userContextRecentReportsLabel = new QLabel;
|
||||||
auto *ucLayout = new QGridLayout(userContextGroup);
|
auto *ucLayout = new QGridLayout(userPage);
|
||||||
ucLayout->setContentsMargins(8, 8, 8, 8);
|
ucLayout->setContentsMargins(8, 8, 8, 8);
|
||||||
ucLayout->addWidget(userContextUserLabel, 0, 0);
|
ucLayout->addWidget(userContextUserLabel, 0, 0);
|
||||||
ucLayout->addWidget(userContextName, 0, 1, 1, 3);
|
ucLayout->addWidget(userContextName, 0, 1, 1, 3);
|
||||||
|
|
@ -200,7 +218,6 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
|
||||||
ucLayout->addWidget(userContextNotes, 3, 1, 1, 3);
|
ucLayout->addWidget(userContextNotes, 3, 1, 1, 3);
|
||||||
ucLayout->addWidget(userContextRecentReportsLabel, 4, 0, 1, 4);
|
ucLayout->addWidget(userContextRecentReportsLabel, 4, 0, 1, 4);
|
||||||
ucLayout->addWidget(userContextRecentReports, 5, 0, 1, 4);
|
ucLayout->addWidget(userContextRecentReports, 5, 0, 1, 4);
|
||||||
userContextGroup->setVisible(false);
|
|
||||||
|
|
||||||
statsGroup = new QGroupBox;
|
statsGroup = new QGroupBox;
|
||||||
statsGroup->setCheckable(true);
|
statsGroup->setCheckable(true);
|
||||||
|
|
@ -228,13 +245,11 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
detailSplitter = new QSplitter(Qt::Vertical);
|
detailTabs = new QTabWidget;
|
||||||
detailSplitter->addWidget(descGroup);
|
detailTabs->addTab(descPage, QString());
|
||||||
detailSplitter->addWidget(chatGroup);
|
detailTabs->addTab(chatPage, QString());
|
||||||
detailSplitter->addWidget(commentsGroup);
|
detailTabs->addTab(commentsPage, QString());
|
||||||
detailSplitter->setStretchFactor(0, 1);
|
detailTabs->addTab(userPage, QString());
|
||||||
detailSplitter->setStretchFactor(1, 1);
|
|
||||||
detailSplitter->setStretchFactor(2, 2);
|
|
||||||
|
|
||||||
assignButton = new QPushButton;
|
assignButton = new QPushButton;
|
||||||
resolveButton = new QPushButton;
|
resolveButton = new QPushButton;
|
||||||
|
|
@ -266,12 +281,14 @@ TabReport::TabReport(TabSupervisor *_tabSupervisor, AbstractClient *_client) : T
|
||||||
layout->addLayout(topBar);
|
layout->addLayout(topBar);
|
||||||
layout->addWidget(statsLabel);
|
layout->addWidget(statsLabel);
|
||||||
layout->addWidget(table, 2);
|
layout->addWidget(table, 2);
|
||||||
layout->addWidget(detailSplitter, 1);
|
layout->addLayout(reportIdentityRow);
|
||||||
layout->addWidget(userContextGroup);
|
layout->addWidget(reportHeaderSubline);
|
||||||
|
layout->addWidget(detailTabs, 2);
|
||||||
layout->addWidget(statsGroup);
|
layout->addWidget(statsGroup);
|
||||||
layout->addLayout(actionBar);
|
layout->addLayout(actionBar);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
clearReportHeader();
|
||||||
|
|
||||||
setActionsEnabled(false);
|
setActionsEnabled(false);
|
||||||
refreshList();
|
refreshList();
|
||||||
|
|
@ -293,18 +310,18 @@ void TabReport::retranslateUi()
|
||||||
table->setHorizontalHeaderLabels({tr("#"), tr("Time"), tr("Reporter"), tr("Reported User"), tr("Category"),
|
table->setHorizontalHeaderLabels({tr("#"), tr("Time"), tr("Reporter"), tr("Reported User"), tr("Category"),
|
||||||
tr("Game ID"), tr("Status"), tr("Assigned To"), tr("Replay"), tr("Room")});
|
tr("Game ID"), tr("Status"), tr("Assigned To"), tr("Replay"), tr("Room")});
|
||||||
|
|
||||||
descGroup->setTitle(tr("Description"));
|
detailTabs->setTabText(0, tr("Description"));
|
||||||
chatGroup->setTitle(tr("Chat Log Context"));
|
detailTabs->setTabText(1, tr("Chat Log Context"));
|
||||||
chatGroup->setToolTip(
|
detailTabs->setTabToolTip(1, tr("Chat log attached by the reporter. It is captured from their client and may be "
|
||||||
tr("Chat log attached by the reporter. It is captured from their client and may be incomplete or edited."));
|
"incomplete or edited."));
|
||||||
commentsGroup->setTitle(tr("Comments / Thread"));
|
detailTabs->setTabText(2, tr("Comments / Thread"));
|
||||||
|
detailTabs->setTabText(3, tr("Reported User"));
|
||||||
descriptionEdit->setPlaceholderText(tr("No description."));
|
descriptionEdit->setPlaceholderText(tr("No description."));
|
||||||
chatLogEdit->setPlaceholderText(tr("No chat log attached."));
|
chatLogEdit->setPlaceholderText(tr("No chat log attached."));
|
||||||
commentsEdit->setPlaceholderText(tr("No comments yet."));
|
commentsEdit->setPlaceholderText(tr("No comments yet."));
|
||||||
commentInput->setPlaceholderText(tr("Type a reply..."));
|
commentInput->setPlaceholderText(tr("Type a reply..."));
|
||||||
commentButton->setText(tr("Send"));
|
commentButton->setText(tr("Send"));
|
||||||
|
|
||||||
userContextGroup->setTitle(tr("Reported User Context"));
|
|
||||||
userContextUserLabel->setText(tr("User:"));
|
userContextUserLabel->setText(tr("User:"));
|
||||||
userContextAgeLabel->setText(tr("Account Age:"));
|
userContextAgeLabel->setText(tr("Account Age:"));
|
||||||
userContextReportsLabel->setText(tr("Reports:"));
|
userContextReportsLabel->setText(tr("Reports:"));
|
||||||
|
|
@ -312,10 +329,18 @@ void TabReport::retranslateUi()
|
||||||
userContextWarnsLabel->setText(tr("Warns:"));
|
userContextWarnsLabel->setText(tr("Warns:"));
|
||||||
userContextNotesLabel->setText(tr("Admin Notes:"));
|
userContextNotesLabel->setText(tr("Admin Notes:"));
|
||||||
userContextRecentReportsLabel->setText(tr("Recent Reports Against User:"));
|
userContextRecentReportsLabel->setText(tr("Recent Reports Against User:"));
|
||||||
userContextAccountAge->setText(QString());
|
|
||||||
userContextReports->setText(QString());
|
if (headerReportId >= 0) {
|
||||||
userContextBans->setText(QString());
|
for (const ServerInfo_Report &r : filteredReports) {
|
||||||
userContextWarns->setText(QString());
|
if (r.report_id() == headerReportId) {
|
||||||
|
updateReportHeader(r);
|
||||||
|
const QString status = QString::fromStdString(r.status());
|
||||||
|
const bool canComment = (status == "open" || status == "assigned");
|
||||||
|
commentInput->setPlaceholderText(canComment ? tr("Type a reply...") : tr("This report is closed."));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
statsGroup->setTitle(tr("Report Statistics"));
|
statsGroup->setTitle(tr("Report Statistics"));
|
||||||
|
|
||||||
|
|
@ -408,7 +433,8 @@ void TabReport::reportListResponse(const Response &response)
|
||||||
chatLogEdit->clear();
|
chatLogEdit->clear();
|
||||||
commentsEdit->clear();
|
commentsEdit->clear();
|
||||||
setActionsEnabled(false);
|
setActionsEnabled(false);
|
||||||
userContextGroup->setVisible(false);
|
clearReportHeader();
|
||||||
|
clearUserContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -445,11 +471,14 @@ 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];
|
||||||
|
|
||||||
report_utils::fillReportTableRow(table, row, r, COL_ID, COL_TIME, COL_REPORTED, COL_CATEGORY, COL_GAMEID,
|
report_utils::fillReportTableRow(table, row, r, COL_ID, COL_TIME, COL_REPORTED, COL_CATEGORY, COL_GAMEID,
|
||||||
COL_STATUS, COL_ASSIGNED);
|
COL_STATUS, COL_ASSIGNED, false);
|
||||||
|
|
||||||
table->setItem(row, COL_REPORTER, new QTableWidgetItem(QString::fromStdString(r.reporter_name())));
|
table->setItem(row, COL_REPORTER, new QTableWidgetItem(QString::fromStdString(r.reporter_name())));
|
||||||
|
|
||||||
|
|
@ -458,12 +487,30 @@ 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()) : ""));
|
||||||
|
|
||||||
|
if (auto *reportedItem = table->item(row, COL_REPORTED)) {
|
||||||
|
reportedItem->setFont(reportedFont);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table->setSortingEnabled(true);
|
table->setSortingEnabled(true);
|
||||||
table->resizeColumnsToContents();
|
table->resizeColumnsToContents();
|
||||||
table->horizontalHeader()->setSectionResizeMode(COL_REPORTED, QHeaderView::Stretch);
|
table->horizontalHeader()->setSectionResizeMode(COL_REPORTED, QHeaderView::Stretch);
|
||||||
|
|
||||||
|
if (headerReportId >= 0) {
|
||||||
|
bool stillVisible = false;
|
||||||
|
for (const ServerInfo_Report &r : filteredReports) {
|
||||||
|
if (r.report_id() == headerReportId) {
|
||||||
|
stillVisible = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!stillVisible) {
|
||||||
|
clearReportHeader();
|
||||||
|
clearUserContext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
statusLabel->setText(tr("%1 report(s)").arg(filteredReports.size()));
|
statusLabel->setText(tr("%1 report(s)").arg(filteredReports.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -490,6 +537,31 @@ void TabReport::updateStats()
|
||||||
.arg(dismissed));
|
.arg(dismissed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabReport::updateReportHeader(const ServerInfo_Report &report)
|
||||||
|
{
|
||||||
|
reportHeaderName->setText(QString::fromStdString(report.reported_user_name()));
|
||||||
|
reportHeaderStatus->setText(report_utils::formatReportStatus(QString::fromStdString(report.status())));
|
||||||
|
|
||||||
|
QStringList parts;
|
||||||
|
parts << QString::fromStdString(report.category());
|
||||||
|
parts << QDateTime::fromSecsSinceEpoch(report.report_time()).toLocalTime().toString("yyyy-MM-dd HH:mm");
|
||||||
|
if (report.has_room_id() && report.room_id() > 0) {
|
||||||
|
parts << tr("Room %1").arg(report.room_id());
|
||||||
|
}
|
||||||
|
if (report.game_id() > 0) {
|
||||||
|
parts << tr("Game %1").arg(report.game_id());
|
||||||
|
}
|
||||||
|
reportHeaderSubline->setText(parts.join(QStringLiteral(" · ")));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabReport::clearReportHeader()
|
||||||
|
{
|
||||||
|
headerReportId = -1;
|
||||||
|
reportHeaderName->setText(tr("Select a report to inspect."));
|
||||||
|
reportHeaderStatus->clear();
|
||||||
|
reportHeaderSubline->clear();
|
||||||
|
}
|
||||||
|
|
||||||
void TabReport::onSelectionChanged()
|
void TabReport::onSelectionChanged()
|
||||||
{
|
{
|
||||||
const int row = table->currentRow();
|
const int row = table->currentRow();
|
||||||
|
|
@ -500,7 +572,8 @@ void TabReport::onSelectionChanged()
|
||||||
commentInput->clear();
|
commentInput->clear();
|
||||||
commentButton->setEnabled(false);
|
commentButton->setEnabled(false);
|
||||||
setActionsEnabled(false);
|
setActionsEnabled(false);
|
||||||
userContextGroup->setVisible(false);
|
clearReportHeader();
|
||||||
|
clearUserContext();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -509,6 +582,18 @@ void TabReport::onSelectionChanged()
|
||||||
updateActionStates();
|
updateActionStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabReport::clearUserContext()
|
||||||
|
{
|
||||||
|
lastRequestedUser.clear();
|
||||||
|
userContextName->setText(tr("—"));
|
||||||
|
userContextAccountAge->clear();
|
||||||
|
userContextReports->clear();
|
||||||
|
userContextBans->clear();
|
||||||
|
userContextWarns->clear();
|
||||||
|
userContextNotes->setPlainText(tr("Select a report to inspect."));
|
||||||
|
userContextRecentReports->clear();
|
||||||
|
}
|
||||||
|
|
||||||
void TabReport::showTableContextMenu(const QPoint &pos)
|
void TabReport::showTableContextMenu(const QPoint &pos)
|
||||||
{
|
{
|
||||||
QTableWidgetItem *clickedItem = table->itemAt(pos);
|
QTableWidgetItem *clickedItem = table->itemAt(pos);
|
||||||
|
|
@ -546,12 +631,17 @@ void TabReport::loadReportDetails(int reportId)
|
||||||
for (const ServerInfo_Report &r : filteredReports) {
|
for (const ServerInfo_Report &r : filteredReports) {
|
||||||
if (r.report_id() == reportId) {
|
if (r.report_id() == reportId) {
|
||||||
descriptionEdit->setPlainText(QString::fromStdString(r.description()));
|
descriptionEdit->setPlainText(QString::fromStdString(r.description()));
|
||||||
|
updateReportHeader(r);
|
||||||
|
if (headerReportId != reportId) {
|
||||||
|
headerReportId = reportId;
|
||||||
|
detailTabs->setCurrentIndex(0);
|
||||||
|
}
|
||||||
|
|
||||||
QString reportedUser = QString::fromStdString(r.reported_user_name());
|
QString reportedUser = QString::fromStdString(r.reported_user_name());
|
||||||
if (!reportedUser.isEmpty()) {
|
if (!reportedUser.isEmpty()) {
|
||||||
requestUserInfo(reportedUser);
|
requestUserInfo(reportedUser);
|
||||||
} else {
|
} else {
|
||||||
userContextGroup->setVisible(false);
|
clearUserContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString status = QString::fromStdString(r.status());
|
QString status = QString::fromStdString(r.status());
|
||||||
|
|
@ -871,12 +961,11 @@ void TabReport::addCommentResponse(const Response &response)
|
||||||
void TabReport::requestUserInfo(const QString &userName)
|
void TabReport::requestUserInfo(const QString &userName)
|
||||||
{
|
{
|
||||||
if (userName.isEmpty()) {
|
if (userName.isEmpty()) {
|
||||||
userContextGroup->setVisible(false);
|
clearUserContext();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastRequestedUser = userName;
|
lastRequestedUser = userName;
|
||||||
userContextGroup->setVisible(true);
|
|
||||||
userContextName->setText(userName);
|
userContextName->setText(userName);
|
||||||
userContextAccountAge->setText(tr("Loading..."));
|
userContextAccountAge->setText(tr("Loading..."));
|
||||||
userContextReports->clear();
|
userContextReports->clear();
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ class QGroupBox;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QSplitter;
|
|
||||||
class QTableWidget;
|
class QTableWidget;
|
||||||
|
class QTabWidget;
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class GameReplay;
|
class GameReplay;
|
||||||
|
|
@ -71,6 +71,9 @@ private:
|
||||||
void applyFilters();
|
void applyFilters();
|
||||||
void updateStats();
|
void updateStats();
|
||||||
void loadReportDetails(int reportId);
|
void loadReportDetails(int reportId);
|
||||||
|
void updateReportHeader(const ServerInfo_Report &report);
|
||||||
|
void clearReportHeader();
|
||||||
|
void clearUserContext();
|
||||||
|
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
|
|
||||||
|
|
@ -80,10 +83,10 @@ private:
|
||||||
QPushButton *refreshButton;
|
QPushButton *refreshButton;
|
||||||
QLabel *statsLabel;
|
QLabel *statsLabel;
|
||||||
QTableWidget *table;
|
QTableWidget *table;
|
||||||
QSplitter *detailSplitter;
|
QLabel *reportHeaderName;
|
||||||
QGroupBox *descGroup;
|
QLabel *reportHeaderStatus;
|
||||||
QGroupBox *chatGroup;
|
QLabel *reportHeaderSubline;
|
||||||
QGroupBox *commentsGroup;
|
QTabWidget *detailTabs;
|
||||||
QTextEdit *descriptionEdit;
|
QTextEdit *descriptionEdit;
|
||||||
QTextEdit *chatLogEdit;
|
QTextEdit *chatLogEdit;
|
||||||
QTextEdit *commentsEdit;
|
QTextEdit *commentsEdit;
|
||||||
|
|
@ -99,7 +102,6 @@ private:
|
||||||
QTimer *refreshTimer;
|
QTimer *refreshTimer;
|
||||||
UserContextMenu *userContextMenu;
|
UserContextMenu *userContextMenu;
|
||||||
|
|
||||||
QGroupBox *userContextGroup;
|
|
||||||
QLabel *userContextName;
|
QLabel *userContextName;
|
||||||
QLabel *userContextAccountAge;
|
QLabel *userContextAccountAge;
|
||||||
QLabel *userContextReports;
|
QLabel *userContextReports;
|
||||||
|
|
@ -124,6 +126,7 @@ private:
|
||||||
|
|
||||||
QList<ServerInfo_Report> allReports;
|
QList<ServerInfo_Report> allReports;
|
||||||
QList<ServerInfo_Report> filteredReports;
|
QList<ServerInfo_Report> filteredReports;
|
||||||
|
int headerReportId = -1;
|
||||||
int detailsRequestedReportId = -1;
|
int detailsRequestedReportId = -1;
|
||||||
int detailsRequestSeq = 0;
|
int detailsRequestSeq = 0;
|
||||||
int selectedReportIdBeforeRefresh = -1;
|
int selectedReportIdBeforeRefresh = -1;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#include "tab.h"
|
#include "tab.h"
|
||||||
#include "tab_account.h"
|
#include "tab_account.h"
|
||||||
#include "tab_admin.h"
|
#include "tab_admin.h"
|
||||||
|
#include "tab_alts.h"
|
||||||
#include "tab_card_art_rules.h"
|
#include "tab_card_art_rules.h"
|
||||||
#include "tab_deck_editor.h"
|
#include "tab_deck_editor.h"
|
||||||
#include "tab_deck_storage.h"
|
#include "tab_deck_storage.h"
|
||||||
|
|
@ -156,7 +157,7 @@ TabSupervisor::TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *
|
||||||
: QTabWidget(parent), userInfo(nullptr), client(_client), tabsMenu(tabsMenu), tabHome(nullptr),
|
: QTabWidget(parent), userInfo(nullptr), client(_client), tabsMenu(tabsMenu), tabHome(nullptr),
|
||||||
tabVisualDeckStorage(nullptr), tabServer(nullptr), tabAccount(nullptr), tabDeckStorage(nullptr),
|
tabVisualDeckStorage(nullptr), tabServer(nullptr), tabAccount(nullptr), tabDeckStorage(nullptr),
|
||||||
tabReplays(nullptr), tabAdmin(nullptr), tabCardArtRules(nullptr), tabLog(nullptr), tabReport(nullptr),
|
tabReplays(nullptr), tabAdmin(nullptr), tabCardArtRules(nullptr), tabLog(nullptr), tabReport(nullptr),
|
||||||
tabModeration(nullptr), tabDeveloper(nullptr), isLocalGame(false)
|
tabModeration(nullptr), tabAlts(nullptr), tabDeveloper(nullptr), isLocalGame(false)
|
||||||
{
|
{
|
||||||
setElideMode(Qt::ElideRight);
|
setElideMode(Qt::ElideRight);
|
||||||
setMovable(true);
|
setMovable(true);
|
||||||
|
|
@ -300,6 +301,7 @@ void TabSupervisor::retranslateUi()
|
||||||
tabs.append(tabLog);
|
tabs.append(tabLog);
|
||||||
tabs.append(tabReport);
|
tabs.append(tabReport);
|
||||||
tabs.append(tabModeration);
|
tabs.append(tabModeration);
|
||||||
|
tabs.append(tabAlts);
|
||||||
tabs.append(tabCardArtRules);
|
tabs.append(tabCardArtRules);
|
||||||
tabs.append(tabDeveloper);
|
tabs.append(tabDeveloper);
|
||||||
QMapIterator<int, TabRoom *> roomIterator(roomTabs);
|
QMapIterator<int, TabRoom *> roomIterator(roomTabs);
|
||||||
|
|
@ -600,6 +602,7 @@ void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
|
||||||
tabLog = nullptr;
|
tabLog = nullptr;
|
||||||
tabReport = nullptr;
|
tabReport = nullptr;
|
||||||
tabModeration = nullptr;
|
tabModeration = nullptr;
|
||||||
|
tabAlts = nullptr;
|
||||||
tabDeveloper = nullptr;
|
tabDeveloper = nullptr;
|
||||||
isLocalGame = true;
|
isLocalGame = true;
|
||||||
userInfo = new ServerInfo_User;
|
userInfo = new ServerInfo_User;
|
||||||
|
|
@ -648,6 +651,9 @@ void TabSupervisor::stop()
|
||||||
if (tabModeration) {
|
if (tabModeration) {
|
||||||
tabModeration->close();
|
tabModeration->close();
|
||||||
}
|
}
|
||||||
|
if (tabAlts) {
|
||||||
|
tabAlts->close();
|
||||||
|
}
|
||||||
if (tabCardArtRules) {
|
if (tabCardArtRules) {
|
||||||
tabCardArtRules->close();
|
tabCardArtRules->close();
|
||||||
}
|
}
|
||||||
|
|
@ -956,6 +962,20 @@ void TabSupervisor::openTabModeration(const QString &userName)
|
||||||
aTabModeration->setChecked(true);
|
aTabModeration->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabSupervisor::openTabAlts(const QString &userName)
|
||||||
|
{
|
||||||
|
if (tabAlts) {
|
||||||
|
setCurrentWidget(tabAlts);
|
||||||
|
if (!userName.isEmpty()) {
|
||||||
|
tabAlts->investigate(userName);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tabAlts = new TabAlts(this, client, userName);
|
||||||
|
myAddTab(tabAlts);
|
||||||
|
connect(tabAlts, &QObject::destroyed, this, [this] { tabAlts = nullptr; });
|
||||||
|
}
|
||||||
|
|
||||||
void TabSupervisor::actTabDeveloper(bool checked)
|
void TabSupervisor::actTabDeveloper(bool checked)
|
||||||
{
|
{
|
||||||
if (checked && !tabDeveloper) {
|
if (checked && !tabDeveloper) {
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ class TabAdmin;
|
||||||
class TabMessage;
|
class TabMessage;
|
||||||
class TabReport;
|
class TabReport;
|
||||||
class TabModeration;
|
class TabModeration;
|
||||||
|
class TabAlts;
|
||||||
class TabAccount;
|
class TabAccount;
|
||||||
class TabDeckEditor;
|
class TabDeckEditor;
|
||||||
class TabDeveloper;
|
class TabDeveloper;
|
||||||
|
|
@ -116,6 +117,7 @@ private:
|
||||||
TabLog *tabLog;
|
TabLog *tabLog;
|
||||||
TabReport *tabReport;
|
TabReport *tabReport;
|
||||||
TabModeration *tabModeration;
|
TabModeration *tabModeration;
|
||||||
|
TabAlts *tabAlts;
|
||||||
TabDeveloper *tabDeveloper;
|
TabDeveloper *tabDeveloper;
|
||||||
QMap<int, TabRoom *> roomTabs;
|
QMap<int, TabRoom *> roomTabs;
|
||||||
QMap<int, TabGame *> gameTabs;
|
QMap<int, TabGame *> gameTabs;
|
||||||
|
|
@ -209,6 +211,7 @@ public slots:
|
||||||
/** Joins or spectates a game listed on a user's profile hover card. */
|
/** Joins or spectates a game listed on a user's profile hover card. */
|
||||||
void joinGameFromUserCard(int gameId, int roomId, bool asSpectator);
|
void joinGameFromUserCard(int gameId, int roomId, bool asSpectator);
|
||||||
void openTabModeration(const QString &userName = {});
|
void openTabModeration(const QString &userName = {});
|
||||||
|
void openTabAlts(const QString &userName = {});
|
||||||
void switchToFirstAvailableNetworkTab();
|
void switchToFirstAvailableNetworkTab();
|
||||||
void maximizeMainWindow();
|
void maximizeMainWindow();
|
||||||
void actTabVisualDeckStorage(bool checked);
|
void actTabVisualDeckStorage(bool checked);
|
||||||
|
|
|
||||||
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
|
||||||
|
|
@ -64,6 +64,23 @@ QString formatReportTime(qint64 secondsSinceEpoch)
|
||||||
return dt.toString("yyyy-MM-dd hh:mm");
|
return dt.toString("yyyy-MM-dd hh:mm");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString formatReportStatus(const QString &status)
|
||||||
|
{
|
||||||
|
if (status == QStringLiteral("open")) {
|
||||||
|
return QObject::tr("Open");
|
||||||
|
}
|
||||||
|
if (status == QStringLiteral("assigned")) {
|
||||||
|
return QObject::tr("Assigned");
|
||||||
|
}
|
||||||
|
if (status == QStringLiteral("resolved")) {
|
||||||
|
return QObject::tr("Resolved");
|
||||||
|
}
|
||||||
|
if (status == QStringLiteral("dismissed")) {
|
||||||
|
return QObject::tr("Dismissed");
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
void fillReportTableRow(QTableWidget *table,
|
void fillReportTableRow(QTableWidget *table,
|
||||||
int row,
|
int row,
|
||||||
const ServerInfo_Report &report,
|
const ServerInfo_Report &report,
|
||||||
|
|
@ -73,7 +90,8 @@ void fillReportTableRow(QTableWidget *table,
|
||||||
int categoryColumn,
|
int categoryColumn,
|
||||||
int gameIdColumn,
|
int gameIdColumn,
|
||||||
int statusColumn,
|
int statusColumn,
|
||||||
int assignedColumn)
|
int assignedColumn,
|
||||||
|
bool colorizeStatus)
|
||||||
{
|
{
|
||||||
auto *idItem = new QTableWidgetItem(QString::number(report.report_id()));
|
auto *idItem = new QTableWidgetItem(QString::number(report.report_id()));
|
||||||
idItem->setData(Qt::UserRole, report.report_id());
|
idItem->setData(Qt::UserRole, report.report_id());
|
||||||
|
|
@ -86,8 +104,12 @@ void fillReportTableRow(QTableWidget *table,
|
||||||
table->setItem(row, gameIdColumn,
|
table->setItem(row, gameIdColumn,
|
||||||
new QTableWidgetItem(report.game_id() > 0 ? QString::number(report.game_id()) : QString()));
|
new QTableWidgetItem(report.game_id() > 0 ? QString::number(report.game_id()) : QString()));
|
||||||
|
|
||||||
auto *statusItem = new QTableWidgetItem(QString::fromStdString(report.status()));
|
const QString rawStatus = QString::fromStdString(report.status());
|
||||||
setReportStatusItemColor(statusItem, QString::fromStdString(report.status()));
|
auto *statusItem = new QTableWidgetItem(formatReportStatus(rawStatus));
|
||||||
|
statusItem->setData(Qt::UserRole, rawStatus);
|
||||||
|
if (colorizeStatus) {
|
||||||
|
setReportStatusItemColor(statusItem, rawStatus);
|
||||||
|
}
|
||||||
table->setItem(row, statusColumn, statusItem);
|
table->setItem(row, statusColumn, statusItem);
|
||||||
|
|
||||||
table->setItem(row, assignedColumn, new QTableWidgetItem(QString::fromStdString(report.assigned_mod_name())));
|
table->setItem(row, assignedColumn, new QTableWidgetItem(QString::fromStdString(report.assigned_mod_name())));
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ namespace report_utils
|
||||||
|
|
||||||
QString formatReportCategory(const QString &category);
|
QString formatReportCategory(const QString &category);
|
||||||
QString formatReportTime(qint64 secondsSinceEpoch);
|
QString formatReportTime(qint64 secondsSinceEpoch);
|
||||||
|
QString formatReportStatus(const QString &status);
|
||||||
|
|
||||||
void fillReportTableRow(QTableWidget *table,
|
void fillReportTableRow(QTableWidget *table,
|
||||||
int row,
|
int row,
|
||||||
|
|
@ -23,7 +24,8 @@ void fillReportTableRow(QTableWidget *table,
|
||||||
int categoryColumn,
|
int categoryColumn,
|
||||||
int gameIdColumn,
|
int gameIdColumn,
|
||||||
int statusColumn,
|
int statusColumn,
|
||||||
int assignedColumn);
|
int assignedColumn,
|
||||||
|
bool colorizeStatus = true);
|
||||||
|
|
||||||
void renderReportDetails(QTextEdit *chatLogEdit,
|
void renderReportDetails(QTextEdit *chatLogEdit,
|
||||||
QTextEdit *commentsEdit,
|
QTextEdit *commentsEdit,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
#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);
|
||||||
|
}
|
||||||
31
cockatrice/src/interface/widgets/utility/table_activation.h
Normal file
31
cockatrice/src/interface/widgets/utility/table_activation.h
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
|
|
@ -165,6 +165,7 @@ message Command_GetUserAlts {
|
||||||
optional Command_GetUserAlts ext = 1014;
|
optional Command_GetUserAlts ext = 1014;
|
||||||
}
|
}
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
message Command_GetModeratorLastLogins {
|
message Command_GetModeratorLastLogins {
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,8 @@ message ServerInfo_UserAlt {
|
||||||
optional uint32 warn_count = 6; // number of warnings on record
|
optional uint32 warn_count = 6; // number of warnings on record
|
||||||
optional uint32 ban_count = 7; // number of bans on record
|
optional uint32 ban_count = 7; // number of bans on record
|
||||||
optional bool is_active = 8; // account is not deactivated/banned
|
optional bool is_active = 8; // account is not deactivated/banned
|
||||||
|
optional string match_reason = 9; // why flagged, e.g. "email", "clientid:abc", "ip:1.2.3.4"; empty = seed/legacy
|
||||||
|
optional uint32 depth = 10; // BFS distance from investigated account; 1 = direct, 2+ = alt-of-alt
|
||||||
|
optional uint32 shared_count =
|
||||||
|
11; // distinct users sharing the matched identifier; high values suggest VPN/shared network
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QVariantList>
|
#include <QVariantList>
|
||||||
|
#include <algorithm>
|
||||||
#include <google/protobuf/stubs/common.h>
|
#include <google/protobuf/stubs/common.h>
|
||||||
#include <libcockatrice/deck_list/deck_list.h>
|
#include <libcockatrice/deck_list/deck_list.h>
|
||||||
#include <libcockatrice/protocol/pb/game_replay.pb.h>
|
#include <libcockatrice/protocol/pb/game_replay.pb.h>
|
||||||
|
|
@ -1621,7 +1622,58 @@ QList<ServerInfo_UserSession> Servatrice_DatabaseInterface::getUserSessions(cons
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QString &userName)
|
namespace
|
||||||
|
{
|
||||||
|
constexpr int MAX_USER_ALT_DEPTH = 3;
|
||||||
|
constexpr int MAX_USER_ALTS_PER_LEVEL = 200;
|
||||||
|
// Bounds per-level work and the prepared-statement cache (keyed by query text,
|
||||||
|
// so every distinct IN-list size is a new entry on the long-lived server).
|
||||||
|
// 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.
|
||||||
|
constexpr int MAX_USER_ALT_IDENTIFIERS = 200;
|
||||||
|
|
||||||
|
QString altInClause(const QString &prefix, const QList<QString> &values)
|
||||||
|
{
|
||||||
|
QStringList placeholders;
|
||||||
|
placeholders.reserve(values.size());
|
||||||
|
for (int i = 0; i < values.size(); ++i) {
|
||||||
|
placeholders << prefix + QString::number(i);
|
||||||
|
}
|
||||||
|
return QStringLiteral("(") + placeholders.join(QStringLiteral(",")) + QStringLiteral(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
void altBindValues(QSqlQuery *query, const QString &prefix, const QList<QString> &values)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < values.size(); ++i) {
|
||||||
|
query->bindValue(prefix + QString::number(i), values.at(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AltCandidate
|
||||||
|
{
|
||||||
|
QString name;
|
||||||
|
QString email;
|
||||||
|
QString clientId;
|
||||||
|
qint64 registrationTime = 0;
|
||||||
|
qint64 lastLogin = 0;
|
||||||
|
bool hasLastLogin = false;
|
||||||
|
int warnCount = 0;
|
||||||
|
int banCount = 0;
|
||||||
|
bool isActive = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
QList<QString> cappedIdentifiers(QSet<QString> values)
|
||||||
|
{
|
||||||
|
QList<QString> list = values.values();
|
||||||
|
std::sort(list.begin(), list.end());
|
||||||
|
if (list.size() > MAX_USER_ALT_IDENTIFIERS) {
|
||||||
|
list.erase(list.begin() + MAX_USER_ALT_IDENTIFIERS, list.end());
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QString &userName, int depth)
|
||||||
{
|
{
|
||||||
QList<ServerInfo_UserAlt> results;
|
QList<ServerInfo_UserAlt> results;
|
||||||
|
|
||||||
|
|
@ -1629,63 +1681,301 @@ QList<ServerInfo_UserAlt> Servatrice_DatabaseInterface::getUserAlts(const QStrin
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seed account identifiers used to find related accounts
|
if (depth < 1) {
|
||||||
QSqlQuery *seedQuery = prepareQuery("SELECT email, clientid FROM {prefix}_users WHERE name = :user_name");
|
depth = 1;
|
||||||
|
} else if (depth > MAX_USER_ALT_DEPTH) {
|
||||||
|
depth = MAX_USER_ALT_DEPTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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), "
|
||||||
|
"UNIX_TIMESTAMP(a.last_login), "
|
||||||
|
"(SELECT COUNT(*) FROM {prefix}_warnings w WHERE w.user_id = u.id), "
|
||||||
|
"(SELECT COUNT(*) FROM {prefix}_bans b WHERE b.user_name = u.name), "
|
||||||
|
"u.active "
|
||||||
|
"FROM {prefix}_users u "
|
||||||
|
"LEFT JOIN {prefix}_user_analytics a ON a.id = u.id "
|
||||||
|
"WHERE u.name = :user_name");
|
||||||
seedQuery->bindValue(":user_name", userName);
|
seedQuery->bindValue(":user_name", userName);
|
||||||
if (!execSqlQuery(seedQuery) || !seedQuery->next()) {
|
if (!execSqlQuery(seedQuery) || !seedQuery->next()) {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
const QString seedEmail = seedQuery->value(0).toString();
|
|
||||||
const QString seedClientId = seedQuery->value(1).toString();
|
|
||||||
|
|
||||||
QString queryString = "SELECT u.name, u.email, u.clientid, UNIX_TIMESTAMP(u.registrationDate), "
|
auto appendAlt = [&results](const AltCandidate &candidate, const QString &matchReason, int matchDepth,
|
||||||
"UNIX_TIMESTAMP(a.last_login), "
|
int sharedCount) {
|
||||||
"(SELECT COUNT(*) FROM {prefix}_warnings w WHERE w.user_id = u.id), "
|
|
||||||
"(SELECT COUNT(*) FROM {prefix}_bans b WHERE b.user_name = u.name), "
|
|
||||||
"u.active "
|
|
||||||
"FROM {prefix}_users u "
|
|
||||||
"LEFT JOIN {prefix}_user_analytics a ON a.id = u.id "
|
|
||||||
"WHERE u.name = :user_name";
|
|
||||||
if (!seedEmail.isEmpty()) {
|
|
||||||
queryString.append(" OR u.email = :seed_email");
|
|
||||||
}
|
|
||||||
if (!seedClientId.isEmpty()) {
|
|
||||||
queryString.append(" OR u.clientid = :seed_clientid");
|
|
||||||
}
|
|
||||||
queryString.append(" OR u.name IN (SELECT DISTINCT s.user_name FROM {prefix}_sessions s "
|
|
||||||
"WHERE s.ip_address IN (SELECT DISTINCT s2.ip_address FROM {prefix}_sessions s2 "
|
|
||||||
"WHERE s2.user_name = :user_name"
|
|
||||||
" AND s2.start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH))"
|
|
||||||
" AND s.start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH)) "
|
|
||||||
"ORDER BY u.name LIMIT 200");
|
|
||||||
|
|
||||||
QSqlQuery *query = prepareQuery(queryString);
|
|
||||||
query->bindValue(":user_name", userName);
|
|
||||||
if (!seedEmail.isEmpty()) {
|
|
||||||
query->bindValue(":seed_email", seedEmail);
|
|
||||||
}
|
|
||||||
if (!seedClientId.isEmpty()) {
|
|
||||||
query->bindValue(":seed_clientid", seedClientId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!execSqlQuery(query)) {
|
|
||||||
qCWarning(DatabaseInterfaceLog) << "Failed to collect user alt information: SQL Error";
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (query->next()) {
|
|
||||||
ServerInfo_UserAlt altDetails;
|
ServerInfo_UserAlt altDetails;
|
||||||
altDetails.set_user_name(query->value(0).toString().toStdString());
|
altDetails.set_user_name(candidate.name.toStdString());
|
||||||
altDetails.set_email(query->value(1).toString().toStdString());
|
altDetails.set_email(candidate.email.toStdString());
|
||||||
altDetails.set_clientid(query->value(2).toString().toStdString());
|
altDetails.set_clientid(candidate.clientId.toStdString());
|
||||||
altDetails.set_registration_time(query->value(3).toLongLong());
|
altDetails.set_registration_time(candidate.registrationTime);
|
||||||
if (!query->value(4).isNull()) {
|
if (candidate.hasLastLogin) {
|
||||||
altDetails.set_last_login(query->value(4).toLongLong());
|
altDetails.set_last_login(candidate.lastLogin);
|
||||||
}
|
}
|
||||||
altDetails.set_warn_count(query->value(5).toInt());
|
altDetails.set_warn_count(candidate.warnCount);
|
||||||
altDetails.set_ban_count(query->value(6).toInt());
|
altDetails.set_ban_count(candidate.banCount);
|
||||||
altDetails.set_is_active(query->value(7).toBool());
|
altDetails.set_is_active(candidate.isActive);
|
||||||
|
altDetails.set_match_reason(matchReason.toStdString());
|
||||||
|
altDetails.set_depth(static_cast<google::protobuf::uint32>(matchDepth));
|
||||||
|
altDetails.set_shared_count(static_cast<google::protobuf::uint32>(sharedCount));
|
||||||
results << altDetails;
|
results << altDetails;
|
||||||
|
};
|
||||||
|
|
||||||
|
AltCandidate seed{.name = seedQuery->value(0).toString(),
|
||||||
|
.email = seedQuery->value(1).toString(),
|
||||||
|
.clientId = seedQuery->value(2).toString(),
|
||||||
|
.registrationTime = seedQuery->value(3).toLongLong(),
|
||||||
|
.lastLogin = seedQuery->value(4).toLongLong(),
|
||||||
|
.hasLastLogin = !seedQuery->value(4).isNull(),
|
||||||
|
.warnCount = seedQuery->value(5).toInt(),
|
||||||
|
.banCount = seedQuery->value(6).toInt(),
|
||||||
|
.isActive = seedQuery->value(7).toBool()};
|
||||||
|
appendAlt(seed, QStringLiteral("self"), 0, 1);
|
||||||
|
|
||||||
|
QSet<QString> visited{userName};
|
||||||
|
QList<QString> frontier{userName};
|
||||||
|
for (int level = 1; level <= depth && !frontier.isEmpty(); ++level) {
|
||||||
|
const QString frontierClause = altInClause(QStringLiteral(":alt_name"), frontier);
|
||||||
|
|
||||||
|
// Current identifiers of the frontier: registration email + client id.
|
||||||
|
QSet<QString> emails;
|
||||||
|
QSet<QString> clientIds;
|
||||||
|
QSet<QString> ips;
|
||||||
|
QSqlQuery *frontierQuery =
|
||||||
|
prepareQuery(QStringLiteral("SELECT email, clientid FROM {prefix}_users WHERE name IN ") + frontierClause);
|
||||||
|
altBindValues(frontierQuery, QStringLiteral(":alt_name"), frontier);
|
||||||
|
if (execSqlQuery(frontierQuery)) {
|
||||||
|
while (frontierQuery->next()) {
|
||||||
|
const QString email = frontierQuery->value(0).toString();
|
||||||
|
const QString clientId = frontierQuery->value(1).toString();
|
||||||
|
if (!email.isEmpty()) {
|
||||||
|
emails << email;
|
||||||
|
}
|
||||||
|
if (!clientId.isEmpty()) {
|
||||||
|
clientIds << clientId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recent session identifiers: IPs plus historic client ids.
|
||||||
|
QSqlQuery *sessionQuery = prepareQuery(
|
||||||
|
QStringLiteral("SELECT DISTINCT ip_address, clientid FROM {prefix}_sessions WHERE user_name IN ") +
|
||||||
|
frontierClause + QStringLiteral(" AND start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH)"));
|
||||||
|
altBindValues(sessionQuery, QStringLiteral(":alt_name"), frontier);
|
||||||
|
if (execSqlQuery(sessionQuery)) {
|
||||||
|
while (sessionQuery->next()) {
|
||||||
|
const QString ip = sessionQuery->value(0).toString();
|
||||||
|
const QString clientId = sessionQuery->value(1).toString();
|
||||||
|
if (!ip.isEmpty()) {
|
||||||
|
ips << ip;
|
||||||
|
}
|
||||||
|
if (!clientId.isEmpty()) {
|
||||||
|
clientIds << clientId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emails.isEmpty() && clientIds.isEmpty() && ips.isEmpty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accounts sharing any frontier identifier. Historic client ids are matched
|
||||||
|
// through past sessions so identifier changes do not hide older alts.
|
||||||
|
QString candidateString =
|
||||||
|
QStringLiteral("SELECT u.name, u.email, u.clientid, UNIX_TIMESTAMP(u.registrationDate), "
|
||||||
|
"UNIX_TIMESTAMP(a.last_login), "
|
||||||
|
"(SELECT COUNT(*) FROM {prefix}_warnings w WHERE w.user_id = u.id), "
|
||||||
|
"(SELECT COUNT(*) FROM {prefix}_bans b WHERE b.user_name = u.name), "
|
||||||
|
"u.active "
|
||||||
|
"FROM {prefix}_users u "
|
||||||
|
"LEFT JOIN {prefix}_user_analytics a ON a.id = u.id "
|
||||||
|
"WHERE ");
|
||||||
|
QStringList conditions;
|
||||||
|
QList<QString> emailList = cappedIdentifiers(emails);
|
||||||
|
QList<QString> clientIdList = cappedIdentifiers(clientIds);
|
||||||
|
QList<QString> ipList = cappedIdentifiers(ips);
|
||||||
|
if (!emailList.isEmpty()) {
|
||||||
|
conditions << QStringLiteral("u.email IN ") + altInClause(QStringLiteral(":alt_email"), emailList);
|
||||||
|
}
|
||||||
|
if (!clientIdList.isEmpty()) {
|
||||||
|
conditions << QStringLiteral("u.clientid IN ") + altInClause(QStringLiteral(":alt_cid"), clientIdList);
|
||||||
|
}
|
||||||
|
if (!ipList.isEmpty()) {
|
||||||
|
conditions << QStringLiteral("u.name IN (SELECT DISTINCT s.user_name FROM {prefix}_sessions s WHERE "
|
||||||
|
"s.ip_address IN ") +
|
||||||
|
altInClause(QStringLiteral(":alt_ip"), ipList) +
|
||||||
|
QStringLiteral(" AND s.start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH))");
|
||||||
|
}
|
||||||
|
if (!clientIdList.isEmpty()) {
|
||||||
|
conditions << QStringLiteral("u.name IN (SELECT DISTINCT s.user_name FROM {prefix}_sessions s WHERE "
|
||||||
|
"s.clientid IN ") +
|
||||||
|
altInClause(QStringLiteral(":alt_hcid"), clientIdList) +
|
||||||
|
QStringLiteral(" AND s.start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH))");
|
||||||
|
}
|
||||||
|
candidateString += conditions.join(QStringLiteral(" OR "));
|
||||||
|
candidateString += QStringLiteral(" ORDER BY u.name LIMIT ") + QString::number(MAX_USER_ALTS_PER_LEVEL);
|
||||||
|
|
||||||
|
QSqlQuery *candidateQuery = prepareQuery(candidateString);
|
||||||
|
altBindValues(candidateQuery, QStringLiteral(":alt_email"), emailList);
|
||||||
|
altBindValues(candidateQuery, QStringLiteral(":alt_cid"), clientIdList);
|
||||||
|
altBindValues(candidateQuery, QStringLiteral(":alt_ip"), ipList);
|
||||||
|
altBindValues(candidateQuery, QStringLiteral(":alt_hcid"), clientIdList);
|
||||||
|
if (!execSqlQuery(candidateQuery)) {
|
||||||
|
qCWarning(DatabaseInterfaceLog) << "Failed to collect user alt information: SQL Error";
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<AltCandidate> candidates;
|
||||||
|
while (candidateQuery->next()) {
|
||||||
|
AltCandidate candidate;
|
||||||
|
candidate.name = candidateQuery->value(0).toString();
|
||||||
|
if (visited.contains(candidate.name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
candidate.email = candidateQuery->value(1).toString();
|
||||||
|
candidate.clientId = candidateQuery->value(2).toString();
|
||||||
|
candidate.registrationTime = candidateQuery->value(3).toLongLong();
|
||||||
|
candidate.hasLastLogin = !candidateQuery->value(4).isNull();
|
||||||
|
candidate.lastLogin = candidateQuery->value(4).toLongLong();
|
||||||
|
candidate.warnCount = candidateQuery->value(5).toInt();
|
||||||
|
candidate.banCount = candidateQuery->value(6).toInt();
|
||||||
|
candidate.isActive = candidateQuery->value(7).toBool();
|
||||||
|
candidates << candidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve session-level evidence (shared IP or historic client id) for
|
||||||
|
// candidates that do not match on current email or client id.
|
||||||
|
QMap<QString, QString> candidateIp;
|
||||||
|
QMap<QString, QString> candidateHistoricClientId;
|
||||||
|
QList<QString> unexplained;
|
||||||
|
for (const AltCandidate &candidate : candidates) {
|
||||||
|
const bool emailMatch = !candidate.email.isEmpty() && emails.contains(candidate.email);
|
||||||
|
const bool clientIdMatch = !candidate.clientId.isEmpty() && clientIds.contains(candidate.clientId);
|
||||||
|
if (!emailMatch && !clientIdMatch) {
|
||||||
|
unexplained << candidate.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!unexplained.isEmpty() && (!ips.isEmpty() || !clientIds.isEmpty())) {
|
||||||
|
QString evidenceString =
|
||||||
|
QStringLiteral("SELECT DISTINCT user_name, ip_address, clientid FROM {prefix}_sessions WHERE "
|
||||||
|
"user_name IN ") +
|
||||||
|
altInClause(QStringLiteral(":alt_ev"), unexplained) + QStringLiteral(" AND (");
|
||||||
|
QStringList evidenceConditions;
|
||||||
|
if (!ipList.isEmpty()) {
|
||||||
|
evidenceConditions << QStringLiteral("ip_address IN ") +
|
||||||
|
altInClause(QStringLiteral(":alt_eip"), ipList);
|
||||||
|
}
|
||||||
|
if (!clientIdList.isEmpty()) {
|
||||||
|
evidenceConditions << QStringLiteral("clientid IN ") +
|
||||||
|
altInClause(QStringLiteral(":alt_ecid"), clientIdList);
|
||||||
|
}
|
||||||
|
evidenceString += evidenceConditions.join(QStringLiteral(" OR "));
|
||||||
|
evidenceString += QStringLiteral(") AND start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH)");
|
||||||
|
|
||||||
|
QSqlQuery *evidenceQuery = prepareQuery(evidenceString);
|
||||||
|
altBindValues(evidenceQuery, QStringLiteral(":alt_ev"), unexplained);
|
||||||
|
altBindValues(evidenceQuery, QStringLiteral(":alt_eip"), ipList);
|
||||||
|
altBindValues(evidenceQuery, QStringLiteral(":alt_ecid"), clientIdList);
|
||||||
|
if (execSqlQuery(evidenceQuery)) {
|
||||||
|
while (evidenceQuery->next()) {
|
||||||
|
const QString name = evidenceQuery->value(0).toString();
|
||||||
|
const QString ip = evidenceQuery->value(1).toString();
|
||||||
|
const QString clientId = evidenceQuery->value(2).toString();
|
||||||
|
if (!ip.isEmpty() && ips.contains(ip) && !candidateIp.contains(name)) {
|
||||||
|
candidateIp.insert(name, ip);
|
||||||
|
}
|
||||||
|
if (!clientId.isEmpty() && clientIds.contains(clientId) &&
|
||||||
|
!candidateHistoricClientId.contains(name)) {
|
||||||
|
candidateHistoricClientId.insert(name, clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fan-out counts so moderators can spot VPN/shared-network false positives.
|
||||||
|
QMap<QString, int> emailCounts;
|
||||||
|
QMap<QString, int> clientIdCounts;
|
||||||
|
QMap<QString, int> ipCounts;
|
||||||
|
QSet<QString> neededEmails;
|
||||||
|
QSet<QString> neededClientIds;
|
||||||
|
QSet<QString> neededIps;
|
||||||
|
for (const AltCandidate &candidate : candidates) {
|
||||||
|
if (!candidate.email.isEmpty() && emails.contains(candidate.email)) {
|
||||||
|
neededEmails << candidate.email;
|
||||||
|
} else if (!candidate.clientId.isEmpty() && clientIds.contains(candidate.clientId)) {
|
||||||
|
neededClientIds << candidate.clientId;
|
||||||
|
} else if (candidateHistoricClientId.contains(candidate.name)) {
|
||||||
|
neededClientIds << candidateHistoricClientId.value(candidate.name);
|
||||||
|
} else if (candidateIp.contains(candidate.name)) {
|
||||||
|
neededIps << candidateIp.value(candidate.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!neededEmails.isEmpty()) {
|
||||||
|
const QList<QString> neededEmailList = neededEmails.values();
|
||||||
|
QSqlQuery *countQuery = prepareQuery(QStringLiteral("SELECT email, COUNT(*) FROM {prefix}_users WHERE "
|
||||||
|
"email IN ") +
|
||||||
|
altInClause(QStringLiteral(":alt_ce"), neededEmailList) +
|
||||||
|
QStringLiteral(" GROUP BY email"));
|
||||||
|
altBindValues(countQuery, QStringLiteral(":alt_ce"), neededEmailList);
|
||||||
|
if (execSqlQuery(countQuery)) {
|
||||||
|
while (countQuery->next()) {
|
||||||
|
emailCounts.insert(countQuery->value(0).toString(), countQuery->value(1).toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!neededClientIds.isEmpty()) {
|
||||||
|
const QList<QString> neededClientIdList = neededClientIds.values();
|
||||||
|
QSqlQuery *countQuery = prepareQuery(QStringLiteral("SELECT clientid, COUNT(*) FROM {prefix}_users WHERE "
|
||||||
|
"clientid IN ") +
|
||||||
|
altInClause(QStringLiteral(":alt_cc"), neededClientIdList) +
|
||||||
|
QStringLiteral(" GROUP BY clientid"));
|
||||||
|
altBindValues(countQuery, QStringLiteral(":alt_cc"), neededClientIdList);
|
||||||
|
if (execSqlQuery(countQuery)) {
|
||||||
|
while (countQuery->next()) {
|
||||||
|
clientIdCounts.insert(countQuery->value(0).toString(), countQuery->value(1).toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!neededIps.isEmpty()) {
|
||||||
|
const QList<QString> neededIpList = neededIps.values();
|
||||||
|
QSqlQuery *countQuery = prepareQuery(
|
||||||
|
QStringLiteral("SELECT ip_address, COUNT(DISTINCT user_name) FROM {prefix}_sessions WHERE "
|
||||||
|
"ip_address IN ") +
|
||||||
|
altInClause(QStringLiteral(":alt_ci"), neededIpList) +
|
||||||
|
QStringLiteral(" AND start_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH) GROUP BY ip_address"));
|
||||||
|
altBindValues(countQuery, QStringLiteral(":alt_ci"), neededIpList);
|
||||||
|
if (execSqlQuery(countQuery)) {
|
||||||
|
while (countQuery->next()) {
|
||||||
|
ipCounts.insert(countQuery->value(0).toString(), countQuery->value(1).toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QString> nextFrontier;
|
||||||
|
for (const AltCandidate &candidate : candidates) {
|
||||||
|
QString matchReason;
|
||||||
|
int sharedCount = 1;
|
||||||
|
if (!candidate.email.isEmpty() && emails.contains(candidate.email)) {
|
||||||
|
matchReason = QStringLiteral("email");
|
||||||
|
sharedCount = qMax(1, emailCounts.value(candidate.email, 1));
|
||||||
|
} else if (!candidate.clientId.isEmpty() && clientIds.contains(candidate.clientId)) {
|
||||||
|
matchReason = QStringLiteral("clientid:") + candidate.clientId;
|
||||||
|
sharedCount = qMax(1, clientIdCounts.value(candidate.clientId, 1));
|
||||||
|
} else if (candidateHistoricClientId.contains(candidate.name)) {
|
||||||
|
const QString historicId = candidateHistoricClientId.value(candidate.name);
|
||||||
|
matchReason = QStringLiteral("clientid:") + historicId;
|
||||||
|
sharedCount = qMax(1, clientIdCounts.value(historicId, 1));
|
||||||
|
} else if (candidateIp.contains(candidate.name)) {
|
||||||
|
const QString ip = candidateIp.value(candidate.name);
|
||||||
|
matchReason = QStringLiteral("ip:") + ip;
|
||||||
|
sharedCount = qMax(1, ipCounts.value(ip, 1));
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
appendAlt(candidate, matchReason, level, sharedCount);
|
||||||
|
visited.insert(candidate.name);
|
||||||
|
nextFrontier << candidate.name;
|
||||||
|
}
|
||||||
|
frontier = nextFrontier;
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ public:
|
||||||
int &range,
|
int &range,
|
||||||
int &maxresults);
|
int &maxresults);
|
||||||
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);
|
QList<ServerInfo_UserAlt> getUserAlts(const QString &userName, int depth = 1);
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -2565,7 +2565,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetUserAlts(const Comma
|
||||||
}
|
}
|
||||||
|
|
||||||
Response_UserAlts *re = new Response_UserAlts;
|
Response_UserAlts *re = new Response_UserAlts;
|
||||||
const QList<ServerInfo_UserAlt> alts = sqlInterface->getUserAlts(userName);
|
const int depth = cmd.has_depth() ? static_cast<int>(cmd.depth()) : 1;
|
||||||
|
const QList<ServerInfo_UserAlt> alts = sqlInterface->getUserAlts(userName, depth);
|
||||||
for (const ServerInfo_UserAlt &alt : alts) {
|
for (const ServerInfo_UserAlt &alt : alts) {
|
||||||
re->add_alts()->CopyFrom(alt);
|
re->add_alts()->CopyFrom(alt);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue