[Server] Move replay access reads and writes into the database interface

cmdReplayList, cmdReplayDownload, cmdReplayModifyMatch and cmdReplayDeleteMatch issued their own SQL through Servatrice_DatabaseInterface. Add ReplayMatchRecord/ReplayEntry and the ReplayAccessResult/ReplayWriteResult enums to Server_DatabaseInterface, implement the list, data, do-not-hide and delete operations with the same statements and response mapping, and let the commands ask the injected interface. checkSql stays in the two write commands where it already was.
This commit is contained in:
Lukas Brübach 2026-11-09 22:11:23 +01:00
parent 653f7f0ef9
commit a5e259fece
4 changed files with 196 additions and 78 deletions

View file

@ -11,6 +11,7 @@
#include "libcockatrice/protocol/pb/serverinfo_warning.pb.h"
#include "server.h"
#include <QByteArray>
#include <QMap>
#include <QObject>
#include <QString>
@ -311,6 +312,55 @@ public:
{
return false;
}
/** @brief One downloaded replay file of a match. */
struct ReplayEntry
{
int replayId = 0;
int duration = 0;
};
/** @brief One replay match visible to a user, with its players and replay files. */
struct ReplayMatchRecord
{
int gameId = 0;
QString replayName;
QString roomName;
int timeStarted = 0;
int timeFinished = 0;
QString description;
bool doNotHide = false;
QStringList playerNames;
QList<ReplayEntry> replays;
};
/** @brief Why a replay read succeeded or not, so callers can map it to a response code. */
enum class ReplayAccessResult
{
Ok,
AccessDenied,
NotFound,
Failed
};
enum class ReplayWriteResult
{
Ok,
NotFound,
Failed
};
virtual QList<ReplayMatchRecord> getReplayList(int /* userId */)
{
return {};
}
virtual ReplayAccessResult getReplayData(int /* replayId */, int /* userId */, QByteArray & /* data */)
{
return ReplayAccessResult::Failed;
}
virtual ReplayWriteResult setReplayDoNotHide(int /* gameId */, int /* userId */, bool /* doNotHide */)
{
return ReplayWriteResult::Failed;
}
virtual ReplayWriteResult deleteReplayAccess(int /* gameId */, int /* userId */)
{
return ReplayWriteResult::Failed;
}
/** @brief Append a moderator/admin action to the server audit log. */
virtual void addAuditRecord(const QString & /* user */,
const QString & /* ipaddress */,