Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/logic/BaseInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "settings/INIFile.h"
#include "BaseVersionList.h"
#include "minecraft/auth/MojangAccount.h"
#include "minecraft/auth/Account.h"
#include "MessageLevel.h"
#include "pathmatcher/IPathMatcher.h"

Expand Down
14 changes: 10 additions & 4 deletions api/logic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,14 @@ set(STATUS_SOURCES
# Support for Minecraft instances and launch
set(MINECRAFT_SOURCES
# Minecraft support
minecraft/auth/AuthProviders.h
minecraft/auth/AuthProviders.cpp
minecraft/auth/AuthSession.h
minecraft/auth/AuthSession.cpp
minecraft/auth/MojangAccountList.h
minecraft/auth/MojangAccountList.cpp
minecraft/auth/MojangAccount.h
minecraft/auth/MojangAccount.cpp
minecraft/auth/AccountList.h
minecraft/auth/AccountList.cpp
minecraft/auth/Account.h
minecraft/auth/Account.cpp
minecraft/auth/YggdrasilTask.h
minecraft/auth/YggdrasilTask.cpp
minecraft/auth/flows/AuthenticateTask.h
Expand All @@ -215,6 +217,10 @@ set(MINECRAFT_SOURCES
minecraft/auth/flows/RefreshTask.cpp
minecraft/auth/flows/ValidateTask.h
minecraft/auth/flows/ValidateTask.cpp
minecraft/auth/providers/BaseAuthProvider.h
minecraft/auth/providers/DummyAuthProvider.h
minecraft/auth/providers/ElybyAuthProvider.h
minecraft/auth/providers/MojangAuthProvider.h

minecraft/gameoptions/GameOptions.h
minecraft/gameoptions/GameOptions.cpp
Expand Down
7 changes: 2 additions & 5 deletions api/logic/minecraft/MinecraftInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,13 +918,10 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt
}

// authlib patch
if (session->m_accountPtr->loginType() != "mojang")
if (session->m_accountPtr->provider()->injectorEndpoint() != "")
{
auto step = new InjectAuthlib(pptr, &m_injector);
if(session->m_accountPtr->loginType() == "dummy")
step->setAuthServer(((QString)"http://localhost:%1").arg(localAuthServerPort));
else if(session->m_accountPtr->loginType() == "elyby")
step->setAuthServer(((QString) "ely.by").arg(localAuthServerPort));
step->setAuthServer(session->m_accountPtr->provider()->injectorEndpoint().arg(localAuthServerPort));
process->appendStep(step);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* limitations under the License.
*/

#include "MojangAccount.h"
#include "Account.h"
#include "AuthProviders.h"
#include "flows/RefreshTask.h"
#include "flows/AuthenticateTask.h"

Expand All @@ -30,7 +31,7 @@

#include <BuildConfig.h>

MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
AccountPtr Account::loadFromJson(const QJsonObject &object)
{
// The JSON object must at least have a username for it to be valid.
if (!object.value("username").isString())
Expand All @@ -40,7 +41,7 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
return nullptr;
}

QString loginType = object.value("loginType").toString("mojang");
QString provider = object.value("loginType").toString("dummy");
QString username = object.value("username").toString("");
QString clientToken = object.value("clientToken").toString("");
QString accessToken = object.value("accessToken").toString("");
Expand Down Expand Up @@ -68,7 +69,7 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
profiles.append({id, name, legacy});
}

MojangAccountPtr account(new MojangAccount());
AccountPtr account(new Account());
if (object.value("user").isObject())
{
User u;
Expand All @@ -85,7 +86,7 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
*/
account->m_user = u;
}
account->m_loginType = loginType;
account->m_provider = AuthProviders::lookup(provider);
account->m_username = username;
account->m_clientToken = clientToken;
account->m_accessToken = accessToken;
Expand All @@ -99,18 +100,18 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
return account;
}

MojangAccountPtr MojangAccount::createFromUsername(const QString &username)
AccountPtr Account::createFromUsername(const QString &username)
{
MojangAccountPtr account(new MojangAccount());
AccountPtr account(new Account());
account->m_clientToken = QUuid::createUuid().toString().remove(QRegExp("[{}-]"));
account->m_username = username;
return account;
}

QJsonObject MojangAccount::saveToJson() const
QJsonObject Account::saveToJson() const
{
QJsonObject json;
json.insert("loginType", m_loginType);
json.insert("loginType", m_provider->id());
json.insert("username", m_username);
json.insert("clientToken", m_clientToken);
json.insert("accessToken", m_accessToken);
Expand Down Expand Up @@ -147,18 +148,15 @@ QJsonObject MojangAccount::saveToJson() const
return json;
}

bool MojangAccount::setLoginType(const QString &loginType)
bool Account::setProvider(AuthProviderPtr provider)
{
// TODO: Implement a cleaner validity check
if (loginType == "mojang" || loginType == "dummy" || loginType == "elyby")
{
m_loginType = loginType;
return true;
}
return false;
if (provider == nullptr)
return false;
m_provider = provider;
return true;
}

bool MojangAccount::setCurrentProfile(const QString &profileId)
bool Account::setCurrentProfile(const QString &profileId)
{
for (int i = 0; i < m_profiles.length(); i++)
{
Expand All @@ -171,47 +169,27 @@ bool MojangAccount::setCurrentProfile(const QString &profileId)
return false;
}

const AccountProfile *MojangAccount::currentProfile() const
const AccountProfile *Account::currentProfile() const
{
if (m_currentProfile == -1)
return nullptr;
return &m_profiles[m_currentProfile];
}

AccountStatus MojangAccount::accountStatus() const
AccountStatus Account::accountStatus() const
{
if (m_accessToken.isEmpty())
return NotVerified;
else
return Verified;
}

QString MojangAccount::authEndpoint() const
{
if(m_loginType == "elyby")
return BuildConfig.AUTH_BASE_ELYBY;

return BuildConfig.AUTH_BASE_MOJANG;
}

QString MojangAccount::displayLoginType() const
{
if(m_loginType == "mojang")
return "Mojang";
if(m_loginType == "dummy")
return "Local";
if(m_loginType == "elyby")
return "Ely.by";

return "Unknown";
}

std::shared_ptr<YggdrasilTask> MojangAccount::login(AuthSessionPtr session, QString password)
std::shared_ptr<YggdrasilTask> Account::login(AuthSessionPtr session, QString password)
{
Q_ASSERT(m_currentTask.get() == nullptr);

// Handling alternative account types
if (m_loginType == "dummy")
if (m_provider->dummyAuth())
{
if (session)
{
Expand Down Expand Up @@ -267,7 +245,7 @@ std::shared_ptr<YggdrasilTask> MojangAccount::login(AuthSessionPtr session, QStr
return m_currentTask;
}

void MojangAccount::authSucceeded()
void Account::authSucceeded()
{
auto session = m_currentTask->getAssignedSession();
if (session)
Expand All @@ -281,7 +259,7 @@ void MojangAccount::authSucceeded()
emit changed();
}

void MojangAccount::authFailed(QString reason)
void Account::authFailed(QString reason)
{
auto session = m_currentTask->getAssignedSession();
// This is emitted when the yggdrasil tasks time out or are cancelled.
Expand Down Expand Up @@ -310,7 +288,7 @@ void MojangAccount::authFailed(QString reason)
m_currentTask.reset();
}

void MojangAccount::fillSession(AuthSessionPtr session)
void Account::fillSession(AuthSessionPtr session)
{
// the user name. you have to have an user name
session->username = m_username;
Expand Down Expand Up @@ -344,7 +322,7 @@ void MojangAccount::fillSession(AuthSessionPtr session)
session->m_accountPtr = shared_from_this();
}

void MojangAccount::decrementUses()
void Account::decrementUses()
{
Usable::decrementUses();
if(!isInUse())
Expand All @@ -354,7 +332,7 @@ void MojangAccount::decrementUses()
}
}

void MojangAccount::incrementUses()
void Account::incrementUses()
{
bool wasInUse = isInUse();
Usable::incrementUses();
Expand All @@ -365,7 +343,7 @@ void MojangAccount::incrementUses()
}
}

void MojangAccount::invalidateClientToken()
void Account::invalidateClientToken()
{
m_clientToken = QUuid::createUuid().toString().remove(QRegExp("[{}-]"));
emit changed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@

#include <memory>
#include "AuthSession.h"
#include "AccountProfile.h"
#include "Usable.h"
#include "providers/BaseAuthProvider.h"

#include "multimc_logic_export.h"

class Task;
class YggdrasilTask;
class MojangAccount;
class Account;

typedef std::shared_ptr<MojangAccount> MojangAccountPtr;
Q_DECLARE_METATYPE(MojangAccountPtr)
typedef std::shared_ptr<Account> AccountPtr;
Q_DECLARE_METATYPE(AccountPtr)

/**
* A profile within someone's Mojang account.
Expand All @@ -42,12 +44,6 @@ Q_DECLARE_METATYPE(MojangAccountPtr)
* but we might as well add some things for it in MultiMC right now so
* we don't have to rip the code to pieces to add it later.
*/
struct AccountProfile
{
QString id;
QString name;
bool legacy;
};

enum AccountStatus
{
Expand All @@ -61,34 +57,33 @@ enum AccountStatus
* Said information may include things such as that account's username, client token, and access
* token if the user chose to stay logged in.
*/
class MULTIMC_LOGIC_EXPORT MojangAccount :
class MULTIMC_LOGIC_EXPORT Account :
public QObject,
public Usable,
public std::enable_shared_from_this<MojangAccount>
public std::enable_shared_from_this<Account>
{
Q_OBJECT
public: /* construction */
//! Do not copy accounts. ever.
explicit MojangAccount(const MojangAccount &other, QObject *parent) = delete;
explicit Account(const Account &other, QObject *parent) = delete;

//! Default constructor
explicit MojangAccount(QObject *parent = 0) : QObject(parent) {};
explicit Account(QObject *parent = 0) : QObject(parent) {};

//! Creates an empty account for the specified user name.
static MojangAccountPtr createFromUsername(const QString &username);
static AccountPtr createFromUsername(const QString &username);

//! Loads a MojangAccount from the given JSON object.
static MojangAccountPtr loadFromJson(const QJsonObject &json);
//! Loads a Account from the given JSON object.
static AccountPtr loadFromJson(const QJsonObject &json);

//! Saves a MojangAccount to a JSON object and returns it.
//! Saves a Account to a JSON object and returns it.
QJsonObject saveToJson() const;

public: /* manipulation */
/**
* Overrides the login type on the account.
* Accepts "mojang" and "dummy". Returns false if other.
*/
bool setLoginType(const QString &loginType);
bool setProvider(AuthProviderPtr provider);

/**
* Sets the currently selected profile to the profile with the given ID string.
Expand All @@ -105,9 +100,9 @@ class MULTIMC_LOGIC_EXPORT MojangAccount :
void invalidateClientToken();

public: /* queries */
const QString &loginType() const
const AuthProviderPtr provider() const
{
return m_loginType;
return m_provider;
}

const QString &username() const
Expand Down Expand Up @@ -141,12 +136,6 @@ class MULTIMC_LOGIC_EXPORT MojangAccount :
//! Returns whether the account is NotVerified, Verified or Online
AccountStatus accountStatus() const;

//! Returns endpoint for authentication
QString authEndpoint() const;

// ! Returns login type to display in account list or account chooser
QString displayLoginType() const;

signals:
/**
* This signal is emitted when the account changes
Expand All @@ -158,7 +147,7 @@ class MULTIMC_LOGIC_EXPORT MojangAccount :
protected: /* variables */
// Authentication system used.
// Usable values: "mojang", "dummy", "elyby"
QString m_loginType;
AuthProviderPtr m_provider;

// Username taken by account.
QString m_username;
Expand Down
Loading