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