mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[Server] Expose moderation history reads on the database interface (#7829)
The ban/warn history, session, alt-account, and moderator-login readers existed only on Servatrice_DatabaseInterface, so the socket handler had to hold the concrete class to call them and to ask checkSql() whether the store was reachable. Declare them on Server_DatabaseInterface with empty-list defaults and a checkSql() that reports ready for stores without a connection, mark the Servatrice implementations as overrides, and let those five commands ask the injected interface.
This commit is contained in:
parent
52d8f84ec8
commit
2ca3117765
4 changed files with 56 additions and 16 deletions
|
|
@ -1,7 +1,12 @@
|
||||||
#ifndef SERVER_DATABASE_INTERFACE_H
|
#ifndef SERVER_DATABASE_INTERFACE_H
|
||||||
#define SERVER_DATABASE_INTERFACE_H
|
#define SERVER_DATABASE_INTERFACE_H
|
||||||
|
|
||||||
|
#include "libcockatrice/protocol/pb/serverinfo_ban.pb.h"
|
||||||
|
#include "libcockatrice/protocol/pb/serverinfo_moderator_login.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_user.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_user.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_warning.pb.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
@ -98,6 +103,41 @@ public:
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
virtual QList<ServerInfo_Ban> getUserBanHistory(const QString & /* userName */)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
virtual QList<ServerInfo_Warning> getUserWarnHistory(const QString & /* userName */)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
virtual QList<ServerInfo_UserSession> getUserSessions(const QString & /* userName */, int /* limit */)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
virtual QList<ServerInfo_UserAlt> getUserAlts(const QString & /* userName */,
|
||||||
|
int /* depth */ = 1,
|
||||||
|
bool /* useEmail */ = true,
|
||||||
|
bool /* useClientId */ = true,
|
||||||
|
bool /* useIp */ = true,
|
||||||
|
int /* sessionMonths */ = 6)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
virtual QList<ServerInfo_ModeratorLogin> getModeratorLastLogins()
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief Whether the backing store is reachable, reconnecting when it is not.
|
||||||
|
*
|
||||||
|
* Implementations that cannot report readiness are always ready, so callers
|
||||||
|
* do not have to know which kind of store they hold.
|
||||||
|
*/
|
||||||
|
virtual bool checkSql()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
virtual ServerInfo_User getUserData(const QString &name, bool withId = false) = 0;
|
virtual ServerInfo_User getUserData(const QString &name, bool withId = false) = 0;
|
||||||
virtual void storeGameInformation(const QString & /* roomName */,
|
virtual void storeGameInformation(const QString & /* roomName */,
|
||||||
const QStringList & /* roomGameTypes */,
|
const QStringList & /* roomGameTypes */,
|
||||||
|
|
|
||||||
|
|
@ -1896,7 +1896,7 @@ void Servatrice_DatabaseInterface::updateUsersLastLoginData(const QString &userN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ServerInfo_Ban> Servatrice_DatabaseInterface::getUserBanHistory(const QString userName)
|
QList<ServerInfo_Ban> Servatrice_DatabaseInterface::getUserBanHistory(const QString &userName)
|
||||||
{
|
{
|
||||||
QList<ServerInfo_Ban> results;
|
QList<ServerInfo_Ban> results;
|
||||||
ServerInfo_Ban banDetails;
|
ServerInfo_Ban banDetails;
|
||||||
|
|
@ -1954,7 +1954,7 @@ bool Servatrice_DatabaseInterface::addWarning(const QString userName,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ServerInfo_Warning> Servatrice_DatabaseInterface::getUserWarnHistory(const QString userName)
|
QList<ServerInfo_Warning> Servatrice_DatabaseInterface::getUserWarnHistory(const QString &userName)
|
||||||
{
|
{
|
||||||
QList<ServerInfo_Warning> results;
|
QList<ServerInfo_Warning> results;
|
||||||
ServerInfo_Warning warnDetails;
|
ServerInfo_Warning warnDetails;
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ public:
|
||||||
const QString &userName,
|
const QString &userName,
|
||||||
const QString &password);
|
const QString &password);
|
||||||
bool openDatabase();
|
bool openDatabase();
|
||||||
bool checkSql();
|
bool checkSql() override;
|
||||||
QSqlQuery *prepareQuery(const QString &queryText);
|
QSqlQuery *prepareQuery(const QString &queryText);
|
||||||
bool execSqlQuery(QSqlQuery *query);
|
bool execSqlQuery(QSqlQuery *query);
|
||||||
const QSqlDatabase &getDatabase()
|
const QSqlDatabase &getDatabase()
|
||||||
|
|
@ -214,10 +214,10 @@ public:
|
||||||
const QString &newPassword,
|
const QString &newPassword,
|
||||||
bool newPasswordNeedsHash) override;
|
bool newPasswordNeedsHash) override;
|
||||||
void setForcePasswordChange(const QString &user, bool force) override;
|
void setForcePasswordChange(const QString &user, bool force) override;
|
||||||
QList<ServerInfo_Ban> getUserBanHistory(const QString userName);
|
QList<ServerInfo_Ban> getUserBanHistory(const QString &userName) override;
|
||||||
bool
|
bool
|
||||||
addWarning(const QString userName, const QString adminName, const QString warningReason, const QString clientID);
|
addWarning(const QString userName, const QString adminName, const QString warningReason, const QString clientID);
|
||||||
QList<ServerInfo_Warning> getUserWarnHistory(const QString userName);
|
QList<ServerInfo_Warning> getUserWarnHistory(const QString &userName) override;
|
||||||
QList<ServerInfo_ChatMessage> getMessageLogHistory(const QString &user,
|
QList<ServerInfo_ChatMessage> getMessageLogHistory(const QString &user,
|
||||||
const QString &ipaddress,
|
const QString &ipaddress,
|
||||||
const QString &gamename,
|
const QString &gamename,
|
||||||
|
|
@ -231,7 +231,7 @@ public:
|
||||||
int offset = 0,
|
int offset = 0,
|
||||||
const QString &beforeTime = QString(),
|
const QString &beforeTime = QString(),
|
||||||
bool *hasMore = nullptr);
|
bool *hasMore = nullptr);
|
||||||
QList<ServerInfo_UserSession> getUserSessions(const QString &userName, int limit);
|
QList<ServerInfo_UserSession> getUserSessions(const QString &userName, int limit) override;
|
||||||
bool getPrivateChatHistory(int callerId,
|
bool getPrivateChatHistory(int callerId,
|
||||||
const QString &callerName,
|
const QString &callerName,
|
||||||
int peerId,
|
int peerId,
|
||||||
|
|
@ -245,8 +245,8 @@ public:
|
||||||
bool useEmail = true,
|
bool useEmail = true,
|
||||||
bool useClientId = true,
|
bool useClientId = true,
|
||||||
bool useIp = true,
|
bool useIp = true,
|
||||||
int sessionMonths = 6);
|
int sessionMonths = 6) override;
|
||||||
QList<ServerInfo_ModeratorLogin> getModeratorLastLogins();
|
QList<ServerInfo_ModeratorLogin> getModeratorLastLogins() override;
|
||||||
|
|
||||||
// Uptime snapshot as recorded by Servatrice::statusUpdate() into the
|
// Uptime snapshot as recorded by Servatrice::statusUpdate() into the
|
||||||
// {prefix}_uptime table. valid is false when no snapshot exists yet.
|
// {prefix}_uptime table. valid is false when no snapshot exists yet.
|
||||||
|
|
|
||||||
|
|
@ -1857,7 +1857,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetBanHistory(const Com
|
||||||
QString userName = nameFromStdString(cmd.user_name());
|
QString userName = nameFromStdString(cmd.user_name());
|
||||||
|
|
||||||
Response_BanHistory *re = new Response_BanHistory;
|
Response_BanHistory *re = new Response_BanHistory;
|
||||||
QListIterator<ServerInfo_Ban> banIterator(sqlInterface->getUserBanHistory(userName));
|
QListIterator<ServerInfo_Ban> banIterator(databaseInterface->getUserBanHistory(userName));
|
||||||
while (banIterator.hasNext()) {
|
while (banIterator.hasNext()) {
|
||||||
re->add_ban_list()->CopyFrom(banIterator.next());
|
re->add_ban_list()->CopyFrom(banIterator.next());
|
||||||
}
|
}
|
||||||
|
|
@ -1889,7 +1889,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetWarnHistory(const Co
|
||||||
QString userName = nameFromStdString(cmd.user_name());
|
QString userName = nameFromStdString(cmd.user_name());
|
||||||
|
|
||||||
Response_WarnHistory *re = new Response_WarnHistory;
|
Response_WarnHistory *re = new Response_WarnHistory;
|
||||||
QListIterator<ServerInfo_Warning> warnIterator(sqlInterface->getUserWarnHistory(userName));
|
QListIterator<ServerInfo_Warning> warnIterator(databaseInterface->getUserWarnHistory(userName));
|
||||||
while (warnIterator.hasNext()) {
|
while (warnIterator.hasNext()) {
|
||||||
re->add_warn_list()->CopyFrom(warnIterator.next());
|
re->add_warn_list()->CopyFrom(warnIterator.next());
|
||||||
}
|
}
|
||||||
|
|
@ -2605,7 +2605,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReportStats(const Comma
|
||||||
Response::ResponseCode AbstractServerSocketInterface::cmdGetUserSessions(const Command_GetUserSessions &cmd,
|
Response::ResponseCode AbstractServerSocketInterface::cmdGetUserSessions(const Command_GetUserSessions &cmd,
|
||||||
ResponseContainer &rc)
|
ResponseContainer &rc)
|
||||||
{
|
{
|
||||||
if (!sqlInterface->checkSql()) {
|
if (!databaseInterface->checkSql()) {
|
||||||
return Response::RespInternalError;
|
return Response::RespInternalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2616,7 +2616,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetUserSessions(const C
|
||||||
|
|
||||||
Response_UserSessions *re = new Response_UserSessions;
|
Response_UserSessions *re = new Response_UserSessions;
|
||||||
const int limit = qMin(static_cast<int>(cmd.limit()), 500);
|
const int limit = qMin(static_cast<int>(cmd.limit()), 500);
|
||||||
const QList<ServerInfo_UserSession> sessions = sqlInterface->getUserSessions(userName, limit);
|
const QList<ServerInfo_UserSession> sessions = databaseInterface->getUserSessions(userName, limit);
|
||||||
for (const ServerInfo_UserSession &session : sessions) {
|
for (const ServerInfo_UserSession &session : sessions) {
|
||||||
re->add_sessions()->CopyFrom(session);
|
re->add_sessions()->CopyFrom(session);
|
||||||
}
|
}
|
||||||
|
|
@ -2627,7 +2627,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetUserSessions(const C
|
||||||
Response::ResponseCode AbstractServerSocketInterface::cmdGetUserAlts(const Command_GetUserAlts &cmd,
|
Response::ResponseCode AbstractServerSocketInterface::cmdGetUserAlts(const Command_GetUserAlts &cmd,
|
||||||
ResponseContainer &rc)
|
ResponseContainer &rc)
|
||||||
{
|
{
|
||||||
if (!sqlInterface->checkSql()) {
|
if (!databaseInterface->checkSql()) {
|
||||||
return Response::RespInternalError;
|
return Response::RespInternalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2639,7 +2639,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetUserAlts(const Comma
|
||||||
Response_UserAlts *re = new Response_UserAlts;
|
Response_UserAlts *re = new Response_UserAlts;
|
||||||
const int depth = cmd.has_depth() ? static_cast<int>(cmd.depth()) : 1;
|
const int depth = cmd.has_depth() ? static_cast<int>(cmd.depth()) : 1;
|
||||||
const int sessionMonths = cmd.has_session_months() ? static_cast<int>(cmd.session_months()) : 6;
|
const int sessionMonths = cmd.has_session_months() ? static_cast<int>(cmd.session_months()) : 6;
|
||||||
const QList<ServerInfo_UserAlt> alts = sqlInterface->getUserAlts(
|
const QList<ServerInfo_UserAlt> alts = databaseInterface->getUserAlts(
|
||||||
userName, depth, cmd.include_email(), cmd.include_clientid(), cmd.include_ip(), sessionMonths);
|
userName, depth, cmd.include_email(), cmd.include_clientid(), cmd.include_ip(), sessionMonths);
|
||||||
for (const ServerInfo_UserAlt &alt : alts) {
|
for (const ServerInfo_UserAlt &alt : alts) {
|
||||||
re->add_alts()->CopyFrom(alt);
|
re->add_alts()->CopyFrom(alt);
|
||||||
|
|
@ -2651,12 +2651,12 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetUserAlts(const Comma
|
||||||
Response::ResponseCode AbstractServerSocketInterface::cmdGetModeratorLastLogins(const Command_GetModeratorLastLogins &,
|
Response::ResponseCode AbstractServerSocketInterface::cmdGetModeratorLastLogins(const Command_GetModeratorLastLogins &,
|
||||||
ResponseContainer &rc)
|
ResponseContainer &rc)
|
||||||
{
|
{
|
||||||
if (!sqlInterface->checkSql()) {
|
if (!databaseInterface->checkSql()) {
|
||||||
return Response::RespInternalError;
|
return Response::RespInternalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
Response_ModeratorLastLogins *re = new Response_ModeratorLastLogins;
|
Response_ModeratorLastLogins *re = new Response_ModeratorLastLogins;
|
||||||
const QList<ServerInfo_ModeratorLogin> logins = sqlInterface->getModeratorLastLogins();
|
const QList<ServerInfo_ModeratorLogin> logins = databaseInterface->getModeratorLastLogins();
|
||||||
for (const ServerInfo_ModeratorLogin &login : logins) {
|
for (const ServerInfo_ModeratorLogin &login : logins) {
|
||||||
re->add_logins()->CopyFrom(login);
|
re->add_logins()->CopyFrom(login);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue