Fix bug that crashes server when old session is logged out during login
This commit is contained in:
parent
8bb6bb04d7
commit
66dce1bf46
1 changed files with 14 additions and 15 deletions
|
@ -111,8 +111,6 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
||||||
|
|
||||||
Server_DatabaseInterface *databaseInterface = getDatabaseInterface();
|
Server_DatabaseInterface *databaseInterface = getDatabaseInterface();
|
||||||
|
|
||||||
QWriteLocker locker(&clientsLock);
|
|
||||||
|
|
||||||
AuthenticationResult authState = databaseInterface->checkUserPassword(session, name, password, clientid, reasonStr, secondsLeft);
|
AuthenticationResult authState = databaseInterface->checkUserPassword(session, name, password, clientid, reasonStr, secondsLeft);
|
||||||
if (authState == NotLoggedIn || authState == UserIsBanned || authState == UsernameInvalid || authState == UserIsInactive)
|
if (authState == NotLoggedIn || authState == UserIsBanned || authState == UsernameInvalid || authState == UserIsInactive)
|
||||||
return authState;
|
return authState;
|
||||||
|
@ -121,24 +119,23 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
||||||
data.set_address(session->getAddress().toStdString());
|
data.set_address(session->getAddress().toStdString());
|
||||||
name = QString::fromStdString(data.name()); // Compensate for case indifference
|
name = QString::fromStdString(data.name()); // Compensate for case indifference
|
||||||
|
|
||||||
databaseInterface->lockSessionTables();
|
|
||||||
|
|
||||||
if (authState == PasswordRight) {
|
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) || databaseInterface->userSessionExists(name)) {
|
||||||
qDebug("Session already logged in, logging old session out");
|
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.");
|
||||||
|
event.set_end_time(QDateTime::currentDateTime().toTime_t());
|
||||||
|
|
||||||
Event_ConnectionClosed event;
|
SessionEvent *se = users.value(name)->prepareSessionEvent(event);
|
||||||
event.set_reason(Event_ConnectionClosed::LOGGEDINELSEWERE);
|
users.value(name)->sendProtocolItem(*se);
|
||||||
event.set_reason_str("You have been logged out due to logging in at another location.");
|
delete se;
|
||||||
event.set_end_time(QDateTime::currentDateTime().toTime_t());
|
|
||||||
|
|
||||||
SessionEvent *se = users.value(name)->prepareSessionEvent(event);
|
|
||||||
users.value(name)->sendProtocolItem(*se);
|
|
||||||
delete se;
|
|
||||||
|
|
||||||
|
users.value(name)->prepareDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (authState == UnknownUser) {
|
} else if (authState == UnknownUser) {
|
||||||
// Change user name so that no two users have the same names,
|
// Change user name so that no two users have the same names,
|
||||||
// don't interfere with registered user names though.
|
// don't interfere with registered user names though.
|
||||||
|
@ -156,6 +153,8 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
||||||
data.set_name(name.toStdString());
|
data.set_name(name.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWriteLocker locker(&clientsLock);
|
||||||
|
databaseInterface->lockSessionTables();
|
||||||
users.insert(name, session);
|
users.insert(name, session);
|
||||||
qDebug() << "Server::loginUser:" << session << "name=" << name;
|
qDebug() << "Server::loginUser:" << session << "name=" << name;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue