GH-4071 Heavily refactor and rearchitect account system

This makes the account system much more modular
and makes it treat errors as something recoverable,
unless they come directly from the MSA refresh token
becoming invalid.
This commit is contained in:
Petr Mrázek
2021-12-04 01:18:05 +01:00
parent ffcef673de
commit 3c46d8a412
68 changed files with 2105 additions and 1446 deletions

View File

@ -24,6 +24,7 @@
#include <QPixmap>
#include <memory>
#include "AuthSession.h"
#include "Usable.h"
#include "AccountData.h"
@ -50,12 +51,6 @@ struct AccountProfile
bool legacy;
};
enum AccountStatus
{
NotVerified,
Verified
};
/**
* Object that stores information about a certain Mojang account.
*
@ -90,15 +85,17 @@ public: /* manipulation */
* Attempt to login. Empty password means we use the token.
* If the attempt fails because we already are performing some task, it returns false.
*/
shared_qobject_ptr<AccountTask> login(AuthSessionPtr session, QString password);
shared_qobject_ptr<AccountTask> login(QString password);
shared_qobject_ptr<AccountTask> loginMSA(AuthSessionPtr session);
shared_qobject_ptr<AccountTask> loginMSA();
shared_qobject_ptr<AccountTask> refresh(AuthSessionPtr session);
shared_qobject_ptr<AccountTask> refresh();
shared_qobject_ptr<AccountTask> currentTask();
public: /* queries */
QString internalId() const {
return m_internalId;
return data.internalId;
}
QString accountDisplayString() const {
@ -123,8 +120,6 @@ public: /* queries */
bool isActive() const;
bool isExpired() const;
bool canMigrate() const {
return data.canMigrateToMSA;
}
@ -133,6 +128,14 @@ public: /* queries */
return data.type == AccountType::MSA;
}
bool ownsMinecraft() const {
return data.minecraftEntitlement.ownsMinecraft;
}
bool hasProfile() const {
return data.profileId().size() != 0;
}
QString typeString() const {
switch(data.type) {
case AccountType::Mojang: {
@ -154,8 +157,8 @@ public: /* queries */
QPixmap getFace() const;
//! Returns whether the account is NotVerified, Verified or Online
AccountStatus accountStatus() const;
//! Returns the current state of the account
AccountState accountState() const;
AccountData * accountData() {
return &data;
@ -163,6 +166,8 @@ public: /* queries */
bool shouldRefresh() const;
void fillSession(AuthSessionPtr session);
signals:
/**
* This signal is emitted when the account changes
@ -174,7 +179,6 @@ signals:
// TODO: better signalling for the various possible state changes - especially errors
protected: /* variables */
QString m_internalId;
AccountData data;
// current task we are executing here
@ -189,7 +193,4 @@ private
slots:
void authSucceeded();
void authFailed(QString reason);
private:
void fillSession(AuthSessionPtr session);
};