mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 11:03:54 -07:00
database interface separated from server, multiple concurrent database connections are now possible
This commit is contained in:
parent
2b89c353bf
commit
b328c1ed4d
21 changed files with 347 additions and 310 deletions
|
|
@ -5,6 +5,7 @@
|
|||
LocalServer::LocalServer(QObject *parent)
|
||||
: Server(parent)
|
||||
{
|
||||
setDatabaseInterface(new LocalServer_DatabaseInterface(this));
|
||||
addRoom(new Server_Room(0, QString(), QString(), false, QString(), QStringList(), this));
|
||||
}
|
||||
|
||||
|
|
@ -15,14 +16,26 @@ LocalServer::~LocalServer()
|
|||
|
||||
LocalServerInterface *LocalServer::newConnection()
|
||||
{
|
||||
LocalServerInterface *lsi = new LocalServerInterface(this);
|
||||
LocalServerInterface *lsi = new LocalServerInterface(this, getDatabaseInterface());
|
||||
addClient(lsi);
|
||||
return lsi;
|
||||
}
|
||||
|
||||
ServerInfo_User LocalServer::getUserData(const QString &name, bool /*withId*/)
|
||||
LocalServer_DatabaseInterface::LocalServer_DatabaseInterface(LocalServer *_localServer)
|
||||
: Server_DatabaseInterface(_localServer),
|
||||
nextGameId(0),
|
||||
nextReplayId(0)
|
||||
{
|
||||
}
|
||||
|
||||
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, QString &reasonStr, int &secondsLeft)
|
||||
{
|
||||
return UnknownUser;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define LOCALSERVER_H
|
||||
|
||||
#include "server.h"
|
||||
#include "server_database_interface.h"
|
||||
|
||||
class LocalServerInterface;
|
||||
|
||||
|
|
@ -13,8 +14,20 @@ public:
|
|||
~LocalServer();
|
||||
|
||||
LocalServerInterface *newConnection();
|
||||
};
|
||||
|
||||
class LocalServer_DatabaseInterface : public Server_DatabaseInterface {
|
||||
Q_OBJECT
|
||||
private:
|
||||
LocalServer *localServer;
|
||||
int nextGameId, nextReplayId;
|
||||
protected:
|
||||
ServerInfo_User getUserData(const QString &name, bool withId = false);
|
||||
public:
|
||||
LocalServer_DatabaseInterface(LocalServer *_localServer);
|
||||
AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft);
|
||||
int getNextGameId() { return ++nextGameId; }
|
||||
int getNextReplayId() { return ++nextReplayId; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -2,8 +2,8 @@
|
|||
#include "localserver.h"
|
||||
#include <QDebug>
|
||||
|
||||
LocalServerInterface::LocalServerInterface(LocalServer *_server)
|
||||
: Server_ProtocolHandler(_server, _server)
|
||||
LocalServerInterface::LocalServerInterface(LocalServer *_server, Server_DatabaseInterface *_databaseInterface)
|
||||
: Server_ProtocolHandler(_server, _databaseInterface, _server)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class LocalServerInterface : public Server_ProtocolHandler
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocalServerInterface(LocalServer *_server);
|
||||
LocalServerInterface(LocalServer *_server, Server_DatabaseInterface *_databaseInterface);
|
||||
~LocalServerInterface();
|
||||
|
||||
QString getAddress() const { return QString(); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue