mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
store sessions in database
This commit is contained in:
parent
a7f3ce4050
commit
1455c093cc
8 changed files with 52 additions and 2 deletions
|
|
@ -300,6 +300,31 @@ int Servatrice::getUsersWithAddress(const QHostAddress &address) const
|
|||
return result;
|
||||
}
|
||||
|
||||
int Servatrice::startSession(const QString &userName, const QString &address)
|
||||
{
|
||||
QMutexLocker locker(&dbMutex);
|
||||
checkSql();
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("insert into " + dbPrefix + "_sessions (user_name, ip_address, start_time) values(:user_name, :ip_address, NOW())");
|
||||
query.bindValue(":user_name", userName);
|
||||
query.bindValue(":ip_address", address);
|
||||
if (execSqlQuery(query))
|
||||
return query.lastInsertId().toInt();
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Servatrice::endSession(int sessionId)
|
||||
{
|
||||
QMutexLocker locker(&dbMutex);
|
||||
checkSql();
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("update " + dbPrefix + "_sessions set end_time=NOW() where id = :id_session");
|
||||
query.bindValue(":id_session", sessionId);
|
||||
execSqlQuery(query);
|
||||
}
|
||||
|
||||
QMap<QString, ServerInfo_User *> Servatrice::getBuddyList(const QString &name)
|
||||
{
|
||||
QMutexLocker locker(&dbMutex);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue