diff --git a/src/main/java/icu/samnyan/aqua/sega/chusan/ChusanServletController.kt b/src/main/java/icu/samnyan/aqua/sega/chusan/ChusanServletController.kt index 8feaa933..da7b6a5f 100644 --- a/src/main/java/icu/samnyan/aqua/sega/chusan/ChusanServletController.kt +++ b/src/main/java/icu/samnyan/aqua/sega/chusan/ChusanServletController.kt @@ -192,16 +192,17 @@ fun ChusanServletController.init() { val a = db.userActivity.findAllByUser_Card_ExtIdAndKind(uid, kind).sortedBy { -it.sortNumber } mapOf("userId" to uid, "length" to a.size, "kind" to kind, "userActivityList" to a) } + "GetUserCharge" { val lst = db.userCharge.findByUser_Card_ExtId(uid) mapOf("userId" to uid, "length" to lst.size, "userChargeList" to lst) } + "GetUserDuel" { val lst = db.userDuel.findByUser_Card_ExtId(uid) mapOf("userId" to uid, "length" to lst.size, "userDuelList" to lst) } - // Other handlers "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) @@ -210,7 +211,7 @@ fun ChusanServletController.init() { "GetUserCMission" { parsing { UserCMissionResp().apply { userId = uid - missionId = data["missionId"]!!.int + missionId = parsing { data["missionId"]!!.int } } }.apply { db.userCMission.findByUser_Card_ExtIdAndMissionId(uid, missionId)()?.let { point = it.point @@ -260,6 +261,33 @@ fun ChusanServletController.init() { mapOf("userId" to uid, "kind" to kind, "length" to lst.size, "nextIndex" to -1, "userFavoriteItemList" to lst) } + + val userPreviewKeys = ("lastLoginDate,userName,reincarnationNum,level,exp,playerRating,lastGameId,lastRomVersion," + + "lastDataVersion,lastPlayDate,trophyId,classEmblemMedal,classEmblemBase,battleRankId").split(',').toSet() + + "GetUserPreview" { + val user = db.userData.findByCard_ExtId(uid)() ?: (400 - "User not found") + val chara = db.userCharacter.findByUserAndCharacterId(user, user.characterId) + val option = db.userGameOption.findSingleByUser(user)() + val userDict = mapper.toMap(mapper.write(user)).filterKeys { it in userPreviewKeys } + + mapOf( + "userId" to uid, "isLogin" to false, "emoneyBrandId" to 0, + "userCharacter" to chara, + "playerLevel" to option?.playerLevel, + "rating" to option?.rating, + "headphone" to option?.headphone, + "chargeState" to 1, "userNameEx" to "", "banState" to 0, + ) + userDict + } + + "GetUserMapArea" { + val maps = parsing { data["mapAreaIdList"] as List> } + .mapNotNull { it["mapAreaId"]?.toIntOrNull() } + + mapOf("userId" to uid, "userMapAreaList" to db.userMap.findAllByUserCardExtIdAndMapAreaIdIn(uid, maps)) + } + // Game settings "GetGameSetting" { val version = data["version"].toString() diff --git a/src/main/java/icu/samnyan/aqua/sega/chusan/handler/GetGameMapAreaConditionHandler.kt b/src/main/java/icu/samnyan/aqua/sega/chusan/handler/GetGameMapAreaConditionHandler.kt deleted file mode 100644 index e2d4ea6c..00000000 --- a/src/main/java/icu/samnyan/aqua/sega/chusan/handler/GetGameMapAreaConditionHandler.kt +++ /dev/null @@ -1,56 +0,0 @@ -package icu.samnyan.aqua.sega.chusan.handler - -import ext.logger -import icu.samnyan.aqua.sega.general.BaseHandler -import icu.samnyan.aqua.sega.util.jackson.StringMapper -import org.springframework.stereotype.Component - -@Component("ChusanGetGameMapAreaConditionHandler") -class GetGameMapAreaConditionHandler(val mapper: StringMapper) : BaseHandler { - override fun handle(request: Map): String { - val cond = listOf( - mapOf("mapAreaId" to 2206201, "mapAreaConditionList" to listOf( - mapOf("type" to 3, "conditionId" to 6832, "logicalOpe" to 1) - )), - mapOf("mapAreaId" to 2206203, "mapAreaConditionList" to listOf( - mapOf("type" to 3, "conditionId" to 6833, "logicalOpe" to 1) - )), - mapOf("mapAreaId" to 2206204, "mapAreaConditionList" to listOf( - mapOf("type" to 3, "conditionId" to 6834, "logicalOpe" to 1), - mapOf("type" to 3, "conditionId" to 6835, "logicalOpe" to 1) - )), - mapOf("mapAreaId" to 2206205, "mapAreaConditionList" to listOf( - mapOf("type" to 3, "conditionId" to 6837, "logicalOpe" to 1) - )), - mapOf("mapAreaId" to 2206206, "mapAreaConditionList" to listOf( - mapOf("type" to 3, "conditionId" to 6838, "logicalOpe" to 1) - )), - mapOf("mapAreaId" to 2206207, "mapAreaConditionList" to listOf( - mapOf("type" to 2, "conditionId" to 2206201, "logicalOpe" to 1), - mapOf("type" to 2, "conditionId" to 2206202, "logicalOpe" to 1), - mapOf("type" to 2, "conditionId" to 2206203, "logicalOpe" to 1), - mapOf("type" to 2, "conditionId" to 2206204, "logicalOpe" to 1), - mapOf("type" to 2, "conditionId" to 2206205, "logicalOpe" to 1), - mapOf("type" to 2, "conditionId" to 2206206, "logicalOpe" to 1) - )), - mapOf("mapAreaId" to 3229301, "mapAreaConditionList" to listOf( - mapOf("type" to 1, "conditionId" to 3020701, "logicalOpe" to 2) - )), - mapOf("mapAreaId" to 3229302, "mapAreaConditionList" to listOf( - mapOf("type" to 1, "conditionId" to 3020701, "logicalOpe" to 1) - )) - ) - - val resultMap: MutableMap = linkedMapOf( - "gameMapAreaConditionList" to cond - ) - - val json = mapper.write(resultMap) - logger.info("Response: $json") - return json - } - - companion object { - private val logger = logger() - } -} diff --git a/src/main/java/icu/samnyan/aqua/sega/chusan/handler/GetUserPreviewHandler.java b/src/main/java/icu/samnyan/aqua/sega/chusan/handler/GetUserPreviewHandler.java deleted file mode 100644 index a56bcfba..00000000 --- a/src/main/java/icu/samnyan/aqua/sega/chusan/handler/GetUserPreviewHandler.java +++ /dev/null @@ -1,104 +0,0 @@ -package icu.samnyan.aqua.sega.chusan.handler; - -import com.fasterxml.jackson.core.JsonProcessingException; -import icu.samnyan.aqua.sega.general.BaseHandler; -import icu.samnyan.aqua.sega.chusan.model.response.GetUserPreviewResp; -import icu.samnyan.aqua.sega.chusan.model.userdata.UserCharacter; -import icu.samnyan.aqua.sega.chusan.model.userdata.Chu3UserData; -import icu.samnyan.aqua.sega.chusan.model.userdata.UserGameOption; -import icu.samnyan.aqua.sega.chusan.service.UserCharacterService; -import icu.samnyan.aqua.sega.chusan.service.UserDataService; -import icu.samnyan.aqua.sega.chusan.service.UserGameOptionService; -import icu.samnyan.aqua.sega.general.service.ClientSettingService; -import icu.samnyan.aqua.sega.util.jackson.StringMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.Map; -import java.util.Optional; - -/** - * The handler for loading basic profile information. - *

