| 167 | } |
| 168 | |
| 169 | void LaunchController::login() |
| 170 | { |
| 171 | decideAccount(); |
| 172 | |
| 173 | if (!m_accountToUse) { |
| 174 | // if no account is selected, ask about demo |
| 175 | if (!m_demo) { |
| 176 | m_demo = askPlayDemo(); |
| 177 | } |
| 178 | if (m_demo) { |
| 179 | // we ask the user for a player name |
| 180 | bool ok = false; |
| 181 | auto name = askOfflineName("Player", m_demo, ok); |
| 182 | if (ok) { |
| 183 | m_session = std::make_shared<AuthSession>(); |
| 184 | m_session->MakeDemo(name, MinecraftAccount::uuidFromUsername(name).toString().remove(QRegularExpression("[{}-]"))); |
| 185 | launchInstance(); |
| 186 | return; |
| 187 | } |
| 188 | } |
| 189 | // if no account is selected, we bail |
| 190 | emitFailed(tr("No account selected for launch.")); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | // we loop until the user succeeds in logging in or gives up |
| 195 | bool tryagain = true; |
| 196 | unsigned int tries = 0; |
| 197 | |
| 198 | if ((m_accountToUse->accountType() != AccountType::Offline && m_accountToUse->accountState() == AccountState::Offline) || |
| 199 | m_accountToUse->shouldRefresh()) { |
| 200 | // Force account refresh on the account used to launch the instance updating the AccountState |
| 201 | // only on first try and if it is not meant to be offline |
| 202 | auto accounts = APPLICATION->accounts(); |
| 203 | accounts->requestRefresh(m_accountToUse->internalId()); |
| 204 | } |
| 205 | while (tryagain) { |
| 206 | if (tries > 0 && tries % 3 == 0) { |
| 207 | auto result = |
| 208 | QMessageBox::question(m_parentWidget, tr("Continue launch?"), |
| 209 | tr("It looks like we couldn't launch after %1 tries. Do you want to continue trying?").arg(tries)); |
| 210 | |
| 211 | if (result == QMessageBox::No) { |
| 212 | emitAborted(); |
| 213 | return; |
| 214 | } |
| 215 | } |
| 216 | tries++; |
| 217 | m_session = std::make_shared<AuthSession>(); |
| 218 | m_session->wants_online = m_online; |
| 219 | m_session->demo = m_demo; |
| 220 | m_accountToUse->fillSession(m_session); |
| 221 | |
| 222 | // Launch immediately in true offline mode |
| 223 | if (m_accountToUse->accountType() == AccountType::Offline) { |
| 224 | launchInstance(); |
| 225 | return; |
| 226 | } |
nothing calls this directly
no test coverage detected