store sessions in database

This commit is contained in:
Max-Wilhelm Bruker 2011-12-04 13:36:53 +01:00
parent a7f3ce4050
commit 1455c093cc
8 changed files with 52 additions and 2 deletions

View file

@ -82,6 +82,9 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
users.insert(name, session);
qDebug() << "Server::loginUser: name=" << name;
session->setSessionId(startSession(name, session->getAddress()));
qDebug() << "session id:" << session->getSessionId();
Event_UserJoined *event = new Event_UserJoined(new ServerInfo_User(data, false));
for (int i = 0; i < clients.size(); ++i)
if (clients[i]->getAcceptsUserListChanges())
@ -111,6 +114,10 @@ void Server::removeClient(Server_ProtocolHandler *client)
users.remove(data->getName());
qDebug() << "Server::removeClient: name=" << data->getName();
if (client->getSessionId() != -1)
endSession(client->getSessionId());
qDebug() << "closed session id:" << client->getSessionId();
}
qDebug() << "Server::removeClient:" << clients.size() << "clients; " << users.size() << "users left";
}

View file

@ -50,6 +50,8 @@ protected:
QMap<QString, Server_ProtocolHandler *> users;
QMap<int, Server_Room *> rooms;
virtual int startSession(const QString &userName, const QString &address) = 0;
virtual void endSession(int sessionId) = 0;
virtual bool userExists(const QString &user) = 0;
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password) = 0;
virtual ServerInfo_User *getUserData(const QString &name) = 0;

View file

@ -14,7 +14,7 @@
#include <QDateTime>
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
: QObject(parent), server(_server), authState(PasswordWrong), acceptsUserListChanges(false), acceptsRoomListChanges(false), userInfo(0), timeRunning(0), lastDataReceived(0), gameListMutex(QMutex::Recursive)
: QObject(parent), server(_server), authState(PasswordWrong), acceptsUserListChanges(false), acceptsRoomListChanges(false), userInfo(0), sessionId(-1), timeRunning(0), lastDataReceived(0), gameListMutex(QMutex::Recursive)
{
connect(server, SIGNAL(pingClockTimeout()), this, SLOT(pingClockTimeout()));
}

View file

@ -31,6 +31,7 @@ protected:
void prepareDestroy();
virtual bool getCompressionSupport() const = 0;
int sessionId;
private:
QList<ProtocolItem *> itemQueue;
QList<int> messageSizeOverTime, messageCountOverTime;
@ -110,6 +111,8 @@ public:
void setUserInfo(ServerInfo_User *_userInfo) { userInfo = _userInfo; }
const QMap<QString, ServerInfo_User *> &getBuddyList() const { return buddyList; }
const QMap<QString, ServerInfo_User *> &getIgnoreList() const { return ignoreList; }
int getSessionId() const { return sessionId; }
void setSessionId(int _sessionId) { sessionId = _sessionId; }
int getLastCommandTime() const { return timeRunning - lastDataReceived; }
void processCommandContainer(CommandContainer *cont);