[O] Everything can be special

This commit is contained in:
Azalea
2024-12-26 17:41:05 -05:00
parent c275c54fca
commit 88863d8d01
3 changed files with 47 additions and 41 deletions

View File

@@ -58,7 +58,7 @@ class ChusanServletController(
val mapper: StringMapper, val mapper: StringMapper,
val db: Chu3Repos, val db: Chu3Repos,
val us: AquaUserServices, val us: AquaUserServices,
val versionHelper: Chu3VersionHelper, val versionHelper: ChusanVersionHelper,
) { ) {
val logger = LoggerFactory.getLogger(ChusanServletController::class.java) val logger = LoggerFactory.getLogger(ChusanServletController::class.java)
@@ -88,9 +88,7 @@ class ChusanServletController(
// Fun! // Fun!
val initH = mutableMapOf<String, SpecialHandler>() val initH = mutableMapOf<String, SpecialHandler>()
infix fun String.special(fn: SpecialHandler) = initH.set(this.lowercase(), fn) infix operator fun String.invoke(fn: SpecialHandler) = initH.set(this.lowercase(), fn)
operator fun String.invoke(fn: (Map<String, Any>) -> Any) = this special { fn(data) }
infix fun String.user(fn: (Map<String, Any>, Long) -> Any) = this { fn(it, parsing { it["userId"]!!.long }) }
infix fun String.static(fn: () -> Any) = mapper.write(fn()).let { resp -> this { resp } } infix fun String.static(fn: () -> Any) = mapper.write(fn()).let { resp -> this { resp } }
val meow = init() val meow = init()
@@ -149,19 +147,19 @@ class ChusanServletController(
fun ChusanServletController.init() { fun ChusanServletController.init() {
// Stub handlers // Stub handlers
"GetGameRanking" { """{"type":"${it["type"]}","length":"0","gameRankingList":[]}""" } "GetGameRanking" { """{"type":"${data["type"]}","length":"0","gameRankingList":[]}""" }
"GetGameIdlist" { """{"type":"${it["type"]}","length":"0","gameIdlistList":[]}""" } "GetGameIdlist" { """{"type":"${data["type"]}","length":"0","gameIdlistList":[]}""" }
"GetTeamCourseSetting" { """{"userId":"${it["userId"]}","length":"0","nextIndex":"0","teamCourseSettingList":[]}""" } "GetTeamCourseSetting" { """{"userId":"${data["userId"]}","length":"0","nextIndex":"0","teamCourseSettingList":[]}""" }
"GetTeamCourseRule" { """{"userId":"${it["userId"]}","length":"0","nextIndex":"0","teamCourseRuleList":[]}""" } "GetTeamCourseRule" { """{"userId":"${data["userId"]}","length":"0","nextIndex":"0","teamCourseRuleList":[]}""" }
"GetUserCtoCPlay" { """{"userId":"${it["userId"]}","orderBy":"0","count":"0","userCtoCPlayList":[]}""" } "GetUserCtoCPlay" { """{"userId":"${data["userId"]}","orderBy":"0","count":"0","userCtoCPlayList":[]}""" }
"GetUserRivalMusic" { """{"userId":"${it["userId"]}","rivalId":"0","length":"0","nextIndex":"0","userRivalMusicList":[]}""" } "GetUserRivalMusic" { """{"userId":"${data["userId"]}","rivalId":"0","length":"0","nextIndex":"0","userRivalMusicList":[]}""" }
"GetUserRivalData" { """{"userId":"${it["userId"]}","length":"0","userRivalData":[]}""" } "GetUserRivalData" { """{"userId":"${data["userId"]}","length":"0","userRivalData":[]}""" }
"GetUserRegion" { """{"userId":"${it["userId"]}","length":"0","userRegionList":[]}""" } "GetUserRegion" { """{"userId":"${data["userId"]}","length":"0","userRegionList":[]}""" }
"GetUserPrintedCard" { """{"userId":"${it["userId"]}","length":0,"nextIndex":-1,"userPrintedCardList":[]}""" } "GetUserPrintedCard" { """{"userId":"${data["userId"]}","length":0,"nextIndex":-1,"userPrintedCardList":[]}""" }
"GetUserSymbolChatSetting" { """{"userId":"${it["userId"]}","length":"0","symbolChatInfoList":[]}""" } "GetUserSymbolChatSetting" { """{"userId":"${data["userId"]}","length":"0","symbolChatInfoList":[]}""" }
"GetUserNetBattleData" { """{"userId":"${it["userId"]}","userNetBattleData":{"recentNBSelectMusicList":[],"recentNBMusicList":[]}}""" } "GetUserNetBattleData" { """{"userId":"${data["userId"]}","userNetBattleData":{"recentNBSelectMusicList":[],"recentNBMusicList":[]}}""" }
"GetUserNetBattleRankingInfo" { """{"userId":"${it["userId"]}","length":"0","userNetBattleRankingInfoList":{}}""" } "GetUserNetBattleRankingInfo" { """{"userId":"${data["userId"]}","length":"0","userNetBattleRankingInfoList":{}}""" }
"CMUpsertUserPrint" { """{"returnCode":1,"orderId":"0","serialId":"FAKECARDIMAG12345678","apiName":"CMUpsertUserPrintApi"}""" } "CMUpsertUserPrint" { """{"returnCode":1,"orderId":"0","serialId":"FAKECARDIMAG12345678","apiName":"CMUpsertUserPrintApi"}""" }
"CMUpsertUserPrintlog" { """{"returnCode":1,"orderId":"0","serialId":"FAKECARDIMAG12345678","apiName":"CMUpsertUserPrintlogApi"}""" } "CMUpsertUserPrintlog" { """{"returnCode":1,"orderId":"0","serialId":"FAKECARDIMAG12345678","apiName":"CMUpsertUserPrintlogApi"}""" }
@@ -171,45 +169,48 @@ fun ChusanServletController.init() {
"GetMatchingState" { """{"matchingWaitState":{"restMSec":"30000","pollingInterval":"10","matchingMemberInfoList":[],"isFinish":"true"}}""" } "GetMatchingState" { """{"matchingWaitState":{"restMSec":"30000","pollingInterval":"10","matchingMemberInfoList":[],"isFinish":"true"}}""" }
// User handlers // User handlers
"GetUserData" user { _, u -> "GetUserData" {
val user = db.userData.findByCard_ExtId(u)() ?: (400 - "User not found") val user = db.userData.findByCard_ExtId(uid)() ?: (400 - "User not found")
mapOf("userId" to u, "userData" to user) mapOf("userId" to uid, "userData" to user)
} }
"GetUserOption" user { _, u -> "GetUserOption" {
val userGameOption = db.userGameOption.findSingleByUser_Card_ExtId(u)() ?: (400 - "User not found") val userGameOption = db.userGameOption.findSingleByUser_Card_ExtId(uid)() ?: (400 - "User not found")
mapOf("userId" to u, "userGameOption" to userGameOption) mapOf("userId" to uid, "userGameOption" to userGameOption)
} }
"GetUserActivity" user { req, u -> "GetUserActivity" {
val kind = parsing { req["kind"]!!.int } val kind = parsing { data["kind"]!!.int }
val a = db.userActivity.findAllByUser_Card_ExtIdAndKind(u, kind).sortedBy { -it.sortNumber } val a = db.userActivity.findAllByUser_Card_ExtIdAndKind(uid, kind).sortedBy { -it.sortNumber }
mapOf("userId" to u, "length" to a.size, "kind" to kind, "userActivityList" to a) mapOf("userId" to uid, "length" to a.size, "kind" to kind, "userActivityList" to a)
} }
"GetUserCharge" user { _, u -> db.userCharge.findByUser_Card_ExtId(u) "GetUserCharge" {
.let { mapOf("userId" to u, "length" to it.size, "userChargeList" to it) } val lst = db.userCharge.findByUser_Card_ExtId(uid)
mapOf("userId" to uid, "length" to lst.size, "userChargeList" to lst)
} }
"GetUserDuel" user { _, u -> db.userDuel.findByUser_Card_ExtId(u) "GetUserDuel" {
.let { mapOf("userId" to u, "length" to it.size, "userDuelList" to it) } val lst = db.userDuel.findByUser_Card_ExtId(uid)
mapOf("userId" to uid, "length" to lst.size, "userDuelList" to lst)
} }
// Other handlers // Other handlers
"GetGameGachaCardById" { db.gameGachaCard.findAllByGachaId(parsing { it["gachaId"]!!.int }).let { "GetGameGachaCardById" { db.gameGachaCard.findAllByGachaId(parsing { data["gachaId"]!!.int }).let {
mapOf("gachaId" to it.size, "length" to it.size, "isPickup" to false, "gameGachaCardList" to it, "emissionList" to empty, "afterCalcList" to empty) mapOf("gachaId" to it.size, "length" to it.size, "isPickup" to false, "gameGachaCardList" to it,
"emissionList" to empty, "afterCalcList" to empty)
} } } }
"GetUserCMission" user { req, u -> "GetUserCMission" {
parsing { UserCMissionResp().apply { parsing { UserCMissionResp().apply {
userId = u userId = uid
missionId = req["missionId"]!!.int missionId = data["missionId"]!!.int
} }.apply { } }.apply {
db.userCMission.findByUser_Card_ExtIdAndMissionId(u, missionId)()?.let { db.userCMission.findByUser_Card_ExtIdAndMissionId(uid, missionId)()?.let {
point = it.point point = it.point
userCMissionProgressList = db.userCMissionProgress.findByUser_Card_ExtIdAndMissionId(u, missionId) userCMissionProgressList = db.userCMissionProgress.findByUser_Card_ExtIdAndMissionId(uid, missionId)
} }
} }
} }
// Game settings // Game settings
"GetGameSetting" special { "GetGameSetting" {
val version = data["version"].toString() val version = data["version"].toString()
// Fixed reboot time triggers chusan maintenance lockout, so let's try minime method which sets it dynamically // Fixed reboot time triggers chusan maintenance lockout, so let's try minime method which sets it dynamically
@@ -247,6 +248,11 @@ fun ChusanServletController.init() {
) )
} }
"GetUserCardPrintError" {
}
// Static // Static
"GetGameEvent" static { db.gameEvent.findByEnable(true).let { mapOf("type" to 1, "length" to it.size, "gameEventList" to it) } } "GetGameEvent" static { db.gameEvent.findByEnable(true).let { mapOf("type" to 1, "length" to it.size, "gameEventList" to it) } }
"GetGameCharge" static { db.gameCharge.findAll().let { mapOf("length" to it.size, "gameChargeList" to it) } } "GetGameCharge" static { db.gameCharge.findAll().let { mapOf("length" to it.size, "gameChargeList" to it) } }

View File

@@ -6,7 +6,7 @@ import org.springframework.stereotype.Component
@Component @Component
class Chu3VersionHelper(val db: Chu3Repos) { class ChusanVersionHelper(val db: Chu3Repos) {
val log = logger() val log = logger()
// Cache of <client id : version> // Cache of <client id : version>

View File

@@ -1,7 +1,7 @@
package icu.samnyan.aqua.sega.chusan.handler package icu.samnyan.aqua.sega.chusan.handler
import ext.* import ext.*
import icu.samnyan.aqua.sega.chusan.Chu3VersionHelper import icu.samnyan.aqua.sega.chusan.ChusanVersionHelper
import icu.samnyan.aqua.sega.chusan.model.Chu3Repos import icu.samnyan.aqua.sega.chusan.model.Chu3Repos
import icu.samnyan.aqua.sega.chusan.model.request.UpsertUserAll import icu.samnyan.aqua.sega.chusan.model.request.UpsertUserAll
import icu.samnyan.aqua.sega.chusan.model.userdata.UserCMission import icu.samnyan.aqua.sega.chusan.model.userdata.UserCMission
@@ -28,7 +28,7 @@ class UpsertUserAllHandler(
val mapper: StringMapper, val mapper: StringMapper,
val rp: Chu3Repos, val rp: Chu3Repos,
val cardRepo: CardRepository, val cardRepo: CardRepository,
val versionHelper: Chu3VersionHelper, val versionHelper: ChusanVersionHelper,
) : BaseHandler { ) : BaseHandler {
val logger = logger() val logger = logger()