diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index a2edd199..1653e7f7 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -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::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()); } QMessageBox::critical(this, tr("Connection closed"), tr("The server has terminated your connection.\nReason: %1").arg(reasonStr)); diff --git a/common/pb/event_connection_closed.proto b/common/pb/event_connection_closed.proto index c59a4f74..c1c85ab5 100644 --- a/common/pb/event_connection_closed.proto +++ b/common/pb/event_connection_closed.proto @@ -12,6 +12,7 @@ message Event_ConnectionClosed { USERNAMEINVALID = 5; USER_LIMIT_REACHED = 6; DEMOTED = 7; + LOGGEDINELSEWERE = 8; } optional CloseReason reason = 1; optional string reason_str = 2; diff --git a/common/server.cpp b/common/server.cpp index 2fb064bc..c320ebba 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -30,6 +30,7 @@ #include "pb/event_user_left.pb.h" #include "pb/event_list_rooms.pb.h" #include "pb/session_event.pb.h" +#include "pb/event_connection_closed.pb.h" #include "pb/isl_message.pb.h" #include #include @@ -126,9 +127,17 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString // verify that new session would not cause problems with older existing session if (users.contains(name) || databaseInterface->userSessionExists(name)) { - qDebug("Login denied: would overwrite old session"); - databaseInterface->unlockSessionTables(); - return WouldOverwriteOldSession; + 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()); + + SessionEvent *se = users.value(name)->prepareSessionEvent(event); + users.value(name)->sendProtocolItem(*se); + delete se; + } } else if (authState == UnknownUser) { // Change user name so that no two users have the same names,