From f4688fa62134a362409724bf46137fc04e8181de Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 22 May 2014 08:12:55 +1000 Subject: [PATCH] Added support to change the online account for the same player. --- src/online/online_player_profile.cpp | 5 ++++- src/states_screens/user_screen.cpp | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/online/online_player_profile.cpp b/src/online/online_player_profile.cpp index 234567e35..5f8d8ecee 100644 --- a/src/online/online_player_profile.cpp +++ b/src/online/online_player_profile.cpp @@ -114,7 +114,10 @@ namespace Online OnlinePlayerProfile::requestSignIn(const core::stringw &username, const core::stringw &password) { - assert(m_online_state == OS_SIGNED_OUT); + // If the player changes the online account, there can be a + // logout stil happening. + assert(m_online_state == OS_SIGNED_OUT || + m_online_state == OS_SIGNING_OUT ); SignInRequest * request = new SignInRequest(false); // We can't use setUserDetail here, since there is no token yet request->setServerURL("client-user.php"); diff --git a/src/states_screens/user_screen.cpp b/src/states_screens/user_screen.cpp index 8db0d3587..d4e5762f2 100644 --- a/src/states_screens/user_screen.cpp +++ b/src/states_screens/user_screen.cpp @@ -303,12 +303,20 @@ void BaseUserScreen::login() PlayerProfile *player = getSelectedPlayer(); PlayerProfile *current = PlayerManager::getCurrentPlayer(); - // If a different player is connecting, log out the current player. - if(player!=current && current && current->isLoggedIn()) + core::stringw new_username = m_username_tb->getText(); + // If a different player is connecting, or the same local player with + // a different online account, log out the current player. + if(current && current->isLoggedIn() && + (player!=current || current->getLastOnlineName()!=new_username) ) { m_sign_out_name = current->getLastOnlineName(); current->requestSignOut(); m_state = (UserScreenState)(m_state | STATE_LOGOUT); + // If the online user name was changed, reset the save data + // for this user (otherwise later the saved session will be + // resumed, not logging the user with the new account). + if(current->getLastOnlineName()!=new_username) + current->clearSession(); } PlayerManager::get()->setCurrentPlayer(player); assert(player);