summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-11-20 18:31:15 -0600
committerAndrew <forkk@forkk.net>2013-11-20 18:31:15 -0600
commitabf8408911c057d8aafe90790f5d2f5de0e1d97c (patch)
treeb6b77a485702c0a7ac45b5b96d6b8b0f41c14af7 /logic
parent03652b01d2ec8a7c54fb39dd8ed660f0bbc2fa2a (diff)
downloadMultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar.gz
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar.lz
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar.xz
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.zip
Nuke and pave the old login system
Also, account list now saves profile lists.
Diffstat (limited to 'logic')
-rw-r--r--logic/BaseInstance.h6
-rw-r--r--logic/InstanceLauncher.cpp3
-rw-r--r--logic/LegacyInstance.cpp6
-rw-r--r--logic/LegacyInstance.h4
-rw-r--r--logic/OneSixInstance.cpp16
-rw-r--r--logic/OneSixInstance.h6
-rw-r--r--logic/auth/MojangAccount.cpp55
-rw-r--r--logic/auth/MojangAccount.h2
-rw-r--r--logic/lists/MojangAccountList.cpp14
9 files changed, 81 insertions, 31 deletions
diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h
index b083c24a..b92d50cc 100644
--- a/logic/BaseInstance.h
+++ b/logic/BaseInstance.h
@@ -22,7 +22,7 @@
#include "inifile.h"
#include "lists/BaseVersionList.h"
-#include "net/LoginTask.h"
+#include "logic/auth/MojangAccount.h"
class QDialog;
class BaseUpdate;
@@ -153,8 +153,8 @@ public:
/// returns a valid update task if update is needed, NULL otherwise
virtual BaseUpdate *doUpdate() = 0;
- /// returns a valid minecraft process, ready for launch
- virtual MinecraftProcess *prepareForLaunch(LoginResponse response) = 0;
+ /// returns a valid minecraft process, ready for launch with the given account.
+ virtual MinecraftProcess *prepareForLaunch(MojangAccountPtr account) = 0;
/// do any necessary cleanups after the instance finishes. also runs before
/// 'prepareForLaunch'
diff --git a/logic/InstanceLauncher.cpp b/logic/InstanceLauncher.cpp
index 9f78e55b..c4df8220 100644
--- a/logic/InstanceLauncher.cpp
+++ b/logic/InstanceLauncher.cpp
@@ -38,6 +38,8 @@ void InstanceLauncher::onTerminated()
void InstanceLauncher::onLoginComplete()
{
+ // TODO: Fix this.
+ /*
LoginTask *task = (LoginTask *)QObject::sender();
auto result = task->getResult();
auto instance = MMC->instances()->getInstanceById(instId);
@@ -55,6 +57,7 @@ void InstanceLauncher::onLoginComplete()
SLOT(write(QString, MessageLevel::Enum)));
proc->launch();
+ */
}
void InstanceLauncher::doLogin(const QString &errorMsg)
diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp
index 9a91b839..3a337140 100644
--- a/logic/LegacyInstance.cpp
+++ b/logic/LegacyInstance.cpp
@@ -50,7 +50,7 @@ BaseUpdate *LegacyInstance::doUpdate()
return new LegacyUpdate(this, this);
}
-MinecraftProcess *LegacyInstance::prepareForLaunch(LoginResponse response)
+MinecraftProcess *LegacyInstance::prepareForLaunch(MojangAccountPtr account)
{
MinecraftProcess *proc = new MinecraftProcess(this);
@@ -103,8 +103,8 @@ MinecraftProcess *LegacyInstance::prepareForLaunch(LoginResponse response)
#endif
args << "-jar" << LAUNCHER_FILE;
- args << response.player_name;
- args << response.session_id;
+ args << account->currentProfile()->name();
+ args << account->accessToken();
args << windowTitle;
args << windowSize;
args << lwjgl;
diff --git a/logic/LegacyInstance.h b/logic/LegacyInstance.h
index 8a8d4b91..e78bfd73 100644
--- a/logic/LegacyInstance.h
+++ b/logic/LegacyInstance.h
@@ -80,7 +80,7 @@ public:
virtual void setShouldUpdate(bool val);
virtual BaseUpdate *doUpdate();
- virtual MinecraftProcess *prepareForLaunch(LoginResponse response);
+ virtual MinecraftProcess *prepareForLaunch(MojangAccountPtr account);
virtual void cleanupAfterRun();
virtual QDialog *createModEditDialog(QWidget *parent);
@@ -93,4 +93,4 @@ public:
protected
slots:
virtual void jarModsChanged();
-}; \ No newline at end of file
+};
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp
index 5c93236b..5a83bafc 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -65,7 +65,7 @@ QString replaceTokensIn(QString text, QMap<QString, QString> with)
return result;
}
-QStringList OneSixInstance::processMinecraftArgs(LoginResponse response)
+QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account)
{
I_D(OneSixInstance);
auto version = d->version;
@@ -73,11 +73,11 @@ QStringList OneSixInstance::processMinecraftArgs(LoginResponse response)
QMap<QString, QString> token_mapping;
// yggdrasil!
- token_mapping["auth_username"] = response.username;
- token_mapping["auth_session"] = response.session_id;
- token_mapping["auth_access_token"] = response.access_token;
- token_mapping["auth_player_name"] = response.player_name;
- token_mapping["auth_uuid"] = response.player_id;
+ token_mapping["auth_username"] = account->username();
+ //token_mapping["auth_session"] = response.session_id;
+ token_mapping["auth_access_token"] = account->accessToken();
+ token_mapping["auth_player_name"] = account->currentProfile()->name();
+ token_mapping["auth_uuid"] = account->currentProfile()->id();
// this is for offline?:
/*
@@ -102,7 +102,7 @@ QStringList OneSixInstance::processMinecraftArgs(LoginResponse response)
return parts;
}
-MinecraftProcess *OneSixInstance::prepareForLaunch(LoginResponse response)
+MinecraftProcess *OneSixInstance::prepareForLaunch(MojangAccountPtr account)
{
I_D(OneSixInstance);
cleanupAfterRun();
@@ -169,7 +169,7 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(LoginResponse response)
args << classPath;
}
args << version->mainClass;
- args.append(processMinecraftArgs(response));
+ args.append(processMinecraftArgs(account));
// Set the width and height for 1.6 instances
bool maximize = settings().get("LaunchMaximized").toBool();
diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h
index 2d02b605..c1c742a8 100644
--- a/logic/OneSixInstance.h
+++ b/logic/OneSixInstance.h
@@ -40,7 +40,7 @@ public:
virtual QString instanceConfigFolder() const;
virtual BaseUpdate *doUpdate();
- virtual MinecraftProcess *prepareForLaunch(LoginResponse response);
+ virtual MinecraftProcess *prepareForLaunch(MojangAccountPtr account);
virtual void cleanupAfterRun();
virtual QString intendedVersionId() const;
@@ -72,5 +72,5 @@ public:
virtual QString getStatusbarDescription();
private:
- QStringList processMinecraftArgs(LoginResponse response);
-}; \ No newline at end of file
+ QStringList processMinecraftArgs(MojangAccountPtr account);
+};
diff --git a/logic/auth/MojangAccount.cpp b/logic/auth/MojangAccount.cpp
index 80b88082..4875e5f7 100644
--- a/logic/auth/MojangAccount.cpp
+++ b/logic/auth/MojangAccount.cpp
@@ -18,6 +18,8 @@
#include "MojangAccount.h"
#include <QUuid>
+#include <QJsonObject>
+#include <QJsonArray>
#include <logger/QsLog.h>
@@ -89,7 +91,12 @@ const QList<AccountProfile> MojangAccount::profiles() const
const AccountProfile* MojangAccount::currentProfile() const
{
if (m_currentProfile < 0)
- return nullptr;
+ {
+ if (m_profiles.length() > 0)
+ return &m_profiles.at(0);
+ else
+ return nullptr;
+ }
else
return &m_profiles.at(m_currentProfile);
}
@@ -128,9 +135,36 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject& object)
QString clientToken = object.value("clientToken").toString("");
QString accessToken = object.value("accessToken").toString("");
- // TODO: Load profiles?
+ QJsonArray profileArray = object.value("profiles").toArray();
+ if (profileArray.size() < 1)
+ {
+ QLOG_ERROR() << "Can't load Mojang account with username \"" << username << "\". No profiles found.";
+ return nullptr;
+ }
+
+ ProfileList profiles;
+ for (QJsonValue profileVal : profileArray)
+ {
+ QJsonObject profileObject = profileVal.toObject();
+ QString id = profileObject.value("id").toString("");
+ QString name = profileObject.value("name").toString("");
+ if (id.isEmpty() || name.isEmpty())
+ {
+ QLOG_WARN() << "Unable to load a profile because it was missing an ID or a name.";
+ continue;
+ }
+ profiles.append(AccountProfile(id, name));
+ }
+
+ MojangAccountPtr account(new MojangAccount(username, clientToken, accessToken));
+ account->loadProfiles(profiles);
- return MojangAccountPtr(new MojangAccount(username, clientToken, accessToken));
+ // Get the currently selected profile.
+ QString currentProfile = object.value("activeProfile").toString("");
+ if (!currentProfile.isEmpty())
+ account->setProfile(currentProfile);
+
+ return account;
}
QJsonObject MojangAccount::saveToJson()
@@ -139,7 +173,20 @@ QJsonObject MojangAccount::saveToJson()
json.insert("username", username());
json.insert("clientToken", clientToken());
json.insert("accessToken", accessToken());
- // TODO: Save profiles?
+
+ QJsonArray profileArray;
+ for (AccountProfile profile : m_profiles)
+ {
+ QJsonObject profileObj;
+ profileObj.insert("id", profile.id());
+ profileObj.insert("name", profile.name());
+ profileArray.append(profileObj);
+ }
+ json.insert("profiles", profileArray);
+
+ if (currentProfile() != nullptr)
+ json.insert("activeProfile", currentProfile()->id());
+
return json;
}
diff --git a/logic/auth/MojangAccount.h b/logic/auth/MojangAccount.h
index 35261d65..e5684b77 100644
--- a/logic/auth/MojangAccount.h
+++ b/logic/auth/MojangAccount.h
@@ -123,7 +123,7 @@ public:
/**
* Returns a pointer to the currently selected profile.
- * If no profile is selected, returns nullptr.
+ * If no profile is selected, returns the first profile in the profile list or nullptr if there are none.
*/
const AccountProfile* currentProfile() const;
diff --git a/logic/lists/MojangAccountList.cpp b/logic/lists/MojangAccountList.cpp
index 68a4da18..32317f84 100644
--- a/logic/lists/MojangAccountList.cpp
+++ b/logic/lists/MojangAccountList.cpp
@@ -185,7 +185,7 @@ bool MojangAccountList::loadList(const QString& filePath)
// TODO: We should probably report this error to the user.
if (!file.open(QIODevice::ReadOnly))
{
- QLOG_ERROR() << "Failed to read the account list file (" << path << ").";
+ QLOG_ERROR() << QString("Failed to read the account list file (%1).").arg(path).toUtf8();
return false;
}
@@ -217,9 +217,9 @@ bool MojangAccountList::loadList(const QString& filePath)
// Make sure the format version matches.
if (root.value("formatVersion").toVariant().toInt() != ACCOUNT_LIST_FORMAT_VERSION)
{
- QString newName = "accountlist-old.json";
- QLOG_WARN() << "Format version mismatch when loading account list. Existing one will be renamed to \""
- << newName << "\".";
+ QString newName = "accounts-old.json";
+ QLOG_WARN() << "Format version mismatch when loading account list. Existing one will be renamed to"
+ << newName;
// Attempt to rename the old version.
file.rename(newName);
@@ -257,7 +257,7 @@ bool MojangAccountList::saveList(const QString& filePath)
return false;
}
- QLOG_INFO() << "Writing account list to \"" << path << "\"...";
+ QLOG_INFO() << "Writing account list to" << path;
QLOG_DEBUG() << "Building JSON data structure.";
// Build the JSON document to write to the list file.
@@ -289,7 +289,7 @@ bool MojangAccountList::saveList(const QString& filePath)
// TODO: We should probably report this error to the user.
if (!file.open(QIODevice::WriteOnly))
{
- QLOG_ERROR() << "Failed to read the account list file (" << path << ").";
+ QLOG_ERROR() << QString("Failed to read the account list file (%1).").arg(path).toUtf8();
return false;
}
@@ -297,7 +297,7 @@ bool MojangAccountList::saveList(const QString& filePath)
file.write(doc.toJson());
file.close();
- QLOG_INFO() << "Saved account list to \"" << path << "\".";
+ QLOG_INFO() << "Saved account list to" << path;
return true;
}