mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
Fix Game Pass library sync when subscription plan rows are omitted (#1193)
This commit is contained in:
1 parent
7775a87129
commit
0663593920
6 files changed
+185
-9
No files matched your search
@@ -54,8 +54,12 @@ object XboxBackend : StoreBackend {
|
||||
}
|
||||
}
|
||||
if (cached != null && !cached.needsRefresh(force)) return@Thread
|
||||
val licenses = XboxCatalog.access(Xodus.run(app, listOf("library", "--json", "--market", market)), account, market)
|
||||
val games = XboxCatalog.products(licenses.keys.toList(), licenses, market).sortedBy { it.title.lowercase() }
|
||||
val response = Xodus.run(app, listOf("library", "--json", "--market", market))
|
||||
val licenses = XboxCatalog.access(response, account, market, report = { StoresState.logLine("Xbox: $it") })
|
||||
val products = XboxCatalog.rawProducts(licenses.keys.toList(), market)
|
||||
val games = products.mapNotNull { XboxCatalog.product(it, licenses) }.sortedBy { it.title.lowercase() }
|
||||
StoresState.logLine("Xbox: library catalog requested=${licenses.size} returned=${products.size} supported=${games.size} " +
|
||||
"filtered=${products.size - games.size} backend-skipped=${response.optInt("skippedEntitlements")}")
|
||||
synchronized(this) {
|
||||
if (current != generation || StoreAccounts.signedInAs(app, store) != account) return@Thread
|
||||
access = licenses
|
||||
|
||||
@@ -11,10 +11,25 @@ internal object XboxCatalog {
|
||||
private val productId = Regex("[A-Z0-9]{12}")
|
||||
private val plans = setOf("CFQ7TTC0KGQ8", "CFQ7TTC0KHS0", "CFQ7TTC0P85B", "CFQ7TTC0K5DJ", "CFQ7TTC0K6L8", "CFQ7TTC10QFD")
|
||||
|
||||
fun access(json: JSONObject, account: String, market: String, now: Instant = Instant.now()): Map<String, String> {
|
||||
fun access(json: JSONObject, account: String, market: String, now: Instant = Instant.now(), report: (String) -> Unit = {}): Map<String, String> {
|
||||
require(json.getInt("schema") == 1 && json.getString("account") == account && json.getString("market") == market)
|
||||
val age = java.time.Duration.between(timestamp(json.getString("checkedAt")), now).seconds
|
||||
require(age in -60..299)
|
||||
val memberships: Set<String>? = if (json.has("subscriptions")) {
|
||||
val subscriptions = json.getJSONArray("subscriptions")
|
||||
require(subscriptions.length() <= plans.size)
|
||||
val seen = HashSet<String>()
|
||||
buildSet {
|
||||
for (i in 0 until subscriptions.length()) {
|
||||
val row = subscriptions.getJSONObject(i)
|
||||
val id = row.getString("productId")
|
||||
require(id in plans && seen.add(id))
|
||||
val status = row.getString("status")
|
||||
val expiry = timestamp(row.getString("endDate"))
|
||||
if (status == "Active" && expiry.isAfter(now)) add(id)
|
||||
}
|
||||
}
|
||||
} else null
|
||||
val array = json.getJSONArray("entitlements")
|
||||
require(array.length() <= 10_000)
|
||||
val rows = LinkedHashMap<String, JSONObject>()
|
||||
@@ -30,6 +45,7 @@ internal object XboxCatalog {
|
||||
}
|
||||
fun active(row: JSONObject) = row.getString("status") == "Active" && !row.getBoolean("isTrial") && !row.getBoolean("special") &&
|
||||
row.getString("sharingSource") == "None" && timestamp(row.getString("endDate")).isAfter(now)
|
||||
fun activePlan(id: String) = rows[id]?.let(::active) ?: (id in memberships.orEmpty())
|
||||
fun kind(id: String, visited: Set<String> = emptySet()): String? {
|
||||
if (id in blocked || id in visited || visited.size >= 16) return null
|
||||
val row = rows[id] ?: return null
|
||||
@@ -37,10 +53,14 @@ internal object XboxCatalog {
|
||||
val parent = row.optString("satisfiedByProductId").takeUnless { it.isBlank() || it == "null" }
|
||||
if (parent == null) return if (id in plans) null else "owned"
|
||||
if (parent in blocked) return null
|
||||
if (parent in plans) return if (rows[parent]?.let(::active) == true) "gamepass" else null
|
||||
if (parent in plans) return if (activePlan(parent)) "gamepass" else null
|
||||
return kind(parent, visited + id)
|
||||
}
|
||||
return rows.keys.mapNotNull { id -> kind(id)?.let { id to it } }.toMap()
|
||||
val result = rows.keys.mapNotNull { id -> kind(id)?.let { id to it } }.toMap()
|
||||
val missingPlan = rows.values.count { row -> row.optString("satisfiedByProductId").let { it in plans && !activePlan(it) } }
|
||||
report("library entitlements=${array.length()} invalid=${array.length() - rows.size} restricted=${rows.values.count { !active(it) }} " +
|
||||
"unverified-plan=$missingPlan owned=${result.values.count { it == "owned" }} gamepass=${result.values.count { it == "gamepass" }}")
|
||||
return result
|
||||
}
|
||||
|
||||
private fun timestamp(value: String): Instant = java.time.OffsetDateTime.parse(value).toInstant()
|
||||
|
||||
Reference in new issue
Block a user