Log old session out of server if logging in from a second location
This commit is contained in:
parent
0c0413f056
commit
b0630b81ca
3 changed files with 14 additions and 3 deletions
|
@ -85,6 +85,7 @@ void MainWindow::processConnectionClosedEvent(const Event_ConnectionClosed &even
|
||||||
}
|
}
|
||||||
case Event_ConnectionClosed::SERVER_SHUTDOWN: reasonStr = tr("Scheduled server shutdown."); break;
|
case Event_ConnectionClosed::SERVER_SHUTDOWN: reasonStr = tr("Scheduled server shutdown."); break;
|
||||||
case Event_ConnectionClosed::USERNAMEINVALID: reasonStr = tr("Invalid username."); break;
|
case Event_ConnectionClosed::USERNAMEINVALID: reasonStr = tr("Invalid username."); break;
|
||||||
|
case Event_ConnectionClosed::LOGGEDINELSEWERE: reasonStr = tr("You have been logged out due to logging in at another location."); break;
|
||||||
default: reasonStr = QString::fromStdString(event.reason_str());
|
default: reasonStr = QString::fromStdString(event.reason_str());
|
||||||
}
|
}
|
||||||
QMessageBox::critical(this, tr("Connection closed"), tr("The server has terminated your connection.\nReason: %1").arg(reasonStr));
|
QMessageBox::critical(this, tr("Connection closed"), tr("The server has terminated your connection.\nReason: %1").arg(reasonStr));
|
||||||
|
|
|
@ -12,6 +12,7 @@ message Event_ConnectionClosed {
|
||||||
USERNAMEINVALID = 5;
|
USERNAMEINVALID = 5;
|
||||||
USER_LIMIT_REACHED = 6;
|
USER_LIMIT_REACHED = 6;
|
||||||
DEMOTED = 7;
|
DEMOTED = 7;
|
||||||
|
LOGGEDINELSEWERE = 8;
|
||||||
}
|
}
|
||||||
optional CloseReason reason = 1;
|
optional CloseReason reason = 1;
|
||||||
optional string reason_str = 2;
|
optional string reason_str = 2;
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "pb/event_user_left.pb.h"
|
#include "pb/event_user_left.pb.h"
|
||||||
#include "pb/event_list_rooms.pb.h"
|
#include "pb/event_list_rooms.pb.h"
|
||||||
#include "pb/session_event.pb.h"
|
#include "pb/session_event.pb.h"
|
||||||
|
#include "pb/event_connection_closed.pb.h"
|
||||||
#include "pb/isl_message.pb.h"
|
#include "pb/isl_message.pb.h"
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
@ -126,9 +127,17 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
||||||
|
|
||||||
// verify that new session would not cause problems with older existing session
|
// 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("Login denied: would overwrite old session");
|
qDebug("Session already logged in, logging old session out");
|
||||||
databaseInterface->unlockSessionTables();
|
|
||||||
return WouldOverwriteOldSession;
|
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());
|
||||||
|
|
||||||
|
SessionEvent *se = users.value(name)->prepareSessionEvent(event);
|
||||||
|
users.value(name)->sendProtocolItem(*se);
|
||||||
|
delete se;
|
||||||
|
|
||||||
}
|
}
|
||||||
} 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,
|
||||||
|
|
Loading…
Reference in a new issue