From 0caacb27c10d2825b68f4ca5d64558891618a837 Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Tue, 10 Nov 2026 12:16:34 +0100 Subject: [PATCH] [Server] Move the database lifecycle calls onto the interface (#7859) --- .../server/remote/server_database_interface.h | 18 ++++++++++++++++++ servatrice/src/servatrice.cpp | 2 +- .../src/servatrice_database_interface.cpp | 2 +- servatrice/src/servatrice_database_interface.h | 8 ++++---- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h b/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h index cd8e1ef74..d98946a67 100644 --- a/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h +++ b/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h @@ -816,6 +816,24 @@ public: return false; } + /** @brief Opens the server's main database connection; false when it cannot be opened. */ + virtual bool openDatabase(const QString & /* type */, + const QString & /* hostName */, + const QString & /* databaseName */, + const QString & /* userName */, + const QString & /* password */) + { + return false; + } + /** @brief Drops expired deck shares; a no-op when persistence is unavailable. */ + virtual void cleanupExpiredDeckShares() + { + } + /** @brief Purges expired legacy password backups; a no-op when persistence is unavailable. */ + virtual void purgeExpiredLegacyBackups() + { + } + virtual void clearSessionTables() { } diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index b6b4a8e61..edd5ebe05 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -382,7 +382,7 @@ bool Servatrice::initServer() if (databaseType != DatabaseNone) { dbPrefix = getDBPrefixString(); - bool dbOpened = servatriceDatabaseInterface->initDatabase( + bool dbOpened = servatriceDatabaseInterface->openDatabase( "QMYSQL", getDBHostNameString(), getDBDatabaseNameString(), getDBUserNameString(), getDBPasswordString()); if (!dbOpened) { qCCritical(ServatriceLog) << "Failed to open the database; refusing to start."; diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index dd59fba98..3bca34c15 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -81,7 +81,7 @@ void Servatrice_DatabaseInterface::initDatabase(const QSqlDatabase &_sqlDatabase } } -bool Servatrice_DatabaseInterface::initDatabase(const QString &type, +bool Servatrice_DatabaseInterface::openDatabase(const QString &type, const QString &hostName, const QString &databaseName, const QString &userName, diff --git a/servatrice/src/servatrice_database_interface.h b/servatrice/src/servatrice_database_interface.h index 18f7f67a2..628d29d1d 100644 --- a/servatrice/src/servatrice_database_interface.h +++ b/servatrice/src/servatrice_database_interface.h @@ -66,11 +66,11 @@ public slots: public: explicit Servatrice_DatabaseInterface(int _instanceId, Servatrice *_server); ~Servatrice_DatabaseInterface() override; - bool initDatabase(const QString &type, + bool openDatabase(const QString &type, const QString &hostName, const QString &databaseName, const QString &userName, - const QString &password); + const QString &password) override; bool openDatabase(); bool checkSql() override; QSqlQuery *prepareQuery(const QString &queryText); @@ -94,7 +94,7 @@ public: /** @brief Drop the account's legacy password backup. */ void clearLegacyBackup(const QString &user); /** @brief Drop every legacy password backup that has not been used within the TTL. */ - void purgeExpiredLegacyBackups(); + void purgeExpiredLegacyBackups() override; int getUserIdInDB(const QString &name); int getUserId(const QString &name) override; bool addToBuddyList(int userId, int targetId) override; @@ -172,7 +172,7 @@ public: ReplayAccessResult getLatestReplayForGame(int gameId, int &replayId, QByteArray &data) override; ReplayWriteResult grantReplayAccessByName(int gameId, const QString &userName) override; /** @brief Deletes all expired share bundles (cascades to their items). */ - void cleanupExpiredDeckShares(); + void cleanupExpiredDeckShares() override; int getNextGameId() override; int getNextReplayId() override;