- * return null if no profile exist - * - * @author samnyan (privateamusement@protonmail.com) - */ -@Component("ChusanGetUserPreviewHandler") -public class GetUserPreviewHandler implements BaseHandler { - - private static final Logger logger = LoggerFactory.getLogger(GetUserPreviewHandler.class); - - private final StringMapper mapper; - - private final UserDataService userDataService; - private final UserCharacterService userCharacterService; - private final UserGameOptionService userGameOptionService; - - @Autowired - public GetUserPreviewHandler(StringMapper mapper, - ClientSettingService clientSettingService, UserDataService userDataService, - UserCharacterService userCharacterService, - UserGameOptionService userGameOptionService - ) { - this.mapper = mapper; - this.userDataService = userDataService; - this.userCharacterService = userCharacterService; - this.userGameOptionService = userGameOptionService; - } - - @Override - public String handle(Map request) throws JsonProcessingException { - String userId = (String) request.get("userId"); - - Optional userData = userDataService.getUserByExtId(userId); - - if (userData.isEmpty()) { - return null; - } - - Chu3UserData user = userData.get(); - - GetUserPreviewResp resp = new GetUserPreviewResp(); - resp.setUserId(userId); - resp.setLogin(false); - resp.setLastLoginDate(user.getLastPlayDate()); // Chusan seems doesn't save LastLoginDate, so use LastPlayDate instead - resp.setUserName(user.getUserName()); - resp.setReincarnationNum(user.getReincarnationNum()); - resp.setLevel(user.getLevel()); - resp.setExp(user.getExp()); - resp.setPlayerRating(user.getPlayerRating()); - resp.setLastGameId(user.getLastGameId()); - - resp.setLastRomVersion(user.getLastRomVersion()); - resp.setLastDataVersion(user.getLastDataVersion()); - - resp.setLastPlayDate(user.getLastPlayDate()); - resp.setEmoneyBrandId(0); - resp.setTrophyId(user.getTrophyId()); - - Optional userCharacterOptional = userCharacterService.getByUserAndCharacterId(user, user.getCharacterId()); - userCharacterOptional.ifPresent(resp::setUserCharacter); - - Optional userGameOptionOptional = userGameOptionService.getByUser(user); - userGameOptionOptional.ifPresent(userGameOption -> { - resp.setPlayerLevel(userGameOption.getPlayerLevel()); - resp.setRating(userGameOption.getRating()); - resp.setHeadphone(userGameOption.getHeadphone()); - }); - - resp.setChargeState(1); - resp.setUserNameEx(""); - resp.setBanState(0); - resp.setClassEmblemMedal(user.getClassEmblemMedal()); - resp.setClassEmblemBase(user.getClassEmblemBase()); - resp.setBattleRankId(user.getBattleRankId()); - - String json = mapper.write(resp); - logger.info("Response: " + json); - return json; - - } -}