mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-12 21:44:18 -07:00
Turn Card, Deck_List, Protocol, RNG, Network (Client, Server), Settings and Utility into libraries and remove cockatrice_common. (#6212)
--------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de> Co-authored-by: ebbit1q <ebbit1q@gmail.com>
This commit is contained in:
parent
be1403c920
commit
1ef07309d6
605 changed files with 3812 additions and 3408 deletions
|
|
@ -0,0 +1,21 @@
|
|||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(HEADERS local_server.h local_server_interface.h)
|
||||
|
||||
set(SOURCES local_server.cpp local_server_interface.cpp)
|
||||
|
||||
if(Qt6_FOUND)
|
||||
qt6_wrap_cpp(MOC_SOURCES ${HEADERS})
|
||||
elseif(Qt5_FOUND)
|
||||
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
|
||||
endif()
|
||||
|
||||
add_library(libcockatrice_network_server_local STATIC ${MOC_SOURCES} ${SOURCES})
|
||||
|
||||
add_dependencies(libcockatrice_network_server_local libcockatrice_protocol)
|
||||
|
||||
target_include_directories(libcockatrice_network_server_local PUBLIC .)
|
||||
|
||||
target_link_libraries(libcockatrice_network_server_local PUBLIC ${COCKATRICE_QT_MODULES} libcockatrice_protocol)
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
#include "local_server.h"
|
||||
|
||||
#include "local_server_interface.h"
|
||||
|
||||
#include <../remote/server_room.h>
|
||||
|
||||
LocalServer::LocalServer(QObject *parent) : Server(parent)
|
||||
{
|
||||
setDatabaseInterface(new LocalServer_DatabaseInterface(this));
|
||||
addRoom(new Server_Room(0, 0, QString(), QString(), QString(), QString(), false, QString(), QStringList(), this));
|
||||
}
|
||||
|
||||
LocalServer::~LocalServer()
|
||||
{
|
||||
// LocalServer is single threaded so it doesn't need locks on this
|
||||
for (auto *client : clients) {
|
||||
client->prepareDestroy();
|
||||
}
|
||||
|
||||
prepareDestroy();
|
||||
}
|
||||
|
||||
LocalServerInterface *LocalServer::newConnection()
|
||||
{
|
||||
LocalServerInterface *lsi = new LocalServerInterface(this, getDatabaseInterface());
|
||||
addClient(lsi);
|
||||
return lsi;
|
||||
}
|
||||
|
||||
LocalServer_DatabaseInterface::LocalServer_DatabaseInterface(LocalServer *_localServer)
|
||||
: Server_DatabaseInterface(_localServer), localServer(_localServer)
|
||||
{
|
||||
}
|
||||
|
||||
ServerInfo_User LocalServer_DatabaseInterface::getUserData(const QString &name, bool /*withId*/)
|
||||
{
|
||||
ServerInfo_User result;
|
||||
result.set_name(name.toStdString());
|
||||
return result;
|
||||
}
|
||||
|
||||
AuthenticationResult LocalServer_DatabaseInterface::checkUserPassword(Server_ProtocolHandler * /* handler */,
|
||||
const QString & /* user */,
|
||||
const QString & /* password */,
|
||||
const QString & /* clientId */,
|
||||
QString & /* reasonStr */,
|
||||
int & /* banSecondsLeft */,
|
||||
bool /* passwordNeedsHash */)
|
||||
{
|
||||
return UnknownUser;
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* @file local_server.h
|
||||
* @ingroup Server
|
||||
* @brief TODO: Document this.
|
||||
*/
|
||||
|
||||
#ifndef LOCALSERVER_H
|
||||
#define LOCALSERVER_H
|
||||
|
||||
#include <../remote/server.h>
|
||||
#include <../remote/server_database_interface.h>
|
||||
|
||||
class LocalServerInterface;
|
||||
|
||||
class LocalServer : public Server
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LocalServer(QObject *parent = nullptr);
|
||||
~LocalServer() override;
|
||||
|
||||
LocalServerInterface *newConnection();
|
||||
};
|
||||
|
||||
class LocalServer_DatabaseInterface : public Server_DatabaseInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
LocalServer *localServer;
|
||||
|
||||
protected:
|
||||
ServerInfo_User getUserData(const QString &name, bool withId = false) override;
|
||||
|
||||
public:
|
||||
explicit LocalServer_DatabaseInterface(LocalServer *_localServer);
|
||||
~LocalServer_DatabaseInterface() override = default;
|
||||
AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler,
|
||||
const QString &user,
|
||||
const QString &password,
|
||||
const QString &clientId,
|
||||
QString &reasonStr,
|
||||
int &secondsLeft,
|
||||
bool passwordNeedsHash) override;
|
||||
int getNextGameId() override
|
||||
{
|
||||
return localServer->getNextLocalGameId();
|
||||
}
|
||||
int getNextReplayId() override
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int getActiveUserCount(QString /* connectionType */) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#include "local_server_interface.h"
|
||||
|
||||
#include "local_server.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
LocalServerInterface::LocalServerInterface(LocalServer *_server, Server_DatabaseInterface *_databaseInterface)
|
||||
: Server_ProtocolHandler(_server, _databaseInterface, _server)
|
||||
{
|
||||
}
|
||||
|
||||
LocalServerInterface::~LocalServerInterface()
|
||||
{
|
||||
}
|
||||
|
||||
void LocalServerInterface::transmitProtocolItem(const ServerMessage &item)
|
||||
{
|
||||
emit itemToClient(item);
|
||||
}
|
||||
|
||||
void LocalServerInterface::itemFromClient(const CommandContainer &item)
|
||||
{
|
||||
processCommandContainer(item);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* @file local_server_interface.h
|
||||
* @ingroup Server
|
||||
* @brief TODO: Document this.
|
||||
*/
|
||||
|
||||
#ifndef LOCALSERVERINTERFACE_H
|
||||
#define LOCALSERVERINTERFACE_H
|
||||
|
||||
#include <../remote/server_protocolhandler.h>
|
||||
|
||||
class LocalServer;
|
||||
|
||||
class LocalServerInterface : public Server_ProtocolHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocalServerInterface(LocalServer *_server, Server_DatabaseInterface *_databaseInterface);
|
||||
~LocalServerInterface() override;
|
||||
|
||||
QString getAddress() const override
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
QString getConnectionType() const override
|
||||
{
|
||||
return "local";
|
||||
};
|
||||
void transmitProtocolItem(const ServerMessage &item) override;
|
||||
signals:
|
||||
void itemToClient(const ServerMessage &item);
|
||||
public slots:
|
||||
void itemFromClient(const CommandContainer &item);
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue