mirror of https://github.com/hykilpikonna/AquaDX
[+] Rewrite More CM
parent
c1323a6ba1
commit
ffcb94674e
|
@ -54,7 +54,7 @@ class ChusanServletController(
|
|||
// Below are code related to handling the handlers
|
||||
val externalHandlers = mutableListOf(
|
||||
"GameLoginApi", "GetUserLoginBonusApi", "GetUserMusicApi", "GetUserRecentRatingApi", "UpsertUserAllApi",
|
||||
"CMGetUserCharacterApi", "CMGetUserItemApi", "CMGetUserPreviewApi", "CMUpsertUserGachaApi",
|
||||
"CMGetUserCharacterApi", "CMUpsertUserGachaApi",
|
||||
"CMUpsertUserPrintCancelApi", "CMUpsertUserPrintSubtractApi")
|
||||
|
||||
val noopEndpoint = setOf("UpsertClientBookkeepingApi", "UpsertClientDevelopApi", "UpsertClientErrorApi",
|
||||
|
@ -64,6 +64,7 @@ class ChusanServletController(
|
|||
// Fun!
|
||||
val initH = mutableMapOf<String, SpecialHandler>()
|
||||
infix operator fun String.invoke(fn: SpecialHandler) = initH.set("${this}Api", fn)
|
||||
infix fun List<String>.all(fn: SpecialHandler) = forEach { it(fn) }
|
||||
infix fun String.static(fn: () -> Any) = mapper.write(fn()).let { resp -> this { resp } }
|
||||
val meow = init()
|
||||
|
||||
|
@ -218,7 +219,7 @@ fun ChusanServletController.init() {
|
|||
}
|
||||
}
|
||||
|
||||
"GetUserItem" {
|
||||
ls("GetUserItem", "CMGetUserItem") all {
|
||||
val kind = parsing { (data["nextIndex"]!!.long / 10000000000L).int }
|
||||
val lst = db.userItem.findAllByUser_Card_ExtIdAndItemKind(uid, kind)
|
||||
|
||||
|
@ -342,4 +343,8 @@ fun ChusanServletController.init() {
|
|||
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")
|
||||
mapOf("userName" to user.userName, "level" to user.level, "medal" to user.medal, "lastDataVersion" to user.lastDataVersion, "isLogin" to false)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,66 +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.userdata.UserItem;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserItemService;
|
||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handler for getting user item.
|
||||
* This get call before profile create.
|
||||
*
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanCMGetUserItemHandler")
|
||||
public class CMGetUserItemHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CMGetUserItemHandler.class);
|
||||
|
||||
private final BasicMapper mapper;
|
||||
|
||||
private final UserItemService userItemService;
|
||||
|
||||
public CMGetUserItemHandler(BasicMapper mapper, UserItemService userItemService) {
|
||||
this.mapper = mapper;
|
||||
this.userItemService = userItemService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = String.valueOf(request.get("userId"));
|
||||
Long nextIndexVal = ((Number) request.get("nextIndex")).longValue();
|
||||
int maxCount = ((Number) request.get("maxCount")).intValue();
|
||||
|
||||
Long mul = 10000000000L;
|
||||
|
||||
int kind = (int) (nextIndexVal / mul);
|
||||
int nextIndex = (int) (nextIndexVal % mul);
|
||||
int pageNum = nextIndex / maxCount;
|
||||
|
||||
Page<UserItem> userItemPage = userItemService.getByUserAndItemKind(userId, kind, pageNum, maxCount);
|
||||
|
||||
List<UserItem> userItemList = userItemPage.getContent();
|
||||
|
||||
long currentIndex = kind * mul + maxCount * pageNum + userItemPage.getNumberOfElements();
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
resultMap.put("length", userItemPage.getNumberOfElements());
|
||||
resultMap.put("nextIndex", userItemPage.getNumberOfElements() < maxCount ? -1 : currentIndex);
|
||||
resultMap.put("itemKind", kind);
|
||||
resultMap.put("userItemList", userItemList);
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
|
@ -1,60 +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.userdata.Chu3UserData;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserDataService;
|
||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanCMGetUserPreviewHandler")
|
||||
public class CMGetUserPreviewHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CMGetUserPreviewHandler.class);
|
||||
|
||||
private final BasicMapper mapper;
|
||||
|
||||
private final UserDataService userDataService;
|
||||
|
||||
@Autowired
|
||||
public CMGetUserPreviewHandler(BasicMapper mapper, UserDataService userDataService) {
|
||||
this.mapper = mapper;
|
||||
this.userDataService = userDataService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = String.valueOf(request.get("userId"));
|
||||
String segaIdAuthKey = String.valueOf(request.get("segaIdAuthKey"));
|
||||
|
||||
Optional<Chu3UserData> userDataOptional = userDataService.getUserByExtId(userId);
|
||||
|
||||
if (userDataOptional.isPresent()) {
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
Chu3UserData user = userDataOptional.get();
|
||||
|
||||
resultMap.put("userName", user.getUserName());
|
||||
resultMap.put("level", user.getLevel());
|
||||
resultMap.put("medal", user.getMedal());
|
||||
resultMap.put("lastDataVersion", user.getLastDataVersion());
|
||||
resultMap.put("isLogin", false);
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue