mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[Server/Client/Protocol] Add developer staff role
Introduce a Developer staff level (proto flag 32, DB admin bit 8) that sits between admin and moderator: no kick/ban/warn/report/admin powers, but gets server log access via a new developer command container family (GET_SERVER_STATS, VIEWLOG_HISTORY) and an idle-timeout exemption. - Protocol: IsDeveloper flag, developer_commands.proto envelope, Command_GetServerStats/Command_GetLogHistory, Response_GetServerStats, Command_AdjustMod.should_be_developer - Servatrice: fail-closed developer dispatcher, uptime snapshot handler, shared log history handler reuse, bit-8 DB mapping - Client: burgundy pawn/badge/labels/sort order, prepareDeveloperCommand, minimal Developer stats tab, log tab access, promote/demote actions Took 24 minutes Took 18 seconds
This commit is contained in:
parent
7d867b9745
commit
1ff7ffcaa4
31 changed files with 515 additions and 23 deletions
|
|
@ -382,6 +382,7 @@ set(cockatrice_SOURCES
|
|||
src/interface/widgets/tabs/tab_card_art_rules.cpp
|
||||
src/interface/widgets/tabs/tab_deck_editor.cpp
|
||||
src/interface/widgets/tabs/tab_deck_storage.cpp
|
||||
src/interface/widgets/tabs/tab_developer.cpp
|
||||
src/interface/widgets/tabs/tab_game.cpp
|
||||
src/interface/widgets/tabs/tab_home.cpp
|
||||
src/interface/widgets/tabs/tab_logs.cpp
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#define DEFAULT_COLOR_MODERATOR_LEFT "#ffffff";
|
||||
#define DEFAULT_COLOR_MODERATOR_RIGHT "#000000";
|
||||
#define DEFAULT_COLOR_ADMIN "#ff2701";
|
||||
#define DEFAULT_COLOR_DEVELOPER "#800020"
|
||||
|
||||
/**
|
||||
* Clamps an svg render size so that rendering does not exceed a multiple of the requested size.
|
||||
|
|
@ -359,6 +360,8 @@ QIcon UserLevelPixmapGenerator::generateIconDefault(int height,
|
|||
|
||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin)) {
|
||||
colorLeft = DEFAULT_COLOR_ADMIN;
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsDeveloper)) {
|
||||
colorLeft = DEFAULT_COLOR_DEVELOPER;
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsModerator)) {
|
||||
colorLeft = DEFAULT_COLOR_MODERATOR_LEFT;
|
||||
colorRight = DEFAULT_COLOR_MODERATOR_RIGHT;
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ UserContextMenu::UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *parent,
|
|||
aDemoteFromMod = new QAction(QString(), this);
|
||||
aPromoteToJudge = new QAction(QString(), this);
|
||||
aDemoteFromJudge = new QAction(QString(), this);
|
||||
aPromoteToDeveloper = new QAction(QString(), this);
|
||||
aDemoteFromDeveloper = new QAction(QString(), this);
|
||||
aGetAdminNotes = new QAction(QString(), this);
|
||||
aInvestigateUser = new QAction(QString(), this);
|
||||
|
||||
|
|
@ -76,6 +78,8 @@ void UserContextMenu::retranslateUi()
|
|||
aDemoteFromMod->setText(tr("Dem&ote user from moderator"));
|
||||
aPromoteToJudge->setText(tr("Promote user to &judge"));
|
||||
aDemoteFromJudge->setText(tr("Demote user from judge"));
|
||||
aPromoteToDeveloper->setText(tr("Promote user to &developer"));
|
||||
aDemoteFromDeveloper->setText(tr("Demote user from de&veloper"));
|
||||
aGetAdminNotes->setText(tr("View admin notes"));
|
||||
aInvestigateUser->setText(tr("Investigate user"));
|
||||
}
|
||||
|
|
@ -268,7 +272,7 @@ void UserContextMenu::adjustMod_processUserResponse(const Response &resp, const
|
|||
const Command_AdjustMod &cmd = commandContainer.admin_command(0).GetExtension(Command_AdjustMod::ext);
|
||||
|
||||
if (resp.response_code() == Response::RespOk) {
|
||||
if (cmd.should_be_mod() || cmd.should_be_judge()) {
|
||||
if (cmd.should_be_mod() || cmd.should_be_judge() || cmd.should_be_developer()) {
|
||||
QMessageBox::information(static_cast<QWidget *>(parent()), tr("Success"),
|
||||
tr("Successfully promoted user."));
|
||||
} else {
|
||||
|
|
@ -276,7 +280,7 @@ void UserContextMenu::adjustMod_processUserResponse(const Response &resp, const
|
|||
}
|
||||
|
||||
} else {
|
||||
if (cmd.should_be_mod() || cmd.should_be_judge()) {
|
||||
if (cmd.should_be_mod() || cmd.should_be_judge() || cmd.should_be_developer()) {
|
||||
QMessageBox::information(static_cast<QWidget *>(parent()), tr("Failed"), tr("Failed to promote user."));
|
||||
} else {
|
||||
QMessageBox::information(static_cast<QWidget *>(parent()), tr("Failed"), tr("Failed to demote user."));
|
||||
|
|
@ -437,6 +441,15 @@ void UserContextMenu::showContextMenu(const QPoint &pos,
|
|||
(tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsAdmin)) {
|
||||
menu->addAction(aPromoteToJudge);
|
||||
}
|
||||
|
||||
if (userLevel.testFlag(ServerInfo_User::IsDeveloper) &&
|
||||
(tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsAdmin)) {
|
||||
menu->addAction(aDemoteFromDeveloper);
|
||||
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsRegistered) &&
|
||||
(tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsAdmin)) {
|
||||
menu->addAction(aPromoteToDeveloper);
|
||||
}
|
||||
}
|
||||
aDetails->setEnabled(true);
|
||||
aChat->setEnabled(anotherUser && online && !userListProxy->isUserIgnored(userName));
|
||||
|
|
@ -455,6 +468,10 @@ void UserContextMenu::showContextMenu(const QPoint &pos,
|
|||
aInvestigateUser->setEnabled(anotherUser);
|
||||
aPromoteToMod->setEnabled(anotherUser);
|
||||
aDemoteFromMod->setEnabled(anotherUser);
|
||||
aPromoteToJudge->setEnabled(anotherUser);
|
||||
aDemoteFromJudge->setEnabled(anotherUser);
|
||||
aPromoteToDeveloper->setEnabled(anotherUser);
|
||||
aDemoteFromDeveloper->setEnabled(anotherUser);
|
||||
|
||||
QAction *actionClicked = menu->exec(pos);
|
||||
if (actionClicked == nullptr) {
|
||||
|
|
@ -489,6 +506,8 @@ void UserContextMenu::showContextMenu(const QPoint &pos,
|
|||
execAdjustMod(userName, actionClicked == aPromoteToMod);
|
||||
} else if (actionClicked == aPromoteToJudge || actionClicked == aDemoteFromJudge) {
|
||||
execAdjustJudge(userName, actionClicked == aPromoteToJudge);
|
||||
} else if (actionClicked == aPromoteToDeveloper || actionClicked == aDemoteFromDeveloper) {
|
||||
execAdjustDeveloper(userName, actionClicked == aPromoteToDeveloper);
|
||||
} else if (actionClicked == aBanHistory) {
|
||||
execBanHistory(userName);
|
||||
} else if (actionClicked == aWarnUser) {
|
||||
|
|
@ -706,4 +725,14 @@ void UserContextMenu::execAdjustJudge(const QString &userName, bool shouldBeJudg
|
|||
PendingCommand *pend = client->prepareAdminCommand(cmd);
|
||||
connect(pend, &PendingCommand::finished, this, &UserContextMenu::adjustMod_processUserResponse);
|
||||
client->sendCommand(pend);
|
||||
}
|
||||
|
||||
void UserContextMenu::execAdjustDeveloper(const QString &userName, bool shouldBeDeveloper)
|
||||
{
|
||||
Command_AdjustMod cmd;
|
||||
cmd.set_user_name(userName.toStdString());
|
||||
cmd.set_should_be_developer(shouldBeDeveloper);
|
||||
PendingCommand *pend = client->prepareAdminCommand(cmd);
|
||||
connect(pend, &PendingCommand::finished, this, &UserContextMenu::adjustMod_processUserResponse);
|
||||
client->sendCommand(pend);
|
||||
}
|
||||
|
|
@ -45,6 +45,7 @@ private:
|
|||
QAction *aBan, *aBanHistory;
|
||||
QAction *aPromoteToMod, *aDemoteFromMod;
|
||||
QAction *aPromoteToJudge, *aDemoteFromJudge;
|
||||
QAction *aPromoteToDeveloper, *aDemoteFromDeveloper;
|
||||
QAction *aWarnUser, *aWarnHistory;
|
||||
QAction *aGetAdminNotes;
|
||||
std::function<QList<GameInviteOption>()> gameInviteLinkProvider;
|
||||
|
|
@ -123,6 +124,7 @@ public:
|
|||
void execInvestigateUser(const QString &userName);
|
||||
void execAdjustMod(const QString &userName, bool shouldBeMod);
|
||||
void execAdjustJudge(const QString &userName, bool shouldBeJudge);
|
||||
void execAdjustDeveloper(const QString &userName, bool shouldBeDeveloper);
|
||||
|
||||
private:
|
||||
void execInvite(const QString &userName, const GameInviteOption &option);
|
||||
|
|
|
|||
|
|
@ -122,6 +122,8 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
|||
QString userLevelText;
|
||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin)) {
|
||||
userLevelText = tr("Administrator");
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsDeveloper)) {
|
||||
userLevelText = tr("Developer");
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsModerator)) {
|
||||
userLevelText = tr("Moderator");
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsRegistered)) {
|
||||
|
|
|
|||
|
|
@ -245,6 +245,9 @@ void UserInfoHeaderWidget::paintEvent(QPaintEvent *)
|
|||
if (level.testFlag(ServerInfo_User::IsAdmin)) {
|
||||
return QColor(245, 158, 11);
|
||||
}
|
||||
if (level.testFlag(ServerInfo_User::IsDeveloper)) {
|
||||
return QColor(185, 28, 28);
|
||||
}
|
||||
if (level.testFlag(ServerInfo_User::IsModerator)) {
|
||||
return QColor(59, 130, 246);
|
||||
}
|
||||
|
|
@ -300,6 +303,8 @@ void UserInfoHeaderWidget::paintEvent(QPaintEvent *)
|
|||
} badge;
|
||||
if (level.testFlag(ServerInfo_User::IsAdmin)) {
|
||||
badge = {"ADMIN", QColor(245, 158, 11)};
|
||||
} else if (level.testFlag(ServerInfo_User::IsDeveloper)) {
|
||||
badge = {"DEV", QColor(185, 28, 28)};
|
||||
} else if (level.testFlag(ServerInfo_User::IsModerator)) {
|
||||
badge = {"MOD", QColor(59, 130, 246)};
|
||||
} else if (level.testFlag(ServerInfo_User::IsJudge)) {
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ QColor UserListPainter::getAccentColor(const UserLevelFlags &userLevel, bool onl
|
|||
|
||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin)) {
|
||||
accentColor = QColor(245, 158, 11);
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsDeveloper)) {
|
||||
accentColor = QColor(185, 28, 28);
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsModerator)) {
|
||||
accentColor = QColor(59, 130, 246);
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsJudge)) {
|
||||
|
|
@ -299,6 +301,8 @@ QList<UserListPainter::Badge> UserListPainter::buildBadges(const UserLevelFlags
|
|||
|
||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin)) {
|
||||
badges << Badge{"ADMIN", QColor(245, 158, 11)};
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsDeveloper)) {
|
||||
badges << Badge{"DEV", QColor(185, 28, 28)};
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsModerator)) {
|
||||
badges << Badge{"MOD", QColor(59, 130, 246)};
|
||||
} else if (userLevel.testFlag(ServerInfo_User::IsJudge)) {
|
||||
|
|
@ -385,9 +389,9 @@ void UserListPainter::paint(QPainter *painter,
|
|||
const QString userName = QString::fromStdString(userInfo.name());
|
||||
const QString privLevel = QString::fromStdString(userInfo.privlevel());
|
||||
const QColor accentColor = getAccentColor(userLevel, online);
|
||||
const bool hasRole = userLevel.testFlag(ServerInfo_User::IsAdmin) ||
|
||||
userLevel.testFlag(ServerInfo_User::IsModerator) ||
|
||||
userLevel.testFlag(ServerInfo_User::IsJudge);
|
||||
const bool hasRole =
|
||||
userLevel.testFlag(ServerInfo_User::IsAdmin) || userLevel.testFlag(ServerInfo_User::IsDeveloper) ||
|
||||
userLevel.testFlag(ServerInfo_User::IsModerator) || userLevel.testFlag(ServerInfo_User::IsJudge);
|
||||
const QRectF cardRect = QRectF(rect).adjusted(3, 2, -3, -2);
|
||||
const int cardRight = getCardRight(option, rect);
|
||||
|
||||
|
|
|
|||
|
|
@ -234,9 +234,11 @@ bool UserListTWI::operator<(const QTreeWidgetItem &other) const
|
|||
const auto &lhsUserLevelFlags = UserLevelFlags(data(0, Qt::UserRole).toInt());
|
||||
const auto &rhsUserLevelFlags = UserLevelFlags(other.data(0, Qt::UserRole).toInt());
|
||||
|
||||
// Admins & Mods need no additional comparison checks, just to see if they're an admin or a moderator
|
||||
// Admins, Developers & Mods need no additional comparison checks, just to see if they're an admin, a developer
|
||||
// or a moderator
|
||||
static const QList<ServerInfo_User_UserLevelFlag> userLevelWithNoOtherPrefOrder = {
|
||||
ServerInfo_User_UserLevelFlag_IsAdmin, ServerInfo_User_UserLevelFlag_IsModerator};
|
||||
ServerInfo_User_UserLevelFlag_IsAdmin, ServerInfo_User_UserLevelFlag_IsDeveloper,
|
||||
ServerInfo_User_UserLevelFlag_IsModerator};
|
||||
for (const auto &userLevelEntry : userLevelWithNoOtherPrefOrder) {
|
||||
if (lhsUserLevelFlags.testFlag(userLevelEntry) &&
|
||||
lhsUserLevelFlags.testFlag(userLevelEntry) == rhsUserLevelFlags.testFlag(userLevelEntry)) {
|
||||
|
|
|
|||
122
cockatrice/src/interface/widgets/tabs/tab_developer.cpp
Normal file
122
cockatrice/src/interface/widgets/tabs/tab_developer.cpp
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/**
|
||||
* @file tab_developer.cpp
|
||||
* @ingroup ServerTabs
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#include "tab_developer.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <libcockatrice/network/client/abstract/abstract_client.h>
|
||||
#include <libcockatrice/protocol/pb/command_get_server_stats.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_get_server_stats.pb.h>
|
||||
#include <libcockatrice/protocol/pending_command.h>
|
||||
|
||||
TabDeveloper::TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_client)
|
||||
: Tab(_tabSupervisor), client(_client)
|
||||
{
|
||||
statsTable = new QTableWidget(0, 2);
|
||||
statsTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
statsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
statsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
statsTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
statsTable->horizontalHeader()->setStretchLastSection(true);
|
||||
statsTable->verticalHeader()->setVisible(false);
|
||||
|
||||
statusLabel = new QLabel;
|
||||
|
||||
refreshButton = new QPushButton;
|
||||
refreshButton->setAutoDefault(true);
|
||||
connect(refreshButton, &QPushButton::clicked, this, &TabDeveloper::refreshClicked);
|
||||
|
||||
auto *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addWidget(statusLabel, 1, Qt::AlignLeft);
|
||||
buttonLayout->addWidget(refreshButton, 0, Qt::AlignRight);
|
||||
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(statsTable);
|
||||
mainLayout->addLayout(buttonLayout);
|
||||
|
||||
auto *central = new QWidget;
|
||||
central->setLayout(mainLayout);
|
||||
setCentralWidget(central);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void TabDeveloper::retranslateUi()
|
||||
{
|
||||
refreshButton->setText(tr("Refresh server stats"));
|
||||
statsTable->setHorizontalHeaderLabels(QString(tr("Statistic;Value")).split(";"));
|
||||
if (statsTable->rowCount() == 0) {
|
||||
statusLabel->clear();
|
||||
}
|
||||
}
|
||||
|
||||
QString TabDeveloper::formatBytes(quint64 bytes)
|
||||
{
|
||||
const quint64 kib = 1024;
|
||||
const quint64 mib = 1024 * kib;
|
||||
const quint64 gib = 1024 * mib;
|
||||
if (bytes >= gib) {
|
||||
return tr("%1 GiB").arg(QString::number(bytes / static_cast<double>(gib), 'f', 2));
|
||||
}
|
||||
if (bytes >= mib) {
|
||||
return tr("%1 MiB").arg(QString::number(bytes / static_cast<double>(mib), 'f', 2));
|
||||
}
|
||||
if (bytes >= kib) {
|
||||
return tr("%1 KiB").arg(QString::number(bytes / static_cast<double>(kib), 'f', 2));
|
||||
}
|
||||
return tr("%1 bytes").arg(bytes);
|
||||
}
|
||||
|
||||
void TabDeveloper::appendStatRow(const QString &name, const QString &value)
|
||||
{
|
||||
const int row = statsTable->rowCount();
|
||||
statsTable->insertRow(row);
|
||||
statsTable->setItem(row, 0, new QTableWidgetItem(name));
|
||||
statsTable->setItem(row, 1, new QTableWidgetItem(value));
|
||||
}
|
||||
|
||||
void TabDeveloper::refreshClicked()
|
||||
{
|
||||
Command_GetServerStats cmd;
|
||||
PendingCommand *pend = client->prepareDeveloperCommand(cmd);
|
||||
connect(pend, &PendingCommand::finished, this, &TabDeveloper::serverStatsResponse);
|
||||
client->sendCommand(pend);
|
||||
}
|
||||
|
||||
void TabDeveloper::serverStatsResponse(const Response &resp)
|
||||
{
|
||||
if (resp.response_code() != Response::RespOk) {
|
||||
statusLabel->setText(tr("Failed to collect server statistics."));
|
||||
return;
|
||||
}
|
||||
|
||||
const Response_GetServerStats &response = resp.GetExtension(Response_GetServerStats::ext);
|
||||
|
||||
statsTable->setRowCount(0);
|
||||
appendStatRow(tr("Registered users online"), QString::number(response.users_count()));
|
||||
appendStatRow(tr("Moderators online"), QString::number(response.mods_count()));
|
||||
appendStatRow(tr("Games running"), QString::number(response.games_count()));
|
||||
appendStatRow(tr("Traffic sent (last tick)"), formatBytes(response.tx_bytes()));
|
||||
appendStatRow(tr("Traffic received (last tick)"), formatBytes(response.rx_bytes()));
|
||||
|
||||
const qint64 uptime = static_cast<qint64>(response.uptime_secs());
|
||||
const int days = static_cast<int>(uptime / 86400);
|
||||
const int hours = static_cast<int>((uptime % 86400) / 3600);
|
||||
const int minutes = static_cast<int>((uptime % 3600) / 60);
|
||||
appendStatRow(tr("Server uptime"), days > 0 ? tr("%1d %2h %3m").arg(days).arg(hours).arg(minutes)
|
||||
: tr("%1h %2m").arg(hours).arg(minutes));
|
||||
|
||||
const QDateTime snapshotTime = QDateTime::fromSecsSinceEpoch(static_cast<qint64>(response.timest()));
|
||||
appendStatRow(tr("Snapshot taken"), snapshotTime.toLocalTime().toString("yyyy-MM-dd HH:mm"));
|
||||
|
||||
statsTable->resizeColumnsToContents();
|
||||
statusLabel->setText(tr("Updated %1").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm")));
|
||||
}
|
||||
43
cockatrice/src/interface/widgets/tabs/tab_developer.h
Normal file
43
cockatrice/src/interface/widgets/tabs/tab_developer.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* @file tab_developer.h
|
||||
* @ingroup ServerTabs
|
||||
*/
|
||||
//! \todo Document this file.
|
||||
|
||||
#ifndef TAB_DEVELOPER_H
|
||||
#define TAB_DEVELOPER_H
|
||||
|
||||
#include "tab.h"
|
||||
|
||||
class AbstractClient;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QTableWidget;
|
||||
class Response;
|
||||
|
||||
class TabDeveloper : public Tab
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
AbstractClient *client;
|
||||
QTableWidget *statsTable;
|
||||
QPushButton *refreshButton;
|
||||
QLabel *statusLabel;
|
||||
|
||||
void appendStatRow(const QString &name, const QString &value);
|
||||
static QString formatBytes(quint64 bytes);
|
||||
|
||||
private slots:
|
||||
void refreshClicked();
|
||||
void serverStatsResponse(const Response &resp);
|
||||
|
||||
public:
|
||||
explicit TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
||||
void retranslateUi() override;
|
||||
[[nodiscard]] QString getTabText() const override
|
||||
{
|
||||
return tr("Developer");
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -14,12 +14,14 @@
|
|||
#include <QTabWidget>
|
||||
#include <QTableWidget>
|
||||
#include <libcockatrice/network/client/abstract/abstract_client.h>
|
||||
#include <libcockatrice/protocol/pb/command_get_log_history.pb.h>
|
||||
#include <libcockatrice/protocol/pb/moderator_commands.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_viewlog_history.pb.h>
|
||||
#include <libcockatrice/protocol/pending_command.h>
|
||||
#include <libcockatrice/utility/string_limits.h>
|
||||
|
||||
TabLog::TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client) : Tab(_tabSupervisor), client(_client)
|
||||
TabLog::TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client, bool _canUseDeveloperCommands)
|
||||
: Tab(_tabSupervisor), client(_client), canUseDeveloperCommands(_canUseDeveloperCommands)
|
||||
{
|
||||
roomTable = new QTableWidget();
|
||||
roomTable->setColumnCount(6);
|
||||
|
|
@ -117,7 +119,26 @@ void TabLog::getClicked()
|
|||
};
|
||||
cmd.set_date_range(dateRange);
|
||||
cmd.set_maximum_results(maximumResults->value());
|
||||
PendingCommand *pend = client->prepareModeratorCommand(cmd);
|
||||
|
||||
PendingCommand *pend;
|
||||
if (canUseDeveloperCommands) {
|
||||
// Developers query logs through the developer command family.
|
||||
Command_GetLogHistory devCmd;
|
||||
devCmd.set_user_name(cmd.user_name());
|
||||
devCmd.set_ip_address(cmd.ip_address());
|
||||
devCmd.set_game_name(cmd.game_name());
|
||||
devCmd.set_game_id(cmd.game_id());
|
||||
devCmd.set_message(cmd.message());
|
||||
for (int i = 0; i < cmd.log_location_size(); ++i) {
|
||||
devCmd.add_log_location(cmd.log_location(i));
|
||||
}
|
||||
devCmd.set_date_range(cmd.date_range());
|
||||
devCmd.set_maximum_results(cmd.maximum_results());
|
||||
pend = client->prepareDeveloperCommand(devCmd);
|
||||
} else {
|
||||
pend = client->prepareModeratorCommand(cmd);
|
||||
}
|
||||
|
||||
connect(pend, &PendingCommand::finished, this, &TabLog::viewLogHistory_processResponse);
|
||||
client->sendCommand(pend);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ class TabLog : public Tab
|
|||
Q_OBJECT
|
||||
private:
|
||||
AbstractClient *client;
|
||||
bool canUseDeveloperCommands;
|
||||
QLabel *labelFindUserName, *labelFindIPAddress, *labelFindGameName, *labelFindGameID, *labelMessage, *labelMaximum,
|
||||
*labelDescription;
|
||||
LineEditUnfocusable *findUsername, *findIPAddress, *findGameName, *findGameID, *findMessage;
|
||||
|
|
@ -58,7 +59,7 @@ private slots:
|
|||
void restartLayout();
|
||||
|
||||
public:
|
||||
TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
||||
TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client, bool _canUseDeveloperCommands = false);
|
||||
~TabLog() override;
|
||||
void retranslateUi() override;
|
||||
[[nodiscard]] QString getTabText() const override
|
||||
|
|
|
|||
|
|
@ -381,6 +381,9 @@ void TabModeration::moderatorLoginsResponse(const Response &response)
|
|||
if (login.user_level() & ServerInfo_User::IsAdmin) {
|
||||
levels << tr("Admin");
|
||||
}
|
||||
if (login.user_level() & ServerInfo_User::IsDeveloper) {
|
||||
levels << tr("Developer");
|
||||
}
|
||||
if (login.user_level() & ServerInfo_User::IsModerator) {
|
||||
levels << tr("Moderator");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include "tab_card_art_rules.h"
|
||||
#include "tab_deck_editor.h"
|
||||
#include "tab_deck_storage.h"
|
||||
#include "tab_developer.h"
|
||||
#include "tab_game.h"
|
||||
#include "tab_home.h"
|
||||
#include "tab_logs.h"
|
||||
|
|
@ -116,10 +117,10 @@ void CloseButton::paintEvent(QPaintEvent * /*event*/)
|
|||
}
|
||||
|
||||
TabSupervisor::TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *parent)
|
||||
: 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),
|
||||
tabReplays(nullptr), tabAdmin(nullptr), tabCardArtRules(nullptr), tabLog(nullptr), tabReport(nullptr),
|
||||
tabModeration(nullptr), isLocalGame(false)
|
||||
tabModeration(nullptr), tabDeveloper(nullptr), isLocalGame(false)
|
||||
{
|
||||
setElideMode(Qt::ElideRight);
|
||||
setMovable(true);
|
||||
|
|
@ -205,6 +206,10 @@ TabSupervisor::TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *
|
|||
aTabModeration->setCheckable(true);
|
||||
connect(aTabModeration, &QAction::triggered, this, &TabSupervisor::actTabModeration);
|
||||
|
||||
aTabDeveloper = new QAction(this);
|
||||
aTabDeveloper->setCheckable(true);
|
||||
connect(aTabDeveloper, &QAction::triggered, this, &TabSupervisor::actTabDeveloper);
|
||||
|
||||
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
||||
&TabSupervisor::refreshShortcuts);
|
||||
refreshShortcuts();
|
||||
|
|
@ -246,7 +251,8 @@ void TabSupervisor::retranslateUi()
|
|||
aTabLog->setText(tr("Logs"));
|
||||
aTabReport->setText(tr("Report Queue"));
|
||||
aTabModeration->setText(tr("Moderation"));
|
||||
aTabCardArtRules->setText(tr("Card Art Rules"));
|
||||
aTabCardArtRules->setText(tr("Card Art Rules"));
|
||||
aTabDeveloper->setText(tr("Developer"));
|
||||
|
||||
// tabs
|
||||
QList<Tab *> tabs;
|
||||
|
|
@ -258,7 +264,8 @@ void TabSupervisor::retranslateUi()
|
|||
tabs.append(tabLog);
|
||||
tabs.append(tabReport);
|
||||
tabs.append(tabModeration);
|
||||
tabs.append(tabCardArtRules);
|
||||
tabs.append(tabCardArtRules);
|
||||
tabs.append(tabDeveloper);
|
||||
QMapIterator<int, TabRoom *> roomIterator(roomTabs);
|
||||
while (roomIterator.hasNext()) {
|
||||
tabs.append(roomIterator.next().value());
|
||||
|
|
@ -528,6 +535,19 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
|||
}
|
||||
}
|
||||
|
||||
if (userInfo->user_level() & ServerInfo_User::IsDeveloper) {
|
||||
tabsMenu->addSeparator();
|
||||
tabsMenu->addAction(aTabDeveloper);
|
||||
// Developers without moderation rights get log access through their
|
||||
// own role. Moderators already have the Logs entry from above.
|
||||
if (!(userInfo->user_level() & ServerInfo_User::IsModerator)) {
|
||||
tabsMenu->addAction(aTabLog);
|
||||
if (SettingsCache::instance().tabs().getTabLogOpen()) {
|
||||
openTabLog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
|
|
@ -540,6 +560,7 @@ void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
|
|||
tabLog = nullptr;
|
||||
tabReport = nullptr;
|
||||
tabModeration = nullptr;
|
||||
tabDeveloper = nullptr;
|
||||
isLocalGame = true;
|
||||
userInfo = new ServerInfo_User;
|
||||
localClients = _clients;
|
||||
|
|
@ -587,9 +608,13 @@ void TabSupervisor::stop()
|
|||
if (tabModeration) {
|
||||
tabModeration->close();
|
||||
}
|
||||
if (tabCardArtRules) {
|
||||
if (tabCardArtRules) {
|
||||
tabCardArtRules->close();
|
||||
}
|
||||
if (tabDeveloper) {
|
||||
tabDeveloper->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<Tab *> tabsToDelete;
|
||||
|
|
@ -819,7 +844,10 @@ void TabSupervisor::actTabLog(bool checked)
|
|||
|
||||
void TabSupervisor::openTabLog()
|
||||
{
|
||||
tabLog = new TabLog(this, client);
|
||||
// Developers without moderation rights query logs through the developer
|
||||
// command family, so tell the tab which family to use.
|
||||
const bool isDeveloper = (userInfo->user_level() & ServerInfo_User::IsDeveloper) != 0;
|
||||
tabLog = new TabLog(this, client, isDeveloper);
|
||||
myAddTab(tabLog, aTabLog);
|
||||
connect(tabLog, &QObject::destroyed, this, [this] {
|
||||
tabLog = nullptr;
|
||||
|
|
@ -881,6 +909,27 @@ void TabSupervisor::openTabModeration(const QString &userName)
|
|||
aTabModeration->setChecked(true);
|
||||
}
|
||||
|
||||
void TabSupervisor::actTabDeveloper(bool checked)
|
||||
{
|
||||
if (checked && !tabDeveloper) {
|
||||
openTabDeveloper();
|
||||
setCurrentWidget(tabDeveloper);
|
||||
} else if (!checked && tabDeveloper) {
|
||||
tabDeveloper->closeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
void TabSupervisor::openTabDeveloper()
|
||||
{
|
||||
tabDeveloper = new TabDeveloper(this, client);
|
||||
myAddTab(tabDeveloper, aTabDeveloper);
|
||||
connect(tabDeveloper, &QObject::destroyed, this, [this] {
|
||||
tabDeveloper = nullptr;
|
||||
aTabDeveloper->setChecked(false);
|
||||
});
|
||||
aTabDeveloper->setChecked(true);
|
||||
}
|
||||
|
||||
void TabSupervisor::updatePingTime(int value, int max)
|
||||
{
|
||||
if (!tabServer) {
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class TabReport;
|
|||
class TabModeration;
|
||||
class TabAccount;
|
||||
class TabDeckEditor;
|
||||
class TabDeveloper;
|
||||
class TabLog;
|
||||
class RoomEvent;
|
||||
class GameEventContainer;
|
||||
|
|
@ -108,6 +109,7 @@ private:
|
|||
TabLog *tabLog;
|
||||
TabReport *tabReport;
|
||||
TabModeration *tabModeration;
|
||||
TabDeveloper *tabDeveloper;
|
||||
QMap<int, TabRoom *> roomTabs;
|
||||
QMap<int, TabGame *> gameTabs;
|
||||
QList<TabGame *> replayTabs;
|
||||
|
|
@ -117,7 +119,7 @@ private:
|
|||
|
||||
QAction *aTabHome, *aTabDeckEditor, *aTabVisualDeckEditor, *aTabEdhRec, *aTabArchidekt, *aTabVisualDeckStorage,
|
||||
*aTabVisualDatabaseDisplay, *aTabServer, *aTabAccount, *aTabDeckStorage, *aTabReplays, *aTabAdmin,
|
||||
*aTabCardArtRules, *aTabLog, *aTabReport, *aTabModeration;
|
||||
*aTabCardArtRules, *aTabLog, *aTabReport, *aTabModeration, *aTabDeveloper;
|
||||
|
||||
int myAddTab(Tab *tab, QAction *manager = nullptr);
|
||||
void addCloseButtonToTab(Tab *tab, int tabIndex, QAction *manager);
|
||||
|
|
@ -207,6 +209,7 @@ private slots:
|
|||
void actTabLog(bool checked);
|
||||
void actTabReport(bool checked);
|
||||
void actTabModeration(bool checked);
|
||||
void actTabDeveloper(bool checked);
|
||||
|
||||
void openTabVisualDeckStorage();
|
||||
void openTabHome();
|
||||
|
|
@ -218,6 +221,7 @@ private slots:
|
|||
void openTabCardArtRules();
|
||||
void openTabLog();
|
||||
void openTabReport();
|
||||
void openTabDeveloper();
|
||||
|
||||
void updateCurrent(int index);
|
||||
void updatePingTime(int value, int max);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue