From abf8408911c057d8aafe90790f5d2f5de0e1d97c Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 20 Nov 2013 18:31:15 -0600 Subject: Nuke and pave the old login system Also, account list now saves profile lists. --- gui/MainWindow.cpp | 134 ++++++++++++++++++++++------------------------------- 1 file changed, 55 insertions(+), 79 deletions(-) (limited to 'gui/MainWindow.cpp') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 3bf248f9..734ed3b4 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -544,11 +544,7 @@ void MainWindow::instanceActivated(QModelIndex index) NagUtils::checkJVMArgs(inst->settings().get("JvmArgs").toString(), this); - bool autoLogin = inst->settings().get("AutoLogin").toBool(); - if (autoLogin) - doAutoLogin(); - else - doLogin(); + doLogin(); } void MainWindow::on_actionLaunchInstance_triggered() @@ -560,56 +556,34 @@ void MainWindow::on_actionLaunchInstance_triggered() } } -void MainWindow::doAutoLogin() +void MainWindow::doLogin(const QString &errorMsg) { if (!m_selectedInstance) return; - Keyring *k = Keyring::instance(); - QStringList accounts = k->getStoredAccounts("minecraft"); - - if (!accounts.isEmpty()) + // Find an account to use. + std::shared_ptr accounts = MMC->accounts(); + MojangAccountPtr account; + if (accounts->count() <= 0) { - QString username = accounts[0]; - QString password = k->getPassword("minecraft", username); - - if (!password.isEmpty()) - { - QLOG_INFO() << "Automatically logging in with stored account: " << username; - m_activeInst = m_selectedInstance; - doLogin(username, password); - } - else - { - QLOG_ERROR() << "Auto login set for account, but no password was found: " - << username; - doLogin(tr("Auto login attempted, but no password is stored.")); - } + // Tell the user they need to log in at least one account in order to play. + CustomMessageBox::selectable(this, tr("No Accounts"), + tr("In order to play Minecraft, you must have at least one Mojang or Minecraft account logged in to MultiMC. Please add an account."), + QMessageBox::Warning)->show(); } else { - QLOG_ERROR() << "Auto login set but no accounts were stored."; - doLogin(tr("Auto login attempted, but no accounts are stored.")); + // TODO: Allow user to select different accounts. + // For now, we'll just use the first one in the list until I get arround to implementing that. + account = accounts->at(0); } -} - -void MainWindow::doLogin(QString username, QString password) -{ - UserInfo uInfo{username, password}; - - ProgressDialog *tDialog = new ProgressDialog(this); - LoginTask *loginTask = new LoginTask(uInfo, tDialog); - connect(loginTask, SIGNAL(succeeded()), SLOT(onLoginComplete()), Qt::QueuedConnection); - connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection); - - tDialog->exec(loginTask); -} -void MainWindow::doLogin(const QString &errorMsg) -{ - if (!m_selectedInstance) - return; + // We'll need to validate the access token to make sure the account is still logged in. + // TODO: Do that ^ + + launchInstance(m_selectedInstance, account); + /* LoginDialog *loginDlg = new LoginDialog(this, errorMsg); if (!m_selectedInstance->lastLaunch()) loginDlg->forceOnline(); @@ -632,6 +606,41 @@ void MainWindow::doLogin(const QString &errorMsg) launchInstance(m_activeInst, m_activeLogin); } } + */ +} + +void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account) +{ + Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); + + proc = instance->prepareForLaunch(account); + if (!proc) + return; + + // Prepare GUI: If it shall stay open disable the required parts + if (MMC->settings()->get("NoHide").toBool()) + { + ui->actionLaunchInstance->setEnabled(false); + } + else + { + this->hide(); + } + + console = new ConsoleWindow(proc); + + connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, + SLOT(write(QString, MessageLevel::Enum))); + connect(proc, SIGNAL(ended(BaseInstance *)), this, SLOT(instanceEnded(BaseInstance *))); + + if (instance->settings().get("ShowConsole").toBool()) + { + console->show(); + } + + // I think this will work... + proc->setLogin(account->username(), account->accessToken()); + proc->launch(); } void MainWindow::onLoginComplete() @@ -644,7 +653,7 @@ void MainWindow::onLoginComplete() BaseUpdate *updateTask = m_activeInst->doUpdate(); if (!updateTask) { - launchInstance(m_activeInst, m_activeLogin); + //launchInstance(m_activeInst, m_activeLogin); } else { @@ -701,7 +710,7 @@ void MainWindow::onLoginComplete() void MainWindow::onGameUpdateComplete() { - launchInstance(m_activeInst, m_activeLogin); + //launchInstance(m_activeInst, m_activeLogin); } void MainWindow::onGameUpdateError(QString error) @@ -710,39 +719,6 @@ void MainWindow::onGameUpdateError(QString error) QMessageBox::Warning)->show(); } -void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) -{ - Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); - - proc = instance->prepareForLaunch(response); - if (!proc) - return; - - // Prepare GUI: If it shall stay open disable the required parts - if (MMC->settings()->get("NoHide").toBool()) - { - ui->actionLaunchInstance->setEnabled(false); - } - else - { - this->hide(); - } - - console = new ConsoleWindow(proc); - - connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, - SLOT(write(QString, MessageLevel::Enum))); - connect(proc, SIGNAL(ended(BaseInstance *)), this, SLOT(instanceEnded(BaseInstance *))); - - if (instance->settings().get("ShowConsole").toBool()) - { - console->show(); - } - - proc->setLogin(response.username, response.session_id); - proc->launch(); -} - void MainWindow::taskStart() { // Nothing to do here yet. -- cgit v1.2.3