Fix bug that crashes server when old session is logged out during login

This commit is contained in:
woogerboy21 2015-08-30 23:22:35 -04:00
parent 8bb6bb04d7
commit 66dce1bf46

View file

@ -111,8 +111,6 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
Server_DatabaseInterface *databaseInterface = getDatabaseInterface();
QWriteLocker locker(&clientsLock);
AuthenticationResult authState = databaseInterface->checkUserPassword(session, name, password, clientid, reasonStr, secondsLeft);
if (authState == NotLoggedIn || authState == UserIsBanned || authState == UsernameInvalid || authState == UserIsInactive)
return authState;
@ -121,14 +119,10 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
data.set_address(session->getAddress().toStdString());
name = QString::fromStdString(data.name()); // Compensate for case indifference
databaseInterface->lockSessionTables();
if (authState == PasswordRight) {
// verify that new session would not cause problems with older existing session
if (users.contains(name) || databaseInterface->userSessionExists(name)) {
if (users.contains(name)) {
qDebug("Session already logged in, logging old session out");
Event_ConnectionClosed event;
event.set_reason(Event_ConnectionClosed::LOGGEDINELSEWERE);
event.set_reason_str("You have been logged out due to logging in at another location.");
@ -138,7 +132,10 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
users.value(name)->sendProtocolItem(*se);
delete se;
users.value(name)->prepareDestroy();
}
}
} else if (authState == UnknownUser) {
// Change user name so that no two users have the same names,
// don't interfere with registered user names though.
@ -156,6 +153,8 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
data.set_name(name.toStdString());
}
QWriteLocker locker(&clientsLock);
databaseInterface->lockSessionTables();
users.insert(name, session);
qDebug() << "Server::loginUser:" << session << "name=" << name;