mirror of
https://github.com/MewoLab/AquaDX.git
synced 2025-12-14 11:56:15 +08:00
Compare commits
29 Commits
01d4262fff
...
drop-the-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6175b372e | ||
|
|
b5e27e859b | ||
|
|
458367668e | ||
|
|
20b6af11cc | ||
|
|
7fd71e389d | ||
|
|
1827c8db55 | ||
|
|
4cdf324f85 | ||
|
|
8e5827eeaf | ||
|
|
3a54798d5f | ||
|
|
55869f9d07 | ||
|
|
8fc2a74f95 | ||
|
|
7e90aec55d | ||
|
|
e90123389c | ||
|
|
b7cb3cb6ea | ||
|
|
619caec2ff | ||
|
|
c7a5458f11 | ||
|
|
419e22cc49 | ||
|
|
8d48ab0d3f | ||
|
|
32c3226db7 | ||
|
|
acf76bd270 | ||
|
|
664365b09b | ||
|
|
38b8831efd | ||
|
|
6767b62fd5 | ||
|
|
458146ae0c | ||
|
|
b2aef08c01 | ||
|
|
e7b96d4b24 | ||
|
|
b87ff18c69 | ||
|
|
f3cf6735e4 | ||
|
|
ccd6367875 |
@@ -1,25 +0,0 @@
|
||||
image: gradle:alpine
|
||||
|
||||
before_script:
|
||||
- GRADLE_USER_HOME="$(pwd)/.gradle"
|
||||
- export GRADLE_USER_HOME
|
||||
|
||||
build:
|
||||
stage: build
|
||||
script: gradle --build-cache assemble
|
||||
cache:
|
||||
key: "$CI_COMMIT_REF_NAME"
|
||||
policy: push
|
||||
paths:
|
||||
- build
|
||||
- .gradle
|
||||
|
||||
test:
|
||||
stage: test
|
||||
script: gradle check
|
||||
cache:
|
||||
key: "$CI_COMMIT_REF_NAME"
|
||||
policy: pull
|
||||
paths:
|
||||
- build
|
||||
- .gradle
|
||||
@@ -7,14 +7,12 @@ plugins {
|
||||
val ktVer = "2.1.10"
|
||||
|
||||
java
|
||||
kotlin("plugin.lombok") version ktVer
|
||||
kotlin("jvm") version ktVer
|
||||
kotlin("plugin.spring") version ktVer
|
||||
kotlin("plugin.jpa") version ktVer
|
||||
kotlin("plugin.serialization") version ktVer
|
||||
kotlin("plugin.allopen") version ktVer
|
||||
kotlin("kapt") version ktVer
|
||||
id("io.freefair.lombok") version "8.6"
|
||||
id("org.springframework.boot") version "3.2.3"
|
||||
id("com.github.ben-manes.versions") version "0.51.0"
|
||||
id("org.hibernate.orm") version "6.4.4.Final"
|
||||
|
||||
@@ -212,6 +212,8 @@ val <K, V> Map<K, V>.mut get() = toMutableMap()
|
||||
val <T> Set<T>.mut get() = toMutableSet()
|
||||
|
||||
fun <T> List<T>.unique(fn: (T) -> Any) = distinctBy(fn).ifEmpty { null }
|
||||
val <T> Collection<T>.csv get() = joinToString(",")
|
||||
val IntArray.csv get() = joinToString(",")
|
||||
|
||||
// Optionals
|
||||
operator fun <T> Optional<T>.invoke(): T? = orElse(null)
|
||||
@@ -228,6 +230,7 @@ fun Str.fromChusanUsername() = String(this.toByteArray(StandardCharsets.ISO_8859
|
||||
fun Str.truncate(len: Int) = if (this.length > len) this.take(len) + "..." else this
|
||||
val Str.some get() = ifBlank { null }
|
||||
val ByteArray.hexStr get() = toHexString()
|
||||
operator fun StringBuilder.plusAssign(other: String) { this.append(other) }
|
||||
|
||||
// Coroutine
|
||||
suspend fun <T> async(block: suspend kotlinx.coroutines.CoroutineScope.() -> T): T = withContext(Dispatchers.IO) { block() }
|
||||
@@ -256,6 +259,7 @@ operator fun <E> List<E>.component13(): E = get(12)
|
||||
|
||||
inline operator fun <reified E> List<Any?>.invoke(i: Int) = get(i) as E
|
||||
val empty = emptyList<Any>()
|
||||
val emptyMap = emptyMap<Any, Any>()
|
||||
|
||||
val <F> Pair<F, *>.l get() = component1()
|
||||
val <S> Pair<*, S>.r get() = component2()
|
||||
|
||||
@@ -4,6 +4,7 @@ import ext.*
|
||||
import icu.samnyan.aqua.net.db.AquaUserServices
|
||||
import icu.samnyan.aqua.net.utils.SUCCESS
|
||||
import icu.samnyan.aqua.sega.chusan.model.Chu3Repos
|
||||
import icu.samnyan.aqua.sega.general.model.Card
|
||||
import icu.samnyan.aqua.sega.general.model.CardStatus
|
||||
import icu.samnyan.aqua.sega.general.model.sensitiveInfo
|
||||
import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
|
||||
@@ -52,7 +53,7 @@ class BotController(
|
||||
secret.checkSecret()
|
||||
|
||||
// 1. Find user card
|
||||
val oc = (us.cardRepo.findByLuid(card)() ?: (404 - "Card not found")).maybeGhost()
|
||||
val oc = (us.cardRepo.findByLuid(card) ?: (404 - "Card not found")).maybeGhost()
|
||||
|
||||
// 2. Change the status to migrated
|
||||
us.cardRepo.save(oc.apply {
|
||||
@@ -66,7 +67,7 @@ class BotController(
|
||||
fun clearMigrateFlag(@RP secret: Str, @RP card: Str): Any {
|
||||
secret.checkSecret()
|
||||
|
||||
val oc = (us.cardRepo.findByLuid(card)() ?: (404 - "Card not found")).maybeGhost()
|
||||
val oc = (us.cardRepo.findByLuid(card) ?: (404 - "Card not found")).maybeGhost()
|
||||
|
||||
us.cardRepo.save(oc.apply {
|
||||
status = CardStatus.NORMAL
|
||||
@@ -82,14 +83,14 @@ class BotController(
|
||||
secret.checkSecret()
|
||||
|
||||
// 1. Check if the card exist
|
||||
var cards = listOfNotNull(
|
||||
us.cardRepo.findByLuid(cardId)(),
|
||||
var cards: MutableList<Card> = listOfNotNull(
|
||||
us.cardRepo.findByLuid(cardId),
|
||||
).mut
|
||||
|
||||
cardId.toLongOrNull()?.let {
|
||||
cards += listOfNotNull(
|
||||
us.cardRepo.findById(it)(),
|
||||
us.cardRepo.findByExtId(it)(),
|
||||
us.cardRepo.findByExtId(it),
|
||||
)
|
||||
|
||||
cards += listOfNotNull(
|
||||
@@ -110,8 +111,8 @@ class BotController(
|
||||
|
||||
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 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
|
||||
|
||||
@@ -8,6 +8,7 @@ import icu.samnyan.aqua.net.games.IUserData
|
||||
import icu.samnyan.aqua.net.utils.AquaNetProps
|
||||
import icu.samnyan.aqua.net.utils.SUCCESS
|
||||
import icu.samnyan.aqua.sega.chusan.model.Chu3UserDataRepo
|
||||
import icu.samnyan.aqua.sega.diva.PlayerProfileRepository
|
||||
import icu.samnyan.aqua.sega.general.dao.CardRepository
|
||||
import icu.samnyan.aqua.sega.general.model.Card
|
||||
import icu.samnyan.aqua.sega.general.service.CardService
|
||||
@@ -19,7 +20,6 @@ import org.springframework.scheduling.annotation.Scheduled
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import java.time.LocalDateTime
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
import kotlin.random.Random
|
||||
|
||||
@RestController
|
||||
@@ -204,7 +204,7 @@ class CardGameService(
|
||||
val chusan: Chu3UserDataRepo,
|
||||
val wacca: WcUserRepo,
|
||||
val ongeki: OgkUserDataRepo,
|
||||
val diva: icu.samnyan.aqua.sega.diva.dao.userdata.PlayerProfileRepository,
|
||||
val diva: PlayerProfileRepository,
|
||||
val safety: AquaNetSafetyService,
|
||||
val cardRepo: CardRepository,
|
||||
val em: EntityManager
|
||||
@@ -238,7 +238,7 @@ class CardGameService(
|
||||
"chu3" to getSummaryFor(chusan, card),
|
||||
"ongeki" to getSummaryFor(ongeki, card),
|
||||
"wacca" to getSummaryFor(wacca, card),
|
||||
"diva" to diva.findByPdId(card.extId).getOrNull()?.let {
|
||||
"diva" to diva.findByPdId(card.extId)()?.let {
|
||||
mapOf(
|
||||
"name" to it.playerName,
|
||||
"rating" to it.level,
|
||||
|
||||
@@ -165,7 +165,7 @@ class Fedy(
|
||||
data class DataPullRes(val error: FedyErr? = null, val result: Any? = null)
|
||||
@API("/data/pull")
|
||||
fun handleDataPull(@RH(KEY_HEADER) key: Str, @RT(REQ_PART) req: DataPullReq): DataPullRes = handleFedy(key) {
|
||||
val card = cardRepo.findByExtId(req.extId).orElse(null)
|
||||
val card = cardRepo.findByExtId(req.extId)
|
||||
?: (404 - "Card with extId ${req.extId} not found")
|
||||
{
|
||||
DataPullRes(result = when (req.game) {
|
||||
@@ -181,10 +181,9 @@ class Fedy(
|
||||
fun handleDataPush(@RH(KEY_HEADER) key: Str, @RT(REQ_PART) req: DataPushReq): Any = handleFedy(key) {
|
||||
val extId = req.extId
|
||||
fun<UserData : IUserData, UserRepo : GenericUserDataRepo<UserData>> removeOldData(repo: UserRepo) {
|
||||
val oldData = repo.findByCard_ExtId(extId)
|
||||
if (oldData.isPresent) {
|
||||
repo.findByCard_ExtId(extId)?.let { oldData ->
|
||||
log.info("Fedy: Deleting old data for $extId (${req.game})")
|
||||
repo.delete(oldData.get());
|
||||
repo.delete(oldData);
|
||||
repo.flush()
|
||||
}
|
||||
}
|
||||
@@ -281,7 +280,7 @@ class Fedy(
|
||||
fun onCardLinked(luid: Str, oldExtId: Long?, ghostExtId: Long, migratedGames: List<Str>) = maybeNotifyAsync(FedyEvent(cardLinked = CardLinkedEvent(luid, oldExtId, ghostExtId, migratedGames)))
|
||||
fun onCardUnlinked(luid: Str) = maybeNotifyAsync(FedyEvent(cardUnlinked = CardUnlinkedEvent(luid)))
|
||||
fun onDataUpdated(extId: Long, game: Str, removeOldData: Bool) = maybeNotifyAsync({
|
||||
val card = cardRepo.findByExtId(extId).orElse(null) ?: return@maybeNotifyAsync null // Card not found, nothing to do
|
||||
val card = cardRepo.findByExtId(extId) ?: return@maybeNotifyAsync null // Card not found, nothing to do
|
||||
FedyEvent(dataUpdated = DataUpdatedEvent(extId, card.isGhost, game, removeOldData))
|
||||
})
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class Frontier(
|
||||
|
||||
if (accessCode.length != 20) 400 - "Invalid access code"
|
||||
// if (!accessCode.startsWith("9900")) 400 - "Frontier access code must start with 9900"
|
||||
if (async { cardService.cardRepo.findByLuid(accessCode) }.isPresent) 400 - "Card already registered"
|
||||
if (async { cardService.cardRepo.findByLuid(accessCode) } != null) 400 - "Card already registered"
|
||||
|
||||
val card = async { cardService.registerByAccessCode(accessCode) }
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package icu.samnyan.aqua.net
|
||||
|
||||
import ext.JACKSON
|
||||
import ext.invoke
|
||||
import ext.logger
|
||||
import ext.parse
|
||||
import icu.samnyan.aqua.net.db.AquaNetUserRepo
|
||||
@@ -24,7 +23,7 @@ class Migrations(
|
||||
|
||||
@PostConstruct
|
||||
fun migrate() {
|
||||
val db = props.findByPropertyKey("migrations")() ?: PropertyEntry("migrations", "[]")
|
||||
val db = props.findByPropertyKey("migrations") ?: PropertyEntry("migrations", "[]")
|
||||
val p = JACKSON.parse<ArrayList<String>>(db.propertyValue)
|
||||
val old = p.size
|
||||
|
||||
@@ -47,7 +46,7 @@ class Migrations(
|
||||
if (c.extId > max) {
|
||||
var new = c.extId and max
|
||||
log.info("Removing signed bit: {${c.extId} -> $new} for ${c.luid}")
|
||||
while (cardRepo.findByExtId(new).isPresent) {
|
||||
while (cardRepo.findByExtId(new) != null) {
|
||||
log.error("> Conflicting card found for ${c.luid}: $new")
|
||||
new++
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ class AquaUserServices(
|
||||
|
||||
suspend fun cardByName(username: Str) =
|
||||
if (username.startsWith("user")) username.substring(4).toLongOrNull()
|
||||
?.let { cardRepo.findById(it).getOrNull() } ?: (404 - "Card not found")
|
||||
?.let { cardRepo.findById(it)() } ?: (404 - "Card not found")
|
||||
else byName(username) { it.ghostCard }
|
||||
|
||||
suspend fun <T> cardByName(username: Str, callback: suspend (Card) -> T) = callback(cardByName(username))
|
||||
|
||||
@@ -118,7 +118,7 @@ abstract class GameApiController<T : IUserData>(val name: String, userDataClass:
|
||||
}
|
||||
|
||||
@API("playlog")
|
||||
fun playlog(@RP id: Long): IGenericGamePlaylog = playlogRepo.findById(id).getOrNull() ?: (404 - "Playlog not found")
|
||||
fun playlog(@RP id: Long): IGenericGamePlaylog = playlogRepo.findById(id)() ?: (404 - "Playlog not found")
|
||||
|
||||
val userDetailFields by lazy { userDataClass.gettersMap().let { vm ->
|
||||
(settableFields.keys.toSet() + gettableFields)
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.springframework.data.repository.NoRepositoryBean
|
||||
import org.springframework.transaction.PlatformTransactionManager
|
||||
import org.springframework.transaction.support.TransactionTemplate
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.writeText
|
||||
import kotlin.reflect.KClass
|
||||
@@ -43,7 +42,7 @@ interface IExportClass<UserModel: IUserData> {
|
||||
@NoRepositoryBean
|
||||
interface IUserRepo<UserModel, ThisModel>: JpaRepository<ThisModel, Long> {
|
||||
fun findByUser(user: UserModel): List<ThisModel>
|
||||
fun findSingleByUser(user: UserModel): Optional<ThisModel>
|
||||
fun findSingleByUser(user: UserModel): ThisModel?
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +88,7 @@ abstract class ImportController<ExportModel: IExportClass<UserModel>, UserModel:
|
||||
userData = userDataRepo.findByCard(c) ?: (404 - "User not found")
|
||||
exportRepos.forEach { (f, u) ->
|
||||
if (f returns List::class) f.set(this, u.findByUser(userData))
|
||||
else u.findSingleByUser(userData)()?.let { f.set(this, it) }
|
||||
else u.findSingleByUser(userData)?.let { f.set(this, it) }
|
||||
}
|
||||
customExporters.forEach { (f, exporter) ->
|
||||
exporter(userData, options)?.let { f.set(this, it) }
|
||||
|
||||
@@ -125,7 +125,7 @@ open class BaseEntity(
|
||||
@NoRepositoryBean
|
||||
interface GenericUserDataRepo<T : IUserData> : JpaRepository<T, Long> {
|
||||
fun findByCard(card: Card): T?
|
||||
fun findByCard_ExtId(extId: Long): Optional<T>
|
||||
fun findByCard_ExtId(extId: Long): T?
|
||||
|
||||
@Query("select e from #{#entityName} e where e.card.rankingBanned = false")
|
||||
fun findAllNonBanned(): List<T>
|
||||
|
||||
@@ -14,6 +14,7 @@ import icu.samnyan.aqua.sega.maimai2.model.userdata.*
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import kotlin.reflect.full.declaredMembers
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@RestController
|
||||
@API("api/v2/game/mai2")
|
||||
class Mai2Import(
|
||||
@@ -61,7 +62,7 @@ class Mai2Import(
|
||||
}
|
||||
},
|
||||
Maimai2DataExport::userFavoriteMusicList to { user: Mai2UserDetail, _: ExportOptions ->
|
||||
repos.userGeneralData.findByUserAndPropertyKey(user, "favorite_music").orElse(null)
|
||||
repos.userGeneralData.findByUserAndPropertyKey(user, "favorite_music")
|
||||
?.propertyValue
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
?.split(",")
|
||||
@@ -78,7 +79,7 @@ class Mai2Import(
|
||||
if (favoriteMusicList.isNotEmpty()) {
|
||||
val key = "favorite_music"
|
||||
// This field always imports as incremental, since the userGeneralData field (for backwards compatibility) is processed before this
|
||||
val data = repos.userGeneralData.findByUserAndPropertyKey(user, key).orElse(null)
|
||||
val data = repos.userGeneralData.findByUserAndPropertyKey(user, key)
|
||||
?: Mai2UserGeneralData().apply { this.user = user; propertyKey = key }
|
||||
repos.userGeneralData.save(data.apply {
|
||||
propertyValue = favoriteMusicList.sortedBy { it.orderId }.map { it.id }.joinToString(",")
|
||||
|
||||
@@ -20,24 +20,18 @@ class Mai2MusicDetailImport(
|
||||
@PostMapping("import-music-detail")
|
||||
suspend fun importMusicDetail(@RP token: String, @RB data: List<Mai2UserMusicDetail>) = us.jwt.auth(token) { u ->
|
||||
us.cardByName(u.username) { card ->
|
||||
val user = repos.userData.findByCardExtId(card.extId).orElse(null) ?: (404 - "User not found")
|
||||
val user = repos.userData.findByCardExtId(card.extId) ?: (404 - "User not found")
|
||||
data.forEach { newMusic ->
|
||||
val musicRec = repos.userMusicDetail.findByUserAndMusicIdAndLevel(user, newMusic.musicId, newMusic.level)
|
||||
if (musicRec.isPresent) {
|
||||
val music = musicRec.get()
|
||||
newMusic.user = user
|
||||
repos.userMusicDetail.findByUserAndMusicIdAndLevel(user, newMusic.musicId, newMusic.level)?.let { m ->
|
||||
newMusic.apply {
|
||||
id = music.id
|
||||
this.user = user
|
||||
achievement = achievement.coerceAtLeast(music.achievement)
|
||||
scoreRank = scoreRank.coerceAtLeast(music.scoreRank)
|
||||
comboStatus = comboStatus.coerceAtLeast(music.comboStatus)
|
||||
syncStatus = syncStatus.coerceAtLeast(music.syncStatus)
|
||||
deluxscoreMax = deluxscoreMax.coerceAtLeast(music.deluxscoreMax)
|
||||
playCount = playCount.coerceAtLeast(music.playCount)
|
||||
}
|
||||
} else {
|
||||
newMusic.apply {
|
||||
this.user = user
|
||||
id = m.id
|
||||
achievement = achievement.coerceAtLeast(m.achievement)
|
||||
scoreRank = scoreRank.coerceAtLeast(m.scoreRank)
|
||||
comboStatus = comboStatus.coerceAtLeast(m.comboStatus)
|
||||
syncStatus = syncStatus.coerceAtLeast(m.syncStatus)
|
||||
deluxscoreMax = deluxscoreMax.coerceAtLeast(m.deluxscoreMax)
|
||||
playCount = playCount.coerceAtLeast(m.playCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +63,9 @@ class Maimai2(
|
||||
us.jwt.auth(t) { u ->
|
||||
if (u.username == username) return@auth null
|
||||
us.cardByName(u.username) { myCard ->
|
||||
val user = repos.userData.findByCardExtId(card.extId).orElse(null) ?: (404 - "User not found")
|
||||
val myRival = repos.userGeneralData.findByUser_Card_ExtIdAndPropertyKey(myCard.extId, "favorite_rival")
|
||||
.map { it.propertyValue.split(',') }.orElse(emptyList()).filter { it.isNotEmpty() }.map { it.long() }
|
||||
val user = repos.userData.findByCardExtId(card.extId) ?: (404 - "User not found")
|
||||
val myRival = (repos.userGeneralData.findByUser_Card_ExtIdAndPropertyKey(myCard.extId, "favorite_rival")?.propertyValue?.split(',') ?: emptyList())
|
||||
.filter { it.isNotEmpty() }.map { it.long() }
|
||||
myRival.contains(user.id)
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class Maimai2(
|
||||
if (loginBonus.none { it.bonusId == bonusId }) {
|
||||
// create one
|
||||
val newBonus = Mai2UserLoginBonus().apply {
|
||||
user = repos.userData.findByCardExtId(card.extId).orElse(null) ?: (404 - "User not found")
|
||||
user = repos.userData.findByCardExtId(card.extId) ?: (404 - "User not found")
|
||||
this.bonusId = bonusId
|
||||
isCurrent = true
|
||||
}
|
||||
@@ -159,10 +159,10 @@ class Maimai2(
|
||||
suspend fun setRival(@RP token: String, @RP rivalUserName: String, @RP isAdd: Boolean) = us.jwt.auth(token) { u ->
|
||||
us.cardByName(u.username) { myCard ->
|
||||
val rivalCard = us.cardByName(rivalUserName) { it }
|
||||
val rivalUser = repos.userData.findByCardExtId(rivalCard.extId).orElse(null) ?: (404 - "User not found")
|
||||
val myRival = repos.userGeneralData.findByUser_Card_ExtIdAndPropertyKey(myCard.extId, "favorite_rival").orElse(null)
|
||||
val rivalUser = repos.userData.findByCardExtId(rivalCard.extId) ?: (404 - "User not found")
|
||||
val myRival = repos.userGeneralData.findByUser_Card_ExtIdAndPropertyKey(myCard.extId, "favorite_rival")
|
||||
?: Mai2UserGeneralData().apply {
|
||||
user = repos.userData.findByCardExtId(myCard.extId).orElse(null) ?: (404 - "User not found")
|
||||
user = repos.userData.findByCardExtId(myCard.extId) ?: (404 - "User not found")
|
||||
propertyKey = "favorite_rival"
|
||||
}
|
||||
val myRivalList = myRival.propertyValue.split(',').filter { it.isNotEmpty() }.mut
|
||||
|
||||
@@ -37,7 +37,7 @@ class Wacca(
|
||||
|
||||
val data = userDataRepo.findByCard_ExtId(card.extId)
|
||||
|
||||
genericUserSummary(card, mapOf(), null, if (data.isPresent) data.get().favoriteSongs else null)
|
||||
genericUserSummary(card, mapOf(), null, data?.favoriteSongs)
|
||||
}
|
||||
|
||||
override val shownRanks: List<Pair<Int, String>> = waccaScores.filter { it.first > 85 * 10000 }
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package icu.samnyan.aqua.sega.aimedb
|
||||
|
||||
import ext.invoke
|
||||
import ext.logger
|
||||
import ext.toHex
|
||||
import icu.samnyan.aqua.net.Fedy
|
||||
@@ -127,7 +126,7 @@ class AimeDB(
|
||||
}
|
||||
}
|
||||
|
||||
fun getCard(accessCode: String) = us.cardRepo.findByLuid(accessCode)()?.maybeGhost()?.let { card ->
|
||||
fun getCard(accessCode: String) = us.cardRepo.findByLuid(accessCode)?.maybeGhost()?.let { card ->
|
||||
// Update card access time and return the extId
|
||||
us.cardRepo.save(card.apply { accessTime = LocalDateTime.now() }).extId
|
||||
} ?: -1
|
||||
@@ -198,7 +197,7 @@ class AimeDB(
|
||||
var status = 0
|
||||
var aimeId = 0L
|
||||
|
||||
if (us.cardRepo.findByLuid(luid).isEmpty) {
|
||||
if (us.cardRepo.findByLuid(luid) == null) {
|
||||
val card: Card = cardService.registerByAccessCode(luid)
|
||||
|
||||
status = 1
|
||||
|
||||
@@ -60,11 +60,8 @@ class CardMakerController(
|
||||
return json
|
||||
}
|
||||
|
||||
fun gameConnect(modelKind: Int, modelVersion: Int, url: String) = mapOf(
|
||||
"modelKind" to modelKind,
|
||||
"modelVersion" to modelVersion,
|
||||
"url" to url
|
||||
)
|
||||
fun gameConnect(modelKind: Int, modelVersion: Int, url: String) =
|
||||
mapOf("modelKind" to modelKind, "modelVersion" to modelVersion, "url" to url)
|
||||
|
||||
@API("GetGameConnectApi")
|
||||
fun getGameConnect(@ModelAttribute request: MutableMap<String, Any>): Any? {
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets
|
||||
@RestControllerAdvice(basePackages = ["icu.samnyan.aqua.sega.cardmaker"])
|
||||
class CardMakerControllerAdvice {
|
||||
val logger = logger()
|
||||
val mapper = ObjectMapper()
|
||||
|
||||
/**
|
||||
* Get the map object from json string
|
||||
@@ -25,7 +26,6 @@ class CardMakerControllerAdvice {
|
||||
val src = request.inputStream.readAllBytes()
|
||||
val outputString = String(src, StandardCharsets.UTF_8).trim { it <= ' ' }
|
||||
logger.info("Request ${request.requestURI}: $outputString")
|
||||
val mapper = ObjectMapper()
|
||||
return mapper.readValue(outputString, object : TypeReference<MutableMap<String, Any>>() {})
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ fun ChusanController.chusanInit() {
|
||||
"GetUserRecMusic".paged("userRecMusicList") {
|
||||
// musicId: int, recMusicList: string
|
||||
// musicId cannot be the same with the id in recMusicList
|
||||
val u = db.userData.findByCard_ExtId(uid)() ?: return@paged empty
|
||||
val u = db.userData.findByCard_ExtId(uid) ?: return@paged empty
|
||||
val list = (chusan.recommendedMusic[u.id] ?: ls()).filter { it != 1 }
|
||||
|
||||
if (list.isEmpty()) empty
|
||||
@@ -87,8 +87,8 @@ fun ChusanController.chusanInit() {
|
||||
|
||||
// Net battle data
|
||||
"GetUserNetBattleData" api@ {
|
||||
val u = db.userData.findByCard_ExtId(uid)() ?: return@api null
|
||||
val misc = db.userMisc.findSingleByUser(u)()
|
||||
val u = db.userData.findByCard_ExtId(uid) ?: return@api null
|
||||
val misc = db.userMisc.findSingleByUser(u)
|
||||
val recent = db.netBattleLog.findTop20ByUserOrderByIdDesc(u)
|
||||
mapOf("userId" to uid, "userNetBattleData" to mapOf(
|
||||
"recentNBSelectMusicList" to (misc?.recentNbSelect ?: empty),
|
||||
@@ -106,7 +106,7 @@ fun ChusanController.chusanInit() {
|
||||
)
|
||||
}
|
||||
|
||||
db.userData.findByCard_ExtId(uid)()?.card?.aquaUser?.gameOptions?.run {
|
||||
db.userData.findByCard_ExtId(uid)?.card?.aquaUser?.gameOptions?.run {
|
||||
listOf(chusanSymbolChat1, chusanSymbolChat2, chusanSymbolChat3, chusanSymbolChat4)
|
||||
.flatMapIndexed { i, sym -> sym?.makeSymbols(i) ?: empty }
|
||||
} ?: empty
|
||||
@@ -114,10 +114,10 @@ fun ChusanController.chusanInit() {
|
||||
|
||||
// User handlers
|
||||
"GetUserData" {
|
||||
db.userData.findByCard_ExtId(uid)()?.let{ u -> mapOf("userId" to uid, "userData" to u) }
|
||||
db.userData.findByCard_ExtId(uid)?.let{ u -> mapOf("userId" to uid, "userData" to u) }
|
||||
}
|
||||
"GetUserOption" {
|
||||
val userGameOption = db.userGameOption.findSingleByUser_Card_ExtId(uid)() ?: (400 - "User not found")
|
||||
val userGameOption = db.userGameOption.findSingleByUser_Card_ExtId(uid) ?: (400 - "User not found")
|
||||
mapOf("userId" to uid, "userGameOption" to userGameOption)
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ fun ChusanController.chusanInit() {
|
||||
parsing { UserCMissionResp().apply {
|
||||
missionId = parsing { data["missionId"]!!.int }
|
||||
} }.apply {
|
||||
db.userCMission.findByUser_Card_ExtIdAndMissionId(uid, missionId)()?.let {
|
||||
db.userCMission.findByUser_Card_ExtIdAndMissionId(uid, missionId)?.let {
|
||||
point = it.point
|
||||
userCMissionProgressList = db.userCMissionProgress.findByUser_Card_ExtIdAndMissionId(uid, missionId)
|
||||
}
|
||||
@@ -151,7 +151,7 @@ fun ChusanController.chusanInit() {
|
||||
// Introduced in LMN+
|
||||
"GetUserCMissionList" api@ {
|
||||
val missions = parsing { (data["userCMissionList"] as List<JDict>).map { it["missionId"]!!.int } }
|
||||
val u = db.userData.findByCard_ExtId(uid)() ?: return@api null
|
||||
val u = db.userData.findByCard_ExtId(uid) ?: return@api null
|
||||
|
||||
db.userCMission.findByUserAndMissionIdIn(u, missions).map {
|
||||
UserCMissionResp().apply {
|
||||
@@ -190,7 +190,7 @@ fun ChusanController.chusanInit() {
|
||||
val items = db.userItem.findAllByUser_Card_ExtIdAndItemKind(uid, kind).mut
|
||||
|
||||
// Check game options
|
||||
db.userData.findByCard_ExtId(uid)()?.card?.aquaUser?.gameOptions?.let {
|
||||
db.userData.findByCard_ExtId(uid)?.card?.aquaUser?.gameOptions?.let {
|
||||
if (it.chusanInfinitePenguins && kind == 5) {
|
||||
items.removeAll { it.itemId in penguins }
|
||||
items.addAll(penguins.map { Chu3UserItem(kind, it, 999, true) })
|
||||
@@ -207,7 +207,7 @@ fun ChusanController.chusanInit() {
|
||||
"GetUserFavoriteItem".pagedWithKind("userFavoriteItemList") {
|
||||
val kind = parsing { data["kind"]!!.int }
|
||||
mapOf("kind" to kind) grabs {
|
||||
val misc = db.userMisc.findSingleByUser_Card_ExtId(uid)()
|
||||
val misc = db.userMisc.findSingleByUser_Card_ExtId(uid)
|
||||
when (kind) {
|
||||
1 -> misc?.favMusic ?: empty
|
||||
3 -> empty // TODO: Favorite character
|
||||
@@ -220,9 +220,9 @@ fun ChusanController.chusanInit() {
|
||||
"lastDataVersion,trophyId,classEmblemMedal,classEmblemBase,battleRankId").split(',').toSet()
|
||||
|
||||
"GetUserPreview" api@ {
|
||||
val user = db.userData.findByCard_ExtId(uid)() ?: return@api null
|
||||
val user = db.userData.findByCard_ExtId(uid) ?: return@api null
|
||||
val chara = db.userCharacter.findByUserAndCharacterId(user, user.characterId)
|
||||
val option = db.userGameOption.findSingleByUser(user)()
|
||||
val option = db.userGameOption.findSingleByUser(user)
|
||||
val userDict = user.toJson().jsonMap().filterKeys { it in userPreviewKeys }
|
||||
|
||||
val res = mutableMapOf(
|
||||
@@ -262,7 +262,7 @@ fun ChusanController.chusanInit() {
|
||||
}
|
||||
|
||||
"GetUserRecentRating".paged("userRecentRatingList") {
|
||||
db.userGeneralData.findByUser_Card_ExtIdAndPropertyKey(uid, "recent_rating_list")()
|
||||
db.userGeneralData.findByUser_Card_ExtIdAndPropertyKey(uid, "recent_rating_list")
|
||||
?.propertyValue?.some
|
||||
?.split(',')?.dropLastWhile { it.isEmpty() }?.map { it.split(':') }
|
||||
?.map { (musicId, level, score) -> UserRecentRating(musicId.int, level.int, "2000001", score.int) }
|
||||
@@ -278,7 +278,7 @@ fun ChusanController.chusanInit() {
|
||||
|
||||
"GetUserTeam" {
|
||||
val playDate = parsing { data["playDate"] as String }
|
||||
val team = db.userData.findByCard_ExtId(uid)()?.card?.aquaUser?.gameOptions?.chusanTeamName?.some
|
||||
val team = db.userData.findByCard_ExtId(uid)?.card?.aquaUser?.gameOptions?.chusanTeamName?.some
|
||||
?: props.teamName?.some ?: "一緒に歌おう!"
|
||||
|
||||
mapOf(
|
||||
@@ -349,7 +349,7 @@ fun ChusanController.chusanInit() {
|
||||
// TODO: Test login bonus
|
||||
"GameLogin" {
|
||||
// fun process() {
|
||||
// val u = db.userData.findByCard_ExtId(uid)() ?: return
|
||||
// val u = db.userData.findByCard_ExtId(uid) ?: return
|
||||
// db.userData.save(u.apply { lastLoginDate = LocalDateTime.now() })
|
||||
//
|
||||
// if (!props.loginBonusEnable) return
|
||||
@@ -357,7 +357,7 @@ fun ChusanController.chusanInit() {
|
||||
//
|
||||
// bonusList.forEach { preset ->
|
||||
// // Check if a user already has some progress and if not, add the login bonus entry
|
||||
// val bonus = db.userLoginBonus.findLoginBonus(uid.int, 1, preset.id)()
|
||||
// val bonus = db.userLoginBonus.findLoginBonus(uid.int, 1, preset.id)
|
||||
// ?: UserLoginBonus(1, uid.int, preset.id).let { db.userLoginBonus.save(it) }
|
||||
// if (bonus.isFinished) return@forEach
|
||||
//
|
||||
@@ -377,10 +377,10 @@ fun ChusanController.chusanInit() {
|
||||
// if (preset.id < 3000) bCount = 1
|
||||
// else finished = true
|
||||
// }
|
||||
// db.gameLoginBonus.findByRequiredDays(1, preset.id, bCount)()?.let {
|
||||
// db.gameLoginBonus.findByRequiredDays(1, preset.id, bCount)?.let {
|
||||
// db.userItem.save(UserItem(6, it.presentId, it.itemNum).apply { user = u })
|
||||
// }
|
||||
// val toSave = db.userLoginBonus.findLoginBonus(uid.int, 1, preset.id)()
|
||||
// val toSave = db.userLoginBonus.findLoginBonus(uid.int, 1, preset.id)
|
||||
// ?: UserLoginBonus().apply { user = uid.int; presetId = preset.id; version = 1 }
|
||||
//
|
||||
// db.userLoginBonus.save(toSave.apply {
|
||||
@@ -394,7 +394,7 @@ fun ChusanController.chusanInit() {
|
||||
// }
|
||||
// process()
|
||||
|
||||
val user = db.userData.findByCard_ExtId(uid)()
|
||||
val user = db.userData.findByCard_ExtId(uid)
|
||||
|
||||
if (user?.card?.status == CardStatus.MIGRATED_TO_MINATO) {
|
||||
"""{"returnCode":"0"}"""
|
||||
|
||||
@@ -14,20 +14,20 @@ fun ChusanController.cmApiInit() {
|
||||
|
||||
// CardMaker (TODO: Somebody test this, I don't have a card maker)
|
||||
"CMGetUserData" {
|
||||
val user = db.userData.findByCard_ExtId(uid)() ?: (400 - "User not found")
|
||||
val user = db.userData.findByCard_ExtId(uid) ?: (400 - "User not found")
|
||||
user.userEmoney = UserEmoney()
|
||||
mapOf("userId" to uid, "userData" to user, "userEmoney" to user.userEmoney)
|
||||
}
|
||||
|
||||
"CMGetUserPreview" {
|
||||
val user = db.userData.findByCard_ExtId(uid)() ?: (400 - "User not found")
|
||||
val user = db.userData.findByCard_ExtId(uid) ?: (400 - "User not found")
|
||||
mapOf("userName" to user.userName, "level" to user.level, "medal" to user.medal, "lastDataVersion" to user.lastDataVersion, "isLogin" to false)
|
||||
}
|
||||
|
||||
"CMUpsertUserGacha" api@ {
|
||||
val (gachaId, placeId) = parsing { data["gachaId"]!!.int to data["placeId"]!!.int }
|
||||
|
||||
val u = db.userData.findByCard_ExtId(uid)() ?: return@api null
|
||||
val u = db.userData.findByCard_ExtId(uid) ?: return@api null
|
||||
val upsertUserGacha = parsing { mapper.convert<UpsertUserGacha>(data["cmUpsertUserGacha"]!!) }
|
||||
|
||||
upsertUserGacha.gameGachaCardList?.let { lst ->
|
||||
@@ -99,7 +99,7 @@ fun ChusanController.cmApiInit() {
|
||||
val userCardPrintState = cmMapper.convert<UserCardPrintState>(parsing { data["userCardPrintState"]!! })
|
||||
val userItemList = cmMapper.convert<List<Chu3UserItem>>(parsing { data["userItemList"]!! })
|
||||
|
||||
val u = db.userData.findByCard_ExtId(uid)() ?: return@api null
|
||||
val u = db.userData.findByCard_ExtId(uid) ?: return@api null
|
||||
|
||||
db.userItem.saveAll(
|
||||
userItemList.mapApply {
|
||||
|
||||
@@ -10,7 +10,7 @@ import icu.samnyan.aqua.sega.general.model.UserRecentRating
|
||||
fun ChusanController.upsertApiInit() {
|
||||
"UpsertUserChargelog" {
|
||||
val charge = parsing { mapper.convert<UserCharge>(data["userCharge"] as JDict) }
|
||||
charge.user = db.userData.findByCard_ExtId(uid)() ?: (400 - "User not found")
|
||||
charge.user = db.userData.findByCard_ExtId(uid) ?: (400 - "User not found")
|
||||
charge.id = db.userCharge.findByUser_Card_ExtIdAndChargeId(uid, charge.chargeId)?.id ?: 0
|
||||
db.userCharge.save(charge)
|
||||
"""{"returnCode":"1"}"""
|
||||
@@ -21,10 +21,10 @@ fun ChusanController.upsertApiInit() {
|
||||
|
||||
req.run {
|
||||
// UserData
|
||||
val oldUser = db.userData.findByCard_ExtId(uid)()
|
||||
val oldUser = db.userData.findByCard_ExtId(uid)
|
||||
val u = (userData?.get(0) ?: return@api null).apply {
|
||||
id = oldUser?.id ?: 0
|
||||
card = oldUser?.card ?: us.cardRepo.findByExtId(uid).expect("Card not found")
|
||||
card = oldUser?.card ?: us.cardRepo.findByExtId(uid) ?: (404 - "Card not found")
|
||||
|
||||
val version = data["version"] as? String ?: "0.00"
|
||||
val versionNumber = version.toDoubleOrNull() ?: 0.0
|
||||
@@ -66,12 +66,12 @@ fun ChusanController.upsertApiInit() {
|
||||
userRatingBaseNextList to "rating_next_list",
|
||||
userRatingBaseNewList to "rating_new_list"
|
||||
).filter { it.first != null }.forEach { (list, key) ->
|
||||
val d = db.userGeneralData.findByUserAndPropertyKey(u, key)()
|
||||
val d = db.userGeneralData.findByUserAndPropertyKey(u, key)
|
||||
?: UserGeneralData().apply { user = u; propertyKey = key }
|
||||
db.userGeneralData.save(d.apply { propertyValue = list!!.str() })
|
||||
}
|
||||
|
||||
val misc = db.userMisc.findSingleByUser(u)() ?: Chu3UserMisc().apply { user = u }
|
||||
val misc = db.userMisc.findSingleByUser(u) ?: Chu3UserMisc().apply { user = u }
|
||||
|
||||
// Favorites
|
||||
userFavoriteMusicList?.filter { it.musicId != -1 }?.ifEmpty { null }?.let { list ->
|
||||
@@ -113,7 +113,7 @@ fun ChusanController.upsertApiInit() {
|
||||
// List data
|
||||
userGameOption?.get(0)?.let { obj ->
|
||||
db.userGameOption.saveAndFlush(obj.apply {
|
||||
id = db.userGameOption.findSingleByUser(u)()?.id ?: 0 }) }
|
||||
id = db.userGameOption.findSingleByUser(u)?.id ?: 0 }) }
|
||||
|
||||
userMapAreaList?.let { list ->
|
||||
db.userMap.saveAll(list.distinctBy { it.mapAreaId }.mapApply {
|
||||
@@ -137,7 +137,7 @@ fun ChusanController.upsertApiInit() {
|
||||
|
||||
userChargeList?.let { list ->
|
||||
db.userCharge.saveAll(list.distinctBy { it.chargeId }.mapApply {
|
||||
id = db.userCharge.findByUserAndChargeId(u, chargeId)()?.id ?: 0 }) }
|
||||
id = db.userCharge.findByUserAndChargeId(u, chargeId)?.id ?: 0 }) }
|
||||
|
||||
userCourseList?.let { list ->
|
||||
db.userCourse.saveAll(list.distinctBy { it.courseId }.mapApply {
|
||||
@@ -155,7 +155,7 @@ fun ChusanController.upsertApiInit() {
|
||||
// userLoginBonusList?.let { list ->
|
||||
// db.userLoginBonus.saveAll(list.distinctBy { it["presetId"] as String }.map {
|
||||
// val id = it["presetId"]!!.int
|
||||
// (db.userLoginBonus.findLoginBonus(uid.int, 1, id)() ?: UserLoginBonus()).apply {
|
||||
// (db.userLoginBonus.findLoginBonus(uid.int, 1, id) ?: UserLoginBonus()).apply {
|
||||
// user = u.id.toInt()
|
||||
// presetId = id
|
||||
// lastUpdateDate = LocalDateTime.now()
|
||||
@@ -165,7 +165,7 @@ fun ChusanController.upsertApiInit() {
|
||||
// }
|
||||
|
||||
req.userCMissionList?.forEach { d ->
|
||||
(db.userCMission.findByUser_Card_ExtIdAndMissionId(uid, d.missionId)()
|
||||
(db.userCMission.findByUser_Card_ExtIdAndMissionId(uid, d.missionId)
|
||||
?: UserCMission().apply {
|
||||
missionId = d.missionId
|
||||
user = u
|
||||
@@ -173,7 +173,7 @@ fun ChusanController.upsertApiInit() {
|
||||
).apply { point = d.point }.also { db.userCMission.save(it) }
|
||||
|
||||
d.userCMissionProgressList?.forEach inner@ { p ->
|
||||
(db.userCMissionProgress.findByUser_Card_ExtIdAndMissionIdAndOrder(uid, d.missionId, p.order)()
|
||||
(db.userCMissionProgress.findByUser_Card_ExtIdAndMissionIdAndOrder(uid, d.missionId, p.order)
|
||||
?: UserCMissionProgress().apply {
|
||||
missionId = d.missionId
|
||||
order = p.order
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.*
|
||||
@NoRepositoryBean
|
||||
interface Chu3UserLinked<T> : IUserRepo<Chu3UserData, T> {
|
||||
fun findByUser_Card_ExtId(extId: Long): List<T>
|
||||
fun findSingleByUser_Card_ExtId(extId: Long): Optional<T>
|
||||
fun findSingleByUser_Card_ExtId(extId: Long): T?
|
||||
fun findByUser_Card_ExtId(extId: Long, pageable: Pageable): Page<T>
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ interface Chu3UserLoginBonusRepo : JpaRepository<UserLoginBonus, Long> {
|
||||
value = "select * from chusan_user_login_bonus where user = ?1 and version = ?2 and preset_id = ?3 limit 1",
|
||||
nativeQuery = true
|
||||
)
|
||||
fun findLoginBonus(userId: Int, version: Int, presetId: Long): Optional<UserLoginBonus>
|
||||
fun findLoginBonus(userId: Int, version: Int, presetId: Long): UserLoginBonus?
|
||||
}
|
||||
|
||||
interface Chu3UserActivityRepo : Chu3UserLinked<Chu3UserActivity> {
|
||||
fun findTopByUserAndActivityIdAndKindOrderByIdDesc(user: Chu3UserData, activityId: Int, kind: Int): Optional<Chu3UserActivity>
|
||||
fun findTopByUserAndActivityIdAndKindOrderByIdDesc(user: Chu3UserData, activityId: Int, kind: Int): Chu3UserActivity?
|
||||
fun findByUserAndActivityIdAndKind(user: Chu3UserData, activityId: Int, kind: Int): Chu3UserActivity?
|
||||
|
||||
fun findAllByUser_Card_ExtIdAndKind(extId: Long, kind: Int): List<Chu3UserActivity>
|
||||
@@ -54,17 +54,17 @@ interface Chu3UserCardPrintStateRepo : Chu3UserLinked<UserCardPrintState> {
|
||||
}
|
||||
|
||||
interface Chu3UserCharacterRepo : Chu3UserLinked<UserCharacter> {
|
||||
fun findTopByUserAndCharacterIdOrderByIdDesc(user: Chu3UserData, characterId: Int): Optional<UserCharacter>
|
||||
fun findTopByUserAndCharacterIdOrderByIdDesc(user: Chu3UserData, characterId: Int): UserCharacter?
|
||||
fun findByUserAndCharacterId(user: Chu3UserData, characterId: Int): UserCharacter?
|
||||
}
|
||||
|
||||
interface Chu3UserChargeRepo : Chu3UserLinked<UserCharge> {
|
||||
fun findByUserAndChargeId(extId: Chu3UserData, chargeId: Int): Optional<UserCharge>
|
||||
fun findByUserAndChargeId(extId: Chu3UserData, chargeId: Int): UserCharge?
|
||||
fun findByUser_Card_ExtIdAndChargeId(ext: Long, chargeId: Int): UserCharge?
|
||||
}
|
||||
|
||||
interface Chu3UserCourseRepo : Chu3UserLinked<UserCourse> {
|
||||
fun findTopByUserAndCourseIdOrderByIdDesc(user: Chu3UserData, courseId: Int): Optional<UserCourse>
|
||||
fun findTopByUserAndCourseIdOrderByIdDesc(user: Chu3UserData, courseId: Int): UserCourse?
|
||||
fun findByUserAndCourseId(user: Chu3UserData, courseId: Int): UserCourse?
|
||||
}
|
||||
|
||||
@@ -73,25 +73,25 @@ interface Chu3UserDataRepo : GenericUserDataRepo<Chu3UserData> {
|
||||
}
|
||||
|
||||
interface Chu3UserDuelRepo : Chu3UserLinked<UserDuel> {
|
||||
fun findTopByUserAndDuelIdOrderByIdDesc(user: Chu3UserData, duelId: Int): Optional<UserDuel>
|
||||
fun findTopByUserAndDuelIdOrderByIdDesc(user: Chu3UserData, duelId: Int): UserDuel?
|
||||
fun findByUserAndDuelId(user: Chu3UserData, duelId: Int): UserDuel?
|
||||
}
|
||||
|
||||
interface Chu3UserGachaRepo : Chu3UserLinked<UserGacha> {
|
||||
fun findByUserAndGachaId(extId: Chu3UserData, gachaId: Int): Optional<UserGacha>
|
||||
fun findByUserAndGachaId(extId: Chu3UserData, gachaId: Int): UserGacha?
|
||||
}
|
||||
|
||||
interface Chu3UserGameOptionRepo : Chu3UserLinked<UserGameOption>
|
||||
|
||||
interface Chu3UserGeneralDataRepo : Chu3UserLinked<UserGeneralData> {
|
||||
fun findByUserAndPropertyKey(user: Chu3UserData, key: String): Optional<UserGeneralData>
|
||||
fun findByUserAndPropertyKey(user: Chu3UserData, key: String): UserGeneralData?
|
||||
|
||||
fun findByUser_Card_ExtIdAndPropertyKey(extId: Long, key: String): Optional<UserGeneralData>
|
||||
fun findByUser_Card_ExtIdAndPropertyKey(extId: Long, key: String): UserGeneralData?
|
||||
}
|
||||
|
||||
interface Chu3UserItemRepo : Chu3UserLinked<Chu3UserItem> {
|
||||
fun findAllByUser(user: Chu3UserData): List<Chu3UserItem>
|
||||
fun findTopByUserAndItemIdAndItemKindOrderByIdDesc(user: Chu3UserData, itemId: Int, itemKind: Int): Optional<Chu3UserItem>
|
||||
fun findTopByUserAndItemIdAndItemKindOrderByIdDesc(user: Chu3UserData, itemId: Int, itemKind: Int): Chu3UserItem?
|
||||
fun findByUserAndItemIdAndItemKind(user: Chu3UserData, itemId: Int, itemKind: Int): Chu3UserItem?
|
||||
|
||||
fun findAllByUser_Card_ExtIdAndItemKind(extId: Long, itemKind: Int, pageable: Pageable): Page<Chu3UserItem>
|
||||
@@ -106,7 +106,7 @@ interface Chu3UserMapRepo : Chu3UserLinked<UserMap> {
|
||||
}
|
||||
|
||||
interface Chu3UserMusicDetailRepo : Chu3UserLinked<UserMusicDetail>, GenericUserMusicRepo<UserMusicDetail> {
|
||||
fun findTopByUserAndMusicIdAndLevelOrderByIdDesc(user: Chu3UserData, musicId: Int, level: Int): Optional<UserMusicDetail>
|
||||
fun findTopByUserAndMusicIdAndLevelOrderByIdDesc(user: Chu3UserData, musicId: Int, level: Int): UserMusicDetail?
|
||||
fun findByUserAndMusicIdAndLevel(user: Chu3UserData, musicId: Int, level: Int): UserMusicDetail?
|
||||
|
||||
fun findByUser_Card_ExtIdAndMusicId(extId: Long, musicId: Int): List<UserMusicDetail>
|
||||
@@ -119,7 +119,7 @@ interface Chu3UserPlaylogRepo : GenericPlaylogRepo<UserPlaylog>, Chu3UserLinked<
|
||||
}
|
||||
|
||||
interface Chu3UserCMissionRepo : Chu3UserLinked<UserCMission> {
|
||||
fun findByUser_Card_ExtIdAndMissionId(extId: Long, missionId: Int): Optional<UserCMission>
|
||||
fun findByUser_Card_ExtIdAndMissionId(extId: Long, missionId: Int): UserCMission?
|
||||
fun findByUserAndMissionIdIn(user: Chu3UserData, missionIds: Collection<Int>): List<UserCMission>
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ interface Chu3UserCMissionProgressRepo : Chu3UserLinked<UserCMissionProgress> {
|
||||
fun findByUser_Card_ExtIdAndMissionId(extId: Long, missionId: Int): List<UserCMissionProgress>
|
||||
fun findByUserAndMissionId(user: Chu3UserData, missionId: Int): List<UserCMissionProgress>
|
||||
|
||||
fun findByUser_Card_ExtIdAndMissionIdAndOrder(extId: Long, missionId: Int, order: Int): Optional<UserCMissionProgress>
|
||||
fun findByUser_Card_ExtIdAndMissionIdAndOrder(extId: Long, missionId: Int, order: Int): UserCMissionProgress?
|
||||
}
|
||||
|
||||
interface Chu3NetBattleLogRepo : Chu3UserLinked<Chu3NetBattleLog> {
|
||||
@@ -171,7 +171,7 @@ interface Chu3GameLoginBonusRepo : JpaRepository<GameLoginBonus, Int> {
|
||||
value = "select * from chusan_game_login_bonus where version = ?1 and preset_id = ?2 and need_login_day_count = ?3 limit 1",
|
||||
nativeQuery = true
|
||||
)
|
||||
fun findByRequiredDays(version: Int, presetId: Int, requiredDays: Int): Optional<GameLoginBonus>
|
||||
fun findByRequiredDays(version: Int, presetId: Int, requiredDays: Int): GameLoginBonus?
|
||||
}
|
||||
|
||||
interface Chu3UserRegionsRepo: Chu3UserLinked<UserRegions> {
|
||||
|
||||
@@ -15,7 +15,6 @@ import icu.samnyan.aqua.sega.general.model.Card
|
||||
import icu.samnyan.aqua.sega.util.AccessCodeSerializer
|
||||
import jakarta.persistence.*
|
||||
import kotlinx.io.IOException
|
||||
import lombok.NoArgsConstructor
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
@@ -33,7 +32,6 @@ class FlexibleDateTimeDeserializer : JsonDeserializer<LocalDateTime?>() {
|
||||
|
||||
@Entity(name = "ChusanUserData")
|
||||
@Table(name = "chusan_user_data")
|
||||
@NoArgsConstructor
|
||||
class Chu3UserData : BaseEntity(), IUserData {
|
||||
@JsonSerialize(using = AccessCodeSerializer::class)
|
||||
@JsonProperty(value = "accessCode", access = JsonProperty.Access.READ_ONLY)
|
||||
|
||||
181
src/main/java/icu/samnyan/aqua/sega/diva/DivaController.kt
Normal file
181
src/main/java/icu/samnyan/aqua/sega/diva/DivaController.kt
Normal file
@@ -0,0 +1,181 @@
|
||||
package icu.samnyan.aqua.sega.diva
|
||||
|
||||
import ext.JDict
|
||||
import ext.MutJDict
|
||||
import ext.emptyMap
|
||||
import ext.logger
|
||||
import icu.samnyan.aqua.sega.diva.handler.AttendHandler
|
||||
import icu.samnyan.aqua.sega.diva.handler.PingHandler
|
||||
import icu.samnyan.aqua.sega.diva.handler.card.CardProcedureHandler
|
||||
import icu.samnyan.aqua.sega.diva.handler.card.ChangeNameHandler
|
||||
import icu.samnyan.aqua.sega.diva.handler.card.ChangePasswdHandler
|
||||
import icu.samnyan.aqua.sega.diva.handler.card.RegistrationHandler
|
||||
import icu.samnyan.aqua.sega.diva.handler.databank.*
|
||||
import icu.samnyan.aqua.sega.diva.handler.ingame.*
|
||||
import icu.samnyan.aqua.sega.diva.handler.user.*
|
||||
import icu.samnyan.aqua.sega.diva.model.*
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaMapper
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaTime
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.multipart.MultipartFile
|
||||
import java.net.URLDecoder
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
val DIVA_BAD = mapOf("stat" to "0")
|
||||
val DIVA_OK = emptyMap
|
||||
val DIVA_INIT = mapOf("db_close" to "0,0", "retry_time" to "FFFF")
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/g/diva")
|
||||
class DivaController(
|
||||
val attendHandler: AttendHandler,
|
||||
val cardProcedureHandler: CardProcedureHandler,
|
||||
val changeNameHandler: ChangeNameHandler,
|
||||
val changePasswdHandler: ChangePasswdHandler,
|
||||
val registrationHandler: RegistrationHandler,
|
||||
val contestInfoHandler: ContestInfoHandler,
|
||||
val festaInfoHandler: FestaInfoHandler,
|
||||
val nvRankingHandler: NvRankingHandler,
|
||||
val psRankingHandler: PsRankingHandler,
|
||||
val pvListHandler: PvListHandler,
|
||||
val shopCatalogHandler: ShopCatalogHandler,
|
||||
val buyCstmzItmHandler: BuyCstmzItmHandler,
|
||||
val buyModuleHandler: BuyModuleHandler,
|
||||
val getPvPdHandler: GetPvPdHandler,
|
||||
val shopExitHandler: ShopExitHandler,
|
||||
val stageResultHandler: StageResultHandler,
|
||||
val stageStartHandler: StageStartHandler,
|
||||
val storeSsHandler: StoreSsHandler,
|
||||
val pingHandler: PingHandler,
|
||||
val endHandler: EndHandler,
|
||||
val pdUnlockHandler: PdUnlockHandler,
|
||||
val preStartHandler: PreStartHandler,
|
||||
val spendCreditHandler: SpendCreditHandler,
|
||||
val startHandler: StartHandler,
|
||||
val db: DivaRepos
|
||||
) {
|
||||
val logger = logger()
|
||||
val mapper = DivaMapper()
|
||||
|
||||
fun buildResultMap(map: JDict) =
|
||||
map.filterValues { it != null && !(it is String && it == "") }
|
||||
.map { (k, v) -> "$k=$v" }.joinToString("&")
|
||||
|
||||
@PostMapping(value = ["/"], consumes = [MediaType.APPLICATION_FORM_URLENCODED_VALUE])
|
||||
fun formRequest(request: HttpServletRequest): String? {
|
||||
val bodyStr = String(request.inputStream.readAllBytes())
|
||||
val body = parse(bodyStr)
|
||||
|
||||
val command = body.getOrDefault("cmd", "") as String?
|
||||
|
||||
logger.info("{}: {}", command, body)
|
||||
val respObj = when (command) {
|
||||
"game_init" -> DIVA_INIT
|
||||
"attend" -> attendHandler.handle()
|
||||
"test" -> DIVA_INIT
|
||||
"nv_ranking" -> nvRankingHandler.handle(mapper.convert(body, BaseRequest::class.java))
|
||||
"ps_ranking" -> psRankingHandler.handle(mapper.convert(body, PsRankingRequest::class.java))
|
||||
|
||||
"pv_list" -> pvListHandler.handle(mapper.convert(body, BaseRequest::class.java))
|
||||
"ng_word" -> DIVA_OK
|
||||
"rmt_wp_list" -> mapOf("rwl_lut" to DivaTime.now, "rw_lst" to "***")
|
||||
"festa_info" -> festaInfoHandler.handle(mapper.convert(body, BaseRequest::class.java))
|
||||
"contest_info" -> contestInfoHandler.handle(mapper.convert(body, BaseRequest::class.java))
|
||||
"pv_def_chr_list" -> mapOf("pdcl_lut" to DivaTime.now, "pdc_lst" to "***")
|
||||
"pv_ng_mdl_list" -> mapOf("pnml_lut" to DivaTime.now, "pnm_lst" to "***")
|
||||
"cstmz_itm_ng_mdl_list" -> mapOf("cinml_lut" to DivaTime.now, "cinm_lst" to "***")
|
||||
|
||||
"banner_info" -> listOf("bi_lut", "bi_id", "bi_st", "bi_et", "bi_ut").associateWith { null }
|
||||
"banner_data" -> mapOf("bd_ut" to DivaTime.now, "bd_ti" to "***", "bd_hs" to "***", "bd_id" to body["bd_id"])
|
||||
|
||||
"cm_ply_info" -> emptyMap
|
||||
"qst_inf" -> mapOf("qi_lut" to DivaTime.now, "qhi_str" to null, "qrai_str" to null)
|
||||
"pstd_h_ctrl" -> mapOf("p_std_hc_lut" to DivaTime.now, "p_std_hc_str" to "***,***")
|
||||
"pstd_item_ng_lst" -> mapOf("p_std_i_n_lut" to DivaTime.now, "p_std_i_ie_n_lst" to "***", "p_std_i_se_n_lst" to "***")
|
||||
|
||||
"shop_catalog" -> shopCatalogHandler.handle(mapper.convert(body, BaseRequest::class.java))
|
||||
"cstmz_itm_ctlg" -> mapOf(
|
||||
"cstmz_itm_ctlg_lut" to DivaTime.now,
|
||||
"cstmz_itm_ctlg" to encode(db.g.customize.findAll().map { it.toInternal() }.joinToString(",") { encode(it) })
|
||||
)
|
||||
"card_procedure" -> cardProcedureHandler.handle(mapper.convert(body, CardProcedureRequest::class.java))
|
||||
|
||||
"registration" -> registrationHandler.handle(mapper.convert(body, RegistrationRequest::class.java))
|
||||
|
||||
"init_passwd" -> DIVA_BAD
|
||||
|
||||
"change_passwd" -> changePasswdHandler.handle(mapper.convert(body, ChangePasswdRequest::class.java))
|
||||
|
||||
"change_name" -> changeNameHandler.handle(mapper.convert(body, ChangeNameRequest::class.java))
|
||||
|
||||
"pre_start" -> preStartHandler.handle(mapper.convert(body, PreStartRequest::class.java))
|
||||
"start" -> startHandler.handle(mapper.convert(body, StartRequest::class.java))
|
||||
"pd_unlock" -> pdUnlockHandler.handle(mapper.convert(body, PdUnlockRequest::class.java))
|
||||
"spend_credit" -> spendCreditHandler.handle(mapper.convert(body, SpendCreditRequest::class.java))
|
||||
|
||||
"no_card_end" -> DIVA_INIT
|
||||
"end" -> endHandler.handle(mapper.convert(body, StageResultRequest::class.java))
|
||||
"get_pv_pd" -> getPvPdHandler.handle(mapper.convert(body, GetPvPdRequest::class.java))
|
||||
"buy_module" -> buyModuleHandler.handle(mapper.convert(body, BuyModuleRequest::class.java))
|
||||
|
||||
"buy_cstmz_itm" -> buyCstmzItmHandler.handle(mapper.convert(body, BuyCstmzItmRequest::class.java))
|
||||
|
||||
"shop_exit" -> shopExitHandler.handle(mapper.convert(body, ShopExitRequest::class.java))
|
||||
"stage_start" -> stageStartHandler.handle(mapper.convert(body, StageStartRequest::class.java))
|
||||
|
||||
"stage_result" -> stageResultHandler.handle(mapper.convert(body, StageResultRequest::class.java))
|
||||
|
||||
"store_ss" -> DIVA_INIT
|
||||
else -> DIVA_BAD
|
||||
}
|
||||
val resp = respObj as? String
|
||||
?: buildResultMap(mapOf("cmd" to command, "req_id" to body["req_id"], "stat" to "ok") + mapper.toMap(respObj))
|
||||
logger.info("Response: {}", resp)
|
||||
return resp
|
||||
}
|
||||
|
||||
@PostMapping(value = ["/"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
|
||||
fun fileRequest(@RequestParam query: String, @RequestParam(required = false) bin: MultipartFile): String? {
|
||||
val body = parse(query)
|
||||
val command = body.getOrDefault("cmd", "") as String?
|
||||
|
||||
logger.info("{}: {}", command, body)
|
||||
|
||||
val respObj = when (command) {
|
||||
"ping" -> pingHandler.handle(mapper.convert(body, BaseRequest::class.java))
|
||||
"investigate" -> DIVA_INIT
|
||||
"store_ss" -> storeSsHandler.handle(mapper.convert(body, StoreSsRequest::class.java), bin)
|
||||
else -> "stat=1"
|
||||
}
|
||||
val resp = respObj as? String ?: buildResultMap(mapper.toMap(respObj))
|
||||
logger.info("Response: {}", resp)
|
||||
return resp
|
||||
}
|
||||
|
||||
fun parse(form: String): MutJDict {
|
||||
val kvps = form.split('&').dropLastWhile { it.isEmpty() }
|
||||
val body: MutJDict = LinkedHashMap()
|
||||
for (kvp in kvps) {
|
||||
var (k, v) = kvp.split('=').dropLastWhile { it.isEmpty() }
|
||||
v = URLDecoder.decode(v, StandardCharsets.UTF_8)
|
||||
body[k] = if (v.contains(",")) { v.deArray() } else { v }
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
fun String.deArray(): Any {
|
||||
if (!contains(',')) return this
|
||||
return split(',').dropLastWhile { it.isEmpty() }
|
||||
.map { URLDecoder.decode(it, StandardCharsets.UTF_8) }
|
||||
.map { it.deArray() }
|
||||
}
|
||||
}
|
||||
150
src/main/java/icu/samnyan/aqua/sega/diva/DivaRepos.kt
Normal file
150
src/main/java/icu/samnyan/aqua/sega/diva/DivaRepos.kt
Normal file
@@ -0,0 +1,150 @@
|
||||
package icu.samnyan.aqua.sega.diva
|
||||
|
||||
import ext.invoke
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Difficulty
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Edition
|
||||
import icu.samnyan.aqua.sega.diva.model.db.gamedata.*
|
||||
import icu.samnyan.aqua.sega.diva.model.db.userdata.*
|
||||
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
|
||||
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.data.repository.query.Param
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.stereotype.Repository
|
||||
import java.util.*
|
||||
|
||||
@Component
|
||||
class DivaGameRepos(
|
||||
val contest: ContestRepository,
|
||||
val customize: DivaCustomizeRepository,
|
||||
val module: DivaModuleRepository,
|
||||
val pv: DivaPvRepository,
|
||||
val festa: FestaRepository,
|
||||
val pvEntry: PvEntryRepository
|
||||
)
|
||||
|
||||
@Component
|
||||
class DivaRepos(
|
||||
val g: DivaGameRepos,
|
||||
val s: DivaServices,
|
||||
val gameSession: GameSessionRepository,
|
||||
val playLog: PlayLogRepository,
|
||||
val contest: PlayerContestRepository,
|
||||
val customize: PlayerCustomizeRepository,
|
||||
val inventory: PlayerInventoryRepository,
|
||||
val module: PlayerModuleRepository,
|
||||
val profile: PlayerProfileRepository,
|
||||
val pvCustomize: PlayerPvCustomizeRepository,
|
||||
val pvRecord: PlayerPvRecordRepository,
|
||||
val screenShot: PlayerScreenShotRepository,
|
||||
) {
|
||||
fun profile(id: Long) = profile.findByPdId(id)() ?: throw ProfileNotFoundException()
|
||||
fun session(id: Long) = profile(id).let { it to (gameSession.findByPdId(it)() ?: throw SessionNotFoundException()) }
|
||||
}
|
||||
|
||||
@Repository
|
||||
interface ContestRepository : JpaRepository<Contest, Int> {
|
||||
fun findTop8ByEnable(enable: Boolean): MutableList<Contest>
|
||||
}
|
||||
|
||||
@Repository
|
||||
interface DivaCustomizeRepository : JpaRepository<DivaCustomize, Int>
|
||||
|
||||
@Repository
|
||||
interface DivaModuleRepository : JpaRepository<DivaModule, Int>
|
||||
|
||||
interface DivaPvRepository : JpaRepository<Pv, Int>
|
||||
|
||||
@Repository
|
||||
interface FestaRepository : JpaRepository<Festa, Int> {
|
||||
fun findTop2ByEnableOrderByCreateDateDesc(enable: Boolean): MutableList<Festa>
|
||||
}
|
||||
|
||||
@Repository
|
||||
interface PvEntryRepository : JpaRepository<PvEntry, Int> {
|
||||
fun findByDifficulty(difficulty: Difficulty): MutableList<PvEntry>
|
||||
}
|
||||
|
||||
interface PlayerContestRepository : JpaRepository<PlayerContest, Long> {
|
||||
fun findByPdIdAndContestId(pdId: PlayerProfile, contestId: Int): Optional<PlayerContest>
|
||||
|
||||
fun findTop4ByPdIdOrderByLastUpdateTimeDesc(pdId: PlayerProfile): MutableList<PlayerContest>
|
||||
}
|
||||
|
||||
@Repository
|
||||
interface GameSessionRepository : JpaRepository<GameSession, Long> {
|
||||
fun findByPdId(profile: PlayerProfile): Optional<GameSession>
|
||||
}
|
||||
|
||||
@Repository
|
||||
interface PlayerCustomizeRepository : JpaRepository<PlayerCustomize, Long> {
|
||||
fun findByPdId(profile: PlayerProfile): MutableList<PlayerCustomize>
|
||||
|
||||
fun findByPdIdAndCustomizeId(currentProfile: PlayerProfile, parseInt: Int): Optional<PlayerCustomize>
|
||||
}
|
||||
|
||||
@Repository
|
||||
interface PlayerInventoryRepository : JpaRepository<PlayerInventory, Long> {
|
||||
fun findByPdIdAndTypeAndValue(profile: PlayerProfile, type: String, value: String): Optional<PlayerInventory>
|
||||
}
|
||||
|
||||
@Repository
|
||||
interface PlayerProfileRepository : JpaRepository<PlayerProfile, Long> {
|
||||
fun findByPdId(pdId: Long): Optional<PlayerProfile>
|
||||
}
|
||||
|
||||
@Repository
|
||||
interface PlayerPvCustomizeRepository : JpaRepository<PlayerPvCustomize, Long> {
|
||||
fun findByPdIdAndPvId(profile: PlayerProfile, pvId: Int): Optional<PlayerPvCustomize>
|
||||
}
|
||||
|
||||
@Repository
|
||||
interface PlayerPvRecordRepository : JpaRepository<PlayerPvRecord, Long> {
|
||||
fun findByPdIdAndPvIdAndEditionAndDifficulty(
|
||||
profile: PlayerProfile,
|
||||
pvId: Int,
|
||||
edition: Edition,
|
||||
difficulty: Difficulty
|
||||
): Optional<PlayerPvRecord>
|
||||
|
||||
fun findByPdId_PdIdAndPvIdAndEditionAndDifficulty(
|
||||
pdId: Long,
|
||||
pvId: Int,
|
||||
edition: Edition,
|
||||
difficulty: Difficulty
|
||||
): Optional<PlayerPvRecord>
|
||||
|
||||
@Query(
|
||||
("SELECT COUNT(t1.id) as ranking from DivaPlayerPvRecord as t1 " +
|
||||
"where t1.maxScore >= (" +
|
||||
"SELECT maxScore from DivaPlayerPvRecord where pvId = :pvId and pdId = :pdId and edition = :edition and difficulty = :difficulty" +
|
||||
") and t1.pvId = :pvId and t1.edition = :edition and t1.difficulty = :difficulty")
|
||||
)
|
||||
fun rankByPvIdAndPdIdAndEditionAndDifficulty(
|
||||
@Param("pvId") pvId: Int,
|
||||
@Param("pdId") pdId: PlayerProfile,
|
||||
@Param("edition") edition: Edition,
|
||||
@Param("difficulty") difficulty: Difficulty
|
||||
): Int
|
||||
|
||||
fun findByPdId(profile: PlayerProfile): MutableList<PlayerPvRecord>
|
||||
|
||||
fun findByPdIdAndEdition(profile: PlayerProfile, edition: Edition): MutableList<PlayerPvRecord>
|
||||
|
||||
fun findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(
|
||||
pvId: Int,
|
||||
edition: Edition,
|
||||
difficulty: Difficulty
|
||||
): MutableList<PlayerPvRecord>
|
||||
}
|
||||
|
||||
interface PlayerScreenShotRepository : JpaRepository<PlayerScreenShot, Long>
|
||||
|
||||
@Repository
|
||||
interface PlayLogRepository : JpaRepository<PlayLog, Long>
|
||||
|
||||
@Repository
|
||||
interface PlayerModuleRepository : JpaRepository<PlayerModule, Long> {
|
||||
fun findByPdId(profile: PlayerProfile): MutableList<PlayerModule>
|
||||
}
|
||||
63
src/main/java/icu/samnyan/aqua/sega/diva/DivaServices.kt
Normal file
63
src/main/java/icu/samnyan/aqua/sega/diva/DivaServices.kt
Normal file
@@ -0,0 +1,63 @@
|
||||
package icu.samnyan.aqua.sega.diva
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.RegistrationRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.db.userdata.PlayerCustomize
|
||||
import icu.samnyan.aqua.sega.diva.model.db.userdata.PlayerModule
|
||||
import icu.samnyan.aqua.sega.diva.model.db.userdata.PlayerProfile
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.stereotype.Service
|
||||
import java.math.BigInteger
|
||||
import java.util.*
|
||||
|
||||
|
||||
@Component
|
||||
class DivaServices(
|
||||
val profile: PlayerProfileService,
|
||||
val module: PlayerModuleService,
|
||||
val customize: PlayerCustomizeService
|
||||
)
|
||||
|
||||
@Service
|
||||
class PlayerModuleService(val repo: PlayerModuleRepository) {
|
||||
fun buy(profile: PlayerProfile, moduleId: Int) = repo.save(PlayerModule(profile, moduleId))
|
||||
|
||||
fun getModuleHaveString(profile: PlayerProfile): String {
|
||||
val moduleList = repo.findByPdId(profile)
|
||||
var module_have = BigInteger("0")
|
||||
for (module in moduleList) {
|
||||
module_have = module_have.or(BigInteger.valueOf(1).shiftLeft(module.moduleId))
|
||||
}
|
||||
println(module_have.toString(2))
|
||||
return StringUtils.leftPad(module_have.toString(16), 250, "0").uppercase(Locale.getDefault())
|
||||
}
|
||||
}
|
||||
|
||||
@Service
|
||||
class PlayerProfileService(val repo: PlayerProfileRepository) {
|
||||
fun findByPdId(pdId: Long): Optional<PlayerProfile> = repo.findByPdId(pdId)
|
||||
|
||||
fun register(request: RegistrationRequest): PlayerProfile {
|
||||
val profile = PlayerProfile()
|
||||
profile.pdId = request.aime_id
|
||||
profile.playerName = request.player_name
|
||||
|
||||
return repo.save(profile)
|
||||
}
|
||||
|
||||
fun save(profile: PlayerProfile) = repo.save(profile)
|
||||
}
|
||||
|
||||
@Service
|
||||
class PlayerCustomizeService(val repo: PlayerCustomizeRepository) {
|
||||
fun buy(profile: PlayerProfile, customizeId: Int) = repo.save(PlayerCustomize(profile, customizeId))
|
||||
|
||||
fun getModuleHaveString(profile: PlayerProfile): String {
|
||||
val customizeList = repo.findByPdId(profile)
|
||||
var customize_have = BigInteger("0")
|
||||
for (customize in customizeList) {
|
||||
customize_have = customize_have.or(BigInteger.valueOf(1).shiftLeft(customize.customizeId))
|
||||
}
|
||||
return StringUtils.leftPad(customize_have.toString(16), 250, "0")
|
||||
}
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.controller;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.boot.AttendHandler;
|
||||
import icu.samnyan.aqua.sega.diva.handler.boot.GameInitHandler;
|
||||
import icu.samnyan.aqua.sega.diva.handler.card.*;
|
||||
import icu.samnyan.aqua.sega.diva.handler.databank.*;
|
||||
import icu.samnyan.aqua.sega.diva.handler.ingame.*;
|
||||
import icu.samnyan.aqua.sega.diva.handler.operation.PingHandler;
|
||||
import icu.samnyan.aqua.sega.diva.handler.user.*;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.boot.GameInitRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.card.CardProcedureRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.card.ChangeNameRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.card.ChangePasswdRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.card.RegistrationRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.databank.BannerDataRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.databank.PsRankingRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.ingame.*;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.user.PdUnlockRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.user.PreStartRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.user.SpendCreditRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.user.StartRequest;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/g/diva")
|
||||
@AllArgsConstructor
|
||||
public class DivaController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DivaController.class);
|
||||
|
||||
private final GameInitHandler gameInitHandler;
|
||||
private final AttendHandler attendHandler;
|
||||
|
||||
private final CardProcedureHandler cardProcedureHandler;
|
||||
private final ChangeNameHandler changeNameHandler;
|
||||
private final ChangePasswdHandler changePasswdHandler;
|
||||
private final InitPasswdHandler initPasswdHandler;
|
||||
private final RegistrationHandler registrationHandler;
|
||||
|
||||
/**
|
||||
* Databank
|
||||
*/
|
||||
private final BannerInfoHandler bannerInfoHandler;
|
||||
private final BannerDataHandler bannerDataHandler;
|
||||
private final CmPlyInfoHandler cmPlyInfoHandler;
|
||||
private final ContestInfoHandler contestInfoHandler;
|
||||
private final CstmzItmCtlgHandler cstmzItmCtlgHandler;
|
||||
private final CstmzItmNgMdlListHandler cstmzItmNgMdlListHandler;
|
||||
private final FestaInfoHandler festaInfoHandler;
|
||||
private final NgWordHandler ngWordHandler;
|
||||
private final NvRankingHandler nvRankingHandler;
|
||||
private final PsRankingHandler psRankingHandler;
|
||||
private final PstdHCtrlHandler pstdHCtrlHandler;
|
||||
private final PstdItemNgLstHandler pstdItemNgLstHandler;
|
||||
private final PvDefChrLstHandler pvDefChrLstHandler;
|
||||
private final PvListHandler pvListHandler;
|
||||
private final PvNgMdlLstHandler pvNgMdlLstHandler;
|
||||
private final QstInfHandler qstInfHandler;
|
||||
private final RmtWpLstHandler rmtWpLstHandler;
|
||||
private final ShopCatalogHandler shopCatalogHandler;
|
||||
|
||||
private final BuyCstmzItmHandler buyCstmzItmHandler;
|
||||
private final BuyModuleHandler buyModuleHandler;
|
||||
private final GetPvPdHandler getPvPdHandler;
|
||||
private final ShopExitHandler shopExitHandler;
|
||||
private final StageResultHandler stageResultHandler;
|
||||
private final StageStartHandler stageStartHandler;
|
||||
private final StoreSsHandler storeSsHandler;
|
||||
|
||||
private final PingHandler pingHandler;
|
||||
|
||||
private final EndHandler endHandler;
|
||||
private final PdUnlockHandler pdUnlockHandler;
|
||||
private final PreStartHandler preStartHandler;
|
||||
private final SpendCreditHandler spendCreditHandler;
|
||||
private final StartHandler startHandler;
|
||||
|
||||
private final DivaMapper mapper;
|
||||
|
||||
@PostMapping(value = "/", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
public String formRequest(HttpServletRequest request) throws IOException {
|
||||
String bodyStr = new String(request.getInputStream().readAllBytes());
|
||||
Map<String, Object> body = parse(bodyStr);
|
||||
|
||||
String command = (String) body.getOrDefault("cmd", "");
|
||||
|
||||
logger.info("{}: {}", command, body);
|
||||
|
||||
return switch (command) {
|
||||
|
||||
// Boot
|
||||
case "game_init" -> gameInitHandler.handle(mapper.convert(body, GameInitRequest.class));
|
||||
case "attend" -> attendHandler.handle(mapper.convert(body, GameInitRequest.class));
|
||||
|
||||
//
|
||||
case "test" -> gameInitHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
|
||||
// Databank
|
||||
case "nv_ranking" -> nvRankingHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "ps_ranking" -> psRankingHandler.handle(mapper.convert(body, PsRankingRequest.class));
|
||||
case "pv_list" -> pvListHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "ng_word" -> ngWordHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "rmt_wp_list" -> rmtWpLstHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "festa_info" -> festaInfoHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "contest_info" -> contestInfoHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "pv_def_chr_list" -> pvDefChrLstHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "pv_ng_mdl_list" -> pvNgMdlLstHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "cstmz_itm_ng_mdl_list" -> cstmzItmNgMdlListHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "banner_info" -> bannerInfoHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "banner_data" -> bannerDataHandler.handle(mapper.convert(body, BannerDataRequest.class));
|
||||
case "cm_ply_info" -> cmPlyInfoHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "qst_inf" -> qstInfHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "pstd_h_ctrl" -> pstdHCtrlHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "pstd_item_ng_lst" -> pstdItemNgLstHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "shop_catalog" -> shopCatalogHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "cstmz_itm_ctlg" -> cstmzItmCtlgHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "card_procedure" -> cardProcedureHandler.handle(mapper.convert(body, CardProcedureRequest.class));
|
||||
case "registration" -> registrationHandler.handle(mapper.convert(body, RegistrationRequest.class));
|
||||
case "init_passwd" -> initPasswdHandler.handle(mapper.convert(body, GameInitRequest.class));
|
||||
case "change_passwd" -> changePasswdHandler.handle(mapper.convert(body, ChangePasswdRequest.class));
|
||||
case "change_name" -> changeNameHandler.handle(mapper.convert(body, ChangeNameRequest.class));
|
||||
case "pre_start" -> preStartHandler.handle(mapper.convert(body, PreStartRequest.class));
|
||||
case "start" -> startHandler.handle(mapper.convert(body, StartRequest.class));
|
||||
case "pd_unlock" -> pdUnlockHandler.handle(mapper.convert(body, PdUnlockRequest.class));
|
||||
case "spend_credit" -> spendCreditHandler.handle(mapper.convert(body, SpendCreditRequest.class));
|
||||
case "no_card_end" -> gameInitHandler.handle(mapper.convert(body, GameInitRequest.class));
|
||||
case "end" -> endHandler.handle(mapper.convert(body, StageResultRequest.class));
|
||||
case "get_pv_pd" -> getPvPdHandler.handle(mapper.convert(body, GetPvPdRequest.class));
|
||||
case "buy_module" -> buyModuleHandler.handle(mapper.convert(body, BuyModuleRequest.class));
|
||||
case "buy_cstmz_itm" -> buyCstmzItmHandler.handle(mapper.convert(body, BuyCstmzItmRequest.class));
|
||||
case "shop_exit" -> shopExitHandler.handle(mapper.convert(body, ShopExitRequest.class));
|
||||
case "stage_start" -> stageStartHandler.handle(mapper.convert(body, StageStartRequest.class));
|
||||
case "stage_result" -> stageResultHandler.handle(mapper.convert(body, StageResultRequest.class));
|
||||
case "store_ss" -> gameInitHandler.handle(mapper.convert(body, GameInitRequest.class));
|
||||
default -> "stat=0";
|
||||
};
|
||||
}
|
||||
|
||||
@PostMapping(value = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public String fileRequest(@RequestParam String query, @RequestParam(required = false) MultipartFile bin) {
|
||||
|
||||
Map<String, Object> body = parse(query);
|
||||
|
||||
String command = (String) body.getOrDefault("cmd", "");
|
||||
|
||||
logger.info("{}: {}", command, body);
|
||||
|
||||
return switch (command) {
|
||||
case "ping" -> pingHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "investigate" -> gameInitHandler.handle(mapper.convert(body, BaseRequest.class));
|
||||
case "store_ss" -> storeSsHandler.handle(mapper.convert(body, StoreSsRequest.class), bin);
|
||||
default -> "stat=1";
|
||||
};
|
||||
}
|
||||
|
||||
private Map<String, Object> parse(String form) {
|
||||
String[] kvps = form.split("&");
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
for (String kvp :
|
||||
kvps) {
|
||||
String[] k = kvp.split("=");
|
||||
k[1] = URLDecoder.decode(k[1], StandardCharsets.UTF_8);
|
||||
Object value;
|
||||
if (k[1].contains(",")) {
|
||||
value = deArray(k[1]);
|
||||
} else {
|
||||
value = k[1];
|
||||
}
|
||||
body.put(k[0], value);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
private Object deArray(String input) {
|
||||
if (!input.contains(",")) return input;
|
||||
return Arrays.stream(input.split(",")).map(x -> URLDecoder.decode(x, StandardCharsets.UTF_8))
|
||||
.map(this::deArray).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@ControllerAdvice(basePackages = "icu.samnyan.aqua.sega.diva")
|
||||
public class DivaControllerAdvice {
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.gamedata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.Contest;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface ContestRepository extends JpaRepository<Contest, Integer> {
|
||||
List<Contest> findTop8ByEnable(boolean enable);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.gamedata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.DivaCustomize;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface DivaCustomizeRepository extends JpaRepository<DivaCustomize, Integer> {
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.gamedata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.DivaModule;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface DivaModuleRepository extends JpaRepository<DivaModule, Integer> {
|
||||
Optional<DivaModule> findById(int id);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.gamedata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.Pv;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public interface DivaPvRepository extends JpaRepository<Pv, Integer> {
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.gamedata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.Festa;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface FestaRepository extends JpaRepository<Festa, Integer> {
|
||||
List<Festa> findTop2ByEnableOrderByCreateDateDesc(boolean enable);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.gamedata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.NgWords;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface NgWordsRepository extends JpaRepository<NgWords, Integer> {
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.gamedata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Difficulty;
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.PvEntry;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface PvEntryRepository extends JpaRepository<PvEntry, Integer> {
|
||||
List<PvEntry> findByDifficulty(Difficulty difficulty);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface GameSessionRepository extends JpaRepository<GameSession, Long> {
|
||||
Optional<GameSession> findByPdId(PlayerProfile profile);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayLog;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface PlayLogRepository extends JpaRepository<PlayLog, Long> {
|
||||
Page<PlayLog> findByPdId_PdIdOrderByDateTimeDesc(long pdId, Pageable page);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerContest;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public interface PlayerContestRepository extends JpaRepository<PlayerContest, Long> {
|
||||
Optional<PlayerContest> findByPdIdAndContestId(PlayerProfile pdId, int contestId);
|
||||
|
||||
List<PlayerContest> findTop4ByPdIdOrderByLastUpdateTimeDesc(PlayerProfile pdId);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerCustomize;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface PlayerCustomizeRepository extends JpaRepository<PlayerCustomize, Long> {
|
||||
List<PlayerCustomize> findByPdId(PlayerProfile profile);
|
||||
|
||||
Page<PlayerCustomize> findByPdId_PdId(long pdId, Pageable page);
|
||||
|
||||
Optional<PlayerCustomize> findByPdIdAndCustomizeId(PlayerProfile currentProfile, int parseInt);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerInventory;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface PlayerInventoryRepository extends JpaRepository<PlayerInventory, Long> {
|
||||
Optional<PlayerInventory> findByPdIdAndTypeAndValue(PlayerProfile profile, String type, String value);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerModule;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface PlayerModuleRepository extends JpaRepository<PlayerModule, Long> {
|
||||
List<PlayerModule> findByPdId(PlayerProfile profile);
|
||||
|
||||
Page<PlayerModule> findByPdId_PdId(long pdId, Pageable pageable);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface PlayerProfileRepository extends JpaRepository<PlayerProfile, Long> {
|
||||
|
||||
Optional<PlayerProfile> findByPdId(long pdId);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvCustomize;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface PlayerPvCustomizeRepository extends JpaRepository<PlayerPvCustomize, Long> {
|
||||
Optional<PlayerPvCustomize> findByPdIdAndPvId(PlayerProfile profile, int pvId);
|
||||
|
||||
Optional<PlayerPvCustomize> findByPdId_PdIdAndPvId(long pdId, int pvId);
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Difficulty;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Edition;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvRecord;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Repository
|
||||
public interface PlayerPvRecordRepository extends JpaRepository<PlayerPvRecord, Long> {
|
||||
Optional<PlayerPvRecord> findByPdIdAndPvIdAndEditionAndDifficulty(PlayerProfile profile, int pvId, Edition edition, Difficulty difficulty);
|
||||
|
||||
Optional<PlayerPvRecord> findByPdId_PdIdAndPvIdAndEditionAndDifficulty(long pdId, int pvId, Edition edition, Difficulty difficulty);
|
||||
|
||||
@Query("SELECT COUNT(t1.id) as ranking from DivaPlayerPvRecord as t1 " +
|
||||
"where t1.maxScore >= (" +
|
||||
"SELECT maxScore from DivaPlayerPvRecord where pvId = :pvId and pdId = :pdId and edition = :edition and difficulty = :difficulty" +
|
||||
") and t1.pvId = :pvId and t1.edition = :edition and t1.difficulty = :difficulty")
|
||||
Integer rankByPvIdAndPdIdAndEditionAndDifficulty(@Param("pvId") int pvId,
|
||||
@Param("pdId") PlayerProfile pdId,
|
||||
@Param("edition") Edition edition,
|
||||
@Param("difficulty") Difficulty difficulty
|
||||
);
|
||||
|
||||
List<PlayerPvRecord> findByPdId(PlayerProfile profile);
|
||||
|
||||
Optional<PlayerPvRecord> findByIdAndPdId_PdId(long id, long pdId);
|
||||
|
||||
List<PlayerPvRecord> findByPdIdAndEdition(PlayerProfile profile, Edition edition);
|
||||
|
||||
List<PlayerPvRecord> findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(int pvId, Edition edition, Difficulty difficulty);
|
||||
|
||||
Page<PlayerPvRecord> findByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(int pvId, Edition edition, Difficulty difficulty, Pageable page);
|
||||
|
||||
Page<PlayerPvRecord> findByPdId_PdIdOrderByPvId(long pdId, Pageable page);
|
||||
|
||||
List<PlayerPvRecord> findByPdId_PdIdAndPvId(long pdId, int pvId);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerScreenShot;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public interface PlayerScreenShotRepository extends JpaRepository<PlayerScreenShot, Long> {
|
||||
List<PlayerScreenShot> findByPdId_PdId(long pdId);
|
||||
Optional<PlayerScreenShot> findByFileName(String fileName);
|
||||
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.exception;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public class ProfileNotFoundException extends RuntimeException {
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.exception;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public class PvRecordDataException extends RuntimeException {
|
||||
public PvRecordDataException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.exception;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public class SessionNotExistException extends RuntimeException {
|
||||
|
||||
public SessionNotExistException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SessionNotExistException() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.exception;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public class SessionNotFoundException extends RuntimeException {
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class BaseHandler {
|
||||
static protected DivaMapper mapper = new DivaMapper();
|
||||
|
||||
protected String build(Map<String, Object> map) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
map.forEach((key, val) -> {
|
||||
if (val != null) {
|
||||
if (val instanceof String) {
|
||||
if (!val.equals("")) {
|
||||
sb.append(key).append("=");
|
||||
sb.append(val);
|
||||
sb.append("&");
|
||||
}
|
||||
} else {
|
||||
sb.append(key).append("=");
|
||||
// sb.append(URLEncoder.encode(String.valueOf(val), StandardCharsets.UTF_8));
|
||||
sb.append(val);
|
||||
sb.append("&");
|
||||
}
|
||||
}
|
||||
});
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler
|
||||
|
||||
import ext.csv
|
||||
import icu.samnyan.aqua.sega.diva.model.BaseRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.PingResponse
|
||||
import icu.samnyan.aqua.sega.general.dao.PropertyEntryRepository
|
||||
import icu.samnyan.aqua.sega.general.model.PropertyEntry
|
||||
import org.springframework.stereotype.Component
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
|
||||
fun gameBalanceParameter(): String {
|
||||
val name_change_price = 100
|
||||
// Trial bids: clear.pay, clear.win, great.pay, great.win, excellent.pay, excellent.win, perfect.pay, perfect.win
|
||||
val easy_trials = listOf(5, 10, 10, 25, 20, 50, 30, 90)
|
||||
val normal_trials = listOf(5, 10, 10, 25, 20, 50, 30, 90)
|
||||
val hard_trials = listOf(5, 10, 10, 25, 20, 50, 30, 90)
|
||||
val extreme_trials = listOf(5, 10, 10, 25, 20, 50, 30, 90)
|
||||
val extra_extreme_trials = listOf(5, 10, 10, 25, 20, 50, 30, 90)
|
||||
|
||||
return (listOf(name_change_price, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1, 1, 3, 4, 5, 1, 1, 1, 4, 5, 6, 1, 1, 1, 5, 6, 7, 4, 4, 4, 9, 10, 14) +
|
||||
easy_trials + normal_trials + hard_trials +
|
||||
extreme_trials + extra_extreme_trials + listOf(10, 30) + Collections.nCopies(100, 0)).take(100).csv
|
||||
}
|
||||
|
||||
fun EtcParameter(): String {
|
||||
val module_shop_close = false
|
||||
val card_reissue_close = true
|
||||
val card_renewal_close = true
|
||||
val reset_passwd_close = true
|
||||
val change_passwd_close = false
|
||||
val change_name_close = false
|
||||
val encore_mode_close = true
|
||||
val third_stg_mode_close = false
|
||||
val slow_down_threshold = 0
|
||||
val log_write_flag = false
|
||||
val daily_quest_close = true
|
||||
val weekly_quest_close = true
|
||||
val special_quest_close = true
|
||||
val nppg_close = false
|
||||
|
||||
val list = listOf(module_shop_close, card_reissue_close, card_renewal_close, reset_passwd_close,
|
||||
change_passwd_close, change_name_close, encore_mode_close, third_stg_mode_close,
|
||||
slow_down_threshold, log_write_flag, daily_quest_close, weekly_quest_close,
|
||||
special_quest_close, nppg_close) + Collections.nCopies(100, 0)
|
||||
return list.take(100).map {
|
||||
if (it is Boolean) if (it) "1" else "0"
|
||||
else if (it is Int) it.toString()
|
||||
else "0"
|
||||
}.csv
|
||||
}
|
||||
|
||||
@Component
|
||||
class AttendHandler {
|
||||
fun handle() = mapOf(
|
||||
"atnd_prm1" to EtcParameter(),
|
||||
"atnd_prm2" to mapOf(
|
||||
"max_pd_items" to 30, "" to 1, "max_ps_rankings" to 100,
|
||||
"max_screenshots" to 2, "ss_upload_delay" to 1, "" to 1
|
||||
).values.plus(Collections.nCopies(100, 0)).take(100).csv,
|
||||
"atnd_prm3" to gameBalanceParameter(),
|
||||
"atnd_lut" to LocalDateTime.now()
|
||||
)
|
||||
}
|
||||
|
||||
@Component
|
||||
class PingHandler(val rp: PropertyEntryRepository) {
|
||||
fun handle(request: BaseRequest): Any {
|
||||
val news: PropertyEntry = rp.findByPropertyKey("diva_news") ?: PropertyEntry("diva_news", "xxx")
|
||||
val warning: PropertyEntry = rp.findByPropertyKey("diva_warning") ?: PropertyEntry("diva_warning", "xxx")
|
||||
|
||||
return PingResponse(
|
||||
news.propertyValue,
|
||||
warning.propertyValue
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.boot;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.attend.DispersalParameter;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.attend.EtcParameter;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.attend.GameBalanceParameter;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.boot.AttendResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class AttendHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AttendHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
AttendResponse response = new AttendResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
new EtcParameter().toInternal(),
|
||||
new DispersalParameter().toInternal(),
|
||||
new GameBalanceParameter().toInternal(),
|
||||
LocalDateTime.now()
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.boot;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.boot.GameInitResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class GameInitHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(GameInitHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
GameInitResponse response = new GameInitResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
"0,0",
|
||||
"FFFF"
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.card;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.StartMode;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.card.CardProcedureRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.card.CardProcedureResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class CardProcedureHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CardProcedureHandler.class);
|
||||
|
||||
private final PlayerProfileService playerProfileService;
|
||||
|
||||
private final GameSessionRepository gameSessionRepository;
|
||||
|
||||
public String handle(CardProcedureRequest request) {
|
||||
Optional<PlayerProfile> profileOptional = playerProfileService.findByPdId(request.getAime_id());
|
||||
CardProcedureResponse response;
|
||||
if (profileOptional.isEmpty()) {
|
||||
response = new CardProcedureResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.FAILED
|
||||
);
|
||||
} else {
|
||||
PlayerProfile profile = profileOptional.get();
|
||||
|
||||
Optional<GameSession> sessionOptional = gameSessionRepository.findByPdId(profile);
|
||||
if (sessionOptional.isPresent()) {
|
||||
GameSession session = sessionOptional.get();
|
||||
if (session.getLastUpdateTime().isBefore(LocalDateTime.now().minusMinutes(5))) {
|
||||
gameSessionRepository.delete(session);
|
||||
}
|
||||
response = new CardProcedureResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.FAILED
|
||||
);
|
||||
} else {
|
||||
GameSession session = new GameSession(
|
||||
ThreadLocalRandom.current().nextInt(100, 99999),
|
||||
profile,
|
||||
StartMode.CARD_PROCEDURE,
|
||||
LocalDateTime.now(),
|
||||
LocalDateTime.now(),
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
profile.getLevel(),
|
||||
profile.getLevelExp(),
|
||||
profile.getLevel(),
|
||||
profile.getLevelExp(),
|
||||
profile.getVocaloidPoints()
|
||||
);
|
||||
|
||||
gameSessionRepository.save(session);
|
||||
response = new CardProcedureResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.SUCCESS,
|
||||
100,
|
||||
session.getAcceptId(),
|
||||
profile.getPdId(),
|
||||
profile.getPlayerName(),
|
||||
profile.getLevel(),
|
||||
profile.getLevelExp(),
|
||||
profile.getLevelTitle(),
|
||||
profile.getPlateEffectId(),
|
||||
profile.getPlateId(),
|
||||
profile.getVocaloidPoints(),
|
||||
profile.getPasswordStatus()
|
||||
);
|
||||
}
|
||||
}
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.card
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.CardProcedureRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.CardProcedureResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result
|
||||
import icu.samnyan.aqua.sega.diva.model.common.StartMode
|
||||
import icu.samnyan.aqua.sega.diva.model.db.userdata.GameSession
|
||||
import org.springframework.stereotype.Component
|
||||
import java.time.LocalDateTime
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class CardProcedureHandler(val db: DivaRepos) {
|
||||
fun handle(request: CardProcedureRequest): Any {
|
||||
val profileOptional = db.profile.findByPdId(request.aime_id)
|
||||
if (profileOptional.isEmpty) {
|
||||
return CardProcedureResponse(
|
||||
Result.FAILED
|
||||
)
|
||||
} else {
|
||||
val profile = profileOptional.get()
|
||||
|
||||
val sessionOptional = db.gameSession.findByPdId(profile)
|
||||
if (sessionOptional.isPresent) {
|
||||
val session = sessionOptional.get()
|
||||
if (session.lastUpdateTime.isBefore(LocalDateTime.now().minusMinutes(5))) {
|
||||
db.gameSession.delete(session)
|
||||
}
|
||||
return CardProcedureResponse(
|
||||
Result.FAILED
|
||||
)
|
||||
} else {
|
||||
val session = GameSession(
|
||||
ThreadLocalRandom.current().nextInt(100, 99999),
|
||||
profile,
|
||||
StartMode.CARD_PROCEDURE,
|
||||
LocalDateTime.now(),
|
||||
LocalDateTime.now(),
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
profile.level,
|
||||
profile.levelExp,
|
||||
profile.level,
|
||||
profile.levelExp,
|
||||
profile.vocaloidPoints
|
||||
)
|
||||
|
||||
db.gameSession.save(session)
|
||||
return CardProcedureResponse(
|
||||
Result.SUCCESS,
|
||||
100,
|
||||
session.acceptId,
|
||||
profile.pdId,
|
||||
profile.playerName,
|
||||
profile.level,
|
||||
profile.levelExp,
|
||||
profile.levelTitle,
|
||||
profile.plateEffectId,
|
||||
profile.plateId,
|
||||
profile.vocaloidPoints,
|
||||
profile.passwordStatus
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.card;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
|
||||
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.card.ChangeNameRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.card.ChangeNameResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ChangeNameHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ChangeNameHandler.class);
|
||||
|
||||
private final PlayerProfileService playerProfileService;
|
||||
|
||||
private final GameSessionRepository gameSessionRepository;
|
||||
|
||||
public String handle(ChangeNameRequest request) {
|
||||
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
|
||||
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
|
||||
|
||||
profile.setPlayerName(request.getPlayer_name());
|
||||
|
||||
ChangeNameResponse response = new ChangeNameResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.SUCCESS,
|
||||
session.getAcceptId(),
|
||||
profile.getPdId(),
|
||||
profile.getPlayerName()
|
||||
);
|
||||
|
||||
playerProfileService.save(profile);
|
||||
gameSessionRepository.delete(session);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.card
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.ChangeNameRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.ChangeNameResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class ChangeNameHandler(val db: DivaRepos) {
|
||||
fun handle(request: ChangeNameRequest): Any {
|
||||
val (profile, session) = db.session(request.pd_id)
|
||||
|
||||
profile.playerName = request.player_name
|
||||
db.profile.save(profile)
|
||||
db.gameSession.delete(session)
|
||||
|
||||
return ChangeNameResponse(
|
||||
Result.SUCCESS,
|
||||
session.acceptId,
|
||||
profile.pdId,
|
||||
profile.playerName
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.card;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
|
||||
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.PassStat;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.card.ChangePasswdRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.card.ChangePasswdResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ChangePasswdHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ChangePasswdHandler.class);
|
||||
private final PlayerProfileService playerProfileService;
|
||||
private final GameSessionRepository gameSessionRepository;
|
||||
|
||||
public String handle(ChangePasswdRequest request) {
|
||||
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
|
||||
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
|
||||
|
||||
profile.setPasswordStatus(PassStat.SET);
|
||||
profile.setPassword(request.getNew_passwd());
|
||||
|
||||
ChangePasswdResponse response = new ChangePasswdResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.SUCCESS,
|
||||
session.getAcceptId(),
|
||||
profile.getPdId()
|
||||
);
|
||||
|
||||
playerProfileService.save(profile);
|
||||
gameSessionRepository.delete(session);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.card
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.ChangePasswdRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.ChangePasswdResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.PassStat
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class ChangePasswdHandler(val db: DivaRepos) {
|
||||
fun handle(request: ChangePasswdRequest): Any {
|
||||
val (profile, session) = db.session(request.pd_id)
|
||||
|
||||
profile.passwordStatus = PassStat.SET
|
||||
profile.password = request.new_passwd
|
||||
db.profile.save(profile)
|
||||
db.gameSession.delete(session)
|
||||
|
||||
return ChangePasswdResponse(
|
||||
Result.SUCCESS,
|
||||
session.acceptId,
|
||||
profile.pdId
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.card;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class InitPasswdHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(InitPasswdHandler.class);
|
||||
private final PlayerProfileService playerProfileService;
|
||||
private final GameSessionRepository gameSessionRepository;
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
BaseResponse response = new BaseResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"0");
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.card;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.card.RegistrationRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.card.RegistrationResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class RegistrationHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RegistrationHandler.class);
|
||||
private final PlayerProfileService playerProfileService;
|
||||
|
||||
public String handle(RegistrationRequest request) {
|
||||
RegistrationResponse response;
|
||||
if (playerProfileService.findByPdId(request.getAime_id()).isPresent()) {
|
||||
response = new RegistrationResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.FAILED,
|
||||
-1);
|
||||
} else {
|
||||
PlayerProfile profile = playerProfileService.register(request);
|
||||
response = new RegistrationResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.SUCCESS,
|
||||
profile.getPdId());
|
||||
}
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.card
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.PlayerProfileService
|
||||
import icu.samnyan.aqua.sega.diva.model.RegistrationRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.RegistrationResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class RegistrationHandler(val service: PlayerProfileService) {
|
||||
fun handle(request: RegistrationRequest) =
|
||||
if (service.findByPdId(request.aime_id).isPresent) {
|
||||
RegistrationResponse(
|
||||
Result.FAILED,
|
||||
-1
|
||||
)
|
||||
} else {
|
||||
val profile = service.register(request)
|
||||
RegistrationResponse(
|
||||
Result.SUCCESS,
|
||||
profile.pdId
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.databank.BannerDataRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.BannerDataResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class BannerDataHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BannerDataHandler.class);
|
||||
|
||||
public String handle(BannerDataRequest request) {
|
||||
BannerDataResponse response = new BannerDataResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
LocalDateTime.now(),
|
||||
"***",
|
||||
"***",
|
||||
request.getBd_id()
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.BannerInfoResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class BannerInfoHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BannerInfoHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
BannerInfoResponse response = new BannerInfoResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class CmPlyInfoHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CmPlyInfoHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
BaseResponse response = new BaseResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok");
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.gamedata.ContestRepository;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.Contest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.ContestInfoResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ContestInfoHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CmPlyInfoHandler.class);
|
||||
private final ContestRepository contestRepository;
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
List<Contest> contestList = contestRepository.findTop8ByEnable(true);
|
||||
String ci_str = "***";
|
||||
if (!contestList.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
contestList.forEach(x -> sb.append(URIEncoder.encode(x.getString())).append(","));
|
||||
sb.append("%2A%2A%2A,".repeat(Math.max(0, 8 - contestList.size())));
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
ci_str = sb.toString();
|
||||
}
|
||||
ContestInfoResponse response = new ContestInfoResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
LocalDateTime.now(),
|
||||
ci_str
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.BaseRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.ContestInfoResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.db.gamedata.Contest
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
|
||||
import org.springframework.stereotype.Component
|
||||
import java.time.LocalDateTime
|
||||
import java.util.function.Consumer
|
||||
import kotlin.math.max
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class ContestInfoHandler(val db: DivaRepos) {
|
||||
fun handle(request: BaseRequest): Any {
|
||||
val contestList = db.g.contest.findTop8ByEnable(true)
|
||||
var ci_str = "***"
|
||||
if (!contestList.isEmpty()) {
|
||||
val sb = StringBuilder()
|
||||
contestList.forEach(Consumer { x: Contest? -> sb.append(encode(x!!.string)).append(",") })
|
||||
sb.append("%2A%2A%2A,".repeat(max(0, 8 - contestList.size)))
|
||||
sb.deleteCharAt(sb.length - 1)
|
||||
ci_str = sb.toString()
|
||||
}
|
||||
return ContestInfoResponse(
|
||||
LocalDateTime.now(),
|
||||
ci_str
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaCustomizeRepository;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.DivaCustomize;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.CstmzItmCtlgResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class CstmzItmCtlgHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CstmzItmCtlgHandler.class);
|
||||
|
||||
private final DivaCustomizeRepository customizeRepository;
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
List<DivaCustomize> customizeList = customizeRepository.findAll();
|
||||
|
||||
CstmzItmCtlgResponse response = new CstmzItmCtlgResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
DivaDateTimeUtil.getString(LocalDateTime.now()),
|
||||
URIEncoder.encode(customizeList.stream().map(DivaCustomize::toInternal).map(URIEncoder::encode)
|
||||
.collect(Collectors.joining(",")))
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.CstmzItmNgMdlListResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class CstmzItmNgMdlListHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CstmzItmCtlgHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
CstmzItmNgMdlListResponse response = new CstmzItmNgMdlListResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
DivaDateTimeUtil.getString(LocalDateTime.now()),
|
||||
"***"
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.gamedata.FestaRepository;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.collection.FestaCollection;
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.Festa;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.FestaInfoResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class FestaInfoHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FestaInfoHandler.class);
|
||||
private final FestaRepository festaRepository;
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
List<Festa> festaList = festaRepository.findTop2ByEnableOrderByCreateDateDesc(true);
|
||||
FestaCollection collection = new FestaCollection(festaList);
|
||||
|
||||
FestaInfoResponse response = new FestaInfoResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
collection.getIds(),
|
||||
collection.getNames(),
|
||||
collection.getKinds(),
|
||||
collection.getDiffs(),
|
||||
collection.getPvIds(),
|
||||
collection.getAttr(),
|
||||
collection.getAddVps(),
|
||||
collection.getVpMultipliers(),
|
||||
collection.getStarts(),
|
||||
collection.getEnds(),
|
||||
collection.getLastUpdateTime()
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.FestaRepository
|
||||
import icu.samnyan.aqua.sega.diva.model.BaseRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.FestaInfoResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.collection.FestaCollection
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class FestaInfoHandler(private val festaRepository: FestaRepository) {
|
||||
fun handle(request: BaseRequest): Any {
|
||||
val festaList = festaRepository.findTop2ByEnableOrderByCreateDateDesc(true)
|
||||
val collection = FestaCollection(festaList)
|
||||
|
||||
return FestaInfoResponse(
|
||||
collection.ids,
|
||||
collection.names,
|
||||
collection.kinds,
|
||||
collection.diffs,
|
||||
collection.pvIds,
|
||||
collection.attr,
|
||||
collection.addVps,
|
||||
collection.vpMultipliers,
|
||||
collection.starts,
|
||||
collection.ends,
|
||||
collection.lastUpdateTime
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class NgWordHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(NgWordHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
BaseResponse response = new BaseResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok");
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.NvRankingResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class NvRankingHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(NvRankingHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
NvRankingResponse response = new NvRankingResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.model.BaseRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.NvRankingResponse
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class NvRankingHandler {
|
||||
fun handle(request: BaseRequest) = NvRankingResponse(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
)
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvRecordRepository;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Difficulty;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Edition;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.collection.PsRankingCollection;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.databank.PsRankingRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.PsRankingResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvRecord;
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class PsRankingHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PsRankingHandler.class);
|
||||
private final PlayerPvRecordRepository playerPvRecordRepository;
|
||||
|
||||
public String handle(PsRankingRequest request) {
|
||||
Edition edition = Edition.ORIGINAL;
|
||||
Difficulty difficulty = Difficulty.HARD;
|
||||
|
||||
switch (request.getRnk_ps_idx()) {
|
||||
case 0:
|
||||
difficulty = Difficulty.HARD;
|
||||
break;
|
||||
case 1:
|
||||
difficulty = Difficulty.EXTREME;
|
||||
break;
|
||||
case 2: {
|
||||
difficulty = Difficulty.EXTREME;
|
||||
edition = Edition.EXTRA;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int[] list = request.getRnk_ps_pv_id_lst();
|
||||
Map<Integer, PsRankingCollection> resultCollections = new LinkedHashMap<>();
|
||||
for (int i :
|
||||
list) {
|
||||
|
||||
List<PlayerPvRecord> records = playerPvRecordRepository.findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(i, edition, difficulty);
|
||||
resultCollections.put(i, new PsRankingCollection(i, edition, records));
|
||||
}
|
||||
|
||||
List<Integer> pvIds = new LinkedList<>();
|
||||
List<Integer> edition1 = new LinkedList<>();
|
||||
List<Integer> edition2 = new LinkedList<>();
|
||||
List<Integer> edition3 = new LinkedList<>();
|
||||
List<Integer> score1 = new LinkedList<>();
|
||||
List<Integer> score2 = new LinkedList<>();
|
||||
List<Integer> score3 = new LinkedList<>();
|
||||
List<String> name1 = new LinkedList<>();
|
||||
List<String> name2 = new LinkedList<>();
|
||||
List<String> name3 = new LinkedList<>();
|
||||
|
||||
resultCollections.forEach((key, obj) -> {
|
||||
pvIds.add(key);
|
||||
edition1.add(obj.getFirst().getEdition().getValue());
|
||||
edition2.add(obj.getSecond().getEdition().getValue());
|
||||
edition3.add(obj.getThird().getEdition().getValue());
|
||||
score1.add(obj.getFirst().getMaxScore());
|
||||
score2.add(obj.getSecond().getMaxScore());
|
||||
score3.add(obj.getThird().getMaxScore());
|
||||
name1.add(URIEncoder.encode(obj.getFirst().getPdId() != null ? obj.getFirst().getPdId().getPlayerName() : "xxx"));
|
||||
name2.add(URIEncoder.encode(obj.getSecond().getPdId() != null ? obj.getSecond().getPdId().getPlayerName() : "xxx"));
|
||||
name3.add(URIEncoder.encode(obj.getThird().getPdId() != null ? obj.getThird().getPdId().getPlayerName() : "xxx"));
|
||||
});
|
||||
|
||||
PsRankingResponse response = new PsRankingResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
LocalDateTime.now(),
|
||||
LocalDateTime.now(),
|
||||
request.getRnk_ps_idx(),
|
||||
pvIds.stream().map(Object::toString).collect(Collectors.joining(",")),
|
||||
edition1.stream().map(Object::toString).collect(Collectors.joining(",")),
|
||||
edition2.stream().map(Object::toString).collect(Collectors.joining(",")),
|
||||
edition3.stream().map(Object::toString).collect(Collectors.joining(",")),
|
||||
score1.stream().map(Object::toString).collect(Collectors.joining(",")),
|
||||
score2.stream().map(Object::toString).collect(Collectors.joining(",")),
|
||||
score3.stream().map(Object::toString).collect(Collectors.joining(",")),
|
||||
name1.stream().map(Object::toString).collect(Collectors.joining(",")),
|
||||
name2.stream().map(Object::toString).collect(Collectors.joining(",")),
|
||||
name3.stream().map(Object::toString).collect(Collectors.joining(","))
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank
|
||||
|
||||
import ext.csv
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.PsRankingRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.PsRankingResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Difficulty
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Edition
|
||||
import icu.samnyan.aqua.sega.diva.model.common.collection.PsRankingCollection
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
|
||||
import org.springframework.stereotype.Component
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class PsRankingHandler(val db: DivaRepos) {
|
||||
fun handle(request: PsRankingRequest): Any {
|
||||
var edition = Edition.ORIGINAL
|
||||
var difficulty = Difficulty.HARD
|
||||
|
||||
when (request.rnk_ps_idx) {
|
||||
0 -> difficulty = Difficulty.HARD
|
||||
1 -> difficulty = Difficulty.EXTREME
|
||||
2 -> {
|
||||
difficulty = Difficulty.EXTREME
|
||||
edition = Edition.EXTRA
|
||||
}
|
||||
}
|
||||
|
||||
val list = request.rnk_ps_pv_id_lst
|
||||
val resultCollections: MutableMap<Int?, PsRankingCollection?> = LinkedHashMap<Int?, PsRankingCollection?>()
|
||||
for (i in list) {
|
||||
val records = db.pvRecord.findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(
|
||||
i,
|
||||
edition,
|
||||
difficulty
|
||||
)
|
||||
resultCollections.put(i, PsRankingCollection(i, edition, records))
|
||||
}
|
||||
|
||||
val pvIds: MutableList<Int?> = LinkedList<Int?>()
|
||||
val edition1: MutableList<Int?> = LinkedList<Int?>()
|
||||
val edition2: MutableList<Int?> = LinkedList<Int?>()
|
||||
val edition3: MutableList<Int?> = LinkedList<Int?>()
|
||||
val score1: MutableList<Int?> = LinkedList<Int?>()
|
||||
val score2: MutableList<Int?> = LinkedList<Int?>()
|
||||
val score3: MutableList<Int?> = LinkedList<Int?>()
|
||||
val name1: MutableList<String?> = LinkedList<String?>()
|
||||
val name2: MutableList<String?> = LinkedList<String?>()
|
||||
val name3: MutableList<String?> = LinkedList<String?>()
|
||||
|
||||
resultCollections.forEach { (key: Int?, obj: PsRankingCollection?) ->
|
||||
pvIds.add(key)
|
||||
edition1.add(obj!!.first.edition.value)
|
||||
edition2.add(obj.second.edition.value)
|
||||
edition3.add(obj.third.edition.value)
|
||||
score1.add(obj.first.maxScore)
|
||||
score2.add(obj.second.maxScore)
|
||||
score3.add(obj.third.maxScore)
|
||||
name1.add(encode(obj.first.pdId?.playerName ?: "xxx"))
|
||||
name2.add(encode(obj.second.pdId?.playerName ?: "xxx"))
|
||||
name3.add(encode(obj.third.pdId?.playerName ?: "xxx"))
|
||||
}
|
||||
|
||||
return PsRankingResponse(
|
||||
LocalDateTime.now(),
|
||||
LocalDateTime.now(),
|
||||
request.rnk_ps_idx,
|
||||
pvIds.csv,
|
||||
edition1.csv,
|
||||
edition2.csv,
|
||||
edition3.csv,
|
||||
score1.csv,
|
||||
score2.csv,
|
||||
score3.csv,
|
||||
name1.csv,
|
||||
name2.csv,
|
||||
name3.csv
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.PstdHCtrlResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class PstdHCtrlHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PstdHCtrlHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
PstdHCtrlResponse response = new PstdHCtrlResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
DivaDateTimeUtil.getString(LocalDateTime.now()),
|
||||
"***,***"
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.PstdItemNgLstResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class PstdItemNgLstHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PstdItemNgLstHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
PstdItemNgLstResponse response = new PstdItemNgLstResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
DivaDateTimeUtil.getString(LocalDateTime.now()),
|
||||
"***",
|
||||
"***"
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.PvDefChrLstResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class PvDefChrLstHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PvDefChrLstHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
PvDefChrLstResponse response = new PvDefChrLstResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
DivaDateTimeUtil.getString(LocalDateTime.now()),
|
||||
"***"
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.gamedata.PvEntryRepository;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Difficulty;
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.PvEntry;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.PvListResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class PvListHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BannerDataHandler.class);
|
||||
private final PvEntryRepository pvEntryRepository;
|
||||
private final DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
List<PvEntry> easyList = pvEntryRepository.findByDifficulty(Difficulty.EASY);
|
||||
List<PvEntry> normalList = pvEntryRepository.findByDifficulty(Difficulty.NORMAL);
|
||||
List<PvEntry> hardList = pvEntryRepository.findByDifficulty(Difficulty.HARD);
|
||||
List<PvEntry> extremeList = pvEntryRepository.findByDifficulty(Difficulty.EXTREME);
|
||||
|
||||
sb.append(URIEncoder.encode(difficultyString(easyList))).append(",");
|
||||
sb.append(URIEncoder.encode(difficultyString(normalList))).append(",");
|
||||
sb.append(URIEncoder.encode(difficultyString(hardList))).append(",");
|
||||
sb.append(URIEncoder.encode(difficultyString(extremeList))).append(",");
|
||||
sb.append("%2A%2A%2A");
|
||||
|
||||
PvListResponse response = new PvListResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
LocalDateTime.now(),
|
||||
sb.toString());
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
private String entryString(PvEntry entry) {
|
||||
return "" + entry.getPvId() + "," +
|
||||
entry.getVersion() + "," +
|
||||
entry.getEdition().getValue() + "," +
|
||||
df.format(entry.getDemoStart()) + "," +
|
||||
df.format(entry.getDemoEnd()) + "," +
|
||||
df.format(entry.getPlayableStart()) + "," +
|
||||
df.format(entry.getPlayableEnd());
|
||||
}
|
||||
|
||||
private String difficultyString(List<PvEntry> list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
list.forEach(x -> sb.append(URIEncoder.encode(entryString(x))).append(","));
|
||||
if (sb.length() > 0) sb.deleteCharAt(sb.length() - 1);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.BaseRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.PvListResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Difficulty
|
||||
import icu.samnyan.aqua.sega.diva.model.db.gamedata.PvEntry
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
|
||||
import org.springframework.stereotype.Component
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.function.Consumer
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class PvListHandler(val db: DivaRepos) {
|
||||
private val df: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
||||
|
||||
fun handle(request: BaseRequest): Any {
|
||||
val sb = StringBuilder()
|
||||
|
||||
val easyList = db.g.pvEntry.findByDifficulty(Difficulty.EASY)
|
||||
val normalList = db.g.pvEntry.findByDifficulty(Difficulty.NORMAL)
|
||||
val hardList = db.g.pvEntry.findByDifficulty(Difficulty.HARD)
|
||||
val extremeList = db.g.pvEntry.findByDifficulty(Difficulty.EXTREME)
|
||||
|
||||
sb.append(encode(difficultyString(easyList))).append(",")
|
||||
sb.append(encode(difficultyString(normalList))).append(",")
|
||||
sb.append(encode(difficultyString(hardList))).append(",")
|
||||
sb.append(encode(difficultyString(extremeList))).append(",")
|
||||
sb.append("%2A%2A%2A")
|
||||
|
||||
return PvListResponse(
|
||||
LocalDateTime.now(),
|
||||
sb.toString()
|
||||
)
|
||||
}
|
||||
|
||||
private fun entryString(entry: PvEntry): String {
|
||||
return "" + entry.pvId + "," +
|
||||
entry.version + "," +
|
||||
entry.edition.value + "," +
|
||||
df.format(entry.demoStart) + "," +
|
||||
df.format(entry.demoEnd) + "," +
|
||||
df.format(entry.playableStart) + "," +
|
||||
df.format(entry.playableEnd)
|
||||
}
|
||||
|
||||
private fun difficultyString(list: MutableList<PvEntry>): String {
|
||||
val sb = StringBuilder()
|
||||
list.forEach(Consumer { sb.append(encode(entryString(it))).append(",") })
|
||||
if (sb.isNotEmpty()) sb.deleteCharAt(sb.length - 1)
|
||||
return sb.toString()
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.PvNgMdlLstResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class PvNgMdlLstHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PvNgMdlLstHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
|
||||
PvNgMdlLstResponse response = new PvNgMdlLstResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
DivaDateTimeUtil.getString(LocalDateTime.now()),
|
||||
"***"
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.QstInfResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class QstInfHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(QstInfHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
|
||||
QstInfResponse response = new QstInfResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
DivaDateTimeUtil.getString(LocalDateTime.now()),
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.RmtWpLstResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class RmtWpLstHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(QstInfHandler.class);
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
RmtWpLstResponse response = new RmtWpLstResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
DivaDateTimeUtil.getString(LocalDateTime.now()),
|
||||
"***"
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaModuleRepository;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.DivaModule;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.databank.ShopCatalogResponse;
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ShopCatalogHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ShopCatalogHandler.class);
|
||||
private final DivaModuleRepository moduleRepository;
|
||||
|
||||
public String handle(BaseRequest request) {
|
||||
List<DivaModule> moduleList = moduleRepository.findAll();
|
||||
|
||||
ShopCatalogResponse response = new ShopCatalogResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
LocalDateTime.now(),
|
||||
URIEncoder.encode(moduleList.stream().map(DivaModule::toInternal).map(URIEncoder::encode)
|
||||
.collect(Collectors.joining(",")))
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.databank
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.DivaModuleRepository
|
||||
import icu.samnyan.aqua.sega.diva.model.BaseRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.ShopCatalogResponse
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
|
||||
import org.springframework.stereotype.Component
|
||||
import java.time.LocalDateTime
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class ShopCatalogHandler(private val moduleRepository: DivaModuleRepository) {
|
||||
fun handle(request: BaseRequest): Any {
|
||||
val moduleList = moduleRepository.findAll()
|
||||
|
||||
return ShopCatalogResponse(
|
||||
LocalDateTime.now(),
|
||||
encode(moduleList.map { it.toInternal() }.joinToString(",") { encode(it) })
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaCustomizeRepository;
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
|
||||
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result;
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.DivaCustomize;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.ingame.BuyCstmzItmRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.ingame.BuyCstmzItmResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerCustomizeService;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class BuyCstmzItmHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BuyCstmzItmHandler.class);
|
||||
|
||||
private final DivaCustomizeRepository divaCustomizeRepository;
|
||||
|
||||
private final PlayerProfileService playerProfileService;
|
||||
|
||||
private final PlayerCustomizeService playerCustomizeService;
|
||||
|
||||
private final GameSessionRepository gameSessionRepository;
|
||||
|
||||
public String handle(BuyCstmzItmRequest request) {
|
||||
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
|
||||
|
||||
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
|
||||
|
||||
Optional<DivaCustomize> customizeOptional = divaCustomizeRepository.findById(request.getCstmz_itm_id());
|
||||
|
||||
BuyCstmzItmResponse response;
|
||||
if (customizeOptional.isEmpty()) {
|
||||
response = new BuyCstmzItmResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.FAILED
|
||||
);
|
||||
} else {
|
||||
if (session.getVp() < customizeOptional.get().getPrice()) {
|
||||
response = new BuyCstmzItmResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.FAILED
|
||||
);
|
||||
} else {
|
||||
playerCustomizeService.buy(profile, request.getCstmz_itm_id());
|
||||
session.setVp(session.getVp() - customizeOptional.get().getPrice());
|
||||
gameSessionRepository.save(session);
|
||||
|
||||
response = new BuyCstmzItmResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.SUCCESS,
|
||||
request.getCstmz_itm_id(),
|
||||
playerCustomizeService.getModuleHaveString(profile),
|
||||
session.getVp()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame
|
||||
|
||||
import ext.invoke
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.BuyCstmzItmRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.BuyCstmzItmResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class BuyCstmzItmHandler(val db: DivaRepos) {
|
||||
fun handle(request: BuyCstmzItmRequest): Any {
|
||||
val (profile, session) = db.session(request.pd_id)
|
||||
|
||||
val customize = db.g.customize.findById(request.cstmz_itm_id)() ?: return BuyCstmzItmResponse(
|
||||
Result.FAILED
|
||||
)
|
||||
|
||||
if (session.vp < customize.price) {
|
||||
return BuyCstmzItmResponse(
|
||||
Result.FAILED
|
||||
)
|
||||
}
|
||||
db.s.customize.buy(profile, request.cstmz_itm_id)
|
||||
session.vp -= customize.price
|
||||
db.gameSession.save(session)
|
||||
|
||||
return BuyCstmzItmResponse(
|
||||
Result.SUCCESS,
|
||||
request.cstmz_itm_id,
|
||||
db.s.customize.getModuleHaveString(profile),
|
||||
session.vp
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaModuleRepository;
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
|
||||
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result;
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.DivaModule;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.ingame.BuyModuleRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.ingame.BuyModuleResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerModuleService;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class BuyModuleHandler extends BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BuyModuleHandler.class);
|
||||
|
||||
private final DivaModuleRepository divaModuleRepository;
|
||||
|
||||
private final PlayerProfileService playerProfileService;
|
||||
|
||||
private final PlayerModuleService playerModuleService;
|
||||
|
||||
private final GameSessionRepository gameSessionRepository;
|
||||
|
||||
public String handle(BuyModuleRequest request) {
|
||||
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
|
||||
|
||||
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
|
||||
|
||||
Optional<DivaModule> moduleOptional = divaModuleRepository.findById(request.getMdl_id());
|
||||
|
||||
BuyModuleResponse response;
|
||||
if (moduleOptional.isEmpty()) {
|
||||
response = new BuyModuleResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.FAILED
|
||||
);
|
||||
} else {
|
||||
if (session.getVp() < moduleOptional.get().getPrice()) {
|
||||
response = new BuyModuleResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.FAILED
|
||||
);
|
||||
} else {
|
||||
playerModuleService.buy(profile, request.getMdl_id());
|
||||
session.setVp(session.getVp() - moduleOptional.get().getPrice());
|
||||
gameSessionRepository.save(session);
|
||||
|
||||
response = new BuyModuleResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.SUCCESS,
|
||||
request.getMdl_id(),
|
||||
playerModuleService.getModuleHaveString(profile),
|
||||
session.getVp()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.BuyModuleRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.BuyModuleResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class BuyModuleHandler(val db: DivaRepos) {
|
||||
fun handle(request: BuyModuleRequest): Any {
|
||||
val (profile, session) = db.session(request.pd_id)
|
||||
val moduleOptional = db.g.module.findById(request.mdl_id)
|
||||
|
||||
if (moduleOptional.isEmpty) {
|
||||
return BuyModuleResponse(
|
||||
Result.FAILED
|
||||
)
|
||||
}
|
||||
if (session.vp < moduleOptional.get().price) {
|
||||
return BuyModuleResponse(
|
||||
Result.FAILED
|
||||
)
|
||||
}
|
||||
db.s.module.buy(profile, request.mdl_id)
|
||||
session.vp -= moduleOptional.get().price
|
||||
db.gameSession.save(session)
|
||||
|
||||
return BuyModuleResponse(
|
||||
Result.SUCCESS,
|
||||
request.mdl_id,
|
||||
db.s.module.getModuleHaveString(profile),
|
||||
session.vp
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvCustomizeRepository;
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvRecordRepository;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Difficulty;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Edition;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.ingame.GetPvPdRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.ingame.GetPvPdResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvCustomize;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvRecord;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class GetPvPdHandler extends BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetPvPdHandler.class);
|
||||
|
||||
private final PlayerPvRecordRepository pvRecordRepository;
|
||||
private final PlayerPvCustomizeRepository pvCustomizeRepository;
|
||||
private final PlayerProfileService playerProfileService;
|
||||
|
||||
public String handle(GetPvPdRequest request) {
|
||||
|
||||
Optional<PlayerProfile> profileO = playerProfileService.findByPdId(request.getPd_id());
|
||||
StringBuilder pd = new StringBuilder();
|
||||
|
||||
for (int pvId :
|
||||
request.getPd_pv_id_lst()) {
|
||||
if (pvId == -1) {
|
||||
pd.append("***").append(",");
|
||||
} else {
|
||||
if (profileO.isEmpty()) {
|
||||
pd.append("***").append(",");
|
||||
} else {
|
||||
var profile = profileO.get();
|
||||
int diff = request.getDifficulty();
|
||||
Difficulty difficulty = Difficulty.fromValue(diff);
|
||||
|
||||
// Myself
|
||||
PlayerPvRecord edition0 = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(profile, pvId, Edition.ORIGINAL, difficulty)
|
||||
.orElseGet(() -> new PlayerPvRecord(pvId, Edition.ORIGINAL));
|
||||
|
||||
PlayerPvRecord edition1 = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(profile, pvId, Edition.EXTRA, difficulty)
|
||||
.orElseGet(() -> new PlayerPvRecord(pvId, Edition.EXTRA));
|
||||
|
||||
// Rival
|
||||
PlayerPvRecord rivalEdition0;
|
||||
PlayerPvRecord rivalEdition1;
|
||||
if (profile.getRivalPdId() != -1) {
|
||||
rivalEdition0 = pvRecordRepository.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(profile.getRivalPdId(), pvId, Edition.ORIGINAL, difficulty)
|
||||
.orElseGet(() -> new PlayerPvRecord(pvId, Edition.ORIGINAL));
|
||||
|
||||
rivalEdition1 = pvRecordRepository.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(profile.getRivalPdId(), pvId, Edition.EXTRA, difficulty)
|
||||
.orElseGet(() -> new PlayerPvRecord(pvId, Edition.EXTRA));
|
||||
} else {
|
||||
rivalEdition0 = new PlayerPvRecord(pvId, Edition.ORIGINAL);
|
||||
rivalEdition1 = new PlayerPvRecord(pvId, Edition.EXTRA);
|
||||
}
|
||||
|
||||
PlayerPvCustomize customize = pvCustomizeRepository.findByPdIdAndPvId(profile, pvId).orElseGet(() -> new PlayerPvCustomize(profile, pvId));
|
||||
|
||||
String str = getString(edition0, customize, rivalEdition0, profile.getRivalPdId()) + "," + getString(edition1, customize, rivalEdition1, profile.getRivalPdId());
|
||||
// logger.info(str);
|
||||
pd.append(URIEncoder.encode(str)).append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
pd.deleteCharAt(pd.length() - 1);
|
||||
|
||||
|
||||
GetPvPdResponse response = new GetPvPdResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
pd.toString(),
|
||||
false,
|
||||
DivaDateTimeUtil.getString(LocalDateTime.now())
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
private String getString(PlayerPvRecord record, PlayerPvCustomize customize, PlayerPvRecord rivalRecord, long rivalId) {
|
||||
return record.getPvId() + "," +
|
||||
record.getEdition().getValue() + "," +
|
||||
record.getResult().getValue() + "," +
|
||||
record.getMaxScore() + "," +
|
||||
record.getMaxAttain() + "," +
|
||||
record.getChallengeKind().getValue() + "," +
|
||||
customize.getModule() + "," +
|
||||
customize.getCustomize() + "," +
|
||||
customize.getCustomizeFlag() + "," +
|
||||
customize.getSkin() + "," +
|
||||
customize.getButtonSe() + "," +
|
||||
customize.getSlideSe() + "," +
|
||||
customize.getChainSlideSe() + "," +
|
||||
customize.getSliderTouchSe() + "," +
|
||||
rivalId + "," +
|
||||
rivalRecord.getMaxScore() + "," +
|
||||
rivalRecord.getMaxAttain() + "," +
|
||||
"-1,-1," +
|
||||
pvRecordRepository.rankByPvIdAndPdIdAndEditionAndDifficulty(record.getPvId(), record.getPdId(), record.getEdition(), record.getDifficulty()) + "," +
|
||||
record.getRgoPurchased() + "," +
|
||||
record.getRgoPlayed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.GetPvPdRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.GetPvPdResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Difficulty
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Edition
|
||||
import icu.samnyan.aqua.sega.diva.model.db.userdata.PlayerPvCustomize
|
||||
import icu.samnyan.aqua.sega.diva.model.db.userdata.PlayerPvRecord
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaTime
|
||||
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
|
||||
import org.springframework.stereotype.Component
|
||||
import java.util.function.Supplier
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class GetPvPdHandler(val db: DivaRepos) {
|
||||
fun handle(request: GetPvPdRequest): Any {
|
||||
val profileO = db.profile.findByPdId(request.pd_id)
|
||||
val pd = StringBuilder()
|
||||
|
||||
for (pvId in request.pd_pv_id_lst) {
|
||||
if (pvId == -1) {
|
||||
pd.append("***").append(",")
|
||||
} else {
|
||||
if (profileO.isEmpty) {
|
||||
pd.append("***").append(",")
|
||||
} else {
|
||||
val profile = profileO.get()
|
||||
val diff = request.difficulty
|
||||
val difficulty = Difficulty.fromValue(diff)
|
||||
|
||||
// Myself
|
||||
val edition0 = db.pvRecord.findByPdIdAndPvIdAndEditionAndDifficulty(
|
||||
profile,
|
||||
pvId,
|
||||
Edition.ORIGINAL,
|
||||
difficulty
|
||||
)
|
||||
.orElseGet(Supplier { PlayerPvRecord(pvId, Edition.ORIGINAL) })
|
||||
|
||||
val edition1 = db.pvRecord.findByPdIdAndPvIdAndEditionAndDifficulty(
|
||||
profile,
|
||||
pvId,
|
||||
Edition.EXTRA,
|
||||
difficulty
|
||||
)
|
||||
.orElseGet(Supplier { PlayerPvRecord(pvId, Edition.EXTRA) })
|
||||
|
||||
// Rival
|
||||
val rivalEdition0: PlayerPvRecord?
|
||||
val rivalEdition1: PlayerPvRecord?
|
||||
if (profile.rivalPdId != -1L) {
|
||||
rivalEdition0 = db.pvRecord.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(
|
||||
profile.rivalPdId,
|
||||
pvId,
|
||||
Edition.ORIGINAL,
|
||||
difficulty
|
||||
)
|
||||
.orElseGet(Supplier { PlayerPvRecord(pvId, Edition.ORIGINAL) })
|
||||
|
||||
rivalEdition1 = db.pvRecord.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(
|
||||
profile.rivalPdId,
|
||||
pvId,
|
||||
Edition.EXTRA,
|
||||
difficulty
|
||||
)
|
||||
.orElseGet(Supplier { PlayerPvRecord(pvId, Edition.EXTRA) })
|
||||
} else {
|
||||
rivalEdition0 = PlayerPvRecord(pvId, Edition.ORIGINAL)
|
||||
rivalEdition1 = PlayerPvRecord(pvId, Edition.EXTRA)
|
||||
}
|
||||
|
||||
val customize = db.pvCustomize.findByPdIdAndPvId(profile, pvId)
|
||||
.orElseGet(Supplier { PlayerPvCustomize(profile, pvId) })
|
||||
|
||||
val str = getString(
|
||||
edition0,
|
||||
customize,
|
||||
rivalEdition0,
|
||||
profile.rivalPdId
|
||||
) + "," + getString(edition1, customize, rivalEdition1, profile.rivalPdId)
|
||||
pd.append(encode(str)).append(",")
|
||||
}
|
||||
}
|
||||
}
|
||||
pd.deleteCharAt(pd.length - 1)
|
||||
|
||||
|
||||
return GetPvPdResponse(
|
||||
pd.toString(),
|
||||
false,
|
||||
DivaTime.now
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun getString(
|
||||
record: PlayerPvRecord,
|
||||
customize: PlayerPvCustomize,
|
||||
rivalRecord: PlayerPvRecord,
|
||||
rivalId: Long
|
||||
): String {
|
||||
return record.pvId.toString() + "," +
|
||||
record.edition.value + "," +
|
||||
record.result.value + "," +
|
||||
record.maxScore + "," +
|
||||
record.maxAttain + "," +
|
||||
record.challengeKind.value + "," +
|
||||
customize.module + "," +
|
||||
customize.customize + "," +
|
||||
customize.customizeFlag + "," +
|
||||
customize.skin + "," +
|
||||
customize.buttonSe + "," +
|
||||
customize.slideSe + "," +
|
||||
customize.chainSlideSe + "," +
|
||||
customize.sliderTouchSe + "," +
|
||||
rivalId + "," +
|
||||
rivalRecord.maxScore + "," +
|
||||
rivalRecord.maxAttain + "," +
|
||||
"-1,-1," +
|
||||
db.pvRecord.rankByPvIdAndPdIdAndEditionAndDifficulty(
|
||||
record.pvId,
|
||||
record.pdId,
|
||||
record.edition,
|
||||
record.difficulty
|
||||
) + "," +
|
||||
record.rgoPurchased + "," +
|
||||
record.rgoPlayed
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvCustomizeRepository;
|
||||
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.ingame.ShopExitRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.ingame.ShopExitResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvCustomize;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static icu.samnyan.aqua.sega.diva.util.DivaStringUtils.arrToCsv;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ShopExitHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ShopExitHandler.class);
|
||||
private final PlayerProfileService playerProfileService;
|
||||
private final PlayerPvCustomizeRepository pvCustomizeRepository;
|
||||
|
||||
public String handle(ShopExitRequest request) {
|
||||
|
||||
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
|
||||
PlayerPvCustomize customize = pvCustomizeRepository.findByPdIdAndPvId(profile, request.getPly_pv_id()).orElseGet(() -> new PlayerPvCustomize(profile, request.getPly_pv_id()));
|
||||
|
||||
if (request.getUse_pv_mdl_eqp() == 1) {
|
||||
customize.setModule(arrToCsv(request.getMdl_eqp_pv_ary()));
|
||||
customize.setCustomize(arrToCsv(request.getC_itm_eqp_pv_ary()));
|
||||
customize.setCustomizeFlag(arrToCsv(request.getMs_itm_flg_pv_ary()));
|
||||
} else {
|
||||
customize.setModule("-1,-1,-1");
|
||||
customize.setCustomize("-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1");
|
||||
customize.setCustomizeFlag("1,1,1,1,1,1,1,1,1,1,1,1");
|
||||
}
|
||||
|
||||
profile.setCommonModule(arrToCsv(request.getMdl_eqp_cmn_ary()));
|
||||
profile.setCommonCustomizeItems(arrToCsv(request.getC_itm_eqp_cmn_ary()));
|
||||
profile.setModuleSelectItemFlag(arrToCsv(request.getMs_itm_flg_cmn_ary()));
|
||||
|
||||
playerProfileService.save(profile);
|
||||
pvCustomizeRepository.save(customize);
|
||||
ShopExitResponse response = new ShopExitResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
Result.SUCCESS
|
||||
);
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame
|
||||
|
||||
import ext.csv
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.ShopExitRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.ShopExitResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.Result
|
||||
import icu.samnyan.aqua.sega.diva.model.db.userdata.PlayerPvCustomize
|
||||
import org.springframework.stereotype.Component
|
||||
import java.util.function.Supplier
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class ShopExitHandler(val db: DivaRepos) {
|
||||
fun handle(request: ShopExitRequest): Any {
|
||||
val profile = db.profile(request.pd_id)
|
||||
val customize = db.pvCustomize.findByPdIdAndPvId(profile, request.ply_pv_id)
|
||||
.orElseGet(Supplier { PlayerPvCustomize(profile, request.ply_pv_id) })
|
||||
|
||||
if (request.use_pv_mdl_eqp == 1) {
|
||||
customize.module = request.mdl_eqp_pv_ary.csv
|
||||
customize.customize = request.c_itm_eqp_pv_ary.csv
|
||||
customize.customizeFlag = request.ms_itm_flg_pv_ary.csv
|
||||
} else {
|
||||
customize.module = "-1,-1,-1"
|
||||
customize.customize = "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"
|
||||
customize.customizeFlag = "1,1,1,1,1,1,1,1,1,1,1,1"
|
||||
}
|
||||
|
||||
profile.commonModule = request.mdl_eqp_cmn_ary.csv
|
||||
profile.commonCustomizeItems = request.c_itm_eqp_cmn_ary.csv
|
||||
profile.moduleSelectItemFlag = request.ms_itm_flg_cmn_ary.csv
|
||||
|
||||
db.profile.save(profile)
|
||||
db.pvCustomize.save(customize)
|
||||
return ShopExitResponse(
|
||||
Result.SUCCESS
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,403 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.gamedata.ContestRepository;
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.*;
|
||||
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.common.*;
|
||||
import icu.samnyan.aqua.sega.diva.model.gamedata.Contest;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageResultRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.ingame.StageResultResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.*;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaCalculator;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
import static icu.samnyan.aqua.sega.diva.model.common.Const.NULL_QUEST;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class StageResultHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(StageResultHandler.class);
|
||||
private final GameSessionRepository gameSessionRepository;
|
||||
private final PlayerPvRecordRepository pvRecordRepository;
|
||||
private final PlayerProfileService playerProfileService;
|
||||
private final PlayLogRepository playLogRepository;
|
||||
private final ContestRepository contestRepository;
|
||||
private final PlayerContestRepository playerContestRepository;
|
||||
private final PlayerCustomizeRepository playerCustomizeRepository;
|
||||
private final PlayerInventoryRepository playerInventoryRepository;
|
||||
|
||||
private final DivaCalculator divaCalculator;
|
||||
|
||||
private PlayerProfile currentProfile = null;
|
||||
|
||||
public String handle(StageResultRequest request) {
|
||||
StageResultResponse response;
|
||||
if (request.getPd_id() != -1) {
|
||||
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
|
||||
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
|
||||
|
||||
currentProfile = profile;
|
||||
// Get the last played index
|
||||
int[] pvIds = request.getStg_ply_pv_id();
|
||||
int[] stageArr = request.getStg_ply_pv_id();
|
||||
int stageIndex = 0;
|
||||
if (stageArr[0] != -1) {
|
||||
stageIndex = 0;
|
||||
}
|
||||
if (stageArr[1] != -1) {
|
||||
stageIndex = 1;
|
||||
}
|
||||
if (stageArr[2] != -1) {
|
||||
stageIndex = 2;
|
||||
}
|
||||
if (stageArr[3] != -1) {
|
||||
stageIndex = 3;
|
||||
}
|
||||
|
||||
// Convert to play log object
|
||||
PlayLog log = getLog(request, profile, stageIndex);
|
||||
logger.debug("Stage Result Object: {}", log.toString());
|
||||
|
||||
PlayerPvRecord record = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(profile, log.getPvId(), log.getEdition(), log.getDifficulty())
|
||||
.orElseGet(() -> new PlayerPvRecord(profile, log.getPvId(), log.getEdition(), log.getDifficulty()));
|
||||
|
||||
// Not save personal record in no fail mode
|
||||
if (request.getGame_type() != 1) {
|
||||
// Only update personal record when using rhythm game option
|
||||
if (log.getRhythmGameOptions().equals("0,0,0")) {
|
||||
// Update pvRecord field
|
||||
record.setMaxScore(Math.max(record.getMaxScore(), log.getScore()));
|
||||
record.setMaxAttain(Math.max(record.getMaxAttain(), log.getAttainPoint()));
|
||||
|
||||
if (record.getResult().getValue() < log.getClearResult().getValue()) {
|
||||
record.setResult(log.getClearResult());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String[] updateRgo = log.getRhythmGameOptions().split(",");
|
||||
String[] oldRgo = record.getRgoPlayed().split(",");
|
||||
for (int i = 0; i < updateRgo.length; i++) {
|
||||
if (updateRgo[i].equals("1")) {
|
||||
oldRgo[i] = "1";
|
||||
}
|
||||
}
|
||||
record.setRgoPlayed(StringUtils.join(oldRgo, ","));
|
||||
|
||||
session.setVp(session.getVp() + log.getVp());
|
||||
session.setLastPvId(log.getPvId());
|
||||
session.setLastUpdateTime(LocalDateTime.now());
|
||||
|
||||
LevelInfo levelInfo = divaCalculator.getLevelInfo(profile);
|
||||
session.setOldLevelNumber(session.getLevelNumber());
|
||||
session.setOldLevelExp(session.getLevelExp());
|
||||
session.setLevelNumber(levelInfo.getLevelNumber());
|
||||
session.setLevelExp(levelInfo.getLevelExp());
|
||||
|
||||
session.setStageResultIndex(stageIndex);
|
||||
|
||||
// Calculate reward
|
||||
// Contest reward
|
||||
String contestSpecifier = String.join(",", request.getCr_sp());
|
||||
String[] contestRewardType = {"-1", "-1", "-1"};
|
||||
String[] contestRewardValue = {"-1", "-1", "-1"};
|
||||
String[] contestRewardString1 = {"***", "***", "***"};
|
||||
String[] contestRewardString2 = {"***", "***", "***"};
|
||||
int contestEntryRewardType = -1;
|
||||
int contestEntryRewardValue = -1;
|
||||
String contestEntryRewardString1 = "***";
|
||||
String contestEntryRewardString2 = "***";
|
||||
int contestId = request.getCr_cid();
|
||||
if (contestId != -1) {
|
||||
List<ContestProgress> progress = getContestProgress(request.getCr_sp());
|
||||
contestSpecifier = getContestSpecifier(progress);
|
||||
|
||||
// Check if the contest info exist
|
||||
Optional<Contest> contestOptional = contestRepository.findById(contestId);
|
||||
if (contestOptional.isPresent()) {
|
||||
Contest contest = contestOptional.get();
|
||||
Optional<PlayerContest> playerContestOptional = playerContestRepository.findByPdIdAndContestId(profile, contestId);
|
||||
|
||||
// Contest Entry Reward
|
||||
// Check if this is first stage
|
||||
if (progress.size() == 1 && playerContestOptional.isEmpty()) {
|
||||
if (StringUtils.isNotBlank(contest.getContestEntryReward())) {
|
||||
// Check if this is first time play this contest
|
||||
String reward = contest.getContestEntryReward();
|
||||
String[] rewardValue = reward.split(":");
|
||||
|
||||
contestEntryRewardType = Integer.parseInt(rewardValue[0]);
|
||||
contestEntryRewardValue = Integer.parseInt(rewardValue[1]);
|
||||
contestEntryRewardString1 = rewardValue[2];
|
||||
contestEntryRewardString2 = rewardValue[3];
|
||||
}
|
||||
}
|
||||
|
||||
// Only if this is the first time reach this value
|
||||
int previousValue = progress.stream().limit(progress.size() - 1).mapToInt(ContestProgress::getScores).sum();
|
||||
int currentValue = progress.stream().mapToInt(ContestProgress::getScores).sum();
|
||||
|
||||
// Bronze Reward
|
||||
Map<String, String> bronze = updateReward(currentValue, previousValue, contest.getBronzeBorders(), contest.getBronzeContestReward());
|
||||
if (bronze != null) {
|
||||
contestRewardType[0] = bronze.get("type");
|
||||
contestRewardValue[0] = bronze.get("value");
|
||||
contestRewardString1[0] = bronze.get("string1");
|
||||
contestRewardString2[2] = bronze.get("string2");
|
||||
}
|
||||
|
||||
// Silver Reward
|
||||
Map<String, String> silver = updateReward(currentValue, previousValue, contest.getSliverBorders(), contest.getSliverContestReward());
|
||||
if (silver != null) {
|
||||
contestRewardType[1] = silver.get("type");
|
||||
contestRewardValue[1] = silver.get("value");
|
||||
contestRewardString1[1] = silver.get("string1");
|
||||
contestRewardString2[2] = silver.get("string2");
|
||||
}
|
||||
|
||||
// Gold Reward
|
||||
Map<String, String> gold = updateReward(currentValue, previousValue, contest.getGoldBorders(), contest.getGoldContestReward());
|
||||
if (gold != null) {
|
||||
contestRewardType[2] = gold.get("type");
|
||||
contestRewardValue[2] = gold.get("value");
|
||||
contestRewardString1[2] = gold.get("string1");
|
||||
contestRewardString2[2] = gold.get("string2");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pvRecordRepository.save(record);
|
||||
playLogRepository.save(log);
|
||||
gameSessionRepository.save(session);
|
||||
|
||||
|
||||
response = new StageResultResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok",
|
||||
ChallengeKind.UNDEFINED.getValue(),
|
||||
session.getOldLevelNumber(),
|
||||
session.getOldLevelExp(),
|
||||
session.getLevelNumber(),
|
||||
session.getLevelExp(),
|
||||
profile.getLevelTitle(),
|
||||
profile.getPlateEffectId(),
|
||||
profile.getPlateId(),
|
||||
session.getVp(),
|
||||
0,
|
||||
request.getCr_cid(),
|
||||
request.getCr_tv(),
|
||||
contestSpecifier,
|
||||
String.join(",", contestRewardType),
|
||||
String.join(",", contestRewardValue),
|
||||
String.join(",", contestRewardString1),
|
||||
String.join(",", contestRewardString2),
|
||||
contestEntryRewardType,
|
||||
contestEntryRewardValue,
|
||||
contestEntryRewardString1,
|
||||
contestEntryRewardString2,
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
"-1,-1,-1,-1,-1",
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
0,
|
||||
LocalDateTime.now(),
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
NULL_QUEST,
|
||||
NULL_QUEST,
|
||||
NULL_QUEST,
|
||||
NULL_QUEST,
|
||||
NULL_QUEST,
|
||||
"-1,-1,-1,-1,-1",
|
||||
"-1,-1,-1,-1,-1",
|
||||
"-1,-1,-1,-1,-1"
|
||||
);
|
||||
} else {
|
||||
response = new StageResultResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok"
|
||||
);
|
||||
}
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
private PlayLog getLog(StageResultRequest request, PlayerProfile profile, int i) {
|
||||
return new PlayLog(
|
||||
profile,
|
||||
request.getStg_ply_pv_id()[i],
|
||||
Difficulty.fromValue(request.getStg_difficulty()[i]),
|
||||
Edition.fromValue(request.getStg_edtn()[i]),
|
||||
request.getStg_scrpt_ver()[i],
|
||||
request.getStg_score()[i],
|
||||
ChallengeKind.fromValue(request.getStg_chllng_kind()[i]),
|
||||
request.getStg_chllng_result()[i],
|
||||
ClearResult.fromValue(request.getStg_clr_kind()[i]),
|
||||
request.getStg_vcld_pts()[i],
|
||||
request.getStg_cool_cnt()[i],
|
||||
request.getStg_cool_pct()[i],
|
||||
request.getStg_fine_cnt()[i],
|
||||
request.getStg_fine_pct()[i],
|
||||
request.getStg_safe_cnt()[i],
|
||||
request.getStg_safe_pct()[i],
|
||||
request.getStg_sad_cnt()[i],
|
||||
request.getStg_sad_pct()[i],
|
||||
request.getStg_wt_wg_cnt()[i],
|
||||
request.getStg_wt_wg_pct()[i],
|
||||
request.getStg_max_cmb()[i],
|
||||
request.getStg_chance_tm()[i],
|
||||
request.getStg_sm_hl()[i],
|
||||
request.getStg_atn_pnt()[i],
|
||||
request.getStg_skin_id()[i],
|
||||
request.getStg_btn_se()[i],
|
||||
request.getStg_btn_se_vol()[i],
|
||||
request.getStg_sld_se()[i],
|
||||
request.getStg_chn_sld_se()[i],
|
||||
request.getStg_sldr_tch_se()[i],
|
||||
slice(request.getStg_mdl_id(), 3, i),
|
||||
request.getStg_cpt_rslt()[i],
|
||||
request.getStg_sld_scr()[i],
|
||||
request.getStg_vcl_chg()[i],
|
||||
slice(request.getStg_c_itm_id(), 12, i),
|
||||
slice(request.getStg_rgo(), 3, i),
|
||||
request.getStg_ss_num()[i],
|
||||
request.getTime_stamp().toLocalDateTime()
|
||||
);
|
||||
}
|
||||
|
||||
public String slice(int[] arr, int length, int offset) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = length * offset; i < length * (offset + 1); i++) {
|
||||
sb.append(arr[i]).append(",");
|
||||
}
|
||||
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private List<ContestProgress> getContestProgress(String[] arr) {
|
||||
List<ContestProgress> result = new LinkedList<>();
|
||||
for (int i = 0; i < arr.length; i = i + 6) {
|
||||
if (!arr[i].equals("-1")) {
|
||||
result.add(new ContestProgress(
|
||||
Integer.parseInt(arr[i]),
|
||||
Integer.parseInt(arr[i + 1]),
|
||||
Integer.parseInt(arr[i + 2]),
|
||||
Integer.parseInt(arr[i + 3]),
|
||||
Integer.parseInt(arr[i + 4]),
|
||||
Integer.parseInt(arr[i + 5])
|
||||
));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getContestSpecifier(List<ContestProgress> progresses) {
|
||||
List<String> result = new LinkedList<>();
|
||||
for (ContestProgress x : progresses) {
|
||||
result.add(String.valueOf(x.getHardness()));
|
||||
result.add(String.valueOf(x.getEdition()));
|
||||
result.add(String.valueOf(x.getStars()));
|
||||
result.add(String.valueOf(x.getScores()));
|
||||
result.add(String.valueOf(x.getVersion()));
|
||||
}
|
||||
while (result.size() < 60) {
|
||||
result.add("-1");
|
||||
}
|
||||
return String.join(",", result);
|
||||
}
|
||||
|
||||
private Map<String, String> updateReward(int currentValue, int previousValue, int borders, String reward) {
|
||||
if (currentValue > borders && previousValue < borders) {
|
||||
if (StringUtils.isNotBlank(reward)) {
|
||||
String[] rewardValue = reward.split(":");
|
||||
Map<String, String> result = new HashMap<>();
|
||||
switch (rewardValue[0]) {
|
||||
case "-1":
|
||||
return null;
|
||||
case "0": {
|
||||
result.put("type", rewardValue[0]);
|
||||
result.put("value", rewardValue[1]);
|
||||
result.put("string1", "***");
|
||||
result.put("string2", "***");
|
||||
break;
|
||||
}
|
||||
case "1": {
|
||||
if (playerInventoryRepository.findByPdIdAndTypeAndValue(currentProfile, "SKIN", rewardValue[1]).isPresent()) {
|
||||
result.put("type", "-1");
|
||||
result.put("value", "-1");
|
||||
result.put("string1", "***");
|
||||
result.put("string2", "***");
|
||||
} else {
|
||||
playerInventoryRepository.save(new PlayerInventory(null, currentProfile, rewardValue[1], "SKIN"));
|
||||
result.put("type", rewardValue[0]);
|
||||
result.put("value", rewardValue[1]);
|
||||
result.put("string1", rewardValue[2]);
|
||||
result.put("string2", rewardValue[3]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "2": {
|
||||
if (playerInventoryRepository.findByPdIdAndTypeAndValue(currentProfile, "PLATE", rewardValue[1]).isPresent()) {
|
||||
result.put("type", "-1");
|
||||
result.put("value", "-1");
|
||||
result.put("string1", "***");
|
||||
result.put("string2", "***");
|
||||
} else {
|
||||
playerInventoryRepository.save(new PlayerInventory(null, currentProfile, rewardValue[1], "PLATE"));
|
||||
result.put("type", rewardValue[0]);
|
||||
result.put("value", rewardValue[1]);
|
||||
result.put("string1", rewardValue[2]);
|
||||
result.put("string2", rewardValue[3]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "3": {
|
||||
if (playerCustomizeRepository.findByPdIdAndCustomizeId(currentProfile, Integer.parseInt(rewardValue[1])).isPresent()) {
|
||||
result.put("type", "-1");
|
||||
result.put("value", "-1");
|
||||
result.put("string1", "***");
|
||||
result.put("string2", "***");
|
||||
} else {
|
||||
playerCustomizeRepository.save(new PlayerCustomize(currentProfile, Integer.parseInt(rewardValue[1])));
|
||||
result.put("type", rewardValue[0]);
|
||||
result.put("value", rewardValue[1]);
|
||||
result.put("string1", rewardValue[2]);
|
||||
result.put("string2", rewardValue[3]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,427 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame
|
||||
|
||||
import ext.logger
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.StageResultRequest
|
||||
import icu.samnyan.aqua.sega.diva.model.StageResultResponse
|
||||
import icu.samnyan.aqua.sega.diva.model.common.*
|
||||
import icu.samnyan.aqua.sega.diva.model.db.userdata.*
|
||||
import icu.samnyan.aqua.sega.diva.util.DivaCalculator
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import org.springframework.stereotype.Component
|
||||
import java.lang.String
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
import java.util.function.Supplier
|
||||
import kotlin.Any
|
||||
import kotlin.Array
|
||||
import kotlin.Int
|
||||
import kotlin.IntArray
|
||||
import kotlin.arrayOf
|
||||
import kotlin.math.max
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class StageResultHandler(val db: DivaRepos, val calc: DivaCalculator) {
|
||||
private var currentProfile: PlayerProfile? = null
|
||||
val logger = logger()
|
||||
|
||||
fun handle(request: StageResultRequest): Any {
|
||||
if (request.pd_id != -1L) {
|
||||
val (profile, session) = db.session(request.pd_id)
|
||||
|
||||
currentProfile = profile
|
||||
// Get the last played index
|
||||
val stageArr = request.stg_ply_pv_id
|
||||
var stageIndex = 0
|
||||
if (stageArr[0] != -1) {
|
||||
stageIndex = 0
|
||||
}
|
||||
if (stageArr[1] != -1) {
|
||||
stageIndex = 1
|
||||
}
|
||||
if (stageArr[2] != -1) {
|
||||
stageIndex = 2
|
||||
}
|
||||
if (stageArr[3] != -1) {
|
||||
stageIndex = 3
|
||||
}
|
||||
|
||||
// Convert to play log object
|
||||
val log = getLog(request, profile, stageIndex)
|
||||
logger.debug("Stage Result Object: {}", log.toString())
|
||||
|
||||
val record = db.pvRecord.findByPdIdAndPvIdAndEditionAndDifficulty(
|
||||
profile,
|
||||
log.pvId,
|
||||
log.edition,
|
||||
log.difficulty
|
||||
)
|
||||
.orElseGet(Supplier { PlayerPvRecord(profile, log.pvId, log.edition, log.difficulty) })
|
||||
|
||||
// Not save personal record in no fail mode
|
||||
if (request.game_type != 1) {
|
||||
// Only update personal record when using rhythm game option
|
||||
if (log.rhythmGameOptions == "0,0,0") {
|
||||
// Update pvRecord field
|
||||
record.maxScore = max(record.maxScore, log.score)
|
||||
record.maxAttain = max(record.maxAttain, log.attainPoint)
|
||||
|
||||
if (record.result.value < log.clearResult.value) {
|
||||
record.result = log.clearResult
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val updateRgo =
|
||||
log.rhythmGameOptions.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
val oldRgo =
|
||||
record.rgoPlayed.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
for (i in updateRgo.indices) {
|
||||
if (updateRgo[i] == "1") {
|
||||
oldRgo[i] = "1"
|
||||
}
|
||||
}
|
||||
record.rgoPlayed = StringUtils.join(oldRgo, ",")
|
||||
|
||||
session.vp = session.vp + log.vp
|
||||
session.lastPvId = log.pvId
|
||||
session.lastUpdateTime = LocalDateTime.now()
|
||||
|
||||
val levelInfo = calc.getLevelInfo(profile)
|
||||
session.oldLevelNumber = session.levelNumber
|
||||
session.oldLevelExp = session.levelExp
|
||||
session.levelNumber = levelInfo.levelNumber
|
||||
session.levelExp = levelInfo.levelExp
|
||||
|
||||
session.stageResultIndex = stageIndex
|
||||
|
||||
// Calculate reward
|
||||
// Contest reward
|
||||
var contestSpecifier = String.join(",", *request.cr_sp)
|
||||
val contestRewardType = arrayOf<kotlin.String?>("-1", "-1", "-1")
|
||||
val contestRewardValue = arrayOf<kotlin.String?>("-1", "-1", "-1")
|
||||
val contestRewardString1 = arrayOf<kotlin.String?>("***", "***", "***")
|
||||
val contestRewardString2 = arrayOf<kotlin.String?>("***", "***", "***")
|
||||
var contestEntryRewardType = -1
|
||||
var contestEntryRewardValue = -1
|
||||
var contestEntryRewardString1: kotlin.String? = "***"
|
||||
var contestEntryRewardString2: kotlin.String? = "***"
|
||||
val contestId = request.cr_cid
|
||||
if (contestId != -1) {
|
||||
val progress = getContestProgress(request.cr_sp)
|
||||
contestSpecifier = getContestSpecifier(progress)
|
||||
|
||||
// Check if the contest info exist
|
||||
val contestOptional = db.g.contest.findById(contestId)
|
||||
if (contestOptional.isPresent) {
|
||||
val contest = contestOptional.get()
|
||||
val playerContestOptional = db.contest.findByPdIdAndContestId(profile, contestId)
|
||||
|
||||
// Contest Entry Reward
|
||||
// Check if this is first stage
|
||||
if (progress.size == 1 && playerContestOptional.isEmpty) {
|
||||
if (StringUtils.isNotBlank(contest.contestEntryReward)) {
|
||||
// Check if this is first time play this contest
|
||||
val reward = contest.contestEntryReward
|
||||
val rewardValue: Array<kotlin.String?> =
|
||||
reward.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
|
||||
contestEntryRewardType = rewardValue[0]!!.toInt()
|
||||
contestEntryRewardValue = rewardValue[1]!!.toInt()
|
||||
contestEntryRewardString1 = rewardValue[2]
|
||||
contestEntryRewardString2 = rewardValue[3]
|
||||
}
|
||||
}
|
||||
|
||||
// Only if this is the first time reach this value
|
||||
val previousValue = progress.stream().limit((progress.size - 1).toLong())
|
||||
.mapToInt { it.scores }.sum()
|
||||
val currentValue = progress.stream().mapToInt { it.scores }.sum()
|
||||
|
||||
// Bronze Reward
|
||||
val bronze = updateReward(
|
||||
currentValue,
|
||||
previousValue,
|
||||
contest.bronzeBorders,
|
||||
contest.bronzeContestReward
|
||||
)
|
||||
if (bronze != null) {
|
||||
contestRewardType[0] = bronze.get("type")
|
||||
contestRewardValue[0] = bronze.get("value")
|
||||
contestRewardString1[0] = bronze.get("string1")
|
||||
contestRewardString2[2] = bronze.get("string2")
|
||||
}
|
||||
|
||||
// Silver Reward
|
||||
val silver = updateReward(
|
||||
currentValue,
|
||||
previousValue,
|
||||
contest.sliverBorders,
|
||||
contest.sliverContestReward
|
||||
)
|
||||
if (silver != null) {
|
||||
contestRewardType[1] = silver.get("type")
|
||||
contestRewardValue[1] = silver.get("value")
|
||||
contestRewardString1[1] = silver.get("string1")
|
||||
contestRewardString2[2] = silver.get("string2")
|
||||
}
|
||||
|
||||
// Gold Reward
|
||||
val gold = updateReward(
|
||||
currentValue,
|
||||
previousValue,
|
||||
contest.goldBorders,
|
||||
contest.goldContestReward
|
||||
)
|
||||
if (gold != null) {
|
||||
contestRewardType[2] = gold.get("type")
|
||||
contestRewardValue[2] = gold.get("value")
|
||||
contestRewardString1[2] = gold.get("string1")
|
||||
contestRewardString2[2] = gold.get("string2")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.pvRecord.save(record)
|
||||
db.playLog.save(log)
|
||||
db.gameSession.save(session)
|
||||
|
||||
|
||||
return StageResultResponse(
|
||||
ChallengeKind.UNDEFINED.value,
|
||||
session.oldLevelNumber,
|
||||
session.oldLevelExp,
|
||||
session.levelNumber,
|
||||
session.levelExp,
|
||||
profile.levelTitle,
|
||||
profile.plateEffectId,
|
||||
profile.plateId,
|
||||
session.vp,
|
||||
0,
|
||||
request.cr_cid,
|
||||
request.cr_tv,
|
||||
contestSpecifier,
|
||||
String.join(",", *contestRewardType),
|
||||
String.join(",", *contestRewardValue),
|
||||
String.join(",", *contestRewardString1),
|
||||
String.join(",", *contestRewardString2),
|
||||
contestEntryRewardType,
|
||||
contestEntryRewardValue,
|
||||
contestEntryRewardString1,
|
||||
contestEntryRewardString2,
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
"-1,-1,-1,-1,-1",
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
"xxx,xxx,xxx,xxx,xxx",
|
||||
0,
|
||||
LocalDateTime.now(),
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
Const.NULL_QUEST,
|
||||
Const.NULL_QUEST,
|
||||
Const.NULL_QUEST,
|
||||
Const.NULL_QUEST,
|
||||
Const.NULL_QUEST,
|
||||
"-1,-1,-1,-1,-1",
|
||||
"-1,-1,-1,-1,-1",
|
||||
"-1,-1,-1,-1,-1"
|
||||
)
|
||||
} else {
|
||||
return StageResultResponse()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLog(request: StageResultRequest, profile: PlayerProfile, i: Int): PlayLog {
|
||||
return PlayLog(
|
||||
profile,
|
||||
request.stg_ply_pv_id[i],
|
||||
Difficulty.fromValue(request.stg_difficulty[i]),
|
||||
Edition.fromValue(request.stg_edtn[i]),
|
||||
request.stg_scrpt_ver[i],
|
||||
request.stg_score[i],
|
||||
ChallengeKind.fromValue(request.stg_chllng_kind[i]),
|
||||
request.stg_chllng_result[i],
|
||||
ClearResult.fromValue(request.stg_clr_kind[i]),
|
||||
request.stg_vcld_pts[i],
|
||||
request.stg_cool_cnt[i],
|
||||
request.stg_cool_pct[i],
|
||||
request.stg_fine_cnt[i],
|
||||
request.stg_fine_pct[i],
|
||||
request.stg_safe_cnt[i],
|
||||
request.stg_safe_pct[i],
|
||||
request.stg_sad_cnt[i],
|
||||
request.stg_sad_pct[i],
|
||||
request.stg_wt_wg_cnt[i],
|
||||
request.stg_wt_wg_pct[i],
|
||||
request.stg_max_cmb[i],
|
||||
request.stg_chance_tm[i],
|
||||
request.stg_sm_hl[i],
|
||||
request.stg_atn_pnt[i],
|
||||
request.stg_skin_id[i],
|
||||
request.stg_btn_se[i],
|
||||
request.stg_btn_se_vol[i],
|
||||
request.stg_sld_se[i],
|
||||
request.stg_chn_sld_se[i],
|
||||
request.stg_sldr_tch_se[i],
|
||||
slice(request.stg_mdl_id, 3, i),
|
||||
request.stg_cpt_rslt[i],
|
||||
request.stg_sld_scr[i],
|
||||
request.stg_vcl_chg[i],
|
||||
slice(request.stg_c_itm_id, 12, i),
|
||||
slice(request.stg_rgo, 3, i),
|
||||
request.stg_ss_num[i],
|
||||
request.time_stamp.toLocalDateTime()
|
||||
)
|
||||
}
|
||||
|
||||
fun slice(arr: IntArray, length: Int, offset: Int): kotlin.String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
for (i in length * offset..<length * (offset + 1)) {
|
||||
sb.append(arr[i]).append(",")
|
||||
}
|
||||
|
||||
sb.deleteCharAt(sb.length - 1)
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
private fun getContestProgress(arr: Array<kotlin.String?>): MutableList<ContestProgress> {
|
||||
val result: MutableList<ContestProgress> = LinkedList<ContestProgress>()
|
||||
var i = 0
|
||||
while (i < arr.size) {
|
||||
if (arr[i] != "-1") {
|
||||
result.add(
|
||||
ContestProgress(
|
||||
arr[i]!!.toInt(),
|
||||
arr[i + 1]!!.toInt(),
|
||||
arr[i + 2]!!.toInt(),
|
||||
arr[i + 3]!!.toInt(),
|
||||
arr[i + 4]!!.toInt(),
|
||||
arr[i + 5]!!.toInt()
|
||||
)
|
||||
)
|
||||
}
|
||||
i += 6
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun getContestSpecifier(progresses: MutableList<ContestProgress>): kotlin.String {
|
||||
val result: MutableList<kotlin.String?> = LinkedList<kotlin.String?>()
|
||||
for (x in progresses) {
|
||||
result.add(x.hardness.toString())
|
||||
result.add(x.edition.toString())
|
||||
result.add(x.stars.toString())
|
||||
result.add(x.scores.toString())
|
||||
result.add(x.version.toString())
|
||||
}
|
||||
while (result.size < 60) {
|
||||
result.add("-1")
|
||||
}
|
||||
return String.join(",", result)
|
||||
}
|
||||
|
||||
private fun updateReward(
|
||||
currentValue: Int,
|
||||
previousValue: Int,
|
||||
borders: Int,
|
||||
reward: kotlin.String?
|
||||
): MutableMap<kotlin.String?, kotlin.String?>? {
|
||||
if (borders in (previousValue + 1)..<currentValue) {
|
||||
if (StringUtils.isNotBlank(reward)) {
|
||||
val rewardValue: Array<kotlin.String?> =
|
||||
reward!!.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
val result: MutableMap<kotlin.String?, kotlin.String?> = HashMap<kotlin.String?, kotlin.String?>()
|
||||
when (rewardValue[0]) {
|
||||
"-1" -> return null
|
||||
"0" -> {
|
||||
result["type"] = rewardValue[0]
|
||||
result["value"] = rewardValue[1]
|
||||
result["string1"] = "***"
|
||||
result["string2"] = "***"
|
||||
}
|
||||
|
||||
"1" -> {
|
||||
if (db.inventory.findByPdIdAndTypeAndValue(currentProfile!!, "SKIN", rewardValue[1]!!)
|
||||
.isPresent
|
||||
) {
|
||||
result["type"] = "-1"
|
||||
result["value"] = "-1"
|
||||
result["string1"] = "***"
|
||||
result["string2"] = "***"
|
||||
} else {
|
||||
db.inventory.save(
|
||||
PlayerInventory(
|
||||
currentProfile!!,
|
||||
rewardValue[1]!!,
|
||||
"SKIN"
|
||||
)
|
||||
)
|
||||
result.put("type", rewardValue[0])
|
||||
result.put("value", rewardValue[1])
|
||||
result.put("string1", rewardValue[2])
|
||||
result.put("string2", rewardValue[3])
|
||||
}
|
||||
}
|
||||
|
||||
"2" -> {
|
||||
if (db.inventory.findByPdIdAndTypeAndValue(currentProfile!!, "PLATE", rewardValue[1]!!)
|
||||
.isPresent
|
||||
) {
|
||||
result.put("type", "-1")
|
||||
result.put("value", "-1")
|
||||
result.put("string1", "***")
|
||||
result.put("string2", "***")
|
||||
} else {
|
||||
db.inventory.save(
|
||||
PlayerInventory(
|
||||
currentProfile!!,
|
||||
rewardValue[1]!!,
|
||||
"PLATE"
|
||||
)
|
||||
)
|
||||
result.put("type", rewardValue[0])
|
||||
result.put("value", rewardValue[1])
|
||||
result.put("string1", rewardValue[2])
|
||||
result.put("string2", rewardValue[3])
|
||||
}
|
||||
}
|
||||
|
||||
"3" -> {
|
||||
if (db.customize.findByPdIdAndCustomizeId(currentProfile!!, rewardValue[1]!!.toInt())
|
||||
.isPresent
|
||||
) {
|
||||
result.put("type", "-1")
|
||||
result.put("value", "-1")
|
||||
result.put("string1", "***")
|
||||
result.put("string2", "***")
|
||||
} else {
|
||||
db.customize.save(
|
||||
PlayerCustomize(
|
||||
currentProfile!!,
|
||||
rewardValue[1]!!.toInt()
|
||||
)
|
||||
)
|
||||
result.put("type", rewardValue[0])
|
||||
result.put("value", rewardValue[1])
|
||||
result.put("string1", rewardValue[2])
|
||||
result.put("string2", rewardValue[3])
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
|
||||
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageStartRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class StageStartHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(StageResultHandler.class);
|
||||
private final GameSessionRepository gameSessionRepository;
|
||||
private final PlayerProfileService playerProfileService;
|
||||
|
||||
public String handle(StageStartRequest request) {
|
||||
if (request.getPd_id() != -1) {
|
||||
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
|
||||
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
|
||||
|
||||
int[] stageArr = request.getStg_ply_pv_id();
|
||||
int stageIndex = 0;
|
||||
if(stageArr[0] != -1) {
|
||||
stageIndex = 0;
|
||||
}
|
||||
if(stageArr[1] != -1) {
|
||||
stageIndex = 1;
|
||||
}
|
||||
if(stageArr[2] != -1) {
|
||||
stageIndex = 2;
|
||||
}
|
||||
if(stageArr[3] != -1) {
|
||||
stageIndex = 3;
|
||||
}
|
||||
session.setStageIndex(stageIndex);
|
||||
gameSessionRepository.save(session);
|
||||
}
|
||||
|
||||
BaseResponse response = new BaseResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok");
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame
|
||||
|
||||
import ext.emptyMap
|
||||
import icu.samnyan.aqua.sega.diva.DivaRepos
|
||||
import icu.samnyan.aqua.sega.diva.model.StageStartRequest
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
class StageStartHandler(val db: DivaRepos) {
|
||||
fun handle(request: StageStartRequest): Any {
|
||||
if (request.pd_id != -1L) {
|
||||
val (_, session) = db.session(request.pd_id)
|
||||
|
||||
val stageArr = request.stg_ply_pv_id
|
||||
var stageIndex = 0
|
||||
if (stageArr[0] != -1) {
|
||||
stageIndex = 0
|
||||
}
|
||||
if (stageArr[1] != -1) {
|
||||
stageIndex = 1
|
||||
}
|
||||
if (stageArr[2] != -1) {
|
||||
stageIndex = 2
|
||||
}
|
||||
if (stageArr[3] != -1) {
|
||||
stageIndex = 3
|
||||
}
|
||||
session.stageIndex = stageIndex
|
||||
db.gameSession.save(session)
|
||||
}
|
||||
|
||||
return emptyMap
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package icu.samnyan.aqua.sega.diva.handler.ingame;
|
||||
|
||||
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerScreenShotRepository;
|
||||
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
|
||||
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.diva.model.request.ingame.StoreSsRequest;
|
||||
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerScreenShot;
|
||||
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import static icu.samnyan.aqua.sega.diva.util.DivaStringUtils.arrToCsv;
|
||||
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class StoreSsHandler extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(StoreSsHandler.class);
|
||||
private final PlayerProfileService playerProfileService;
|
||||
private final PlayerScreenShotRepository screenShotRepository;
|
||||
|
||||
public String handle(StoreSsRequest request, MultipartFile file) {
|
||||
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
|
||||
|
||||
BaseResponse response;
|
||||
try {
|
||||
String filename = request.getPd_id() + "-" + LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + ".jpg";
|
||||
Files.write(Paths.get("data/" + filename), file.getBytes());
|
||||
|
||||
PlayerScreenShot ss = new PlayerScreenShot(
|
||||
profile,
|
||||
filename,
|
||||
request.getPd_id(),
|
||||
arrToCsv(request.getSs_mdl_id()),
|
||||
arrToCsv(request.getSs_c_itm_id())
|
||||
);
|
||||
screenShotRepository.save(ss);
|
||||
|
||||
response = new BaseResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"ok");
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error("Screenshot save failed", e);
|
||||
|
||||
response = new BaseResponse(
|
||||
request.getCmd(),
|
||||
request.getReq_id(),
|
||||
"0");
|
||||
}
|
||||
|
||||
String resp = this.build(mapper.toMap(response));
|
||||
logger.info("Response: {}", resp);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user