NOISSUE add setting capes, tweak missing profile message, fix cape IDs
This commit is contained in:
@ -78,8 +78,8 @@ void profileToJSONV3(QJsonObject &parent, MinecraftProfile p, const char * token
|
||||
QJsonObject out;
|
||||
out["id"] = QJsonValue(p.id);
|
||||
out["name"] = QJsonValue(p.name);
|
||||
if(p.currentCape != -1) {
|
||||
out["cape"] = p.capes[p.currentCape].id;
|
||||
if(!p.currentCape.isEmpty()) {
|
||||
out["cape"] = p.currentCape;
|
||||
}
|
||||
|
||||
{
|
||||
@ -155,41 +155,53 @@ MinecraftProfile profileFromJSONV3(const QJsonObject &parent, const char * token
|
||||
}
|
||||
}
|
||||
|
||||
auto capesV = tokenObject.value("capes");
|
||||
if(!capesV.isArray()) {
|
||||
qWarning() << "capes is not an array!";
|
||||
return MinecraftProfile();
|
||||
}
|
||||
auto capesArray = capesV.toArray();
|
||||
for(auto capeV: capesArray) {
|
||||
if(!capeV.isObject()) {
|
||||
qWarning() << "cape is not an object!";
|
||||
{
|
||||
auto capesV = tokenObject.value("capes");
|
||||
if(!capesV.isArray()) {
|
||||
qWarning() << "capes is not an array!";
|
||||
return MinecraftProfile();
|
||||
}
|
||||
auto capeObj = capeV.toObject();
|
||||
auto idV = capeObj.value("id");
|
||||
auto urlV = capeObj.value("url");
|
||||
auto aliasV = capeObj.value("alias");
|
||||
if(!idV.isString() || !urlV.isString() || !aliasV.isString()) {
|
||||
qWarning() << "mandatory skin attributes are missing or of unexpected type";
|
||||
return MinecraftProfile();
|
||||
}
|
||||
Cape cape;
|
||||
cape.id = idV.toString();
|
||||
cape.url = urlV.toString();
|
||||
cape.alias = aliasV.toString();
|
||||
auto capesArray = capesV.toArray();
|
||||
for(auto capeV: capesArray) {
|
||||
if(!capeV.isObject()) {
|
||||
qWarning() << "cape is not an object!";
|
||||
return MinecraftProfile();
|
||||
}
|
||||
auto capeObj = capeV.toObject();
|
||||
auto idV = capeObj.value("id");
|
||||
auto urlV = capeObj.value("url");
|
||||
auto aliasV = capeObj.value("alias");
|
||||
if(!idV.isString() || !urlV.isString() || !aliasV.isString()) {
|
||||
qWarning() << "mandatory skin attributes are missing or of unexpected type";
|
||||
return MinecraftProfile();
|
||||
}
|
||||
Cape cape;
|
||||
cape.id = idV.toString();
|
||||
cape.url = urlV.toString();
|
||||
cape.alias = aliasV.toString();
|
||||
|
||||
// data for cape is optional.
|
||||
auto dataV = capeObj.value("data");
|
||||
if(dataV.isString()) {
|
||||
// TODO: validate base64
|
||||
cape.data = QByteArray::fromBase64(dataV.toString().toLatin1());
|
||||
// data for cape is optional.
|
||||
auto dataV = capeObj.value("data");
|
||||
if(dataV.isString()) {
|
||||
// TODO: validate base64
|
||||
cape.data = QByteArray::fromBase64(dataV.toString().toLatin1());
|
||||
}
|
||||
else if (!dataV.isUndefined()) {
|
||||
qWarning() << "cape data is something unexpected";
|
||||
return MinecraftProfile();
|
||||
}
|
||||
out.capes[cape.id] = cape;
|
||||
}
|
||||
else if (!dataV.isUndefined()) {
|
||||
qWarning() << "cape data is something unexpected";
|
||||
return MinecraftProfile();
|
||||
}
|
||||
// current cape
|
||||
{
|
||||
auto capeV = tokenObject.value("cape");
|
||||
if(capeV.isString()) {
|
||||
auto currentCape = capeV.toString();
|
||||
if(out.capes.contains(currentCape)) {
|
||||
out.currentCape = currentCape;
|
||||
}
|
||||
}
|
||||
out.capes.push_back(cape);
|
||||
}
|
||||
out.validity = Katabasis::Validity::Assumed;
|
||||
return out;
|
||||
|
@ -25,8 +25,8 @@ struct MinecraftProfile {
|
||||
QString id;
|
||||
QString name;
|
||||
Skin skin;
|
||||
int currentCape = -1;
|
||||
QVector<Cape> capes;
|
||||
QString currentCape;
|
||||
QMap<QString, Cape> capes;
|
||||
Katabasis::Validity validity = Katabasis::Validity::None;
|
||||
};
|
||||
|
||||
|
@ -576,7 +576,9 @@ void AuthContext::onXBoxProfileDone(
|
||||
}
|
||||
|
||||
void AuthContext::checkResult() {
|
||||
qDebug() << "AuthContext::checkResult called";
|
||||
if(m_requestsDone != 2) {
|
||||
qDebug() << "Number of ready results:" << m_requestsDone;
|
||||
return;
|
||||
}
|
||||
if(m_mcAuthSucceeded && m_xboxProfileSucceeded) {
|
||||
@ -638,10 +640,9 @@ bool parseMinecraftProfile(QByteArray & data, MinecraftProfile &output) {
|
||||
break;
|
||||
}
|
||||
auto capesArray = obj.value("capes").toArray();
|
||||
int i = -1;
|
||||
int currentCape = -1;
|
||||
|
||||
QString currentCape;
|
||||
for(auto cape: capesArray) {
|
||||
i++;
|
||||
auto capeObj = cape.toObject();
|
||||
Cape capeOut;
|
||||
if(!getString(capeObj.value("id"), capeOut.id)) {
|
||||
@ -652,7 +653,7 @@ bool parseMinecraftProfile(QByteArray & data, MinecraftProfile &output) {
|
||||
continue;
|
||||
}
|
||||
if(state == "ACTIVE") {
|
||||
currentCape = i;
|
||||
currentCape = capeOut.id;
|
||||
}
|
||||
if(!getString(capeObj.value("url"), capeOut.url)) {
|
||||
continue;
|
||||
@ -661,8 +662,7 @@ bool parseMinecraftProfile(QByteArray & data, MinecraftProfile &output) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// we deal with only the active skin
|
||||
output.capes.push_back(capeOut);
|
||||
output.capes[capeOut.id] = capeOut;
|
||||
}
|
||||
output.currentCape = currentCape;
|
||||
output.validity = Katabasis::Validity::Certain;
|
||||
@ -692,18 +692,18 @@ void AuthContext::onMinecraftProfileDone(int, QNetworkReply::NetworkError error,
|
||||
if (error == QNetworkReply::ContentNotFoundError) {
|
||||
m_data->minecraftProfile = MinecraftProfile();
|
||||
finishActivity();
|
||||
changeState(STATE_FAILED_HARD, tr("Account is missing a profile"));
|
||||
changeState(STATE_FAILED_HARD, tr("Account is missing a Minecraft Java profile.\n\nWhile the Microsoft account is valid, it does not own the game.\n\nYou might own Bedrock on this account, but that does not give you access to Java currently."));
|
||||
return;
|
||||
}
|
||||
if (error != QNetworkReply::NoError) {
|
||||
finishActivity();
|
||||
changeState(STATE_FAILED_HARD, tr("Profile acquisition failed"));
|
||||
changeState(STATE_FAILED_HARD, tr("Minecraft Java profile acquisition failed."));
|
||||
return;
|
||||
}
|
||||
if(!parseMinecraftProfile(data, m_data->minecraftProfile)) {
|
||||
m_data->minecraftProfile = MinecraftProfile();
|
||||
finishActivity();
|
||||
changeState(STATE_FAILED_HARD, tr("Profile response could not be parsed"));
|
||||
changeState(STATE_FAILED_HARD, tr("Minecraft Java profile response could not be parsed"));
|
||||
return;
|
||||
}
|
||||
doGetSkin();
|
||||
|
67
launcher/minecraft/services/CapeChange.cpp
Normal file
67
launcher/minecraft/services/CapeChange.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include "CapeChange.h"
|
||||
#include <QNetworkRequest>
|
||||
#include <QHttpMultiPart>
|
||||
#include <Env.h>
|
||||
|
||||
CapeChange::CapeChange(QObject *parent, AuthSessionPtr session, QString cape)
|
||||
: Task(parent), m_capeId(cape), m_session(session)
|
||||
{
|
||||
}
|
||||
|
||||
void CapeChange::setCape(QString& cape) {
|
||||
QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active"));
|
||||
auto requestString = QString("{\"capeId\":\"%1\"}").arg(m_capeId);
|
||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_session->access_token).toLocal8Bit());
|
||||
QNetworkReply *rep = ENV.qnam().put(request, requestString.toUtf8());
|
||||
|
||||
setStatus(tr("Equipping cape"));
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress);
|
||||
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
|
||||
connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished()));
|
||||
}
|
||||
|
||||
void CapeChange::clearCape() {
|
||||
QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active"));
|
||||
auto requestString = QString("{\"capeId\":\"%1\"}").arg(m_capeId);
|
||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_session->access_token).toLocal8Bit());
|
||||
QNetworkReply *rep = ENV.qnam().deleteResource(request);
|
||||
|
||||
setStatus(tr("Removing cape"));
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress);
|
||||
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
|
||||
connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished()));
|
||||
}
|
||||
|
||||
|
||||
void CapeChange::executeTask()
|
||||
{
|
||||
if(m_capeId.isEmpty()) {
|
||||
clearCape();
|
||||
}
|
||||
else {
|
||||
setCape(m_capeId);
|
||||
}
|
||||
}
|
||||
|
||||
void CapeChange::downloadError(QNetworkReply::NetworkError error)
|
||||
{
|
||||
// error happened during download.
|
||||
qCritical() << "Network error: " << error;
|
||||
emitFailed(m_reply->errorString());
|
||||
}
|
||||
|
||||
void CapeChange::downloadFinished()
|
||||
{
|
||||
// if the download failed
|
||||
if (m_reply->error() != QNetworkReply::NetworkError::NoError)
|
||||
{
|
||||
emitFailed(QString("Network error: %1").arg(m_reply->errorString()));
|
||||
m_reply.reset();
|
||||
return;
|
||||
}
|
||||
emitSucceeded();
|
||||
}
|
32
launcher/minecraft/services/CapeChange.h
Normal file
32
launcher/minecraft/services/CapeChange.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QFile>
|
||||
#include <QtNetwork/QtNetwork>
|
||||
#include <memory>
|
||||
#include <minecraft/auth/AuthSession.h>
|
||||
#include "tasks/Task.h"
|
||||
|
||||
class CapeChange : public Task
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CapeChange(QObject *parent, AuthSessionPtr session, QString capeId);
|
||||
virtual ~CapeChange() {}
|
||||
|
||||
private:
|
||||
void setCape(QString & cape);
|
||||
void clearCape();
|
||||
|
||||
private:
|
||||
QString m_capeId;
|
||||
AuthSessionPtr m_session;
|
||||
std::shared_ptr<QNetworkReply> m_reply;
|
||||
|
||||
protected:
|
||||
virtual void executeTask();
|
||||
|
||||
public slots:
|
||||
void downloadError(QNetworkReply::NetworkError);
|
||||
void downloadFinished();
|
||||
};
|
||||
|
Reference in New Issue
Block a user