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:
parent
2eaf33816b
commit
f27a6c39ea
@ -276,11 +276,14 @@ logic/auth/MojangAccount.h
|
|||||||
logic/auth/MojangAccount.cpp
|
logic/auth/MojangAccount.cpp
|
||||||
logic/auth/YggdrasilTask.h
|
logic/auth/YggdrasilTask.h
|
||||||
logic/auth/YggdrasilTask.cpp
|
logic/auth/YggdrasilTask.cpp
|
||||||
logic/auth/AuthenticateTask.h
|
logic/auth/flows/AuthenticateTask.h
|
||||||
logic/auth/AuthenticateTask.cpp
|
logic/auth/flows/AuthenticateTask.cpp
|
||||||
logic/auth/ValidateTask.h
|
logic/auth/flows/RefreshTask.cpp
|
||||||
logic/auth/ValidateTask.cpp
|
logic/auth/flows/RefreshTask.cpp
|
||||||
|
logic/auth/flows/ValidateTask.h
|
||||||
|
logic/auth/flows/ValidateTask.cpp
|
||||||
|
logic/auth/flows/InvalidateTask.h
|
||||||
|
logic/auth/flows/InvalidateTask.cpp
|
||||||
|
|
||||||
# legacy instances
|
# legacy instances
|
||||||
logic/LegacyInstance.h
|
logic/LegacyInstance.h
|
||||||
@ -592,5 +595,3 @@ endif (UPDATE_TRANSLATIONS)
|
|||||||
add_custom_target (translations DEPENDS ${QM_FILES})
|
add_custom_target (translations DEPENDS ${QM_FILES})
|
||||||
|
|
||||||
install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/translations)
|
install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/translations)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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));
|
ui->text->appendHtml(QString("<font color=\"%1\">%2</font>").arg(color).arg(text));
|
||||||
else
|
else
|
||||||
ui->text->appendPlainText(text);
|
ui->text->appendPlainText(text);
|
||||||
// scroll down
|
|
||||||
QScrollBar *bar = ui->text->verticalScrollBar();
|
|
||||||
bar->setValue(bar->maximum());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleWindow::write(QString data, MessageLevel::Enum mode)
|
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'))
|
if (data.endsWith('\n'))
|
||||||
data = data.left(data.length() - 1);
|
data = data.left(data.length() - 1);
|
||||||
QStringList paragraphs = data.split('\n');
|
QStringList paragraphs = data.split('\n');
|
||||||
@ -93,6 +103,11 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode)
|
|||||||
else
|
else
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
writeColor(iter.next());
|
writeColor(iter.next());
|
||||||
|
if(m_scroll_active)
|
||||||
|
{
|
||||||
|
bar->setValue(bar->maximum());
|
||||||
|
}
|
||||||
|
m_last_scroll_value = bar->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleWindow::clear()
|
void ConsoleWindow::clear()
|
||||||
|
@ -38,6 +38,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setMayClose(bool mayclose);
|
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:
|
signals:
|
||||||
void isClosing();
|
void isClosing();
|
||||||
|
|
||||||
@ -51,15 +61,6 @@ slots:
|
|||||||
*/
|
*/
|
||||||
void write(QString data, MessageLevel::Enum level = MessageLevel::MultiMC);
|
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
|
* @brief clear the text widget
|
||||||
*/
|
*/
|
||||||
@ -82,4 +83,6 @@ private:
|
|||||||
Ui::ConsoleWindow *ui = nullptr;
|
Ui::ConsoleWindow *ui = nullptr;
|
||||||
MinecraftProcess *proc = nullptr;
|
MinecraftProcess *proc = nullptr;
|
||||||
bool m_mayclose = true;
|
bool m_mayclose = true;
|
||||||
|
int m_last_scroll_value = 0;
|
||||||
|
bool m_scroll_active = true;
|
||||||
};
|
};
|
||||||
|
@ -69,8 +69,9 @@
|
|||||||
#include "logic/lists/IconList.h"
|
#include "logic/lists/IconList.h"
|
||||||
#include "logic/lists/JavaVersionList.h"
|
#include "logic/lists/JavaVersionList.h"
|
||||||
|
|
||||||
#include "logic/auth/AuthenticateTask.h"
|
#include "logic/auth/flows/AuthenticateTask.h"
|
||||||
#include "logic/auth/ValidateTask.h"
|
#include "logic/auth/flows/RefreshTask.h"
|
||||||
|
#include "logic/auth/flows/ValidateTask.h"
|
||||||
|
|
||||||
#include "logic/BaseInstance.h"
|
#include "logic/BaseInstance.h"
|
||||||
#include "logic/InstanceFactory.h"
|
#include "logic/InstanceFactory.h"
|
||||||
@ -276,7 +277,6 @@ MainWindow::~MainWindow()
|
|||||||
delete assets_downloader;
|
delete assets_downloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::repopulateAccountsMenu()
|
void MainWindow::repopulateAccountsMenu()
|
||||||
{
|
{
|
||||||
accountMenu->clear();
|
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.
|
// We'll need to validate the access token to make sure the account is still logged in.
|
||||||
ProgressDialog progDialog(this);
|
ProgressDialog progDialog(this);
|
||||||
ValidateTask validateTask(account, &progDialog);
|
RefreshTask refreshtask(account, &progDialog);
|
||||||
progDialog.exec(&validateTask);
|
progDialog.exec(&refreshtask);
|
||||||
|
|
||||||
if (validateTask.successful())
|
if (refreshtask.successful())
|
||||||
{
|
{
|
||||||
prepareLaunch(m_selectedInstance, account);
|
prepareLaunch(m_selectedInstance, account);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
YggdrasilTask::Error* error = validateTask.getError();
|
YggdrasilTask::Error *error = refreshtask.getError();
|
||||||
|
|
||||||
if (error != nullptr)
|
if (error != nullptr)
|
||||||
{
|
{
|
||||||
@ -812,7 +812,8 @@ void MainWindow::doLaunchInst(BaseInstance* instance, MojangAccountPtr account)
|
|||||||
}
|
}
|
||||||
else
|
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"
|
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();
|
QMessageBox::Warning, QMessageBox::Ok)->exec();
|
||||||
@ -820,9 +821,11 @@ void MainWindow::doLaunchInst(BaseInstance* instance, MojangAccountPtr account)
|
|||||||
}
|
}
|
||||||
else
|
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."
|
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();
|
QMessageBox::Warning, QMessageBox::Ok)->exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -879,10 +882,7 @@ void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account
|
|||||||
console = new ConsoleWindow(proc);
|
console = new ConsoleWindow(proc);
|
||||||
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
|
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
|
||||||
|
|
||||||
// I think this will work...
|
proc->setLogin(account);
|
||||||
QString username = account->username();
|
|
||||||
QString session_id = account->accessToken();
|
|
||||||
proc->setLogin(username, session_id);
|
|
||||||
proc->launch();
|
proc->launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <logger/QsLog.h>
|
#include <logger/QsLog.h>
|
||||||
|
|
||||||
#include <logic/auth/AuthenticateTask.h>
|
#include <logic/auth/flows/AuthenticateTask.h>
|
||||||
#include <logic/net/NetJob.h>
|
#include <logic/net/NetJob.h>
|
||||||
|
|
||||||
#include <gui/dialogs/EditAccountDialog.h>
|
#include <gui/dialogs/EditAccountDialog.h>
|
||||||
@ -29,9 +29,8 @@
|
|||||||
|
|
||||||
#include <MultiMC.h>
|
#include <MultiMC.h>
|
||||||
|
|
||||||
AccountListDialog::AccountListDialog(QWidget *parent) :
|
AccountListDialog::AccountListDialog(QWidget *parent)
|
||||||
QDialog(parent),
|
: QDialog(parent), ui(new Ui::AccountListDialog)
|
||||||
ui(new Ui::AccountListDialog)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -44,8 +43,8 @@ AccountListDialog::AccountListDialog(QWidget *parent) :
|
|||||||
connect(selectionModel, &QItemSelectionModel::selectionChanged,
|
connect(selectionModel, &QItemSelectionModel::selectionChanged,
|
||||||
[this] (const QItemSelection& sel, const QItemSelection& dsel) { updateButtonStates(); });
|
[this] (const QItemSelection& sel, const QItemSelection& dsel) { updateButtonStates(); });
|
||||||
|
|
||||||
connect(m_accounts.get(), SIGNAL(listChanged), SLOT(listChanged));
|
connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
|
||||||
connect(m_accounts.get(), SIGNAL(activeAccountChanged), SLOT(listChanged));
|
connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
|
||||||
|
|
||||||
updateButtonStates();
|
updateButtonStates();
|
||||||
}
|
}
|
||||||
@ -60,7 +59,6 @@ void AccountListDialog::listChanged()
|
|||||||
updateButtonStates();
|
updateButtonStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AccountListDialog::on_addAccountBtn_clicked()
|
void AccountListDialog::on_addAccountBtn_clicked()
|
||||||
{
|
{
|
||||||
addAccount(tr("Please enter your Mojang or Minecraft account username and password to add your account."));
|
addAccount(tr("Please enter your Mojang or Minecraft account username and password to add your account."));
|
||||||
@ -146,4 +144,3 @@ void AccountListDialog::addAccount(const QString& errMsg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
|
|
||||||
#include "logic/lists/MojangAccountList.h"
|
#include "logic/lists/MojangAccountList.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class AccountListDialog;
|
class AccountListDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ class AuthenticateTask;
|
|||||||
|
|
||||||
class AccountListDialog : public QDialog
|
class AccountListDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit AccountListDialog(QWidget *parent = 0);
|
explicit AccountListDialog(QWidget *parent = 0);
|
||||||
~AccountListDialog();
|
~AccountListDialog();
|
||||||
@ -62,4 +63,3 @@ slots:
|
|||||||
private:
|
private:
|
||||||
Ui::AccountListDialog *ui;
|
Ui::AccountListDialog *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,15 +20,14 @@
|
|||||||
|
|
||||||
#include <logger/QsLog.h>
|
#include <logger/QsLog.h>
|
||||||
|
|
||||||
#include <logic/auth/AuthenticateTask.h>
|
#include <logic/auth/flows/AuthenticateTask.h>
|
||||||
|
|
||||||
#include <gui/dialogs/ProgressDialog.h>
|
#include <gui/dialogs/ProgressDialog.h>
|
||||||
|
|
||||||
#include <MultiMC.h>
|
#include <MultiMC.h>
|
||||||
|
|
||||||
AccountSelectDialog::AccountSelectDialog(const QString& message, int flags, QWidget *parent) :
|
AccountSelectDialog::AccountSelectDialog(const QString &message, int flags, QWidget *parent)
|
||||||
QDialog(parent),
|
: QDialog(parent), ui(new Ui::AccountSelectDialog)
|
||||||
ui(new Ui::AccountSelectDialog)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -85,4 +84,3 @@ void AccountSelectDialog::on_buttonBox_rejected()
|
|||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,17 +21,18 @@
|
|||||||
|
|
||||||
#include "logic/lists/MojangAccountList.h"
|
#include "logic/lists/MojangAccountList.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class AccountSelectDialog;
|
class AccountSelectDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AccountSelectDialog : public QDialog
|
class AccountSelectDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum Flags
|
enum Flags
|
||||||
{
|
{
|
||||||
NoFlags=0,
|
NoFlags = 0,
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Shows a check box on the dialog that allows the user to specify that the account
|
* Shows a check box on the dialog that allows the user to specify that the account
|
||||||
@ -87,4 +88,3 @@ protected:
|
|||||||
private:
|
private:
|
||||||
Ui::AccountSelectDialog *ui;
|
Ui::AccountSelectDialog *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,9 +16,8 @@
|
|||||||
#include "EditAccountDialog.h"
|
#include "EditAccountDialog.h"
|
||||||
#include "ui_EditAccountDialog.h"
|
#include "ui_EditAccountDialog.h"
|
||||||
|
|
||||||
EditAccountDialog::EditAccountDialog(const QString& text, QWidget *parent, int flags) :
|
EditAccountDialog::EditAccountDialog(const QString &text, QWidget *parent, int flags)
|
||||||
QDialog(parent),
|
: QDialog(parent), ui(new Ui::EditAccountDialog)
|
||||||
ui(new Ui::EditAccountDialog)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -43,4 +42,3 @@ QString EditAccountDialog::password() const
|
|||||||
{
|
{
|
||||||
return ui->passTextBox->text();
|
return ui->passTextBox->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,16 +17,18 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui
|
||||||
|
{
|
||||||
class EditAccountDialog;
|
class EditAccountDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class EditAccountDialog : public QDialog
|
class EditAccountDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
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();
|
~EditAccountDialog();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -41,7 +43,7 @@ public:
|
|||||||
|
|
||||||
enum Flags
|
enum Flags
|
||||||
{
|
{
|
||||||
NoFlags=0,
|
NoFlags = 0,
|
||||||
|
|
||||||
//! Specifies that the dialog should have a username field.
|
//! Specifies that the dialog should have a username field.
|
||||||
UsernameField,
|
UsernameField,
|
||||||
@ -53,4 +55,3 @@ public:
|
|||||||
private:
|
private:
|
||||||
Ui::EditAccountDialog *ui;
|
Ui::EditAccountDialog *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -71,6 +71,26 @@ void MinecraftProcess::setWorkdir(QString path)
|
|||||||
m_prepostlaunchprocess.setWorkingDirectory(mcDir.absolutePath());
|
m_prepostlaunchprocess.setWorkingDirectory(mcDir.absolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString MinecraftProcess::censorPrivateInfo(QString in)
|
||||||
|
{
|
||||||
|
if(!m_account)
|
||||||
|
return in;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString sessionId = m_account->sessionId();
|
||||||
|
QString accessToken = m_account->accessToken();
|
||||||
|
QString clientToken = m_account->clientToken();
|
||||||
|
QString profileId = m_account->currentProfile()->id();
|
||||||
|
QString profileName = m_account->currentProfile()->name();
|
||||||
|
in.replace(sessionId, "<SESSION ID>");
|
||||||
|
in.replace(accessToken, "<ACCESS TOKEN>");
|
||||||
|
in.replace(clientToken, "<CLIENT TOKEN>");
|
||||||
|
in.replace(clientToken, "<PROFILE ID>");
|
||||||
|
in.replace(clientToken, "<PROFILE NAME>");
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// console window
|
// console window
|
||||||
void MinecraftProcess::on_stdErr()
|
void MinecraftProcess::on_stdErr()
|
||||||
{
|
{
|
||||||
@ -83,8 +103,7 @@ void MinecraftProcess::on_stdErr()
|
|||||||
for (int i = 0; i < lines.size() - 1; i++)
|
for (int i = 0; i < lines.size() - 1; i++)
|
||||||
{
|
{
|
||||||
QString &line = lines[i];
|
QString &line = lines[i];
|
||||||
emit log(line /*.replace(username, "<Username>").replace(sessionID, "<Session ID>")*/,
|
emit log(censorPrivateInfo(line), getLevel(line, MessageLevel::Error));
|
||||||
getLevel(line, MessageLevel::Error));
|
|
||||||
}
|
}
|
||||||
if (!complete)
|
if (!complete)
|
||||||
m_err_leftover = lines.last();
|
m_err_leftover = lines.last();
|
||||||
@ -101,8 +120,7 @@ void MinecraftProcess::on_stdOut()
|
|||||||
for (int i = 0; i < lines.size() - 1; i++)
|
for (int i = 0; i < lines.size() - 1; i++)
|
||||||
{
|
{
|
||||||
QString &line = lines[i];
|
QString &line = lines[i];
|
||||||
emit log(line.replace(username, "<Username>").replace(sessionID, "<Session ID>"),
|
emit log(censorPrivateInfo(line), getLevel(line, MessageLevel::Message));
|
||||||
getLevel(line, MessageLevel::Message));
|
|
||||||
}
|
}
|
||||||
if (!complete)
|
if (!complete)
|
||||||
m_out_leftover = lines.last();
|
m_out_leftover = lines.last();
|
||||||
@ -173,8 +191,8 @@ void MinecraftProcess::launch()
|
|||||||
emit log(QString("Minecraft folder is: '%1'").arg(workingDirectory()));
|
emit log(QString("Minecraft folder is: '%1'").arg(workingDirectory()));
|
||||||
QString JavaPath = m_instance->settings().get("JavaPath").toString();
|
QString JavaPath = m_instance->settings().get("JavaPath").toString();
|
||||||
emit log(QString("Java path: '%1'").arg(JavaPath));
|
emit log(QString("Java path: '%1'").arg(JavaPath));
|
||||||
emit log(QString("Arguments: '%1'").arg(
|
QString allArgs = m_args.join("' '");
|
||||||
m_args.join("' '").replace(username, "<Username>").replace(sessionID, "<Session ID>")));
|
emit log(QString("Arguments: '%1'").arg(censorPrivateInfo(allArgs)));
|
||||||
start(JavaPath, m_args);
|
start(JavaPath, m_args);
|
||||||
if (!waitForStarted())
|
if (!waitForStarted())
|
||||||
{
|
{
|
||||||
|
@ -69,10 +69,9 @@ public:
|
|||||||
|
|
||||||
void killMinecraft();
|
void killMinecraft();
|
||||||
|
|
||||||
inline void setLogin(QString user, QString sid)
|
inline void setLogin(MojangAccountPtr account)
|
||||||
{
|
{
|
||||||
username = user;
|
m_account = account;
|
||||||
sessionID = sid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -104,11 +103,13 @@ signals:
|
|||||||
void log(QString text, MessageLevel::Enum level = MessageLevel::MultiMC);
|
void log(QString text, MessageLevel::Enum level = MessageLevel::MultiMC);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BaseInstance *m_instance;
|
BaseInstance *m_instance = nullptr;
|
||||||
QStringList m_args;
|
QStringList m_args;
|
||||||
QString m_err_leftover;
|
QString m_err_leftover;
|
||||||
QString m_out_leftover;
|
QString m_out_leftover;
|
||||||
QProcess m_prepostlaunchprocess;
|
QProcess m_prepostlaunchprocess;
|
||||||
|
bool killed = false;
|
||||||
|
MojangAccountPtr m_account;
|
||||||
|
|
||||||
protected
|
protected
|
||||||
slots:
|
slots:
|
||||||
@ -117,8 +118,7 @@ slots:
|
|||||||
void on_stdOut();
|
void on_stdOut();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool killed;
|
QString censorPrivateInfo(QString in);
|
||||||
MessageLevel::Enum getLevel(const QString &message, MessageLevel::Enum defaultLevel);
|
MessageLevel::Enum getLevel(const QString &message, MessageLevel::Enum defaultLevel);
|
||||||
QString sessionID;
|
|
||||||
QString username;
|
|
||||||
};
|
};
|
||||||
|
@ -23,8 +23,7 @@
|
|||||||
|
|
||||||
#include <logger/QsLog.h>
|
#include <logger/QsLog.h>
|
||||||
|
|
||||||
MojangAccount::MojangAccount(const QString& username, QObject* parent) :
|
MojangAccount::MojangAccount(const QString &username, QObject *parent) : QObject(parent)
|
||||||
QObject(parent)
|
|
||||||
{
|
{
|
||||||
// Generate a client token.
|
// Generate a client token.
|
||||||
m_clientToken = QUuid::createUuid().toString();
|
m_clientToken = QUuid::createUuid().toString();
|
||||||
@ -34,9 +33,9 @@ MojangAccount::MojangAccount(const QString& username, QObject* parent) :
|
|||||||
m_currentProfile = -1;
|
m_currentProfile = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
MojangAccount::MojangAccount(const QString& username, const QString& clientToken,
|
MojangAccount::MojangAccount(const QString &username, const QString &clientToken,
|
||||||
const QString& accessToken, QObject* parent) :
|
const QString &accessToken, QObject *parent)
|
||||||
QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
m_username = username;
|
m_username = username;
|
||||||
m_clientToken = clientToken;
|
m_clientToken = clientToken;
|
||||||
@ -45,7 +44,7 @@ MojangAccount::MojangAccount(const QString& username, const QString& clientToken
|
|||||||
m_currentProfile = -1;
|
m_currentProfile = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
MojangAccount::MojangAccount(const MojangAccount& other, QObject* parent)
|
MojangAccount::MojangAccount(const MojangAccount &other, QObject *parent)
|
||||||
{
|
{
|
||||||
m_username = other.username();
|
m_username = other.username();
|
||||||
m_clientToken = other.clientToken();
|
m_clientToken = other.clientToken();
|
||||||
@ -55,7 +54,6 @@ MojangAccount::MojangAccount(const MojangAccount& other, QObject* parent)
|
|||||||
m_currentProfile = other.m_currentProfile;
|
m_currentProfile = other.m_currentProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString MojangAccount::username() const
|
QString MojangAccount::username() const
|
||||||
{
|
{
|
||||||
return m_username;
|
return m_username;
|
||||||
@ -66,18 +64,17 @@ QString MojangAccount::clientToken() const
|
|||||||
return m_clientToken;
|
return m_clientToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MojangAccount::setClientToken(const QString& clientToken)
|
void MojangAccount::setClientToken(const QString &clientToken)
|
||||||
{
|
{
|
||||||
m_clientToken = clientToken;
|
m_clientToken = clientToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString MojangAccount::accessToken() const
|
QString MojangAccount::accessToken() const
|
||||||
{
|
{
|
||||||
return m_accessToken;
|
return m_accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MojangAccount::setAccessToken(const QString& accessToken)
|
void MojangAccount::setAccessToken(const QString &accessToken)
|
||||||
{
|
{
|
||||||
m_accessToken = accessToken;
|
m_accessToken = accessToken;
|
||||||
}
|
}
|
||||||
@ -92,7 +89,7 @@ const QList<AccountProfile> MojangAccount::profiles() const
|
|||||||
return m_profiles;
|
return m_profiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AccountProfile* MojangAccount::currentProfile() const
|
const AccountProfile *MojangAccount::currentProfile() const
|
||||||
{
|
{
|
||||||
if (m_currentProfile < 0)
|
if (m_currentProfile < 0)
|
||||||
{
|
{
|
||||||
@ -105,9 +102,9 @@ const AccountProfile* MojangAccount::currentProfile() const
|
|||||||
return &m_profiles.at(m_currentProfile);
|
return &m_profiles.at(m_currentProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MojangAccount::setProfile(const QString& profileId)
|
bool MojangAccount::setProfile(const QString &profileId)
|
||||||
{
|
{
|
||||||
const QList<AccountProfile>& profiles = this->profiles();
|
const QList<AccountProfile> &profiles = this->profiles();
|
||||||
for (int i = 0; i < profiles.length(); i++)
|
for (int i = 0; i < profiles.length(); i++)
|
||||||
{
|
{
|
||||||
if (profiles.at(i).id() == profileId)
|
if (profiles.at(i).id() == profileId)
|
||||||
@ -119,14 +116,14 @@ bool MojangAccount::setProfile(const QString& profileId)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MojangAccount::loadProfiles(const ProfileList& profiles)
|
void MojangAccount::loadProfiles(const ProfileList &profiles)
|
||||||
{
|
{
|
||||||
m_profiles.clear();
|
m_profiles.clear();
|
||||||
for (auto profile : profiles)
|
for (auto profile : profiles)
|
||||||
m_profiles.append(profile);
|
m_profiles.append(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject& object)
|
MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
|
||||||
{
|
{
|
||||||
// The JSON object must at least have a username for it to be valid.
|
// The JSON object must at least have a username for it to be valid.
|
||||||
if (!object.value("username").isString())
|
if (!object.value("username").isString())
|
||||||
@ -201,7 +198,7 @@ AccountProfile::AccountProfile(const QString& id, const QString& name)
|
|||||||
m_name = name;
|
m_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountProfile::AccountProfile(const AccountProfile& other)
|
AccountProfile::AccountProfile(const AccountProfile &other)
|
||||||
{
|
{
|
||||||
m_id = other.m_id;
|
m_id = other.m_id;
|
||||||
m_name = other.m_name;
|
m_name = other.m_name;
|
||||||
@ -217,4 +214,7 @@ QString AccountProfile::name() const
|
|||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MojangAccount::propagateChange()
|
||||||
|
{
|
||||||
|
emit changed();
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QPair>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -27,7 +28,6 @@ class MojangAccount;
|
|||||||
typedef std::shared_ptr<MojangAccount> MojangAccountPtr;
|
typedef std::shared_ptr<MojangAccount> MojangAccountPtr;
|
||||||
Q_DECLARE_METATYPE(MojangAccountPtr)
|
Q_DECLARE_METATYPE(MojangAccountPtr)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that represents a profile within someone's Mojang account.
|
* Class that represents a profile within someone's Mojang account.
|
||||||
*
|
*
|
||||||
@ -38,19 +38,26 @@ Q_DECLARE_METATYPE(MojangAccountPtr)
|
|||||||
class AccountProfile
|
class AccountProfile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AccountProfile(const QString& id, const QString& name);
|
AccountProfile(const QString &id, const QString &name);
|
||||||
AccountProfile(const AccountProfile& other);
|
AccountProfile(const AccountProfile &other);
|
||||||
|
|
||||||
QString id() const;
|
QString id() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_id;
|
QString m_id;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef QList<AccountProfile> ProfileList;
|
typedef QList<AccountProfile> ProfileList;
|
||||||
|
|
||||||
|
struct User
|
||||||
|
{
|
||||||
|
QString id;
|
||||||
|
// pair of key:value
|
||||||
|
// we don't know if the keys:value mapping is 1:1, so a list is used.
|
||||||
|
QList<QPair<QString, QString>> properties;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object that stores information about a certain Mojang account.
|
* Object that stores information about a certain Mojang account.
|
||||||
@ -60,34 +67,40 @@ typedef QList<AccountProfile> ProfileList;
|
|||||||
*/
|
*/
|
||||||
class MojangAccount : public QObject
|
class MojangAccount : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructs a new MojangAccount with the given username.
|
* Constructs a new MojangAccount with the given username.
|
||||||
* The client token will be generated automatically and the access token will be blank.
|
* The client token will be generated automatically and the access token will be blank.
|
||||||
*/
|
*/
|
||||||
explicit MojangAccount(const QString& username, QObject* parent = 0);
|
explicit MojangAccount(const QString &username, QObject *parent = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new MojangAccount with the given username, client token, and access token.
|
* Constructs a new MojangAccount with the given username, client token, and access token.
|
||||||
*/
|
*/
|
||||||
explicit MojangAccount(const QString& username, const QString& clientToken, const QString& accessToken, QObject* parent = 0);
|
explicit MojangAccount(const QString &username, const QString &clientToken,
|
||||||
|
const QString &accessToken, QObject *parent = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new MojangAccount matching the given account.
|
* Constructs a new MojangAccount matching the given account.
|
||||||
*/
|
*/
|
||||||
MojangAccount(const MojangAccount& other, QObject* parent);
|
MojangAccount(const MojangAccount &other, QObject *parent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a MojangAccount from the given JSON object.
|
* Loads a MojangAccount from the given JSON object.
|
||||||
*/
|
*/
|
||||||
static MojangAccountPtr loadFromJson(const QJsonObject& json);
|
static MojangAccountPtr loadFromJson(const QJsonObject &json);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a MojangAccount to a JSON object and returns it.
|
* Saves a MojangAccount to a JSON object and returns it.
|
||||||
*/
|
*/
|
||||||
QJsonObject saveToJson();
|
QJsonObject saveToJson();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the account on disk and lists (it changed, for whatever reason)
|
||||||
|
* This is called by various Yggdrasil tasks.
|
||||||
|
*/
|
||||||
|
void propagateChange();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This MojangAccount's username. May be an email address if the account is migrated.
|
* This MojangAccount's username. May be an email address if the account is migrated.
|
||||||
@ -103,7 +116,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Sets the MojangAccount's client token to the given value.
|
* Sets the MojangAccount's client token to the given value.
|
||||||
*/
|
*/
|
||||||
void setClientToken(const QString& token);
|
void setClientToken(const QString &token);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This MojangAccount's access token.
|
* This MojangAccount's access token.
|
||||||
@ -114,7 +127,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Changes this MojangAccount's access token to the given value.
|
* Changes this MojangAccount's access token to the given value.
|
||||||
*/
|
*/
|
||||||
void setAccessToken(const QString& token);
|
void setAccessToken(const QString &token);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get full session ID
|
* Get full session ID
|
||||||
@ -130,25 +143,31 @@ public:
|
|||||||
* Returns a pointer to the currently selected profile.
|
* Returns a pointer to the currently selected profile.
|
||||||
* If no profile is selected, returns the first profile in the profile list or nullptr if there are none.
|
* If no profile is selected, returns the first profile in the profile list or nullptr if there are none.
|
||||||
*/
|
*/
|
||||||
const AccountProfile* currentProfile() const;
|
const AccountProfile *currentProfile() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the currently selected profile to the profile with the given ID string.
|
* Sets the currently selected profile to the profile with the given ID string.
|
||||||
* If profileId is not in the list of available profiles, the function will simply return false.
|
* If profileId is not in the list of available profiles, the function will simply return false.
|
||||||
*/
|
*/
|
||||||
bool setProfile(const QString& profileId);
|
bool setProfile(const QString &profileId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the current account profile list and replaces it with the given profile list.
|
* Clears the current account profile list and replaces it with the given profile list.
|
||||||
*/
|
*/
|
||||||
void loadProfiles(const ProfileList& profiles);
|
void loadProfiles(const ProfileList &profiles);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/**
|
||||||
|
* This isgnal is emitted whrn the account changes
|
||||||
|
*/
|
||||||
|
void changed();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_username;
|
QString m_username;
|
||||||
QString m_clientToken;
|
QString m_clientToken;
|
||||||
QString m_accessToken; // Blank if not logged in.
|
QString m_accessToken; // Blank if not logged in.
|
||||||
int m_currentProfile; // Index of the selected profile within the list of available profiles. -1 if nothing is selected.
|
int m_currentProfile; // Index of the selected profile within the list of available
|
||||||
|
// profiles. -1 if nothing is selected.
|
||||||
ProfileList m_profiles; // List of available profiles.
|
ProfileList m_profiles; // List of available profiles.
|
||||||
|
User m_user; // the user structure, whatever it is.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,13 +25,12 @@
|
|||||||
#include <MultiMC.h>
|
#include <MultiMC.h>
|
||||||
#include <logic/auth/MojangAccount.h>
|
#include <logic/auth/MojangAccount.h>
|
||||||
|
|
||||||
YggdrasilTask::YggdrasilTask(MojangAccountPtr account, QObject* parent) : Task(parent)
|
YggdrasilTask::YggdrasilTask(MojangAccountPtr account, QObject *parent) : Task(parent)
|
||||||
{
|
{
|
||||||
m_error = nullptr;
|
m_error = nullptr;
|
||||||
m_account = account;
|
m_account = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
YggdrasilTask::~YggdrasilTask()
|
YggdrasilTask::~YggdrasilTask()
|
||||||
{
|
{
|
||||||
if (m_error)
|
if (m_error)
|
||||||
@ -46,17 +45,18 @@ void YggdrasilTask::executeTask()
|
|||||||
QJsonDocument doc(getRequestContent());
|
QJsonDocument doc(getRequestContent());
|
||||||
|
|
||||||
auto worker = MMC->qnam();
|
auto worker = MMC->qnam();
|
||||||
connect(worker.get(), SIGNAL(finished(QNetworkReply*)), this,
|
connect(worker.get(), SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(processReply(QNetworkReply*)));
|
SLOT(processReply(QNetworkReply *)));
|
||||||
|
|
||||||
QUrl reqUrl("https://authserver.mojang.com/" + getEndpoint());
|
QUrl reqUrl("https://authserver.mojang.com/" + getEndpoint());
|
||||||
QNetworkRequest netRequest(reqUrl);
|
QNetworkRequest netRequest(reqUrl);
|
||||||
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
|
|
||||||
m_netReply = worker->post(netRequest, doc.toJson());
|
QByteArray requestData = doc.toJson();
|
||||||
|
m_netReply = worker->post(netRequest, requestData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YggdrasilTask::processReply(QNetworkReply* reply)
|
void YggdrasilTask::processReply(QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
setStatus(getStateMessage(STATE_PROCESSING_RESPONSE));
|
setStatus(getStateMessage(STATE_PROCESSING_RESPONSE));
|
||||||
|
|
||||||
@ -76,7 +76,6 @@ void YggdrasilTask::processReply(QNetworkReply* reply)
|
|||||||
QJsonParseError jsonError;
|
QJsonParseError jsonError;
|
||||||
QByteArray replyData = reply->readAll();
|
QByteArray replyData = reply->readAll();
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(replyData, &jsonError);
|
QJsonDocument doc = QJsonDocument::fromJson(replyData, &jsonError);
|
||||||
|
|
||||||
// Check the response code.
|
// Check the response code.
|
||||||
int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
|
||||||
@ -89,11 +88,12 @@ void YggdrasilTask::processReply(QNetworkReply* reply)
|
|||||||
{
|
{
|
||||||
if (!processResponse(replyData.size() > 0 ? doc.object() : QJsonObject()))
|
if (!processResponse(replyData.size() > 0 ? doc.object() : QJsonObject()))
|
||||||
{
|
{
|
||||||
YggdrasilTask::Error* err = getError();
|
YggdrasilTask::Error *err = getError();
|
||||||
if (err)
|
if (err)
|
||||||
emitFailed(err->getErrorMessage());
|
emitFailed(err->getErrorMessage());
|
||||||
else
|
else
|
||||||
emitFailed(tr("An unknown error occurred when processing the response from the authentication server."));
|
emitFailed(tr("An unknown error occurred when processing the response "
|
||||||
|
"from the authentication server."));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -166,4 +166,3 @@ MojangAccountPtr YggdrasilTask::getMojangAccount() const
|
|||||||
{
|
{
|
||||||
return this->m_account;
|
return this->m_account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,15 +24,14 @@
|
|||||||
|
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Yggdrasil task is a task that performs an operation on a given mojang account.
|
* A Yggdrasil task is a task that performs an operation on a given mojang account.
|
||||||
*/
|
*/
|
||||||
class YggdrasilTask : public Task
|
class YggdrasilTask : public Task
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit YggdrasilTask(MojangAccountPtr account, QObject* parent=0);
|
explicit YggdrasilTask(MojangAccountPtr account, QObject *parent = 0);
|
||||||
~YggdrasilTask();
|
~YggdrasilTask();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +48,10 @@ public:
|
|||||||
QString getCause() const { return m_cause; }
|
QString getCause() const { return m_cause; }
|
||||||
|
|
||||||
/// Gets the string to display in the GUI for describing this error.
|
/// Gets the string to display in the GUI for describing this error.
|
||||||
QString getDisplayMessage() { return getErrorMessage(); }
|
QString getDisplayMessage()
|
||||||
|
{
|
||||||
|
return getErrorMessage();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_shortError;
|
QString m_shortError;
|
||||||
@ -66,7 +68,7 @@ public:
|
|||||||
* Returns a pointer to a YggdrasilTask::Error object if an error has occurred.
|
* Returns a pointer to a YggdrasilTask::Error object if an error has occurred.
|
||||||
* If no error has occurred, returns a null pointer.
|
* If no error has occurred, returns a null pointer.
|
||||||
*/
|
*/
|
||||||
virtual Error* getError() const;
|
virtual Error *getError() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@ -120,11 +122,11 @@ protected:
|
|||||||
|
|
||||||
MojangAccountPtr m_account;
|
MojangAccountPtr m_account;
|
||||||
|
|
||||||
QNetworkReply* m_netReply;
|
QNetworkReply *m_netReply;
|
||||||
|
|
||||||
Error* m_error;
|
Error *m_error;
|
||||||
|
|
||||||
protected slots:
|
protected
|
||||||
void processReply(QNetworkReply* reply);
|
slots:
|
||||||
|
void processReply(QNetworkReply *reply);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <logic/auth/AuthenticateTask.h>
|
#include <logic/auth/flows/AuthenticateTask.h>
|
||||||
|
|
||||||
#include <logic/auth/MojangAccount.h>
|
#include <logic/auth/MojangAccount.h>
|
||||||
|
|
||||||
@ -26,8 +26,9 @@
|
|||||||
|
|
||||||
#include "logger/QsLog.h"
|
#include "logger/QsLog.h"
|
||||||
|
|
||||||
AuthenticateTask::AuthenticateTask(MojangAccountPtr account, const QString& password, QObject* parent) :
|
AuthenticateTask::AuthenticateTask(MojangAccountPtr account, const QString &password,
|
||||||
YggdrasilTask(account, parent), m_password(password)
|
QObject *parent)
|
||||||
|
: YggdrasilTask(account, parent), m_password(password)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,13 +45,15 @@ QJsonObject AuthenticateTask::getRequestContent() const
|
|||||||
// unmigrated accounts
|
// unmigrated accounts
|
||||||
* "password": "mojang account password",
|
* "password": "mojang account password",
|
||||||
* "clientToken": "client identifier" // optional
|
* "clientToken": "client identifier" // optional
|
||||||
|
* "requestUser": true/false // request the user structure
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
QJsonObject req;
|
QJsonObject req;
|
||||||
|
|
||||||
{
|
{
|
||||||
QJsonObject agent;
|
QJsonObject agent;
|
||||||
// C++ makes string literals void* for some stupid reason, so we have to tell it QString... Thanks Obama.
|
// C++ makes string literals void* for some stupid reason, so we have to tell it
|
||||||
|
// QString... Thanks Obama.
|
||||||
agent.insert("name", QString("Minecraft"));
|
agent.insert("name", QString("Minecraft"));
|
||||||
agent.insert("version", 1);
|
agent.insert("version", 1);
|
||||||
req.insert("agent", agent);
|
req.insert("agent", agent);
|
||||||
@ -58,6 +61,7 @@ QJsonObject AuthenticateTask::getRequestContent() const
|
|||||||
|
|
||||||
req.insert("username", getMojangAccount()->username());
|
req.insert("username", getMojangAccount()->username());
|
||||||
req.insert("password", m_password);
|
req.insert("password", m_password);
|
||||||
|
req.insert("requestUser", true);
|
||||||
|
|
||||||
// If we already have a client token, give it to the server.
|
// If we already have a client token, give it to the server.
|
||||||
// Otherwise, let the server give us one.
|
// Otherwise, let the server give us one.
|
||||||
@ -69,10 +73,12 @@ QJsonObject AuthenticateTask::getRequestContent() const
|
|||||||
|
|
||||||
bool AuthenticateTask::processResponse(QJsonObject responseData)
|
bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||||
{
|
{
|
||||||
// Read the response data. We need to get the client token, access token, and the selected profile.
|
// Read the response data. We need to get the client token, access token, and the selected
|
||||||
|
// profile.
|
||||||
QLOG_DEBUG() << "Processing authentication response.";
|
QLOG_DEBUG() << "Processing authentication response.";
|
||||||
|
|
||||||
// If we already have a client token, make sure the one the server gave us matches our existing one.
|
// If we already have a client token, make sure the one the server gave us matches our
|
||||||
|
// existing one.
|
||||||
QLOG_DEBUG() << "Getting client token.";
|
QLOG_DEBUG() << "Getting client token.";
|
||||||
QString clientToken = responseData.value("clientToken").toString("");
|
QString clientToken = responseData.value("clientToken").toString("");
|
||||||
if (clientToken.isEmpty())
|
if (clientToken.isEmpty())
|
||||||
@ -82,16 +88,17 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
|||||||
QLOG_ERROR() << "Server didn't send a client token.";
|
QLOG_ERROR() << "Server didn't send a client token.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!getMojangAccount()->clientToken().isEmpty() && clientToken != getMojangAccount()->clientToken())
|
if (!getMojangAccount()->clientToken().isEmpty() &&
|
||||||
|
clientToken != getMojangAccount()->clientToken())
|
||||||
{
|
{
|
||||||
// The server changed our client token! Obey its wishes, but complain. That's what I do for my parents, so...
|
// The server changed our client token! Obey its wishes, but complain. That's what I do
|
||||||
|
// for my parents, so...
|
||||||
QLOG_WARN() << "Server changed our client token to '" << clientToken
|
QLOG_WARN() << "Server changed our client token to '" << clientToken
|
||||||
<< "'. This shouldn't happen, but it isn't really a big deal.";
|
<< "'. This shouldn't happen, but it isn't really a big deal.";
|
||||||
}
|
}
|
||||||
// Set the client token.
|
// Set the client token.
|
||||||
getMojangAccount()->setClientToken(clientToken);
|
getMojangAccount()->setClientToken(clientToken);
|
||||||
|
|
||||||
|
|
||||||
// Now, we set the access token.
|
// Now, we set the access token.
|
||||||
QLOG_DEBUG() << "Getting access token.";
|
QLOG_DEBUG() << "Getting access token.";
|
||||||
QString accessToken = responseData.value("accessToken").toString("");
|
QString accessToken = responseData.value("accessToken").toString("");
|
||||||
@ -104,7 +111,6 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
|||||||
// Set the access token.
|
// Set the access token.
|
||||||
getMojangAccount()->setAccessToken(accessToken);
|
getMojangAccount()->setAccessToken(accessToken);
|
||||||
|
|
||||||
|
|
||||||
// Now we load the list of available profiles.
|
// Now we load the list of available profiles.
|
||||||
// Mojang hasn't yet implemented the profile system,
|
// Mojang hasn't yet implemented the profile system,
|
||||||
// but we might as well support what's there so we
|
// but we might as well support what's there so we
|
||||||
@ -124,7 +130,8 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
|||||||
// This should never happen, but we might as well
|
// This should never happen, but we might as well
|
||||||
// warn about it if it does so we can debug it easily.
|
// warn about it if it does so we can debug it easily.
|
||||||
// You never know when Mojang might do something truly derpy.
|
// You never know when Mojang might do something truly derpy.
|
||||||
QLOG_WARN() << "Found entry in available profiles list with missing ID or name field. Ignoring it.";
|
QLOG_WARN() << "Found entry in available profiles list with missing ID or name "
|
||||||
|
"field. Ignoring it.";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, add a new AccountProfile entry to the list.
|
// Now, add a new AccountProfile entry to the list.
|
||||||
@ -133,8 +140,6 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
|||||||
// Put the list of profiles we loaded into the MojangAccount object.
|
// Put the list of profiles we loaded into the MojangAccount object.
|
||||||
getMojangAccount()->loadProfiles(loadedProfiles);
|
getMojangAccount()->loadProfiles(loadedProfiles);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Finally, we set the current profile to the correct value. This is pretty simple.
|
// Finally, we set the current profile to the correct value. This is pretty simple.
|
||||||
// We do need to make sure that the current profile that the server gave us
|
// We do need to make sure that the current profile that the server gave us
|
||||||
// is actually in the available profiles list.
|
// is actually in the available profiles list.
|
||||||
@ -151,51 +156,23 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
|||||||
if (!getMojangAccount()->setProfile(currentProfileId))
|
if (!getMojangAccount()->setProfile(currentProfileId))
|
||||||
{
|
{
|
||||||
// TODO: Set an error to display to the user.
|
// TODO: Set an error to display to the user.
|
||||||
QLOG_ERROR() << "Server specified a selected profile that wasn't in the available profiles list.";
|
QLOG_ERROR() << "Server specified a selected profile that wasn't in the available "
|
||||||
|
"profiles list.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public class User
|
|
||||||
{
|
|
||||||
private String id;
|
|
||||||
private List<Property> properties;
|
|
||||||
|
|
||||||
public String getId()
|
|
||||||
{
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Property> getProperties() {
|
|
||||||
return this.properties;
|
|
||||||
}
|
|
||||||
public class Property {
|
|
||||||
private String name;
|
|
||||||
private String value;
|
|
||||||
|
|
||||||
public Property() { }
|
|
||||||
public String getKey() { return this.name; }
|
|
||||||
|
|
||||||
public String getValue()
|
|
||||||
{
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// this is what the vanilla launcher passes to the userProperties launch param
|
// this is what the vanilla launcher passes to the userProperties launch param
|
||||||
// doesn't seem to be used for anything so far? I don't get any of this data on my account
|
// doesn't seem to be used for anything so far? I don't get any of this data on my account
|
||||||
// (peterixxx)
|
// (peterixxx)
|
||||||
// is it a good idea to log this?
|
// is it a good idea to log this?
|
||||||
if(responseData.contains("user"))
|
if (responseData.contains("user"))
|
||||||
{
|
{
|
||||||
auto obj = responseData.value("user").toObject();
|
auto obj = responseData.value("user").toObject();
|
||||||
auto userId = obj.value("id").toString();
|
auto userId = obj.value("id").toString();
|
||||||
auto propArray = obj.value("properties").toArray();
|
auto propArray = obj.value("properties").toArray();
|
||||||
QLOG_DEBUG() << "User ID: " << userId;
|
QLOG_DEBUG() << "User ID: " << userId;
|
||||||
QLOG_DEBUG() << "User Properties: ";
|
QLOG_DEBUG() << "User Properties: ";
|
||||||
for(auto prop: propArray)
|
for (auto prop : propArray)
|
||||||
{
|
{
|
||||||
auto propTuple = prop.toObject();
|
auto propTuple = prop.toObject();
|
||||||
auto name = propTuple.value("name").toString();
|
auto name = propTuple.value("name").toString();
|
||||||
@ -204,7 +181,8 @@ public class User
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We've made it through the minefield of possible errors. Return true to indicate that we've succeeded.
|
// We've made it through the minefield of possible errors. Return true to indicate that
|
||||||
|
// we've succeeded.
|
||||||
QLOG_DEBUG() << "Finished reading authentication response.";
|
QLOG_DEBUG() << "Finished reading authentication response.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -226,5 +204,3 @@ QString AuthenticateTask::getStateMessage(const YggdrasilTask::State state) cons
|
|||||||
return YggdrasilTask::getStateMessage(state);
|
return YggdrasilTask::getStateMessage(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,14 +22,15 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The authenticate task takes a MojangAccount with no access token and password and attempts to authenticate with Mojang's servers.
|
* The authenticate task takes a MojangAccount with no access token and password and attempts to
|
||||||
|
* authenticate with Mojang's servers.
|
||||||
* If successful, it will set the MojangAccount's access token.
|
* If successful, it will set the MojangAccount's access token.
|
||||||
*/
|
*/
|
||||||
class AuthenticateTask : public YggdrasilTask
|
class AuthenticateTask : public YggdrasilTask
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AuthenticateTask(MojangAccountPtr account, const QString& password, QObject* parent=0);
|
AuthenticateTask(MojangAccountPtr account, const QString &password, QObject *parent = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QJsonObject getRequestContent() const;
|
virtual QJsonObject getRequestContent() const;
|
||||||
@ -43,4 +44,3 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QString m_password;
|
QString m_password;
|
||||||
};
|
};
|
||||||
|
|
0
logic/auth/flows/InvalidateTask.cpp
Normal file
0
logic/auth/flows/InvalidateTask.cpp
Normal file
0
logic/auth/flows/InvalidateTask.h
Normal file
0
logic/auth/flows/InvalidateTask.h
Normal file
156
logic/auth/flows/RefreshTask.cpp
Normal file
156
logic/auth/flows/RefreshTask.cpp
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
/* Copyright 2013 MultiMC Contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <logic/auth/flows/RefreshTask.h>
|
||||||
|
|
||||||
|
#include <logic/auth/MojangAccount.h>
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "logger/QsLog.h"
|
||||||
|
|
||||||
|
RefreshTask::RefreshTask(MojangAccountPtr account, QObject *parent)
|
||||||
|
: YggdrasilTask(account, parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject RefreshTask::getRequestContent() const
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* {
|
||||||
|
* "clientToken": "client identifier"
|
||||||
|
* "accessToken": "current access token to be refreshed"
|
||||||
|
* "selectedProfile": // specifying this causes errors
|
||||||
|
* {
|
||||||
|
* "id": "profile ID"
|
||||||
|
* "name": "profile name"
|
||||||
|
* }
|
||||||
|
* "requestUser": true/false // request the user structure
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
auto account = getMojangAccount();
|
||||||
|
QJsonObject req;
|
||||||
|
req.insert("clientToken", account->clientToken());
|
||||||
|
req.insert("accessToken", account->accessToken());
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
auto currentProfile = account->currentProfile();
|
||||||
|
QJsonObject profile;
|
||||||
|
profile.insert("id", currentProfile->id());
|
||||||
|
profile.insert("name", currentProfile->name());
|
||||||
|
req.insert("selectedProfile", profile);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
req.insert("requestUser", true);
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RefreshTask::processResponse(QJsonObject responseData)
|
||||||
|
{
|
||||||
|
auto account = getMojangAccount();
|
||||||
|
|
||||||
|
// Read the response data. We need to get the client token, access token, and the selected
|
||||||
|
// profile.
|
||||||
|
QLOG_DEBUG() << "Processing authentication response.";
|
||||||
|
|
||||||
|
// If we already have a client token, make sure the one the server gave us matches our
|
||||||
|
// existing one.
|
||||||
|
QString clientToken = responseData.value("clientToken").toString("");
|
||||||
|
if (clientToken.isEmpty())
|
||||||
|
{
|
||||||
|
// Fail if the server gave us an empty client token
|
||||||
|
// TODO: Set an error properly to display to the user.
|
||||||
|
QLOG_ERROR() << "Server didn't send a client token.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!account->clientToken().isEmpty() && clientToken != account->clientToken())
|
||||||
|
{
|
||||||
|
// The server changed our client token! Obey its wishes, but complain. That's what I do
|
||||||
|
// for my parents, so...
|
||||||
|
QLOG_ERROR() << "Server changed our client token to '" << clientToken
|
||||||
|
<< "'. This shouldn't happen, but it isn't really a big deal.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now, we set the access token.
|
||||||
|
QLOG_DEBUG() << "Getting new access token.";
|
||||||
|
QString accessToken = responseData.value("accessToken").toString("");
|
||||||
|
if (accessToken.isEmpty())
|
||||||
|
{
|
||||||
|
// Fail if the server didn't give us an access token.
|
||||||
|
// TODO: Set an error properly to display to the user.
|
||||||
|
QLOG_ERROR() << "Server didn't send an access token.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we validate that the server responded right. (our current profile = returned current
|
||||||
|
// profile)
|
||||||
|
QJsonObject currentProfile = responseData.value("selectedProfile").toObject();
|
||||||
|
QString currentProfileId = currentProfile.value("id").toString("");
|
||||||
|
if (account->currentProfile()->id() != currentProfileId)
|
||||||
|
{
|
||||||
|
// TODO: Set an error to display to the user.
|
||||||
|
QLOG_ERROR() << "Server didn't specify the same selected profile as ours.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is what the vanilla launcher passes to the userProperties launch param
|
||||||
|
if (responseData.contains("user"))
|
||||||
|
{
|
||||||
|
auto obj = responseData.value("user").toObject();
|
||||||
|
auto userId = obj.value("id").toString();
|
||||||
|
auto propArray = obj.value("properties").toArray();
|
||||||
|
QLOG_DEBUG() << "User ID: " << userId;
|
||||||
|
QLOG_DEBUG() << "User Properties: ";
|
||||||
|
for (auto prop : propArray)
|
||||||
|
{
|
||||||
|
auto propTuple = prop.toObject();
|
||||||
|
auto name = propTuple.value("name").toString();
|
||||||
|
auto value = propTuple.value("value").toString();
|
||||||
|
QLOG_DEBUG() << name << " : " << value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We've made it through the minefield of possible errors. Return true to indicate that
|
||||||
|
// we've succeeded.
|
||||||
|
QLOG_DEBUG() << "Finished reading refresh response.";
|
||||||
|
// Reset the access token.
|
||||||
|
account->setAccessToken(accessToken);
|
||||||
|
account->propagateChange();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RefreshTask::getEndpoint() const
|
||||||
|
{
|
||||||
|
return "refresh";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RefreshTask::getStateMessage(const YggdrasilTask::State state) const
|
||||||
|
{
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case STATE_SENDING_REQUEST:
|
||||||
|
return tr("Refreshing: Sending request.");
|
||||||
|
case STATE_PROCESSING_RESPONSE:
|
||||||
|
return tr("Refreshing: Processing response.");
|
||||||
|
default:
|
||||||
|
return YggdrasilTask::getStateMessage(state);
|
||||||
|
}
|
||||||
|
}
|
43
logic/auth/flows/RefreshTask.h
Normal file
43
logic/auth/flows/RefreshTask.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/* Copyright 2013 MultiMC Contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <logic/auth/YggdrasilTask.h>
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The authenticate task takes a MojangAccount with a possibly timed-out access token
|
||||||
|
* and attempts to authenticate with Mojang's servers.
|
||||||
|
* If successful, it will set the new access token. The token is considered validated.
|
||||||
|
*/
|
||||||
|
class RefreshTask : public YggdrasilTask
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
RefreshTask(MojangAccountPtr account, QObject *parent = 0);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QJsonObject getRequestContent() const;
|
||||||
|
|
||||||
|
virtual QString getEndpoint() const;
|
||||||
|
|
||||||
|
virtual bool processResponse(QJsonObject responseData);
|
||||||
|
|
||||||
|
QString getStateMessage(const YggdrasilTask::State state) const;
|
||||||
|
};
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <logic/auth/ValidateTask.h>
|
#include <logic/auth/flows/ValidateTask.h>
|
||||||
|
|
||||||
#include <logic/auth/MojangAccount.h>
|
#include <logic/auth/MojangAccount.h>
|
||||||
|
|
||||||
@ -26,8 +26,8 @@
|
|||||||
|
|
||||||
#include "logger/QsLog.h"
|
#include "logger/QsLog.h"
|
||||||
|
|
||||||
ValidateTask::ValidateTask(MojangAccountPtr account, QObject* parent) :
|
ValidateTask::ValidateTask(MojangAccountPtr account, QObject *parent)
|
||||||
YggdrasilTask(account, parent)
|
: YggdrasilTask(account, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,5 +62,3 @@ QString ValidateTask::getStateMessage(const YggdrasilTask::State state) const
|
|||||||
return YggdrasilTask::getStateMessage(state);
|
return YggdrasilTask::getStateMessage(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,9 +26,9 @@
|
|||||||
*/
|
*/
|
||||||
class ValidateTask : public YggdrasilTask
|
class ValidateTask : public YggdrasilTask
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ValidateTask(MojangAccountPtr account, QObject* parent=0);
|
ValidateTask(MojangAccountPtr account, QObject *parent = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QJsonObject getRequestContent() const;
|
virtual QJsonObject getRequestContent() const;
|
||||||
@ -41,4 +41,3 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
@ -44,7 +44,6 @@ MojangAccountPtr MojangAccountList::findAccount(const QString &username) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const MojangAccountPtr MojangAccountList::at(int i) const
|
const MojangAccountPtr MojangAccountList::at(int i) const
|
||||||
{
|
{
|
||||||
return MojangAccountPtr(m_accounts.at(i));
|
return MojangAccountPtr(m_accounts.at(i));
|
||||||
@ -53,12 +52,13 @@ const MojangAccountPtr MojangAccountList::at(int i) const
|
|||||||
void MojangAccountList::addAccount(const MojangAccountPtr account)
|
void MojangAccountList::addAccount(const MojangAccountPtr account)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
connect(account.get(), SIGNAL(changed()), SLOT(accountChanged()));
|
||||||
m_accounts.append(account);
|
m_accounts.append(account);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
onListChanged();
|
onListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MojangAccountList::removeAccount(const QString& username)
|
void MojangAccountList::removeAccount(const QString &username)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
for (auto account : m_accounts)
|
for (auto account : m_accounts)
|
||||||
@ -81,7 +81,6 @@ void MojangAccountList::removeAccount(QModelIndex index)
|
|||||||
onListChanged();
|
onListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MojangAccountPtr MojangAccountList::activeAccount() const
|
MojangAccountPtr MojangAccountList::activeAccount() const
|
||||||
{
|
{
|
||||||
if (m_activeAccount.isEmpty())
|
if (m_activeAccount.isEmpty())
|
||||||
@ -90,7 +89,7 @@ MojangAccountPtr MojangAccountList::activeAccount() const
|
|||||||
return findAccount(m_activeAccount);
|
return findAccount(m_activeAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MojangAccountList::setActiveAccount(const QString& username)
|
void MojangAccountList::setActiveAccount(const QString &username)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
if (username.isEmpty())
|
if (username.isEmpty())
|
||||||
@ -109,6 +108,11 @@ void MojangAccountList::setActiveAccount(const QString& username)
|
|||||||
onActiveChanged();
|
onActiveChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MojangAccountList::accountChanged()
|
||||||
|
{
|
||||||
|
// the list changed. there is no doubt.
|
||||||
|
onListChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void MojangAccountList::onListChanged()
|
void MojangAccountList::onListChanged()
|
||||||
{
|
{
|
||||||
@ -127,13 +131,11 @@ void MojangAccountList::onActiveChanged()
|
|||||||
emit activeAccountChanged();
|
emit activeAccountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int MojangAccountList::count() const
|
int MojangAccountList::count() const
|
||||||
{
|
{
|
||||||
return m_accounts.count();
|
return m_accounts.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant MojangAccountList::data(const QModelIndex &index, int role) const
|
QVariant MojangAccountList::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
@ -220,10 +222,11 @@ void MojangAccountList::updateListData(QList<MojangAccountPtr> versions)
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MojangAccountList::loadList(const QString& filePath)
|
bool MojangAccountList::loadList(const QString &filePath)
|
||||||
{
|
{
|
||||||
QString path = filePath;
|
QString path = filePath;
|
||||||
if (path.isEmpty()) path = m_listFilePath;
|
if (path.isEmpty())
|
||||||
|
path = m_listFilePath;
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
{
|
{
|
||||||
QLOG_ERROR() << "Can't load Mojang account list. No file path given and no default set.";
|
QLOG_ERROR() << "Can't load Mojang account list. No file path given and no default set.";
|
||||||
@ -286,6 +289,7 @@ bool MojangAccountList::loadList(const QString& filePath)
|
|||||||
MojangAccountPtr account = MojangAccount::loadFromJson(accountObj);
|
MojangAccountPtr account = MojangAccount::loadFromJson(accountObj);
|
||||||
if (account.get() != nullptr)
|
if (account.get() != nullptr)
|
||||||
{
|
{
|
||||||
|
connect(account.get(), SIGNAL(changed()), SLOT(accountChanged()));
|
||||||
m_accounts.append(account);
|
m_accounts.append(account);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -301,10 +305,11 @@ bool MojangAccountList::loadList(const QString& filePath)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MojangAccountList::saveList(const QString& filePath)
|
bool MojangAccountList::saveList(const QString &filePath)
|
||||||
{
|
{
|
||||||
QString path(filePath);
|
QString path(filePath);
|
||||||
if (path.isEmpty()) path = m_listFilePath;
|
if (path.isEmpty())
|
||||||
|
path = m_listFilePath;
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
{
|
{
|
||||||
QLOG_ERROR() << "Can't save Mojang account list. No file path given and no default set.";
|
QLOG_ERROR() << "Can't save Mojang account list. No file path given and no default set.";
|
||||||
@ -337,7 +342,6 @@ bool MojangAccountList::saveList(const QString& filePath)
|
|||||||
// Create a JSON document object to convert our JSON to bytes.
|
// Create a JSON document object to convert our JSON to bytes.
|
||||||
QJsonDocument doc(root);
|
QJsonDocument doc(root);
|
||||||
|
|
||||||
|
|
||||||
// Now that we're done building the JSON object, we can write it to the file.
|
// Now that we're done building the JSON object, we can write it to the file.
|
||||||
QLOG_DEBUG() << "Writing account list to file.";
|
QLOG_DEBUG() << "Writing account list to file.";
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
@ -362,6 +366,5 @@ bool MojangAccountList::saveList(const QString& filePath)
|
|||||||
void MojangAccountList::setListFilePath(QString path, bool autosave)
|
void MojangAccountList::setListFilePath(QString path, bool autosave)
|
||||||
{
|
{
|
||||||
m_listFilePath = path;
|
m_listFilePath = path;
|
||||||
autosave = autosave;
|
m_autosave = autosave;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
#include "logic/auth/MojangAccount.h"
|
#include "logic/auth/MojangAccount.h"
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief List of available Mojang accounts.
|
* \brief List of available Mojang accounts.
|
||||||
* This should be loaded in the background by MultiMC on startup.
|
* This should be loaded in the background by MultiMC on startup.
|
||||||
@ -74,7 +73,7 @@ public:
|
|||||||
/*!
|
/*!
|
||||||
* Removes the mojang account with the given username from the account list.
|
* Removes the mojang account with the given username from the account list.
|
||||||
*/
|
*/
|
||||||
virtual void removeAccount(const QString& username);
|
virtual void removeAccount(const QString &username);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Removes the account at the given QModelIndex.
|
* Removes the account at the given QModelIndex.
|
||||||
@ -96,21 +95,21 @@ public:
|
|||||||
* after calling this function to ensure an autosaved change doesn't overwrite the list you intended
|
* after calling this function to ensure an autosaved change doesn't overwrite the list you intended
|
||||||
* to load.
|
* to load.
|
||||||
*/
|
*/
|
||||||
virtual void setListFilePath(QString path, bool autosave=false);
|
virtual void setListFilePath(QString path, bool autosave = false);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Loads the account list from the given file path.
|
* \brief Loads the account list from the given file path.
|
||||||
* If the given file is an empty string (default), will load from the default account list file.
|
* If the given file is an empty string (default), will load from the default account list file.
|
||||||
* \return True if successful, otherwise false.
|
* \return True if successful, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool loadList(const QString& file="");
|
virtual bool loadList(const QString &file = "");
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Saves the account list to the given file.
|
* \brief Saves the account list to the given file.
|
||||||
* If the given file is an empty string (default), will save from the default account list file.
|
* If the given file is an empty string (default), will save from the default account list file.
|
||||||
* \return True if successful, otherwise false.
|
* \return True if successful, otherwise false.
|
||||||
*/
|
*/
|
||||||
virtual bool saveList(const QString& file="");
|
virtual bool saveList(const QString &file = "");
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Gets a pointer to the account that the user has selected as their "active" account.
|
* \brief Gets a pointer to the account that the user has selected as their "active" account.
|
||||||
@ -124,12 +123,13 @@ public:
|
|||||||
* Sets the given account as the current active account.
|
* Sets the given account as the current active account.
|
||||||
* If the username given is an empty string, sets the active account to nothing.
|
* If the username given is an empty string, sets the active account to nothing.
|
||||||
*/
|
*/
|
||||||
virtual void setActiveAccount(const QString& username);
|
virtual void setActiveAccount(const QString &username);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/*!
|
/*!
|
||||||
* Signal emitted to indicate that the account list has changed.
|
* Signal emitted to indicate that the account list has changed.
|
||||||
* This will also fire if the value of an element in the list changes (will be implemented later).
|
* This will also fire if the value of an element in the list changes (will be implemented
|
||||||
|
* later).
|
||||||
*/
|
*/
|
||||||
void listChanged();
|
void listChanged();
|
||||||
|
|
||||||
@ -138,6 +138,13 @@ signals:
|
|||||||
*/
|
*/
|
||||||
void activeAccountChanged();
|
void activeAccountChanged();
|
||||||
|
|
||||||
|
public
|
||||||
|
slots:
|
||||||
|
/**
|
||||||
|
* This is called when one of the accounts changes and the list needs to be updated
|
||||||
|
*/
|
||||||
|
void accountChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*!
|
/*!
|
||||||
* Called whenever the list changes.
|
* Called whenever the list changes.
|
||||||
@ -166,7 +173,7 @@ protected:
|
|||||||
* If true, the account list will automatically save to the account list path when it changes.
|
* If true, the account list will automatically save to the account list path when it changes.
|
||||||
* Ignored if m_listFilePath is blank.
|
* Ignored if m_listFilePath is blank.
|
||||||
*/
|
*/
|
||||||
bool m_autosave;
|
bool m_autosave = false;
|
||||||
|
|
||||||
protected
|
protected
|
||||||
slots:
|
slots:
|
||||||
@ -184,4 +191,3 @@ slots:
|
|||||||
*/
|
*/
|
||||||
virtual void updateListData(QList<MojangAccountPtr> versions);
|
virtual void updateListData(QList<MojangAccountPtr> versions);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
60
test.cpp
60
test.cpp
@ -1,60 +0,0 @@
|
|||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "keyring.h"
|
|
||||||
#include "cmdutils.h"
|
|
||||||
|
|
||||||
using namespace Util::Commandline;
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
QCoreApplication app(argc, argv);
|
|
||||||
app.setApplicationName("MMC Keyring test");
|
|
||||||
app.setOrganizationName("Orochimarufan");
|
|
||||||
|
|
||||||
Parser p;
|
|
||||||
p.addArgument("user", false);
|
|
||||||
p.addArgument("password", false);
|
|
||||||
p.addSwitch("set");
|
|
||||||
p.addSwitch("get");
|
|
||||||
p.addSwitch("list");
|
|
||||||
p.addOption("service", "Test");
|
|
||||||
p.addShortOpt("service", 's');
|
|
||||||
|
|
||||||
QHash<QString, QVariant> args;
|
|
||||||
try {
|
|
||||||
args = p.parse(app.arguments());
|
|
||||||
} catch (ParsingError) {
|
|
||||||
std::cout << "Syntax error." << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args["set"].toBool()) {
|
|
||||||
if (args["user"].isNull() || args["password"].isNull()) {
|
|
||||||
std::cout << "set operation needs bot user and password set" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Keyring::instance()->storePassword(args["service"].toString(),
|
|
||||||
args["user"].toString(), args["password"].toString());
|
|
||||||
} else if (args["get"].toBool()) {
|
|
||||||
if (args["user"].isNull()) {
|
|
||||||
std::cout << "get operation needs user set" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "Password: " << qPrintable(Keyring::instance()->getPassword(args["service"].toString(),
|
|
||||||
args["user"].toString())) << std::endl;
|
|
||||||
return 0;
|
|
||||||
} else if (args["list"].toBool()) {
|
|
||||||
QStringList accounts = Keyring::instance()->getStoredAccounts(args["service"].toString());
|
|
||||||
std::cout << "stored accounts:" << std::endl << '\t' << qPrintable(accounts.join("\n\t")) << std::endl;
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
std::cout << "No operation given!" << std::endl;
|
|
||||||
std::cout << qPrintable(p.compileHelp(argv[0])) << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user