Add clientid field to sessions table.
This commit is contained in:
parent
de1b925b7d
commit
eb5833609a
6 changed files with 13 additions and 7 deletions
|
@ -150,7 +150,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
||||||
users.insert(name, session);
|
users.insert(name, session);
|
||||||
qDebug() << "Server::loginUser:" << session << "name=" << name;
|
qDebug() << "Server::loginUser:" << session << "name=" << name;
|
||||||
|
|
||||||
data.set_session_id(databaseInterface->startSession(name, session->getAddress()));
|
data.set_session_id(databaseInterface->startSession(name, session->getAddress(), clientid));
|
||||||
databaseInterface->unlockSessionTables();
|
databaseInterface->unlockSessionTables();
|
||||||
|
|
||||||
usersBySessionId.insert(data.session_id(), session);
|
usersBySessionId.insert(data.session_id(), session);
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
virtual void storeGameInformation(const QString & /* roomName */, const QStringList & /* roomGameTypes */, const ServerInfo_Game & /* gameInfo */, const QSet<QString> & /* allPlayersEver */, const QSet<QString> & /* allSpectatorsEver */, const QList<GameReplay *> & /* replayList */) { }
|
virtual void storeGameInformation(const QString & /* roomName */, const QStringList & /* roomGameTypes */, const ServerInfo_Game & /* gameInfo */, const QSet<QString> & /* allPlayersEver */, const QSet<QString> & /* allSpectatorsEver */, const QList<GameReplay *> & /* replayList */) { }
|
||||||
virtual DeckList *getDeckFromDatabase(int /* deckId */, int /* userId */) { return 0; }
|
virtual DeckList *getDeckFromDatabase(int /* deckId */, int /* userId */) { return 0; }
|
||||||
|
|
||||||
virtual qint64 startSession(const QString & /* userName */, const QString & /* address */) { return 0; }
|
virtual qint64 startSession(const QString & /* userName */, const QString & /* address */, const QString & /* clientId */) { return 0; }
|
||||||
virtual bool usernameIsValid(const QString & /*userName */, QString & /* error */) { return true; };
|
virtual bool usernameIsValid(const QString & /*userName */, QString & /* error */) { return true; };
|
||||||
public slots:
|
public slots:
|
||||||
virtual void endSession(qint64 /* sessionId */ ) { }
|
virtual void endSession(qint64 /* sessionId */ ) { }
|
||||||
|
|
5
servatrice/migrations/servatrice_0003_to_0004.sql
Normal file
5
servatrice/migrations/servatrice_0003_to_0004.sql
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
-- Servatrice db migration from version 3 to version 4
|
||||||
|
|
||||||
|
alter table cockatrice_sessions add clientid varchar(15) not null;
|
||||||
|
|
||||||
|
UPDATE cockatrice_schema_version SET version=4 WHERE version=3;
|
|
@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_schema_version` (
|
||||||
PRIMARY KEY (`version`)
|
PRIMARY KEY (`version`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
INSERT INTO cockatrice_schema_version VALUES(3);
|
INSERT INTO cockatrice_schema_version VALUES(4);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `cockatrice_decklist_files` (
|
CREATE TABLE IF NOT EXISTS `cockatrice_decklist_files` (
|
||||||
`id` int(7) unsigned zerofill NOT NULL auto_increment,
|
`id` int(7) unsigned zerofill NOT NULL auto_increment,
|
||||||
|
|
|
@ -536,7 +536,7 @@ bool Servatrice_DatabaseInterface::userSessionExists(const QString &userName)
|
||||||
return query->next();
|
return query->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 Servatrice_DatabaseInterface::startSession(const QString &userName, const QString &address)
|
qint64 Servatrice_DatabaseInterface::startSession(const QString &userName, const QString &address, const QString &clientId)
|
||||||
{
|
{
|
||||||
if (server->getAuthenticationMethod() == Servatrice::AuthenticationNone)
|
if (server->getAuthenticationMethod() == Servatrice::AuthenticationNone)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -544,10 +544,11 @@ qint64 Servatrice_DatabaseInterface::startSession(const QString &userName, const
|
||||||
if (!checkSql())
|
if (!checkSql())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
QSqlQuery *query = prepareQuery("insert into {prefix}_sessions (user_name, id_server, ip_address, start_time) values(:user_name, :id_server, :ip_address, NOW())");
|
QSqlQuery *query = prepareQuery("insert into {prefix}_sessions (user_name, id_server, ip_address, start_time, clientid) values(:user_name, :id_server, :ip_address, NOW(), :client_id)");
|
||||||
query->bindValue(":user_name", userName);
|
query->bindValue(":user_name", userName);
|
||||||
query->bindValue(":id_server", server->getServerId());
|
query->bindValue(":id_server", server->getServerId());
|
||||||
query->bindValue(":ip_address", address);
|
query->bindValue(":ip_address", address);
|
||||||
|
query->bindValue(":client_id", clientId);
|
||||||
if (execSqlQuery(query))
|
if (execSqlQuery(query))
|
||||||
return query->lastInsertId().toInt();
|
return query->lastInsertId().toInt();
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "server_database_interface.h"
|
#include "server_database_interface.h"
|
||||||
|
|
||||||
#define DATABASE_SCHEMA_VERSION 3
|
#define DATABASE_SCHEMA_VERSION 4
|
||||||
|
|
||||||
class Servatrice;
|
class Servatrice;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public:
|
||||||
int getNextGameId();
|
int getNextGameId();
|
||||||
int getNextReplayId();
|
int getNextReplayId();
|
||||||
int getActiveUserCount();
|
int getActiveUserCount();
|
||||||
qint64 startSession(const QString &userName, const QString &address);
|
qint64 startSession(const QString &userName, const QString &address, const QString &clientId);
|
||||||
void endSession(qint64 sessionId);
|
void endSession(qint64 sessionId);
|
||||||
void clearSessionTables();
|
void clearSessionTables();
|
||||||
void lockSessionTables();
|
void lockSessionTables();
|
||||||
|
|
Loading…
Reference in a new issue