/** Called when OK or OK-and-save is clicked. * This will trigger the actual login (if requested) etc. * \param remember_me True if the login details should be remembered, * so that next time this menu can be skipped. */ void BaseUserScreen::login() { // If an error occurs, the callback informing this screen about the // problem will activate the widget again. m_options_widget->setActive(false); m_state = STATE_NONE; PlayerProfile *player = getSelectedPlayer(); PlayerProfile *current = PlayerManager::getCurrentPlayer(); 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(true/*ignoreRTL*/)!=new_username) ) { m_sign_out_name = current->getLastOnlineName(true/*ignoreRTL*/); 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(player==current && current->getLastOnlineName(true/*ignoreRTL*/)!=new_username) current->clearSession(); } PlayerManager::get()->setCurrentPlayer(player); assert(player); // If no online login requested, log the player out (if necessary) // and go to the main menu screen (though logout needs to finish first) if(!m_online_cb->getState()) { if(player->isLoggedIn()) { m_sign_out_name =player->getLastOnlineName(true/*ignoreRTL*/); player->requestSignOut(); m_state =(UserScreenState)(m_state| STATE_LOGOUT); } player->setWasOnlineLastTime(false); if(m_state==STATE_NONE) { closeScreen(); } return; } // Player wants to be online, and is already online - nothing to do if(player->isLoggedIn()) { player->setWasOnlineLastTime(true); closeScreen(); return; } m_state = (UserScreenState) (m_state | STATE_LOGIN); // Now we need to start a login request to the server // This implies that this screen will wait till the server responds, so // that error messages ('invalid password') can be shown, and the user // can decide what to do about them. if (player->hasSavedSession()) { m_sign_in_name = player->getLastOnlineName(true/*ignoreRTL*/); // Online login with saved token player->requestSavedSession(); } else { // Online login with password --> we need a valid password if (m_password_tb->getText() == "") { m_info_widget->setText(_("You need to enter a password."), true); SFXManager::get()->quickSound("anvil"); m_options_widget->setActive(true); return; } m_sign_in_name = m_username_tb->getText(); player->requestSignIn(m_username_tb->getText(), m_password_tb->getText()); } // !hasSavedSession } // login