Clean up inter-library dependencies with interfaces (#6280)

* Have CardDatabase::getPreferredPrintingInfo respect card provider ID overrides (pinned printings)

Took 13 minutes

Took 37 seconds

Took 10 seconds

Took 10 seconds

# Commit time for manual adjustment:
# Took 30 seconds

Took 15 seconds


Took 8 minutes

Took 21 seconds

* Move settings cache and settings card preference provider out of libcockatrice_settings and into cockatrice

Took 52 minutes

Took 9 minutes

Took 1 minute

* Temp cache.

Took 16 minutes

* Dependency Injection for SettingsCache

* Turn SettingsCache into a QSharedPointer.
* Implement interfaces for settings that need it

Took 2 hours 38 minutes

* Adjust oracle.

Took 5 minutes

* Move abstract/noop interfaces to libcockatrice_interfaces so they can be linked against independently.

Took 52 minutes

* Clean up some links.

Took 3 minutes

* Cleanup two includes.

Took 3 minutes

* More fixes.

Took 7 minutes

* More includes that slipped past.

Took 3 minutes

* Stop mocking and start injecting for tests.

Took 15 minutes

* I don't know why remote_client was including main.

Took 4 minutes

* Include.

Took 3 minutes

* Lint.

Took 2 minutes

* Don't use Qt pointers.

Took 1 hour 7 minutes

* Make parser use CardSettingsInterface

Took 13 minutes

* Also adjust constructor lol.

Took 8 minutes

* Lint.

Took 32 minutes

* Revert "Lint."

This reverts commit ecb596c39e.


Took 3 minutes

* Test.

Took 3 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-11-08 22:19:40 +01:00 committed by GitHub
parent fb30515f72
commit a8a3fca8c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
152 changed files with 609 additions and 750 deletions

View file

@ -20,5 +20,5 @@ target_include_directories(libcockatrice_network_client_remote PUBLIC .)
target_link_libraries(
libcockatrice_network_client_remote PUBLIC ${COCKATRICE_QT_MODULES} libcockatrice_network_client_abstract
libcockatrice_settings libcockatrice_utility libcockatrice_protocol
libcockatrice_interfaces libcockatrice_utility libcockatrice_protocol
)

View file

@ -1,6 +1,5 @@
#include "remote_client.h"
#include "../../../../cockatrice/src/main.h"
#include "version_string.h"
#include <QCryptographicHash>
@ -11,6 +10,7 @@
#include <QThread>
#include <QTimer>
#include <QWebSocket>
#include <libcockatrice/interfaces/interface_network_settings_provider.h>
#include <libcockatrice/protocol/debug_pb_message.h>
#include <libcockatrice/protocol/pb/event_server_identification.pb.h>
#include <libcockatrice/protocol/pb/response_activate.pb.h>
@ -21,19 +21,18 @@
#include <libcockatrice/protocol/pb/server_message.pb.h>
#include <libcockatrice/protocol/pb/session_commands.pb.h>
#include <libcockatrice/protocol/pending_command.h>
#include <libcockatrice/settings/cache_settings.h>
#include <libcockatrice/utility/passwordhasher.h>
static const unsigned int protocolVersion = 14;
RemoteClient::RemoteClient(QObject *parent)
: AbstractClient(parent), timeRunning(0), lastDataReceived(0), messageInProgress(false), handshakeStarted(false),
usingWebSocket(false), messageLength(0), hashedPassword()
RemoteClient::RemoteClient(QObject *parent, INetworkSettingsProvider *_networkSettingsProvider)
: AbstractClient(parent), networkSettingsProvider(_networkSettingsProvider), timeRunning(0), lastDataReceived(0),
messageInProgress(false), handshakeStarted(false), usingWebSocket(false), messageLength(0), hashedPassword()
{
clearNewClientFeatures();
maxTimeout = SettingsCache::instance().getTimeOut();
int keepalive = SettingsCache::instance().getKeepAlive();
maxTimeout = networkSettingsProvider->getTimeOut();
int keepalive = networkSettingsProvider->getKeepAlive();
timer = new QTimer(this);
timer->setInterval(keepalive * 1000);
connect(timer, &QTimer::timeout, this, &RemoteClient::ping);
@ -308,8 +307,8 @@ void RemoteClient::loginResponse(const Response &response)
emit ignoreListReceived(ignoreList);
if (newMissingFeatureFound(possibleMissingFeatures) && resp.missing_features_size() > 0 &&
SettingsCache::instance().getNotifyAboutUpdates()) {
SettingsCache::instance().setKnownMissingFeatures(possibleMissingFeatures);
networkSettingsProvider->getNotifyAboutUpdates()) {
networkSettingsProvider->setKnownMissingFeatures(possibleMissingFeatures);
emit notifyUserAboutUpdate();
}
@ -586,7 +585,7 @@ void RemoteClient::disconnectFromServer()
QString RemoteClient::getSrvClientID(const QString &_hostname)
{
QString srvClientID = SettingsCache::instance().getClientID();
QString srvClientID = networkSettingsProvider->getClientID();
QHostInfo hostInfo = QHostInfo::fromName(_hostname);
if (!hostInfo.error()) {
QHostAddress hostAddress = hostInfo.addresses().first();
@ -606,7 +605,7 @@ bool RemoteClient::newMissingFeatureFound(const QString &_serversMissingFeatures
QStringList serversMissingFeaturesList = _serversMissingFeatures.split(",");
for (const QString &feature : serversMissingFeaturesList) {
if (!feature.isEmpty()) {
if (!SettingsCache::instance().getKnownMissingFeatures().contains(feature))
if (!networkSettingsProvider->getKnownMissingFeatures().contains(feature))
return true;
}
}
@ -616,14 +615,14 @@ bool RemoteClient::newMissingFeatureFound(const QString &_serversMissingFeatures
void RemoteClient::clearNewClientFeatures()
{
QString newKnownMissingFeatures;
QStringList existingKnownMissingFeatures = SettingsCache::instance().getKnownMissingFeatures().split(",");
QStringList existingKnownMissingFeatures = networkSettingsProvider->getKnownMissingFeatures().split(",");
for (const QString &existingKnownFeature : existingKnownMissingFeatures) {
if (!existingKnownFeature.isEmpty()) {
if (!clientFeatures.contains(existingKnownFeature))
newKnownMissingFeatures.append("," + existingKnownFeature);
}
}
SettingsCache::instance().setKnownMissingFeatures(newKnownMissingFeatures);
networkSettingsProvider->setKnownMissingFeatures(newKnownMissingFeatures);
}
void RemoteClient::requestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName)

View file

@ -12,6 +12,7 @@
#include <QLoggingCategory>
#include <QTcpSocket>
#include <QWebSocket>
#include <libcockatrice/interfaces/interface_network_settings_provider.h>
#include <libcockatrice/protocol/pb/commands.pb.h>
inline Q_LOGGING_CATEGORY(RemoteClientLog, "remote_client");
@ -97,6 +98,7 @@ private slots:
void submitForgotPasswordChallengeResponse(const Response &response);
private:
INetworkSettingsProvider *networkSettingsProvider;
int maxTimeout;
int timeRunning, lastDataReceived;
QByteArray inputBuffer;
@ -120,7 +122,7 @@ protected slots:
void sendCommandContainer(const CommandContainer &cont) override;
public:
explicit RemoteClient(QObject *parent = nullptr);
explicit RemoteClient(QObject *parent = nullptr, INetworkSettingsProvider *networkSettingsProvider = nullptr);
~RemoteClient() override;
QString peerName() const
{