Offline mode support, part 1
Refactor MojangAccount so it exposes a less generic interface and supports login. Hide the ugly details. Yggdrasil tasks are now only used from MojangAccount.
This commit is contained in:
@ -26,7 +26,7 @@
|
||||
|
||||
#include "logger/QsLog.h"
|
||||
|
||||
AuthenticateTask::AuthenticateTask(MojangAccountPtr account, const QString &password,
|
||||
AuthenticateTask::AuthenticateTask(MojangAccount * account, const QString &password,
|
||||
QObject *parent)
|
||||
: YggdrasilTask(account, parent), m_password(password)
|
||||
{
|
||||
@ -59,14 +59,14 @@ QJsonObject AuthenticateTask::getRequestContent() const
|
||||
req.insert("agent", agent);
|
||||
}
|
||||
|
||||
req.insert("username", getMojangAccount()->username());
|
||||
req.insert("username", m_account->username());
|
||||
req.insert("password", m_password);
|
||||
req.insert("requestUser", true);
|
||||
|
||||
// If we already have a client token, give it to the server.
|
||||
// Otherwise, let the server give us one.
|
||||
if (!getMojangAccount()->clientToken().isEmpty())
|
||||
req.insert("clientToken", getMojangAccount()->clientToken());
|
||||
if (!m_account->m_clientToken.isEmpty())
|
||||
req.insert("clientToken", m_account->m_clientToken);
|
||||
|
||||
return req;
|
||||
}
|
||||
@ -88,8 +88,7 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
QLOG_ERROR() << "Server didn't send a client token.";
|
||||
return false;
|
||||
}
|
||||
if (!getMojangAccount()->clientToken().isEmpty() &&
|
||||
clientToken != getMojangAccount()->clientToken())
|
||||
if (!m_account->m_clientToken.isEmpty() && clientToken != m_account->m_clientToken)
|
||||
{
|
||||
// The server changed our client token! Obey its wishes, but complain. That's what I do
|
||||
// for my parents, so...
|
||||
@ -97,7 +96,7 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
<< "'. This shouldn't happen, but it isn't really a big deal.";
|
||||
}
|
||||
// Set the client token.
|
||||
getMojangAccount()->setClientToken(clientToken);
|
||||
m_account->m_clientToken = clientToken;
|
||||
|
||||
// Now, we set the access token.
|
||||
QLOG_DEBUG() << "Getting access token.";
|
||||
@ -109,7 +108,7 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
QLOG_ERROR() << "Server didn't send an access token.";
|
||||
}
|
||||
// Set the access token.
|
||||
getMojangAccount()->setAccessToken(accessToken);
|
||||
m_account->m_accessToken = accessToken;
|
||||
|
||||
// Now we load the list of available profiles.
|
||||
// Mojang hasn't yet implemented the profile system,
|
||||
@ -117,7 +116,7 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
// don't have trouble implementing it later.
|
||||
QLOG_DEBUG() << "Loading profile list.";
|
||||
QJsonArray availableProfiles = responseData.value("availableProfiles").toArray();
|
||||
ProfileList loadedProfiles;
|
||||
QList<AccountProfile> loadedProfiles;
|
||||
for (auto iter : availableProfiles)
|
||||
{
|
||||
QJsonObject profile = iter.toObject();
|
||||
@ -135,10 +134,10 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
}
|
||||
|
||||
// Now, add a new AccountProfile entry to the list.
|
||||
loadedProfiles.append(AccountProfile(id, name));
|
||||
loadedProfiles.append({id, name});
|
||||
}
|
||||
// Put the list of profiles we loaded into the MojangAccount object.
|
||||
getMojangAccount()->loadProfiles(loadedProfiles);
|
||||
m_account->m_profiles = loadedProfiles;
|
||||
|
||||
// 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
|
||||
@ -153,7 +152,7 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
|
||||
QLOG_ERROR() << "Server didn't specify a currently selected profile.";
|
||||
return false;
|
||||
}
|
||||
if (!getMojangAccount()->setProfile(currentProfileId))
|
||||
if (!m_account->setCurrentProfile(currentProfileId))
|
||||
{
|
||||
// TODO: Set an error to display to the user.
|
||||
QLOG_ERROR() << "Server specified a selected profile that wasn't in the available "
|
||||
|
Reference in New Issue
Block a user