From a1e35ccda5cb0872a8ee34c418413000eccd4ecd Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 17 Jul 2012 18:47:00 +0200 Subject: [PATCH] servatrice: create correct game ids when not using a database --- cockatrice/src/localserver.cpp | 4 +--- cockatrice/src/localserver.h | 7 +++---- common/server.cpp | 2 +- common/server.h | 3 +++ servatrice/src/servatrice_database_interface.cpp | 3 +++ 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cockatrice/src/localserver.cpp b/cockatrice/src/localserver.cpp index 26c5427c..833b4446 100644 --- a/cockatrice/src/localserver.cpp +++ b/cockatrice/src/localserver.cpp @@ -22,9 +22,7 @@ LocalServerInterface *LocalServer::newConnection() } LocalServer_DatabaseInterface::LocalServer_DatabaseInterface(LocalServer *_localServer) - : Server_DatabaseInterface(_localServer), - nextGameId(0), - nextReplayId(0) + : Server_DatabaseInterface(_localServer), localServer(_localServer) { } diff --git a/cockatrice/src/localserver.h b/cockatrice/src/localserver.h index ac6a8475..c77e6e7c 100644 --- a/cockatrice/src/localserver.h +++ b/cockatrice/src/localserver.h @@ -20,14 +20,13 @@ 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; } + int getNextGameId() { return localServer->getNextLocalGameId(); } + int getNextReplayId() { return -1; } }; -#endif \ No newline at end of file +#endif diff --git a/common/server.cpp b/common/server.cpp index e273bd40..32f3c878 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -36,7 +36,7 @@ #include Server::Server(bool _threaded, QObject *parent) - : QObject(parent), threaded(_threaded), clientsLock(QReadWriteLock::Recursive) + : QObject(parent), threaded(_threaded), clientsLock(QReadWriteLock::Recursive), nextLocalGameId(0) { qRegisterMetaType("ServerInfo_Game"); qRegisterMetaType("ServerInfo_Room"); diff --git a/common/server.h b/common/server.h index 1d87dc9e..aeb11bad 100644 --- a/common/server.h +++ b/common/server.h @@ -61,6 +61,7 @@ public: virtual bool getThreaded() const { return false; } Server_DatabaseInterface *getDatabaseInterface() const; + int getNextLocalGameId() { QMutexLocker locker(&nextLocalGameIdMutex); return ++nextLocalGameId; } virtual void storeGameInformation(int secondsElapsed, const QSet &allPlayersEver, const QSet &allSpectatorsEver, const QList &replays) { } void sendIsl_Response(const Response &item, int serverId = -1, qint64 sessionId = -1); @@ -81,6 +82,8 @@ private: bool threaded; QMultiMap persistentPlayers; mutable QReadWriteLock persistentPlayersLock; + int nextLocalGameId; + QMutex nextLocalGameIdMutex; protected slots: void externalUserJoined(const ServerInfo_User &userInfo); void externalUserLeft(const QString &userName); diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index e79ca79f..15e7084f 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -389,6 +389,9 @@ QMap Servatrice_DatabaseInterface::getIgnoreList(const int Servatrice_DatabaseInterface::getNextGameId() { + if (!sqlDatabase.isValid()) + return server->getNextLocalGameId(); + if (!checkSql()) return -1;