Fix login and startup logging issues

Auth uses the refresh endpoint instead of validate. This means less password entering.
Console will now only autoscroll when already scrolled all the way down.
Better conformance with the Yggdrasil auth protocol (not complete yet, but Mojang launcher isn't complete either).
Fix bug that prevented saving the account data (uninitialized variable).
Accounts can now trigger account list saving, this is used for the refresh endpoint.
This commit is contained in:
Petr Mrázek
2013-12-01 02:00:42 +01:00
parent 2eaf33816b
commit f27a6c39ea
27 changed files with 471 additions and 299 deletions

View File

@ -58,13 +58,23 @@ void ConsoleWindow::writeColor(QString text, const char *color)
ui->text->appendHtml(QString("<font color=\"%1\">%2</font>").arg(color).arg(text));
else
ui->text->appendPlainText(text);
// scroll down
QScrollBar *bar = ui->text->verticalScrollBar();
bar->setValue(bar->maximum());
}
void ConsoleWindow::write(QString data, MessageLevel::Enum mode)
{
QScrollBar *bar = ui->text->verticalScrollBar();
int max_bar = bar->maximum();
int val_bar = bar->value();
if(m_scroll_active)
{
if(m_last_scroll_value > val_bar)
m_scroll_active = false;
}
else
{
m_scroll_active = val_bar == max_bar;
}
if (data.endsWith('\n'))
data = data.left(data.length() - 1);
QStringList paragraphs = data.split('\n');
@ -93,6 +103,11 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode)
else
while (iter.hasNext())
writeColor(iter.next());
if(m_scroll_active)
{
bar->setValue(bar->maximum());
}
m_last_scroll_value = bar->value();
}
void ConsoleWindow::clear()

View File

@ -38,6 +38,16 @@ public:
*/
void setMayClose(bool mayclose);
private:
/**
* @brief write a colored paragraph
* @param data the string
* @param color the css color name
* this will only insert a single paragraph.
* \n are ignored. a real \n is always appended.
*/
void writeColor(QString data, const char *color = nullptr);
signals:
void isClosing();
@ -51,15 +61,6 @@ slots:
*/
void write(QString data, MessageLevel::Enum level = MessageLevel::MultiMC);
/**
* @brief write a colored paragraph
* @param data the string
* @param color the css color name
* this will only insert a single paragraph.
* \n are ignored. a real \n is always appended.
*/
void writeColor(QString data, const char *color = nullptr);
/**
* @brief clear the text widget
*/
@ -82,4 +83,6 @@ private:
Ui::ConsoleWindow *ui = nullptr;
MinecraftProcess *proc = nullptr;
bool m_mayclose = true;
int m_last_scroll_value = 0;
bool m_scroll_active = true;
};

View File

@ -69,8 +69,9 @@
#include "logic/lists/IconList.h"
#include "logic/lists/JavaVersionList.h"
#include "logic/auth/AuthenticateTask.h"
#include "logic/auth/ValidateTask.h"
#include "logic/auth/flows/AuthenticateTask.h"
#include "logic/auth/flows/RefreshTask.h"
#include "logic/auth/flows/ValidateTask.h"
#include "logic/BaseInstance.h"
#include "logic/InstanceFactory.h"
@ -276,7 +277,6 @@ MainWindow::~MainWindow()
delete assets_downloader;
}
void MainWindow::repopulateAccountsMenu()
{
accountMenu->clear();
@ -791,16 +791,16 @@ void MainWindow::doLaunchInst(BaseInstance* instance, MojangAccountPtr account)
{
// We'll need to validate the access token to make sure the account is still logged in.
ProgressDialog progDialog(this);
ValidateTask validateTask(account, &progDialog);
progDialog.exec(&validateTask);
if (validateTask.successful())
RefreshTask refreshtask(account, &progDialog);
progDialog.exec(&refreshtask);
if (refreshtask.successful())
{
prepareLaunch(m_selectedInstance, account);
}
else
{
YggdrasilTask::Error* error = validateTask.getError();
YggdrasilTask::Error *error = refreshtask.getError();
if (error != nullptr)
{
@ -812,17 +812,20 @@ void MainWindow::doLaunchInst(BaseInstance* instance, MojangAccountPtr account)
}
else
{
CustomMessageBox::selectable(this, tr("Access Token Validation Error"),
CustomMessageBox::selectable(
this, tr("Access Token Validation Error"),
tr("There was an error when trying to validate your access token.\n"
"Details: %s").arg(error->getDisplayMessage()),
"Details: %s").arg(error->getDisplayMessage()),
QMessageBox::Warning, QMessageBox::Ok)->exec();
}
}
else
{
CustomMessageBox::selectable(this, tr("Access Token Validation Error"),
CustomMessageBox::selectable(
this, tr("Access Token Validation Error"),
tr("There was an unknown error when trying to validate your access token."
"The authentication server might be down, or you might not be connected to the Internet."),
"The authentication server might be down, or you might not be connected to "
"the Internet."),
QMessageBox::Warning, QMessageBox::Ok)->exec();
}
}
@ -879,10 +882,7 @@ void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account
console = new ConsoleWindow(proc);
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
// I think this will work...
QString username = account->username();
QString session_id = account->accessToken();
proc->setLogin(username, session_id);
proc->setLogin(account);
proc->launch();
}

View File

