mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-10 16:27:28 +08:00
[+] Add authentication token at poweron
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
package icu.samnyan.aqua.sega.allnet
|
package icu.samnyan.aqua.sega.allnet
|
||||||
|
|
||||||
import ext.API
|
import ext.*
|
||||||
import ext.plus
|
import icu.samnyan.aqua.net.db.AquaNetUserRepo
|
||||||
import ext.plusAssign
|
|
||||||
import ext.toUrl
|
|
||||||
import icu.samnyan.aqua.sega.util.AquaConst
|
import icu.samnyan.aqua.sega.util.AquaConst
|
||||||
import icu.samnyan.aqua.sega.util.Decoder.decodeAllNet
|
import icu.samnyan.aqua.sega.util.Decoder.decodeAllNet
|
||||||
import jakarta.servlet.http.HttpServletRequest
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
@@ -25,6 +23,7 @@ import java.util.*
|
|||||||
class AllNetProps {
|
class AllNetProps {
|
||||||
var host: String = ""
|
var host: String = ""
|
||||||
var port: Int? = null
|
var port: Int? = null
|
||||||
|
val keychipSesExpire: Long = 172800000 // milliseconds
|
||||||
var checkKeychip: Boolean = false
|
var checkKeychip: Boolean = false
|
||||||
|
|
||||||
var placeName: String = ""
|
var placeName: String = ""
|
||||||
@@ -61,6 +60,8 @@ class AllNetProps {
|
|||||||
@Suppress("HttpUrlsUsage")
|
@Suppress("HttpUrlsUsage")
|
||||||
@RestController
|
@RestController
|
||||||
class AllNet(
|
class AllNet(
|
||||||
|
val userRepo: AquaNetUserRepo,
|
||||||
|
val keychipSessionService: KeychipSessionService,
|
||||||
val keychipRepo: KeyChipRepo,
|
val keychipRepo: KeyChipRepo,
|
||||||
val props: AllNetProps
|
val props: AllNetProps
|
||||||
) {
|
) {
|
||||||
@@ -100,13 +101,22 @@ class AllNet(
|
|||||||
// game_id SDEZ, ver 1.35, serial A0000001234, ip, firm_ver 50000, boot_ver 0000,
|
// game_id SDEZ, ver 1.35, serial A0000001234, ip, firm_ver 50000, boot_ver 0000,
|
||||||
// encode UTF-8, format_ver 3, hops 1, token 2010451813
|
// encode UTF-8, format_ver 3, hops 1, token 2010451813
|
||||||
val reqMap = decodeAllNet(dataStream.readAllBytes())
|
val reqMap = decodeAllNet(dataStream.readAllBytes())
|
||||||
var serial = reqMap["serial"]
|
var serial = reqMap["serial"] ?: ""
|
||||||
logger.info("AllNet /PowerOn : $reqMap")
|
logger.info("AllNet /PowerOn : $reqMap")
|
||||||
|
|
||||||
// TODO: Proper keychip authentication
|
// Proper keychip authentication
|
||||||
if (props.checkKeychip) {
|
if (props.checkKeychip) {
|
||||||
// This will cause an allnet auth bad on client side
|
// If it's a user keychip, it should be in user database
|
||||||
if (serial == null || !keychipRepo.existsByKeychipId(serial)) {
|
val u = userRepo.findByKeychip(serial)
|
||||||
|
if (u != null) {
|
||||||
|
// Create a new session for the user
|
||||||
|
logger.info("> Keychip authenticated: ${u.auId} ${u.computedName}")
|
||||||
|
serial = keychipSessionService.new(u).token
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's a whitelisted keychip
|
||||||
|
else if (serial.isEmpty() || !keychipRepo.existsByKeychipId(serial)) {
|
||||||
|
// This will cause an allnet auth bad on client side
|
||||||
return "".also { logger.warn("> Rejected: Keychip not found") }
|
return "".also { logger.warn("> Rejected: Keychip not found") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,11 +124,10 @@ class AllNet(
|
|||||||
val gameId = reqMap["game_id"] ?: return "".also { logger.warn("> Rejected: No game_id provided") }
|
val gameId = reqMap["game_id"] ?: return "".also { logger.warn("> Rejected: No game_id provided") }
|
||||||
val ver = reqMap["ver"] ?: "1.0"
|
val ver = reqMap["ver"] ?: "1.0"
|
||||||
|
|
||||||
serial = UUID.randomUUID().toString()
|
|
||||||
val formatVer = reqMap["format_ver"] ?: ""
|
val formatVer = reqMap["format_ver"] ?: ""
|
||||||
val resp = props.map.toMutableMap() + mapOf(
|
val resp = props.map.toMutableMap() + mapOf(
|
||||||
"uri" to switchUri(localAddr, localPort, gameId, ver, serial),
|
"uri" to switchUri(localAddr, localPort, gameId, ver, serial),
|
||||||
"host" to switchHost(localAddr, localPort, gameId),
|
"host" to props.host.ifBlank { localAddr },
|
||||||
)
|
)
|
||||||
|
|
||||||
// Different responses for different versions
|
// Different responses for different versions
|
||||||
@@ -150,32 +159,25 @@ class AllNet(
|
|||||||
return resp.toUrl() + "\n"
|
return resp.toUrl() + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun switchUri(localAddr: String, localPort: String, gameId: String, ver: String, serial: String): String {
|
private fun switchUri(localAddr: Str, localPort: Str, gameId: Str, ver: Str, serial: Str): Str {
|
||||||
val addr = props.host.ifBlank { localAddr }
|
val addr = props.host.ifBlank { localAddr }
|
||||||
val port = props.port?.toString() ?: localPort
|
val port = props.port?.toString() ?: localPort
|
||||||
|
|
||||||
return "http://$addr:$port" + when (gameId) {
|
// If keychip authentication is enabled, the game URLs will be set to /gs/{token}/{game}/...
|
||||||
"SDBT" -> "/g/chu2/$ver/$serial/"
|
val base = if (props.checkKeychip) "/gs/$serial" else "/g"
|
||||||
"SDHD" -> "/g/chu3/$ver/"
|
|
||||||
"SBZV" -> "/g/diva/"
|
return "http://$addr:$port/$base" + when (gameId) {
|
||||||
"SDDT" -> "/g/ongeki/"
|
"SDBT" -> "/chu2/$ver/$serial/"
|
||||||
"SDEY" -> "/g/mai/"
|
"SDHD" -> "/chu3/$ver/"
|
||||||
"SDEZ" -> "/g/mai2/"
|
"SBZV" -> "/diva/"
|
||||||
"SDED" -> "/g/card/"
|
"SDDT" -> "/ongeki/"
|
||||||
|
"SDEY" -> "/mai/"
|
||||||
|
"SDEZ" -> "/mai2/"
|
||||||
|
"SDED" -> "/card/"
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun switchHost(localAddr: String, localPort: String, gameId: String): String {
|
|
||||||
val addr = props.host.ifBlank { localAddr }
|
|
||||||
val port = props.port?.toString() ?: localPort
|
|
||||||
|
|
||||||
return when (gameId) {
|
|
||||||
"SDDF" -> "$addr:$port/"
|
|
||||||
else -> addr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val logger: Logger = LoggerFactory.getLogger(AllNet::class.java)
|
val logger: Logger = LoggerFactory.getLogger(AllNet::class.java)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user