mirror of https://github.com/hykilpikonna/AquaDX
[O] Merge more apis
parent
c5b40f64e4
commit
64827ec0fc
|
@ -2,6 +2,9 @@ package icu.samnyan.aqua.sega.maimai2
|
||||||
|
|
||||||
import ext.*
|
import ext.*
|
||||||
import icu.samnyan.aqua.sega.general.PagedHandler
|
import icu.samnyan.aqua.sega.general.PagedHandler
|
||||||
|
import icu.samnyan.aqua.sega.maimai2.model.response.data.UserRivalMusic
|
||||||
|
import icu.samnyan.aqua.sega.maimai2.model.response.data.UserRivalMusicDetail
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
fun Maimai2ServletController.initApis() {
|
fun Maimai2ServletController.initApis() {
|
||||||
// Used because maimai does not actually require paging implementation
|
// Used because maimai does not actually require paging implementation
|
||||||
|
@ -72,6 +75,13 @@ fun Maimai2ServletController.initApis() {
|
||||||
) }
|
) }
|
||||||
|
|
||||||
"CreateToken" static { """{"Bearer":"meow"}""" }
|
"CreateToken" static { """{"Bearer":"meow"}""" }
|
||||||
|
"UserLogin" static { mapOf(
|
||||||
|
"returnCode" to 1, "loginCount" to 1,
|
||||||
|
"lastLoginDate" to "2020-01-01 00:00:00.0",
|
||||||
|
"consecutiveLoginCount" to 0, "loginId" to 1,
|
||||||
|
"Bearer" to "meow", "bearer" to "meow"
|
||||||
|
) }
|
||||||
|
|
||||||
"CMUpsertUserPrintlog" static { """{"returnCode":1,"orderId":"0","serialId":"FAKECARDIMAG12345678"}""" }
|
"CMUpsertUserPrintlog" static { """{"returnCode":1,"orderId":"0","serialId":"FAKECARDIMAG12345678"}""" }
|
||||||
|
|
||||||
"CMGetSellingCard" static { db.gameSellingCard.findAll().let {
|
"CMGetSellingCard" static { db.gameSellingCard.findAll().let {
|
||||||
|
@ -138,6 +148,29 @@ fun Maimai2ServletController.initApis() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"GetUserRivalData" {
|
||||||
|
val rivalId = parsing { data["rivalId"]!!.long }
|
||||||
|
mapOf("userId" to uid, "userRivalData" to mapOf(
|
||||||
|
"rivalId" to rivalId,
|
||||||
|
"rivalName" to (db.userData.findByCardExtId(rivalId)()?.userName ?: "")
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
"GetUserRivalMusic" {
|
||||||
|
val rivalId = parsing { data["rivalId"]!!.long }
|
||||||
|
|
||||||
|
val lst = db.userMusicDetail.findByUserId(rivalId)
|
||||||
|
val res = lst.associate { it.musicId to UserRivalMusic(it.musicId, LinkedList()) }
|
||||||
|
|
||||||
|
lst.forEach {
|
||||||
|
res[it.musicId]!!.userRivalMusicDetailList.add(
|
||||||
|
UserRivalMusicDetail(it.level, it.achievement, it.deluxscoreMax)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
mapOf("userId" to uid, "rivalId" to rivalId, "nextIndex" to 0, "userRivalMusicList" to res.values)
|
||||||
|
}
|
||||||
|
|
||||||
// Empty List Handlers
|
// Empty List Handlers
|
||||||
"GetUserRecommendRateMusic" { mapOf(
|
"GetUserRecommendRateMusic" { mapOf(
|
||||||
"uid" to uid,
|
"uid" to uid,
|
||||||
|
|
|
@ -21,7 +21,6 @@ import kotlin.reflect.full.declaredMemberProperties
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(path = ["/g/mai2/Maimai2Servlet/", "/g/mai2/"])
|
@RequestMapping(path = ["/g/mai2/Maimai2Servlet/", "/g/mai2/"])
|
||||||
class Maimai2ServletController(
|
class Maimai2ServletController(
|
||||||
val userLogin: UserLoginHandler,
|
|
||||||
val upsertUserAll: UpsertUserAllHandler,
|
val upsertUserAll: UpsertUserAllHandler,
|
||||||
val getUserItem: GetUserItemHandler,
|
val getUserItem: GetUserItemHandler,
|
||||||
val getUserRating: GetUserRatingHandler,
|
val getUserRating: GetUserRatingHandler,
|
||||||
|
@ -31,7 +30,6 @@ class Maimai2ServletController(
|
||||||
val uploadUserPortrait: UploadUserPortraitHandler,
|
val uploadUserPortrait: UploadUserPortraitHandler,
|
||||||
val upsertUserPrint: UpsertUserPrintHandler,
|
val upsertUserPrint: UpsertUserPrintHandler,
|
||||||
val getUserFavoriteItem: GetUserFavoriteItemHandler,
|
val getUserFavoriteItem: GetUserFavoriteItemHandler,
|
||||||
val getUserRivalMusic: GetUserRivalMusicHandler,
|
|
||||||
val getUserCharacter: GetUserCharacterHandler,
|
val getUserCharacter: GetUserCharacterHandler,
|
||||||
val getGameRanking: GetGameRankingHandler,
|
val getGameRanking: GetGameRankingHandler,
|
||||||
val db: Mai2Repos
|
val db: Mai2Repos
|
||||||
|
@ -47,21 +45,17 @@ class Maimai2ServletController(
|
||||||
init { initApis() }
|
init { initApis() }
|
||||||
|
|
||||||
val endpointList = setOf("GetGameRankingApi","GetUserCharacterApi","GetUserItemApi","GetUserPortraitApi",
|
val endpointList = setOf("GetGameRankingApi","GetUserCharacterApi","GetUserItemApi","GetUserPortraitApi",
|
||||||
"GetUserRatingApi","UploadUserPhotoApi","UploadUserPlaylogApi","UploadUserPortraitApi","UserLoginApi",
|
"GetUserRatingApi","UploadUserPhotoApi","UploadUserPlaylogApi","UploadUserPortraitApi","UpsertUserAllApi",
|
||||||
"UserLogoutApi","UpsertUserAllApi","CMGetUserCardApi","CMGetUserCardPrintErrorApi","CMGetUserDataApi",
|
"CMGetUserCardApi","CMGetUserCardPrintErrorApi","CMGetUserDataApi","CMGetUserItemApi","CMUpsertUserPrintApi",
|
||||||
"CMGetUserItemApi","CMUpsertUserPrintApi","GetUserFavoriteItemApi","GetUserRivalMusicApi","GetUserScoreRankingApi",
|
"GetUserFavoriteItemApi")
|
||||||
"UpsertClientBookkeepingApi","UpsertClientSettingApi","UpsertClientTestmodeApi","UpsertClientUploadApi",
|
|
||||||
"Ping","RemoveTokenApi","CMLoginApi","CMLogoutApi","CMUpsertBuyCardApi").mut.also {
|
|
||||||
println(it.filter { it !in initH.keys }.toJson())
|
|
||||||
}
|
|
||||||
|
|
||||||
val noopEndpoint = setOf("GetUserScoreRankingApi", "UpsertClientBookkeepingApi",
|
val noopEndpoint = setOf("GetUserScoreRankingApi", "UpsertClientBookkeepingApi",
|
||||||
"UpsertClientSettingApi", "UpsertClientTestmodeApi", "UpsertClientUploadApi", "Ping", "RemoveTokenApi",
|
"UpsertClientSettingApi", "UpsertClientTestmodeApi", "UpsertClientUploadApi", "Ping", "RemoveTokenApi",
|
||||||
"CMLoginApi", "CMLogoutApi", "CMUpsertBuyCardApi", "UserLogoutApi", "GetGameMapAreaConditionApi",
|
"CMLoginApi", "CMLogoutApi", "CMUpsertBuyCardApi", "UserLogoutApi", "GetGameMapAreaConditionApi",
|
||||||
"UpsertUserChargelogApi").also { endpointList.removeAll(it) }
|
"UpsertUserChargelogApi")
|
||||||
|
|
||||||
val members = this::class.declaredMemberProperties
|
val members = this::class.declaredMemberProperties
|
||||||
val handlers: Map<String, SpecialHandler> = endpointList.associateWith { api ->
|
val handlers: Map<String, SpecialHandler> = initH + endpointList.associateWith { api ->
|
||||||
val name = api.replace("Api", "").lowercase()
|
val name = api.replace("Api", "").lowercase()
|
||||||
(members.find { it.name.lowercase() == name } ?: members.find { it.name.lowercase() == name.replace("cm", "") })
|
(members.find { it.name.lowercase() == name } ?: members.find { it.name.lowercase() == name.replace("cm", "") })
|
||||||
?.let { (it.call(this) as BaseHandler).toSpecial() }
|
?.let { (it.call(this) as BaseHandler).toSpecial() }
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
package icu.samnyan.aqua.sega.maimai2.handler
|
|
||||||
|
|
||||||
import ext.invoke
|
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler
|
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
|
|
||||||
import org.slf4j.Logger
|
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import org.springframework.stereotype.Component
|
|
||||||
|
|
||||||
@Component("Maimai2GetUserRivalDataHandler")
|
|
||||||
class GetUserRivalDataHandler(val repos: Mai2Repos) : BaseHandler {
|
|
||||||
override fun handle(request: Map<String, Any>): Any {
|
|
||||||
val userId = (request["userId"] as Number).toLong()
|
|
||||||
val rivalId = (request["rivalId"] as Number).toLong()
|
|
||||||
|
|
||||||
return mapOf(
|
|
||||||
"userId" to userId,
|
|
||||||
"userRivalData" to mapOf(
|
|
||||||
"rivalId" to rivalId,
|
|
||||||
"rivalName" to (repos.userData.findByCardExtId(rivalId)()?.userName ?: "")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package icu.samnyan.aqua.sega.maimai2.handler;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
|
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.Mai2UserMusicDetailRepo;
|
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.response.data.UserRivalMusic;
|
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.response.data.UserRivalMusicDetail;
|
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.userdata.Mai2UserMusicDetail;
|
|
||||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
|
|
||||||
|
|
||||||
@Component("Maimai2GetUserRivalMusicHandler")
|
|
||||||
public class GetUserRivalMusicHandler implements BaseHandler {
|
|
||||||
private static final Logger logger = LoggerFactory
|
|
||||||
.getLogger(GetUserRivalMusicHandler.class);
|
|
||||||
|
|
||||||
private final StringMapper mapper;
|
|
||||||
private final Mai2UserMusicDetailRepo userMusicDetailRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public GetUserRivalMusicHandler(StringMapper mapper, Mai2UserMusicDetailRepo userMusicDetailRepository) {
|
|
||||||
this.mapper = mapper;
|
|
||||||
this.userMusicDetailRepository = userMusicDetailRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
|
||||||
long userId = ((Number) request.get("userId")).longValue();
|
|
||||||
long rivalId = ((Number) request.get("rivalId")).intValue();
|
|
||||||
|
|
||||||
List<Mai2UserMusicDetail> details = userMusicDetailRepository.findByUserId(rivalId);
|
|
||||||
List<UserRivalMusic> userRivalMusicList = new LinkedList<>();
|
|
||||||
Map<Integer, UserRivalMusic> userRivalMusicMap = new HashMap<>();
|
|
||||||
for (Mai2UserMusicDetail detail : details) {
|
|
||||||
int musicId = detail.getMusicId();
|
|
||||||
UserRivalMusic info = userRivalMusicMap.getOrDefault(musicId, null);
|
|
||||||
if (info == null) {
|
|
||||||
info = new UserRivalMusic(musicId, new LinkedList<>());
|
|
||||||
userRivalMusicList.add(info);
|
|
||||||
userRivalMusicMap.put(musicId, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
info.getUserRivalMusicDetailList().add(
|
|
||||||
new UserRivalMusicDetail(detail.getLevel(), detail.getAchievement(), detail.getDeluxscoreMax())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
|
||||||
resultMap.put("userId", userId);
|
|
||||||
resultMap.put("rivalId", rivalId);
|
|
||||||
resultMap.put("nextIndex", 0);
|
|
||||||
resultMap.put("userRivalMusicList", userRivalMusicList);
|
|
||||||
|
|
||||||
return mapper.write(resultMap);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package icu.samnyan.aqua.sega.maimai2.handler
|
|
||||||
|
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler
|
|
||||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper
|
|
||||||
import org.springframework.stereotype.Component
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Component("Maimai2UserLoginHandler")
|
|
||||||
class UserLoginHandler(mapper: BasicMapper) : BaseHandler {
|
|
||||||
val resp = mapper.write(mapOf(
|
|
||||||
"returnCode" to 1,
|
|
||||||
"lastLoginDate" to "2020-01-01 00:00:00.0",
|
|
||||||
"loginCount" to 1,
|
|
||||||
"consecutiveLoginCount" to 0,
|
|
||||||
"loginId" to 1,
|
|
||||||
"Bearer" to "meow", // Isn't actually used by the game
|
|
||||||
"bearer" to "meow"
|
|
||||||
))
|
|
||||||
|
|
||||||
override fun handle(request: Map<String, Any>) = resp
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
package icu.samnyan.aqua.sega.maimai2.handler
|
|
||||||
|
|
||||||
import ext.parsing
|
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler
|
|
||||||
|
|
||||||
fun interface UserReqHandler : BaseHandler {
|
|
||||||
override fun handle(request: Map<String, Any>): Any {
|
|
||||||
val userId = parsing { (request["userId"] as Number).toLong() }
|
|
||||||
return handleThis(request, userId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun handleThis(request: Map<String, Any>, userId: Long): Any
|
|
||||||
}
|
|
Loading…
Reference in New Issue