mirror of https://github.com/hykilpikonna/AquaDX
[F] Fix DFI response compat
parent
4f3a6cba45
commit
e7085f7602
|
@ -1,11 +1,11 @@
|
||||||
package icu.samnyan.aqua.net.transfer
|
package icu.samnyan.aqua.net.transfer
|
||||||
|
|
||||||
import ext.bodyString
|
|
||||||
import ext.header
|
import ext.header
|
||||||
import ext.post
|
import ext.post
|
||||||
import ext.request
|
import ext.request
|
||||||
import icu.samnyan.aqua.sega.aimedb.AimeDbClient
|
import icu.samnyan.aqua.sega.aimedb.AimeDbClient
|
||||||
import icu.samnyan.aqua.sega.util.AllNetBillingDecoder
|
import icu.samnyan.aqua.sega.allnet.AllNetBillingDecoder
|
||||||
|
import icu.samnyan.aqua.sega.allnet.AllNetBillingDecoder.decodeAllNetResp
|
||||||
|
|
||||||
val keychipPattern = Regex("([A-Z\\d]{4}-[A-Z\\d]{11}|[A-Z\\d]{11})")
|
val keychipPattern = Regex("([A-Z\\d]{4}-[A-Z\\d]{11}|[A-Z\\d]{11})")
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ class AllNetClient(val dns: String, val keychip: String, val game: String, val v
|
||||||
// Send AllNet PowerOn request to obtain game URL
|
// Send AllNet PowerOn request to obtain game URL
|
||||||
val gameUrl by lazy {
|
val gameUrl by lazy {
|
||||||
"$dns/sys/servlet/PowerOn".request()
|
"$dns/sys/servlet/PowerOn".request()
|
||||||
|
.header("User-Agent" to "AquaTrans/1.0")
|
||||||
.header("Content-Type" to "application/x-www-form-urlencoded")
|
.header("Content-Type" to "application/x-www-form-urlencoded")
|
||||||
.header("Pragma" to "DFI")
|
.header("Pragma" to "DFI")
|
||||||
.post(AllNetBillingDecoder.encodeAllNet(mapOf(
|
.post(AllNetBillingDecoder.encodeAllNet(mapOf(
|
||||||
|
@ -37,11 +38,10 @@ class AllNetClient(val dns: String, val keychip: String, val game: String, val v
|
||||||
"ip" to "127.0.0.1", "firm_ver" to "60001", "boot_ver" to "0000",
|
"ip" to "127.0.0.1", "firm_ver" to "60001", "boot_ver" to "0000",
|
||||||
"encode" to "UTF-8", "format_ver" to "3", "hops" to "1", "token" to "2864179931"
|
"encode" to "UTF-8", "format_ver" to "3", "hops" to "1", "token" to "2864179931"
|
||||||
)))
|
)))
|
||||||
.bodyString()
|
?.also {
|
||||||
?.split("&")
|
println(it)
|
||||||
?.map { it.split("=") }
|
}
|
||||||
?.filter { it.size == 2 }
|
?.decodeAllNetResp()?.get("uri")
|
||||||
?.associate { it[0] to it[1] }?.get("uri")
|
|
||||||
?: throw Exception("PowerOn Failed: No game URL returned")
|
?: throw Exception("PowerOn Failed: No game URL returned")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,8 @@ abstract class DataBroker(
|
||||||
|
|
||||||
inline fun <reified T> String.get(key: String, data: JDict): T = getNullable(key, data) ?: run {
|
inline fun <reified T> String.get(key: String, data: JDict): T = getNullable(key, data) ?: run {
|
||||||
log("❌ $this")
|
log("❌ $this")
|
||||||
throw Exception("Failed to get $this")
|
if (this == "GetUserDataApi") 404 - "Failed to get $this (User not found?)"
|
||||||
|
else 417 - "Failed to get $this"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun prePull(): Pair<Map<String, Long>, MutableMap<String, Long>> {
|
fun prePull(): Pair<Map<String, Long>, MutableMap<String, Long>> {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package icu.samnyan.aqua.sega.allnet
|
||||||
|
|
||||||
import ext.*
|
import ext.*
|
||||||
import icu.samnyan.aqua.net.db.AquaNetUserRepo
|
import icu.samnyan.aqua.net.db.AquaNetUserRepo
|
||||||
import icu.samnyan.aqua.sega.util.AllNetBillingDecoder.decodeAllNet
|
import icu.samnyan.aqua.sega.allnet.AllNetBillingDecoder.decodeAllNet
|
||||||
import icu.samnyan.aqua.sega.util.AquaConst
|
import icu.samnyan.aqua.sega.util.AquaConst
|
||||||
import jakarta.servlet.http.HttpServletRequest
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
import jakarta.servlet.http.HttpServletResponse
|
import jakarta.servlet.http.HttpServletResponse
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
package icu.samnyan.aqua.sega.util
|
package icu.samnyan.aqua.sega.allnet
|
||||||
|
|
||||||
|
import ext.bodyString
|
||||||
|
import ext.header
|
||||||
|
import icu.samnyan.aqua.sega.util.ZLib
|
||||||
|
import java.net.http.HttpResponse
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.text.Charsets.UTF_8
|
import kotlin.text.Charsets.UTF_8
|
||||||
|
|
||||||
object AllNetBillingDecoder {
|
object AllNetBillingDecoder {
|
||||||
|
fun String.urlToMap() = split("&").map { it.split("=") }.filter { it.size == 2 }.associate { it[0] to it[1] }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode the input byte array from Base64 MIME encoding and decompress the decoded byte array
|
* Decode the input byte array from Base64 MIME encoding and decompress the decoded byte array
|
||||||
*/
|
*/
|
||||||
|
@ -15,10 +21,7 @@ object AllNetBillingDecoder {
|
||||||
val output = ZLib.decompress(bytes, nowrap).toString(UTF_8).trim()
|
val output = ZLib.decompress(bytes, nowrap).toString(UTF_8).trim()
|
||||||
|
|
||||||
// Split the string by '&' symbol to separate key-value pairs
|
// Split the string by '&' symbol to separate key-value pairs
|
||||||
return output.split("&").associate {
|
return output.urlToMap()
|
||||||
val (key, value) = it.split("=")
|
|
||||||
key to value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun encode(src: Map<String, String>, base64: Boolean): ByteArray {
|
fun encode(src: Map<String, String>, base64: Boolean): ByteArray {
|
||||||
|
@ -29,7 +32,7 @@ object AllNetBillingDecoder {
|
||||||
val bytes = ZLib.compress(output.toByteArray(UTF_8))
|
val bytes = ZLib.compress(output.toByteArray(UTF_8))
|
||||||
|
|
||||||
// Encode the compressed byte array to Base64 MIME encoding
|
// Encode the compressed byte array to Base64 MIME encoding
|
||||||
return if (!base64) bytes else Base64.getMimeEncoder().encode(bytes)
|
return if (!base64) bytes else Base64.getEncoder().encode(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@ -38,4 +41,10 @@ object AllNetBillingDecoder {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun decodeBilling(src: ByteArray) = decode(src, base64 = false, nowrap = true)
|
fun decodeBilling(src: ByteArray) = decode(src, base64 = false, nowrap = true)
|
||||||
|
|
||||||
|
fun HttpResponse<ByteArray>.decodeAllNetResp() =
|
||||||
|
if (header("Pragma") == "DFI") decodeAllNet(body())
|
||||||
|
else bodyString()?.urlToMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package icu.samnyan.aqua.sega.billing
|
||||||
|
|
||||||
import ext.logger
|
import ext.logger
|
||||||
import ext.toUrl
|
import ext.toUrl
|
||||||
import icu.samnyan.aqua.sega.util.AllNetBillingDecoder.decodeBilling
|
import icu.samnyan.aqua.sega.allnet.AllNetBillingDecoder.decodeBilling
|
||||||
import jakarta.annotation.PostConstruct
|
import jakarta.annotation.PostConstruct
|
||||||
import jakarta.servlet.http.HttpServletRequest
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
import org.eclipse.jetty.http.HttpVersion
|
import org.eclipse.jetty.http.HttpVersion
|
||||||
|
|
Loading…
Reference in New Issue