diff options
author | Petr Mrázek <peterix@gmail.com> | 2021-08-20 01:34:32 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2021-08-20 01:34:32 +0200 |
commit | 1b68d51da634ddab39fe872fcc28a4f491c0c8a4 (patch) | |
tree | 9a22465d682018830635a8929eab3cc8482b1faa /launcher/minecraft/auth/AccountData.cpp | |
parent | 94fd9a3535ae9a55c228720858292ed2bb69ff98 (diff) | |
download | PrismLauncher-1b68d51da634ddab39fe872fcc28a4f491c0c8a4.tar.gz PrismLauncher-1b68d51da634ddab39fe872fcc28a4f491c0c8a4.tar.bz2 PrismLauncher-1b68d51da634ddab39fe872fcc28a4f491c0c8a4.zip |
NOISSUE add setting capes, tweak missing profile message, fix cape IDs
Diffstat (limited to 'launcher/minecraft/auth/AccountData.cpp')
-rw-r--r-- | launcher/minecraft/auth/AccountData.cpp | 78 |
1 files changed, 45 insertions, 33 deletions
diff --git a/launcher/minecraft/auth/AccountData.cpp b/launcher/minecraft/auth/AccountData.cpp index 77c73c1b..5c6de9df 100644 --- a/launcher/minecraft/auth/AccountData.cpp +++ b/launcher/minecraft/auth/AccountData.cpp @@ -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!"; - 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"; + { + auto capesV = tokenObject.value("capes"); + if(!capesV.isArray()) { + qWarning() << "capes is not an array!"; 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()); + 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()); + } + 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; |