servatrice: create correct game ids when not using a database

This commit is contained in:
Max-Wilhelm Bruker 2012-07-17 18:47:00 +02:00
parent c8852b450d
commit a1e35ccda5
5 changed files with 11 additions and 8 deletions

View file

@ -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)
{
}

View file

@ -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
#endif

View file

@ -36,7 +36,7 @@
#include <QDebug>
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>("ServerInfo_Game");
qRegisterMetaType<ServerInfo_Room>("ServerInfo_Room");

View file

@ -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<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const QList<GameReplay *> &replays) { }
void sendIsl_Response(const Response &item, int serverId = -1, qint64 sessionId = -1);
@ -81,6 +82,8 @@ private:
bool threaded;
QMultiMap<QString, PlayerReference> persistentPlayers;
mutable QReadWriteLock persistentPlayersLock;
int nextLocalGameId;
QMutex nextLocalGameIdMutex;
protected slots:
void externalUserJoined(const ServerInfo_User &userInfo);
void externalUserLeft(const QString &userName);

View file

@ -389,6 +389,9 @@ QMap<QString, ServerInfo_User> Servatrice_DatabaseInterface::getIgnoreList(const
int Servatrice_DatabaseInterface::getNextGameId()
{
if (!sqlDatabase.isValid())
return server->getNextLocalGameId();
if (!checkSql())
return -1;