Add support for 1.7.4 user_type (needs testing with legacy accounts)
This commit is contained in:
		| @@ -305,6 +305,8 @@ logic/net/PasteUpload.h | |||||||
| logic/net/PasteUpload.cpp | logic/net/PasteUpload.cpp | ||||||
|  |  | ||||||
| # Yggdrasil login stuff | # Yggdrasil login stuff | ||||||
|  | logic/auth/MojangAccountList.h | ||||||
|  | logic/auth/MojangAccountList.cpp | ||||||
| logic/auth/MojangAccount.h | logic/auth/MojangAccount.h | ||||||
| logic/auth/MojangAccount.cpp | logic/auth/MojangAccount.cpp | ||||||
| logic/auth/YggdrasilTask.h | logic/auth/YggdrasilTask.h | ||||||
| @@ -367,8 +369,6 @@ logic/lists/ForgeVersionList.h | |||||||
| logic/lists/ForgeVersionList.cpp | logic/lists/ForgeVersionList.cpp | ||||||
| logic/lists/JavaVersionList.h | logic/lists/JavaVersionList.h | ||||||
| logic/lists/JavaVersionList.cpp | logic/lists/JavaVersionList.cpp | ||||||
| logic/lists/MojangAccountList.h |  | ||||||
| logic/lists/MojangAccountList.cpp |  | ||||||
|  |  | ||||||
| # misc model/view | # misc model/view | ||||||
| logic/EnabledItemFilter.h | logic/EnabledItemFilter.h | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								MultiMC.cpp
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								MultiMC.cpp
									
									
									
									
									
								
							| @@ -12,7 +12,7 @@ | |||||||
