| 141 | } |
| 142 | |
| 143 | bool parseMinecraftProfile(QByteArray& data, MinecraftProfile& output) |
| 144 | { |
| 145 | qDebug() << "Parsing Minecraft profile..."; |
| 146 | qCDebug(authCredentials()) << data; |
| 147 | |
| 148 | QJsonParseError jsonError; |
| 149 | QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); |
| 150 | if (jsonError.error) { |
| 151 | qWarning() << "Failed to parse response from user.auth.xboxlive.com as JSON: " << jsonError.errorString(); |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | auto obj = doc.object(); |
| 156 | if (!getString(obj.value("id"), output.id)) { |
| 157 | qWarning() << "Minecraft profile id is not a string"; |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | if (!getString(obj.value("name"), output.name)) { |
| 162 | qWarning() << "Minecraft profile name is not a string"; |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | auto skinsArray = obj.value("skins").toArray(); |
| 167 | for (auto skin : skinsArray) { |
| 168 | auto skinObj = skin.toObject(); |
| 169 | Skin skinOut; |
| 170 | if (!getString(skinObj.value("id"), skinOut.id)) { |
| 171 | continue; |
| 172 | } |
| 173 | QString state; |
| 174 | if (!getString(skinObj.value("state"), state)) { |
| 175 | continue; |
| 176 | } |
| 177 | if (state != "ACTIVE") { |
| 178 | continue; |
| 179 | } |
| 180 | if (!getString(skinObj.value("url"), skinOut.url)) { |
| 181 | continue; |
| 182 | } |
| 183 | skinOut.url.replace("http://textures.minecraft.net", "https://textures.minecraft.net"); |
| 184 | if (!getString(skinObj.value("variant"), skinOut.variant)) { |
| 185 | continue; |
| 186 | } |
| 187 | // we deal with only the active skin |
| 188 | output.skin = skinOut; |
| 189 | break; |
| 190 | } |
| 191 | auto capesArray = obj.value("capes").toArray(); |
| 192 | |
| 193 | QString currentCape; |
| 194 | for (auto cape : capesArray) { |
| 195 | auto capeObj = cape.toObject(); |
| 196 | Cape capeOut; |
| 197 | if (!getString(capeObj.value("id"), capeOut.id)) { |
| 198 | continue; |
| 199 | } |
| 200 | QString state; |
no test coverage detected