@ -20,7 +20,7 @@
#include <logger/QsLog.h>
#include <logic/auth/AuthenticateTask.h>
#include <logic/auth/flows/AuthenticateTask.h>
#include <logic/net/NetJob.h>
#include <gui/dialogs/EditAccountDialog.h>
@ -29,9 +29,8 @@
#include <MultiMC.h>
AccountListDialog::AccountListDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AccountListDialog)
AccountListDialog::AccountListDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::AccountListDialog)
{
ui->setupUi(this);
@ -44,8 +43,8 @@ AccountListDialog::AccountListDialog(QWidget *parent) :
connect(selectionModel, &QItemSelectionModel::selectionChanged,
[this] (const QItemSelection& sel, const QItemSelection& dsel) { updateButtonStates(); });
connect(m_accounts.get(), SIGNAL(listChanged), SLOT(listChanged));
connect(m_accounts.get(), SIGNAL(activeAccountChanged), SLOT(listChanged));
connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
updateButtonStates();
}
@ -60,7 +59,6 @@ void AccountListDialog::listChanged()
updateButtonStates();
}
void AccountListDialog::on_addAccountBtn_clicked()
{
addAccount(tr("Please enter your Mojang or Minecraft account username and password to add your account."));
@ -84,7 +82,7 @@ void AccountListDialog::on_setDefaultBtn_clicked()
QModelIndex selected = selection.first();
MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
m_accounts->setActiveAccount(account->username());
}
}
}
void AccountListDialog::on_noDefaultBtn_clicked()
@ -104,7 +102,7 @@ void AccountListDialog::updateButtonStates()
ui->rmAccountBtn->setEnabled(selection.size() > 0);
ui->setDefaultBtn->setEnabled(selection.size() > 0);
ui->noDefaultBtn->setDown(m_accounts->activeAccount().get() == nullptr);
}
@ -146,4 +144,3 @@ void AccountListDialog::addAccount(const QString& errMsg)
}
}
}

View File

@ -21,7 +21,8 @@
#include "logic/lists/MojangAccountList.h"
namespace Ui {
namespace Ui
{
class AccountListDialog;
}
@ -29,7 +30,7 @@ class AuthenticateTask;
class AccountListDialog : public QDialog
{
Q_OBJECT
Q_OBJECT
public:
explicit AccountListDialog(QWidget *parent = 0);
~AccountListDialog();
@ -62,4 +63,3 @@ slots:
private:
Ui::AccountListDialog *ui;
};

View File

@ -20,15 +20,14 @@
#include <logger/QsLog.h>
#include <logic/auth/AuthenticateTask.h>
#include <logic/auth/flows/AuthenticateTask.h>
#include <gui/dialogs/ProgressDialog.h>
#include <MultiMC.h>
AccountSelectDialog::AccountSelectDialog(const QString& message, int flags, QWidget *parent) :
QDialog(parent),
ui(new Ui::AccountSelectDialog)
AccountSelectDialog::AccountSelectDialog(const QString &message, int flags, QWidget *parent)
: QDialog(parent), ui(new Ui::AccountSelectDialog)
{
ui->setupUi(this);
@ -85,4 +84,3 @@ void AccountSelectDialog::on_buttonBox_rejected()
{
close();
}

View File

@ -21,17 +21,18 @@
#include "logic/lists/MojangAccountList.h"
namespace Ui {
namespace Ui
{
class AccountSelectDialog;
}
class AccountSelectDialog : public QDialog
{
Q_OBJECT
Q_OBJECT
public:
enum Flags
{
NoFlags=0,
NoFlags = 0,
/*!
* Shows a check box on the dialog that allows the user to specify that the account
@ -75,7 +76,7 @@ public:
public
slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
protected:
@ -87,4 +88,3 @@ protected:
private:
Ui::AccountSelectDialog *ui;
};

View File

@ -16,11 +16,10 @@
#include "EditAccountDialog.h"
#include "ui_EditAccountDialog.h"
EditAccountDialog::EditAccountDialog(const QString& text, QWidget *parent, int flags) :
QDialog(parent),
ui(new Ui::EditAccountDialog)
EditAccountDialog::EditAccountDialog(const QString &text, QWidget *parent, int flags)
: QDialog(parent), ui(new Ui::EditAccountDialog)
{
ui->setupUi(this);
ui->setupUi(this);
ui->label->setText(text);
ui->label->setVisible(!text.isEmpty());
@ -31,7 +30,7 @@ EditAccountDialog::EditAccountDialog(const QString& text, QWidget *parent, int f
EditAccountDialog::~EditAccountDialog()
{
delete ui;
delete ui;
}
QString EditAccountDialog::username() const
@ -43,4 +42,3 @@ QString EditAccountDialog::password() const
{
return ui->passTextBox->text();
}

View File

@ -17,16 +17,18 @@
#include <QDialog>
namespace Ui {
namespace Ui
{
class EditAccountDialog;
}
class EditAccountDialog : public QDialog
{
Q_OBJECT
Q_OBJECT
public:
explicit EditAccountDialog(const QString& text="", QWidget *parent = 0, int flags=UsernameField | PasswordField);
explicit EditAccountDialog(const QString &text = "", QWidget *parent = 0,
int flags = UsernameField | PasswordField);
~EditAccountDialog();
/*!
@ -41,7 +43,7 @@ public:
enum Flags
{
NoFlags=0,
NoFlags = 0,
//! Specifies that the dialog should have a username field.
UsernameField,
@ -53,4 +55,3 @@ public:
private:
Ui::EditAccountDialog *ui;
};