diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 6d090e8f..3d39a785 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -176,6 +176,7 @@ void MainWindow::serverError(ResponseCode r) { switch (r) { case RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Invalid login data.")); break; + case RespWouldOverwriteOldSession: QMessageBox::critical(this, tr("Error"), tr("There is already an active session using this user name.\nPlease close that session first and re-login.")); break; default: ; } } diff --git a/common/protocol.cpp b/common/protocol.cpp index 1185e90b..726803e1 100644 --- a/common/protocol.cpp +++ b/common/protocol.cpp @@ -267,6 +267,7 @@ void ProtocolResponse::initializeHash() responseHash.insert("only_buddies", RespOnlyBuddies); responseHash.insert("user_level_too_low", RespUserLevelTooLow); responseHash.insert("in_ignore_list", RespInIgnoreList); + responseHash.insert("would_overwrite_old_session", RespWouldOverwriteOldSession); } Response_JoinRoom::Response_JoinRoom(int _cmdId, ResponseCode _responseCode, ServerInfo_Room *_roomInfo) diff --git a/common/protocol_datastructures.h b/common/protocol_datastructures.h index 9fcfb295..dea6988c 100644 --- a/common/protocol_datastructures.h +++ b/common/protocol_datastructures.h @@ -8,7 +8,7 @@ class DeckList; -enum ResponseCode { RespNothing, RespOk, RespInternalError, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespFunctionNotAllowed, RespGameNotStarted, RespGameFull, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed, RespOnlyBuddies, RespUserLevelTooLow, RespInIgnoreList }; +enum ResponseCode { RespNothing, RespOk, RespInternalError, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespFunctionNotAllowed, RespGameNotStarted, RespGameFull, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed, RespOnlyBuddies, RespUserLevelTooLow, RespInIgnoreList, RespWouldOverwriteOldSession }; // PrivateZone: Contents of the zone are always visible to the owner, // but not to anyone else. diff --git a/common/server.cpp b/common/server.cpp index ac4b5e63..6e6bf488 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -46,8 +46,11 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString if (authState == PasswordRight) { Server_ProtocolHandler *oldSession = users.value(name); - if (oldSession) + if (oldSession) { + if (!(oldSession->getUserInfo()->getUserLevel() & ServerInfo_User::IsRegistered)) + return WouldOverwriteOldSession; delete oldSession; // ~Server_ProtocolHandler() will call Server::removeClient + } } else if (authState == UnknownUser) { // Change user name so that no two users have the same names, // don't interfere with registered user names though. diff --git a/common/server.h b/common/server.h index 2f4527b9..3816cef4 100644 --- a/common/server.h +++ b/common/server.h @@ -10,7 +10,7 @@ class Server_Room; class Server_ProtocolHandler; class ServerInfo_User; -enum AuthenticationResult { PasswordWrong = 0, PasswordRight = 1, UnknownUser = 2 }; +enum AuthenticationResult { PasswordWrong = 0, PasswordRight = 1, UnknownUser = 2, WouldOverwriteOldSession = 3 }; class Server : public QObject { diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 71d56a05..7f0ebe4a 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -237,6 +237,8 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain authState = server->loginUser(this, userName, cmd->getPassword()); if (authState == PasswordWrong) return RespWrongPassword; + if (authState == WouldOverwriteOldSession) + return RespWouldOverwriteOldSession; enqueueProtocolItem(new Event_ServerMessage(server->getLoginMessage()));