[+] debug-user-profile

matching
Azalea 2024-12-29 00:41:08 -05:00
parent 5c80aec50b
commit a4e8cbe9e1
1 changed files with 52 additions and 7 deletions

View File

@ -3,7 +3,10 @@ package icu.samnyan.aqua.net
import ext.*
import icu.samnyan.aqua.net.db.AquaUserServices
import icu.samnyan.aqua.net.utils.SUCCESS
import icu.samnyan.aqua.sega.general.service.CardService
import icu.samnyan.aqua.sega.chusan.model.Chu3Repos
import icu.samnyan.aqua.sega.general.model.sensitiveInfo
import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
import jakarta.transaction.Transactional
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration
@ -18,12 +21,13 @@ class BotProps {
}
@RestController
@ConditionalOnProperty("aqua-net.frontier.enabled", havingValue = "true")
@ConditionalOnProperty("aqua-net.bot.enabled", havingValue = "true")
@API("/api/v2/bot")
class BotController(
val cardService: CardService,
val us: AquaUserServices,
val props: BotProps
val props: BotProps,
val chu3Db: Chu3Repos,
val mai2Db: Mai2Repos,
) {
fun Str.checkSecret() {
if (this != props.secret) 403 - "Invalid Secret"
@ -31,14 +35,55 @@ class BotController(
@PostMapping("/ranking-ban")
@Doc("Ban a user from the leaderboard", "Success status")
suspend fun rankingBan(@RP secret: Str, @RP username: Str) {
suspend fun rankingBan(@RP secret: Str, @RP username: Str): Any {
secret.checkSecret()
us.cardByName(username) { card ->
return us.cardByName(username) { card ->
card.rankingBanned = true
cardService.cardRepo.save(card)
us.cardRepo.save(card)
SUCCESS
}
}
@Transactional
@PostMapping("/debug-user-profile")
@Doc("Obtain debug information for a user card", "User card details")
fun debugUserProfile(@RP secret: Str, @RP cardId: Str): Any {
secret.checkSecret()
// 1. Check if the card exist
var cards = listOfNotNull(
us.cardRepo.findByExtId(cardId.long)(),
us.cardRepo.findByLuid(cardId)(),
us.cardRepo.findById(cardId.long)(),
).toMutableList()
cards += cards.flatMap {
(it.aquaUser?.cards ?: emptyList()) + listOfNotNull(it.aquaUser?.ghostCard)
}
cards = cards.distinctBy { it.id }.toMutableList()
return cards.map { card ->
// Find all games played by this card
val chu3 = chu3Db.userData.findByCard_ExtId(card.extId)()
val mai2 = mai2Db.userData.findByCard_ExtId(card.extId)()
val gamesDict = listOfNotNull(chu3, mai2).map {
// Find the keychip owner
val keychip = it.lastClientId
val keychipOwner = keychip?.let { us.userRepo.findByKeychip(it) }
mapOf(
"userData" to it,
"keychip" to keychip,
"keychipOwner" to keychipOwner,
"keychipOwnerCards" to keychipOwner?.cards?.map { it.sensitiveInfo() }
)
}
mapOf(
"card" to card.sensitiveInfo(),
"games" to gamesDict
)
}
}
}