force users to log out their unregistered session after logging in with a new registered account

This commit is contained in:
Max-Wilhelm Bruker 2011-03-02 17:18:44 +01:00
parent 1bee788210
commit 3bb1d9a1de
6 changed files with 10 additions and 3 deletions

View file

@ -176,6 +176,7 @@ void MainWindow::serverError(ResponseCode r)
{ {
switch (r) { switch (r) {
case RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Invalid login data.")); break; 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: ; default: ;
} }
} }

View file

@ -267,6 +267,7 @@ void ProtocolResponse::initializeHash()
responseHash.insert("only_buddies", RespOnlyBuddies); responseHash.insert("only_buddies", RespOnlyBuddies);
responseHash.insert("user_level_too_low", RespUserLevelTooLow); responseHash.insert("user_level_too_low", RespUserLevelTooLow);
responseHash.insert("in_ignore_list", RespInIgnoreList); responseHash.insert("in_ignore_list", RespInIgnoreList);
responseHash.insert("would_overwrite_old_session", RespWouldOverwriteOldSession);
} }
Response_JoinRoom::Response_JoinRoom(int _cmdId, ResponseCode _responseCode, ServerInfo_Room *_roomInfo) Response_JoinRoom::Response_JoinRoom(int _cmdId, ResponseCode _responseCode, ServerInfo_Room *_roomInfo)

View file

@ -8,7 +8,7 @@
class DeckList; 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, // PrivateZone: Contents of the zone are always visible to the owner,
// but not to anyone else. // but not to anyone else.

View file

@ -46,8 +46,11 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
if (authState == PasswordRight) { if (authState == PasswordRight) {
Server_ProtocolHandler *oldSession = users.value(name); 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 delete oldSession; // ~Server_ProtocolHandler() will call Server::removeClient
}
} 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.

View file

@ -10,7 +10,7 @@ class Server_Room;
class Server_ProtocolHandler; class Server_ProtocolHandler;
class ServerInfo_User; 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 class Server : public QObject
{ {

View file

@ -237,6 +237,8 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain
authState = server->loginUser(this, userName, cmd->getPassword()); authState = server->loginUser(this, userName, cmd->getPassword());
if (authState == PasswordWrong) if (authState == PasswordWrong)
return RespWrongPassword; return RespWrongPassword;
if (authState == WouldOverwriteOldSession)
return RespWouldOverwriteOldSession;
enqueueProtocolItem(new Event_ServerMessage(server->getLoginMessage())); enqueueProtocolItem(new Event_ServerMessage(server->getLoginMessage()));