| #include "gui/MainWindow.h" | #include "gui/MainWindow.h" | ||||||
| #include "gui/dialogs/VersionSelectDialog.h" | #include "gui/dialogs/VersionSelectDialog.h" | ||||||
| #include "logic/lists/InstanceList.h" | #include "logic/lists/InstanceList.h" | ||||||
| #include "logic/lists/MojangAccountList.h" | #include "logic/auth/MojangAccountList.h" | ||||||
| #include "logic/lists/IconList.h" | #include "logic/lists/IconList.h" | ||||||
| #include "logic/lists/LwjglVersionList.h" | #include "logic/lists/LwjglVersionList.h" | ||||||
| #include "logic/lists/MinecraftVersionList.h" | #include "logic/lists/MinecraftVersionList.h" | ||||||
| @@ -78,11 +78,13 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv), | |||||||
| 		parser.addShortOpt("quietupdate", 'U'); | 		parser.addShortOpt("quietupdate", 'U'); | ||||||
| 		parser.addDocumentation("quietupdate", | 		parser.addDocumentation("quietupdate", | ||||||
| 								"doesn't restart MultiMC after installing updates"); | 								"doesn't restart MultiMC after installing updates"); | ||||||
|  | 		// WARNING: disabled until further notice | ||||||
|  | 		/* | ||||||
| 		// --launch | 		// --launch | ||||||
| 		parser.addOption("launch"); | 		parser.addOption("launch"); | ||||||
| 		parser.addShortOpt("launch", 'l'); | 		parser.addShortOpt("launch", 'l'); | ||||||
| 		parser.addDocumentation("launch", "tries to launch the given instance", "<inst>"); | 		parser.addDocumentation("launch", "tries to launch the given instance", "<inst>"); | ||||||
|  | */ | ||||||
| 		// parse the arguments | 		// parse the arguments | ||||||
| 		try | 		try | ||||||
| 		{ | 		{ | ||||||
| @@ -212,6 +214,8 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv), | |||||||
| 	m_qnam.reset(new QNetworkAccessManager(this)); | 	m_qnam.reset(new QNetworkAccessManager(this)); | ||||||
|  |  | ||||||
| 	// launch instance, if that's what should be done | 	// launch instance, if that's what should be done | ||||||
|  | 	// WARNING: disabled until further notice | ||||||
|  | 	/* | ||||||
| 	if (!args["launch"].isNull()) | 	if (!args["launch"].isNull()) | ||||||
| 	{ | 	{ | ||||||
| 		if (InstanceLauncher(args["launch"].toString()).launch()) | 		if (InstanceLauncher(args["launch"].toString()).launch()) | ||||||
| @@ -220,7 +224,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv), | |||||||
| 			m_status = MultiMC::Failed; | 			m_status = MultiMC::Failed; | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  | */ | ||||||
| 	m_status = MultiMC::Initialized; | 	m_status = MultiMC::Initialized; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ | |||||||
|  |  | ||||||
| #include <memory> | #include <memory> | ||||||
|  |  | ||||||
| #include "logic/lists/MojangAccountList.h" | #include "logic/auth/MojangAccountList.h" | ||||||
|  |  | ||||||
| namespace Ui | namespace Ui | ||||||
| { | { | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ | |||||||
|  |  | ||||||
| #include <memory> | #include <memory> | ||||||
|  |  | ||||||
| #include "logic/lists/MojangAccountList.h" | #include "logic/auth/MojangAccountList.h" | ||||||
|  |  | ||||||
| namespace Ui | namespace Ui | ||||||
| { | { | ||||||
|   | |||||||
| @@ -154,7 +154,7 @@ QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account) | |||||||
| 	token_mapping["game_assets"] = reconstructAssets(d->version).absolutePath(); | 	token_mapping["game_assets"] = reconstructAssets(d->version).absolutePath(); | ||||||
| 	//TODO: this is something new and not even fully implemented in the vanilla launcher. | 	//TODO: this is something new and not even fully implemented in the vanilla launcher. | ||||||
| 	token_mapping["user_properties"] = "{ }"; | 	token_mapping["user_properties"] = "{ }"; | ||||||
|  | 	token_mapping["user_type"] = account->currentProfile()->legacy ? "legacy" : "mojang"; | ||||||
| 	// 1.7.3+ assets tokens | 	// 1.7.3+ assets tokens | ||||||
| 	token_mapping["assets_root"] = absAssetsDir; | 	token_mapping["assets_root"] = absAssetsDir; | ||||||
| 	token_mapping["assets_index_name"] = version->assets; | 	token_mapping["assets_index_name"] = version->assets; | ||||||
|   | |||||||
| @@ -165,7 +165,7 @@ std::shared_ptr<OneSixVersion> OneSixVersion::fromJson(QJsonObject root) | |||||||
| 		root.value("minimumLauncherVersion").toDouble(); | 		root.value("minimumLauncherVersion").toDouble(); | ||||||
|  |  | ||||||
| 	// ADD MORE HERE :D | 	// ADD MORE HERE :D | ||||||
| 	if (launcher_ver > 0 && launcher_ver <= 12) | 	if (launcher_ver > 0 && launcher_ver <= 13) | ||||||
| 		return fromJsonV4(root, readVersion); | 		return fromJsonV4(root, readVersion); | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ | |||||||
| #include <QJsonObject> | #include <QJsonObject> | ||||||
| #include <QJsonArray> | #include <QJsonArray> | ||||||
| #include <QRegExp> | #include <QRegExp> | ||||||
|  | #include <QStringList> | ||||||
|  |  | ||||||
| #include <logger/QsLog.h> | #include <logger/QsLog.h> | ||||||
|  |  | ||||||
| @@ -52,15 +53,30 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object) | |||||||
| 		QJsonObject profileObject = profileVal.toObject(); | 		QJsonObject profileObject = profileVal.toObject(); | ||||||
| 		QString id = profileObject.value("id").toString(""); | 		QString id = profileObject.value("id").toString(""); | ||||||
| 		QString name = profileObject.value("name").toString(""); | 		QString name = profileObject.value("name").toString(""); | ||||||
|  | 		bool legacy = profileObject.value("legacy").toBool(false); | ||||||
| 		if (id.isEmpty() || name.isEmpty()) | 		if (id.isEmpty() || name.isEmpty()) | ||||||
| 		{ | 		{ | ||||||
| 			QLOG_WARN() << "Unable to load a profile because it was missing an ID or a name."; | 			QLOG_WARN() << "Unable to load a profile because it was missing an ID or a name."; | ||||||
| 			continue; | 			continue; | ||||||
| 		} | 		} | ||||||
| 		profiles.append({id, name}); | 		profiles.append({id, name, legacy}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	MojangAccountPtr account(new MojangAccount()); | 	MojangAccountPtr account(new MojangAccount()); | ||||||
|  | 	if(object.value("user").isObject()) | ||||||
|  | 	{ | ||||||
|  | 		User u; | ||||||
|  | 		QJsonObject userStructure = object.value("user").toObject(); | ||||||
|  | 		u.id = userStructure.value("id").toString(); | ||||||
|  | 		QJsonObject propMap = userStructure.value("properties").toObject(); | ||||||
|  | 		for(auto key: propMap.keys()) | ||||||
|  | 		{ | ||||||
|  | 			auto values = propMap.operator[](key).toArray(); | ||||||
|  | 			for(auto value: values) | ||||||
|  | 				u.properties.insert(key, value.toString()); | ||||||
|  | 		} | ||||||
|  | 		account->m_user = u; | ||||||
|  | 	} | ||||||
| 	account->m_username = username; | 	account->m_username = username; | ||||||
| 	account->m_clientToken = clientToken; | 	account->m_clientToken = clientToken; | ||||||
| 	account->m_accessToken = accessToken; | 	account->m_accessToken = accessToken; | ||||||
| @@ -95,10 +111,24 @@ QJsonObject MojangAccount::saveToJson() const | |||||||
| 		QJsonObject profileObj; | 		QJsonObject profileObj; | ||||||
| 		profileObj.insert("id", profile.id); | 		profileObj.insert("id", profile.id); | ||||||
| 		profileObj.insert("name", profile.name); | 		profileObj.insert("name", profile.name); | ||||||
|  | 		profileObj.insert("legacy", profile.legacy); | ||||||
| 		profileArray.append(profileObj); | 		profileArray.append(profileObj); | ||||||
| 	} | 	} | ||||||
| 	json.insert("profiles", profileArray); | 	json.insert("profiles", profileArray); | ||||||
|  |  | ||||||
|  | 	QJsonObject userStructure; | ||||||
|  | 	{ | ||||||
|  | 		userStructure.insert("id", m_user.id); | ||||||
|  | 		QJsonObject userAttrs; | ||||||
|  | 		for(auto key: m_user.properties.keys()) | ||||||
|  | 		{ | ||||||
|  | 			auto array = QJsonArray::fromStringList(m_user.properties.values(key)); | ||||||
|  | 			userAttrs.insert(key, array); | ||||||
|  | 		} | ||||||
|  | 		userStructure.insert("properties", userAttrs); | ||||||
|  | 	} | ||||||
|  | 	json.insert("user", userStructure); | ||||||
|  |  | ||||||
| 	if (m_currentProfile != -1) | 	if (m_currentProfile != -1) | ||||||
| 		json.insert("activeProfile", currentProfile()->id); | 		json.insert("activeProfile", currentProfile()->id); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ | |||||||
| #include <QList> | #include <QList> | ||||||
| #include <QJsonObject> | #include <QJsonObject> | ||||||
| #include <QPair> | #include <QPair> | ||||||
|  | #include <QMap> | ||||||
|  |  | ||||||
| #include <memory> | #include <memory> | ||||||
|  |  | ||||||
| @@ -41,14 +42,13 @@ struct AccountProfile | |||||||
| { | { | ||||||
| 	QString id; | 	QString id; | ||||||
| 	QString name; | 	QString name; | ||||||
|  | 	bool legacy; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| struct User | struct User | ||||||
| { | { | ||||||
| 	QString id; | 	QString id; | ||||||
| 	// pair of key:value | 	QMultiMap<QString,QString> properties; | ||||||
| 	// we don't know if the keys:value mapping is 1:1, so a list is used. |  | ||||||
| 	QList<QPair<QString, QString>> properties; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| enum AccountStatus | enum AccountStatus | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ | |||||||
|  * limitations under the License. |  * limitations under the License. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include "logic/lists/MojangAccountList.h" | #include "logic/auth/MojangAccountList.h" | ||||||
| 
 | 
 | ||||||
| #include <QIODevice> | #include <QIODevice> | ||||||
| #include <QFile> | #include <QFile> | ||||||
| @@ -27,7 +27,7 @@ | |||||||
| 
 | 
 | ||||||
| #include "logic/auth/MojangAccount.h" | #include "logic/auth/MojangAccount.h" | ||||||
| 
 | 
 | ||||||
| #define ACCOUNT_LIST_FORMAT_VERSION 1 | #define ACCOUNT_LIST_FORMAT_VERSION 2 | ||||||
| 
 | 
 | ||||||
| MojangAccountList::MojangAccountList(QObject *parent) : QAbstractListModel(parent) | MojangAccountList::MojangAccountList(QObject *parent) : QAbstractListModel(parent) | ||||||
| { | { | ||||||
| @@ -76,7 +76,7 @@ bool AuthenticateTask::processResponse(QJsonObject responseData) | |||||||
| 	// Read the response data. We need to get the client token, access token, and the selected | 	// Read the response data. We need to get the client token, access token, and the selected | ||||||
| 	// profile. | 	// profile. | ||||||
| 	QLOG_DEBUG() << "Processing authentication response."; | 	QLOG_DEBUG() << "Processing authentication response."; | ||||||
|  | 	QLOG_DEBUG() << responseData; | ||||||
| 	// If we already have a client token, make sure the one the server gave us matches our | 	// If we already have a client token, make sure the one the server gave us matches our | ||||||
| 	// existing one. | 	// existing one. | ||||||
| 	QLOG_DEBUG() << "Getting client token."; | 	QLOG_DEBUG() << "Getting client token."; | ||||||
| @@ -123,6 +123,7 @@ bool AuthenticateTask::processResponse(QJsonObject responseData) | |||||||
| 		// Profiles are easy, we just need their ID and name. | 		// Profiles are easy, we just need their ID and name. | ||||||
| 		QString id = profile.value("id").toString(""); | 		QString id = profile.value("id").toString(""); | ||||||
| 		QString name = profile.value("name").toString(""); | 		QString name = profile.value("name").toString(""); | ||||||
|  | 		bool legacy = profile.value("legacy").toBool(false); | ||||||
|  |  | ||||||
| 		if (id.isEmpty() || name.isEmpty()) | 		if (id.isEmpty() || name.isEmpty()) | ||||||
| 		{ | 		{ | ||||||
| @@ -134,7 +135,7 @@ bool AuthenticateTask::processResponse(QJsonObject responseData) | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		// Now, add a new AccountProfile entry to the list. | 		// Now, add a new AccountProfile entry to the list. | ||||||
| 		loadedProfiles.append({id, name}); | 		loadedProfiles.append({id, name, legacy}); | ||||||
| 	} | 	} | ||||||
| 	// Put the list of profiles we loaded into the MojangAccount object. | 	// Put the list of profiles we loaded into the MojangAccount object. | ||||||
| 	m_account->m_profiles = loadedProfiles; | 	m_account->m_profiles = loadedProfiles; | ||||||
| @@ -166,10 +167,11 @@ bool AuthenticateTask::processResponse(QJsonObject responseData) | |||||||
| 	// is it a good idea to log this? | 	// is it a good idea to log this? | ||||||
| 	if (responseData.contains("user")) | 	if (responseData.contains("user")) | ||||||
| 	{ | 	{ | ||||||
|  | 		User u; | ||||||
| 		auto obj = responseData.value("user").toObject(); | 		auto obj = responseData.value("user").toObject(); | ||||||
| 		auto userId = obj.value("id").toString(); | 		u.id = obj.value("id").toString(); | ||||||
|  | 		QLOG_DEBUG() << "User ID: " << u.id ; | ||||||
| 		auto propArray = obj.value("properties").toArray(); | 		auto propArray = obj.value("properties").toArray(); | ||||||
| 		QLOG_DEBUG() << "User ID: " << userId; |  | ||||||
| 		QLOG_DEBUG() << "User Properties: "; | 		QLOG_DEBUG() << "User Properties: "; | ||||||
| 		for (auto prop : propArray) | 		for (auto prop : propArray) | ||||||
| 		{ | 		{ | ||||||
| @@ -177,7 +179,9 @@ bool AuthenticateTask::processResponse(QJsonObject responseData) | |||||||
| 			auto name = propTuple.value("name").toString(); | 			auto name = propTuple.value("name").toString(); | ||||||
| 			auto value = propTuple.value("value").toString(); | 			auto value = propTuple.value("value").toString(); | ||||||
| 			QLOG_DEBUG() << name << " : " << value; | 			QLOG_DEBUG() << name << " : " << value; | ||||||
|  | 			u.properties.insert(name, value); | ||||||
| 		} | 		} | ||||||
|  | 		m_account->m_user = u; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// We've made it through the minefield of possible errors. Return true to indicate that | 	// We've made it through the minefield of possible errors. Return true to indicate that | ||||||
|   | |||||||
| @@ -67,6 +67,7 @@ bool RefreshTask::processResponse(QJsonObject responseData) | |||||||
| 	// profile. | 	// profile. | ||||||
| 	QLOG_DEBUG() << "Processing authentication response."; | 	QLOG_DEBUG() << "Processing authentication response."; | ||||||
|  |  | ||||||
|  | 	QLOG_DEBUG() << responseData; | ||||||
| 	// If we already have a client token, make sure the one the server gave us matches our | 	// If we already have a client token, make sure the one the server gave us matches our | ||||||
| 	// existing one. | 	// existing one. | ||||||
| 	QString clientToken = responseData.value("clientToken").toString(""); | 	QString clientToken = responseData.value("clientToken").toString(""); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user