mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[Server/Client/Protocol] Add developer staff role (#7211)
* [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 * [Server/Client/Protocol] Address developer role review feedback Address ZeizaZach's review of the developer staff role: - Nudge the developer log query to exclude private chat and sender IPs (the ModeratorCommand path still sees everything). - Deduplicate Command_GetLogHistory into Command_ViewLogHistory, which now extends both ModeratorCommand (ext) and DeveloperCommand (dev_ext); the client picks the DeveloperCommand-scoped extension by extendee, and the server reads it via the extension number. - Pull the uptime snapshot SQL into Servatrice_DatabaseInterface as getLatestUptimeSnapshot() and widen the reported counters to 64-bit. - Document the admin bitfield (1 admin, 2 moderator, 4 judge, 8 developer) and add a server-side test for the developer command path. * Add missing trailing newline to user_context_menu.cpp * Remove stale includes of deleted command_get_log_history proto The Command_GetLogHistory message was folded into Command_ViewLogHistory, which deleted command_get_log_history.proto, but serversocketinterface still #included its generated header. Fresh CI builds fail on the missing file; local builds masked it by reusing a previously generated header. * [Server] Exclude chat rows when private-chat filter is bypassable A developer who omits log_location entirely — or sends only "chat" — leaves chatType, gameType, roomType all false, so getMessageLogHistory skips the target_type clause and returns every row, private messages included. When !allowPrivateChat the server now forces game+room when no surviving location was requested, guaranteeing the query always carries a target_type restriction. [Client] Demote mod+dev to moderator path in log-tab dispatch The developer command family is strictly weaker than the moderator one (no private chat, no sender_ip, ip filter ignored), so granting the developer bit to an existing moderator must not silently strip their capabilities. useDeveloperCommands is now true only when the user holds the developer bit and not the moderator bit. [Client] Hide the IP-address filter for developer log tab users The developer path ignores the ip_address query field server-side. Showing the field lets a developer type an IP and get results that are silently unfiltered by it rather than an empty result set — reads as a broken filter. Hide labelFindIPAddress/findIPAddress alongside the privateChat checkbox. * Developer pawn is silver. * [Client] Fix indentation of merged Card Art Rules / Developer tabs --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
7d867b9745
commit
d5d99e4dfb
35 changed files with 708 additions and 27 deletions
|
|
@ -641,6 +641,10 @@ ServerInfo_User Servatrice_DatabaseInterface::evalUserQueryResult(const QSqlQuer
|
|||
userLevel |= ServerInfo_User::IsJudge;
|
||||
}
|
||||
|
||||
if (is_admin & 8) {
|
||||
userLevel |= ServerInfo_User::IsDeveloper;
|
||||
}
|
||||
|
||||
result.set_user_level(userLevel);
|
||||
|
||||
const QString country = query->value(3).toString();
|
||||
|
|
@ -1448,7 +1452,7 @@ QList<ServerInfo_ModeratorLogin> Servatrice_DatabaseInterface::getModeratorLastL
|
|||
QSqlQuery *query = prepareQuery("SELECT u.name, u.admin, UNIX_TIMESTAMP(a.last_login) "
|
||||
"FROM {prefix}_users u "
|
||||
"LEFT JOIN {prefix}_user_analytics a ON a.id = u.id "
|
||||
"WHERE (u.admin & 7) <> 0 ORDER BY u.name");
|
||||
"WHERE (u.admin & 15) <> 0 ORDER BY u.name");
|
||||
|
||||
if (!execSqlQuery(query)) {
|
||||
qCWarning(DatabaseInterfaceLog) << "Failed to collect moderator login information: SQL Error";
|
||||
|
|
@ -1469,6 +1473,9 @@ QList<ServerInfo_ModeratorLogin> Servatrice_DatabaseInterface::getModeratorLastL
|
|||
if (isAdmin & 4) {
|
||||
userLevel |= ServerInfo_User::IsJudge;
|
||||
}
|
||||
if (isAdmin & 8) {
|
||||
userLevel |= ServerInfo_User::IsDeveloper;
|
||||
}
|
||||
loginDetails.set_user_level(userLevel);
|
||||
|
||||
if (!query->value(2).isNull()) {
|
||||
|
|
@ -1480,6 +1487,38 @@ QList<ServerInfo_ModeratorLogin> Servatrice_DatabaseInterface::getModeratorLastL
|
|||
return results;
|
||||
}
|
||||
|
||||
Servatrice_DatabaseInterface::UptimeSnapshot Servatrice_DatabaseInterface::getLatestUptimeSnapshot(int serverId)
|
||||
{
|
||||
UptimeSnapshot snapshot;
|
||||
|
||||
if (!checkSql()) {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
QSqlQuery *query = prepareQuery("SELECT users_count, mods_count, games_count, tx_bytes, rx_bytes, uptime, "
|
||||
"UNIX_TIMESTAMP(timest) FROM {prefix}_uptime "
|
||||
"WHERE id_server = :id_server ORDER BY timest DESC LIMIT 1");
|
||||
query->bindValue(":id_server", serverId);
|
||||
|
||||
if (!execSqlQuery(query)) {
|
||||
qCWarning(DatabaseInterfaceLog) << "Failed to collect server stats snapshot: SQL Error";
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
if (query->next()) {
|
||||
snapshot.valid = true;
|
||||
snapshot.usersCount = query->value(0).toULongLong();
|
||||
snapshot.modsCount = query->value(1).toULongLong();
|
||||
snapshot.gamesCount = query->value(2).toULongLong();
|
||||
snapshot.txBytes = query->value(3).toULongLong();
|
||||
snapshot.rxBytes = query->value(4).toULongLong();
|
||||
snapshot.uptimeSecs = query->value(5).toULongLong();
|
||||
snapshot.timest = query->value(6).toULongLong();
|
||||
}
|
||||
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
bool Servatrice_DatabaseInterface::removeUserAvatar(const QString &userName)
|
||||
{
|
||||
if (!checkSql()) {
|
||||
|
|
|
|||
|
|
@ -140,6 +140,21 @@ public:
|
|||
QList<ServerInfo_UserSession> getUserSessions(const QString &userName, int limit);
|
||||
QList<ServerInfo_UserAlt> getUserAlts(const QString &userName);
|
||||
QList<ServerInfo_ModeratorLogin> getModeratorLastLogins();
|
||||
|
||||
// Uptime snapshot as recorded by Servatrice::statusUpdate() into the
|
||||
// {prefix}_uptime table. valid is false when no snapshot exists yet.
|
||||
struct UptimeSnapshot
|
||||
{
|
||||
bool valid = false;
|
||||
quint64 usersCount = 0;
|
||||
quint64 modsCount = 0;
|
||||
quint64 gamesCount = 0;
|
||||
quint64 txBytes = 0;
|
||||
quint64 rxBytes = 0;
|
||||
quint64 uptimeSecs = 0;
|
||||
quint64 timest = 0;
|
||||
};
|
||||
UptimeSnapshot getLatestUptimeSnapshot(int serverId);
|
||||
bool removeUserAvatar(const QString &userName);
|
||||
bool addForgotPassword(const QString &user);
|
||||
bool removeForgotPassword(const QString &user) override;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@
|
|||
#include <libcockatrice/protocol/pb/command_deck_list.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_deck_new_dir.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_deck_upload.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_get_server_stats.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_replay_delete_match.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_replay_download.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_replay_download_by_game_id.pb.h>
|
||||
|
|
@ -80,6 +81,7 @@
|
|||
#include <libcockatrice/protocol/pb/response_deck_upload.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_forgotpasswordrequest.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_get_admin_notes.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_get_server_stats.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_moderator_last_logins.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_password_salt.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response_register.pb.h>
|
||||
|
|
@ -284,7 +286,7 @@ Response::ResponseCode AbstractServerSocketInterface::processExtendedModeratorCo
|
|||
case ModeratorCommand::REPORT_RESOLVE:
|
||||
return cmdReportResolve(cmd.GetExtension(Command_ReportResolve::ext), rc);
|
||||
case ModeratorCommand::VIEWLOG_HISTORY:
|
||||
return cmdGetLogHistory(cmd.GetExtension(Command_ViewLogHistory::ext), rc);
|
||||
return cmdGetLogHistory(cmd.GetExtension(Command_ViewLogHistory::ext), rc, true);
|
||||
case ModeratorCommand::GRANT_REPLAY_ACCESS:
|
||||
return cmdGrantReplayAccess(cmd.GetExtension(Command_GrantReplayAccess::ext), rc);
|
||||
case ModeratorCommand::REPLAY_DOWNLOAD_BY_GAME_ID:
|
||||
|
|
@ -337,6 +339,26 @@ AbstractServerSocketInterface::processExtendedAdminCommand(int cmdType, const Ad
|
|||
}
|
||||
}
|
||||
|
||||
// DEVELOPER FUNCTIONS.
|
||||
// Permission is checked by processDeveloperCommandContainer. Only stats-style
|
||||
// queries live here, never community moderation or server administration.
|
||||
Response::ResponseCode AbstractServerSocketInterface::processExtendedDeveloperCommand(int cmdType,
|
||||
const DeveloperCommand &cmd,
|
||||
ResponseContainer &rc)
|
||||
{
|
||||
switch ((DeveloperCommand::DeveloperCommandType)cmdType) {
|
||||
case DeveloperCommand::GET_SERVER_STATS:
|
||||
return cmdGetServerStats(cmd.GetExtension(Command_GetServerStats::ext), rc);
|
||||
case DeveloperCommand::VIEWLOG_HISTORY: {
|
||||
// Same query as the moderator log view, carried by the developer
|
||||
// command family, but narrows out private chats and sender IPs.
|
||||
return cmdGetLogHistory(cmd.GetExtension(Command_ViewLogHistory::dev_ext), rc, false);
|
||||
}
|
||||
default:
|
||||
return Response::RespFunctionNotAllowed;
|
||||
}
|
||||
}
|
||||
|
||||
Response::ResponseCode AbstractServerSocketInterface::cmdAddToList(const Command_AddToList &cmd, ResponseContainer &rc)
|
||||
{
|
||||
if (authState != PasswordRight) {
|
||||
|
|
@ -1020,12 +1042,13 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReplaySubmitCode(const
|
|||
// MODERATOR FUNCTIONS.
|
||||
// May be called by admins and moderators. Permission is checked by the calling function.
|
||||
Response::ResponseCode AbstractServerSocketInterface::cmdGetLogHistory(const Command_ViewLogHistory &cmd,
|
||||
ResponseContainer &rc)
|
||||
ResponseContainer &rc,
|
||||
bool allowPrivateChat)
|
||||
{
|
||||
|
||||
QList<ServerInfo_ChatMessage> messageList;
|
||||
QString userName = nameFromStdString(cmd.user_name());
|
||||
QString ipAddress = nameFromStdString(cmd.ip_address());
|
||||
QString ipAddress = allowPrivateChat ? nameFromStdString(cmd.ip_address()) : QString();
|
||||
QString gameName = nameFromStdString(cmd.game_name());
|
||||
QString gameID = nameFromStdString(cmd.game_id());
|
||||
QString message = textFromStdString(cmd.message());
|
||||
|
|
@ -1040,11 +1063,21 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetLogHistory(const Com
|
|||
if (nameFromStdString(cmd.log_location(i)).simplified() == "game") {
|
||||
gameType = true;
|
||||
}
|
||||
if (nameFromStdString(cmd.log_location(i)).simplified() == "chat") {
|
||||
if (nameFromStdString(cmd.log_location(i)).simplified() == "chat" && allowPrivateChat) {
|
||||
chatType = true;
|
||||
}
|
||||
}
|
||||
|
||||
// For callers that must not see private conversations, never leave the
|
||||
// target-type filter empty: if the request only asked for "chat" (or for
|
||||
// nothing at all) the query below would carry no target_type restriction
|
||||
// and would return every row, private messages included. Fall back to the
|
||||
// game/room diagnostics the caller is allowed to see.
|
||||
if (!allowPrivateChat && !gameType && !roomType) {
|
||||
gameType = true;
|
||||
roomType = true;
|
||||
}
|
||||
|
||||
int dateRange = cmd.date_range();
|
||||
int maximumResults = cmd.maximum_results();
|
||||
|
||||
|
|
@ -1054,7 +1087,11 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetLogHistory(const Com
|
|||
QListIterator<ServerInfo_ChatMessage> messageIterator(sqlInterface->getMessageLogHistory(
|
||||
userName, ipAddress, gameName, gameID, message, chatType, gameType, roomType, dateRange, maximumResults));
|
||||
while (messageIterator.hasNext()) {
|
||||
re->add_log_message()->CopyFrom(messageIterator.next());
|
||||
ServerInfo_ChatMessage chatMessage = messageIterator.next();
|
||||
if (!allowPrivateChat) {
|
||||
chatMessage.clear_sender_ip();
|
||||
}
|
||||
re->add_log_message()->CopyFrom(chatMessage);
|
||||
}
|
||||
} else {
|
||||
ServerInfo_ChatMessage chatMessage;
|
||||
|
|
@ -1643,6 +1680,34 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReportUserInfo(const Co
|
|||
return Response::RespOk;
|
||||
}
|
||||
|
||||
Response::ResponseCode AbstractServerSocketInterface::cmdGetServerStats(const Command_GetServerStats & /*cmd */,
|
||||
ResponseContainer &rc)
|
||||
{
|
||||
if (!sqlInterface->checkSql()) {
|
||||
return Response::RespInternalError;
|
||||
}
|
||||
|
||||
// Servatrice::statusUpdate() periodically snapshots server health into the
|
||||
// uptime table. Serve the freshest snapshot for this server.
|
||||
const auto snapshot = sqlInterface->getLatestUptimeSnapshot(servatrice->getServerID());
|
||||
if (!snapshot.valid) {
|
||||
// No snapshot yet (fresh server, or statusUpdate() has not ticked).
|
||||
return Response::RespInternalError;
|
||||
}
|
||||
|
||||
auto *re = new Response_GetServerStats;
|
||||
re->set_users_count(snapshot.usersCount);
|
||||
re->set_mods_count(snapshot.modsCount);
|
||||
re->set_games_count(snapshot.gamesCount);
|
||||
re->set_tx_bytes(snapshot.txBytes);
|
||||
re->set_rx_bytes(snapshot.rxBytes);
|
||||
re->set_uptime_secs(snapshot.uptimeSecs);
|
||||
re->set_timest(snapshot.timest);
|
||||
|
||||
rc.setResponseExtension(re);
|
||||
return Response::RespOk;
|
||||
}
|
||||
|
||||
Response::ResponseCode AbstractServerSocketInterface::cmdReportStats(const Command_ReportStats & /*cmd */,
|
||||
ResponseContainer &rc)
|
||||
{
|
||||
|
|
@ -3215,7 +3280,7 @@ bool AbstractServerSocketInterface::removeAdminFlagFromUser(const QString &userN
|
|||
if (user) {
|
||||
Event_ConnectionClosed event;
|
||||
event.set_reason(Event_ConnectionClosed::DEMOTED);
|
||||
event.set_reason_str("Your moderator and/or judge status has been revoked.");
|
||||
event.set_reason_str("Your moderator, judge, and/or developer status has been revoked.");
|
||||
event.set_end_time(QDateTime::currentDateTime().toSecsSinceEpoch());
|
||||
|
||||
SessionEvent *se = user->prepareSessionEvent(event);
|
||||
|
|
@ -3257,6 +3322,18 @@ Response::ResponseCode AbstractServerSocketInterface::cmdAdjustMod(const Command
|
|||
}
|
||||
}
|
||||
|
||||
if (cmd.has_should_be_developer()) {
|
||||
if (cmd.should_be_developer()) {
|
||||
if (!addAdminFlagToUser(userName, 8)) {
|
||||
return Response::RespInternalError;
|
||||
}
|
||||
} else {
|
||||
if (!removeAdminFlagFromUser(userName, 8)) {
|
||||
return Response::RespInternalError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Response::RespOk;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include <QMutex>
|
||||
#include <QTcpSocket>
|
||||
#include <QWebSocket>
|
||||
#include <libcockatrice/protocol/pb/command_get_server_stats.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_replay_download_by_game_id.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_report.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_report_add_comment.pb.h>
|
||||
|
|
@ -115,7 +116,8 @@ private:
|
|||
Response::ResponseCode cmdBanFromServer(const Command_BanFromServer &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdReportList(const Command_ReportList &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdWarnUser(const Command_WarnUser &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdGetLogHistory(const Command_ViewLogHistory &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode
|
||||
cmdGetLogHistory(const Command_ViewLogHistory &cmd, ResponseContainer &rc, bool allowPrivateChat);
|
||||
Response::ResponseCode cmdGetBanHistory(const Command_GetBanHistory &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdGetWarnList(const Command_GetWarnList &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdGetWarnHistory(const Command_GetWarnHistory &cmd, ResponseContainer &rc);
|
||||
|
|
@ -151,6 +153,8 @@ private:
|
|||
processExtendedModeratorCommand(int cmdType, const ModeratorCommand &cmd, ResponseContainer &rc) override;
|
||||
Response::ResponseCode
|
||||
processExtendedAdminCommand(int cmdType, const AdminCommand &cmd, ResponseContainer &rc) override;
|
||||
Response::ResponseCode
|
||||
processExtendedDeveloperCommand(int cmdType, const DeveloperCommand &cmd, ResponseContainer &rc) override;
|
||||
|
||||
Response::ResponseCode cmdAccountEdit(const Command_AccountEdit &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdAccountImage(const Command_AccountImage &cmd, ResponseContainer &rc);
|
||||
|
|
@ -172,6 +176,8 @@ private:
|
|||
Response::ResponseCode cmdResetUserPassword(const Command_ResetUserPassword &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdRemoveUserAvatar(const Command_RemoveUserAvatar &cmd, ResponseContainer &rc);
|
||||
|
||||
Response::ResponseCode cmdGetServerStats(const Command_GetServerStats &cmd, ResponseContainer &rc);
|
||||
|
||||
bool addAdminFlagToUser(const QString &user, int flag);
|
||||
bool removeAdminFlagFromUser(const QString &user, int flag);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue