mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-06 15:47:36 +08:00
Merge rinsama/aqua : Ensure Chusan compatibility and add support for SunPlus
7a7076b1- [chusan]Attempting to ensure compatibility with all known versions of Chusan, both before and after SunPlusc8e1c5fb- fix BooleanStringIntDeserializer always returns false50ceaf60- Add Support for sunplus Co-authored-by: Sanheiii <35133371+Sanheiii@users.noreply.github.com> Co-authored-by: HoshimiRIN <admin@sakuramoe.dev>
This commit is contained in:
@@ -188,7 +188,7 @@ public class AllNetController {
|
||||
return "http://" + addr + ":" + port + "/Maimai2Servlet/";
|
||||
}
|
||||
case "SDHD":
|
||||
return "http://" + addr + ":" + port + "/ChusanServlet/";
|
||||
return "http://" + addr + ":" + port + "/ChusanServlet/" + ver + "/";
|
||||
case "SDED":
|
||||
return "http://" + addr + ":" + port + "/CardMakerServlet/";
|
||||
default:
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping({"/ChusanServlet/ChuniServlet", "/ChusanServlet"})
|
||||
@RequestMapping({"/ChusanServlet/{version}/ChuniServlet", "/ChusanServlet/{version}"})
|
||||
public class ChusanServletController {
|
||||
|
||||
private final GameLoginHandler gameLoginHandler;
|
||||
@@ -235,7 +235,8 @@ public class ChusanServletController {
|
||||
}
|
||||
|
||||
@PostMapping("GetUserMusicApi")
|
||||
String getUserMusic(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
|
||||
String getUserMusic(@ModelAttribute Map<String, Object> request, @PathVariable String version) throws JsonProcessingException {
|
||||
request.put("version", version);
|
||||
return getUserMusicHandler.handle(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package icu.samnyan.aqua.sega.chusan.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({
|
||||
"musicId",
|
||||
"level",
|
||||
"playCount",
|
||||
"scoreMax",
|
||||
"missCount",
|
||||
"maxComboCount",
|
||||
"isFullCombo",
|
||||
"isAllJustice",
|
||||
"isSuccess",
|
||||
"fullChain",
|
||||
"maxChain",
|
||||
"isLock",
|
||||
"theoryCount",
|
||||
"ext1"
|
||||
})
|
||||
public class UserMusicDetailForAncientChusan implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int musicId;
|
||||
|
||||
private int level;
|
||||
|
||||
private int playCount;
|
||||
|
||||
private int scoreMax;
|
||||
|
||||
private int missCount;
|
||||
|
||||
private int maxComboCount;
|
||||
|
||||
@JsonProperty("isFullCombo")
|
||||
private boolean isFullCombo;
|
||||
|
||||
@JsonProperty("isAllJustice")
|
||||
private boolean isAllJustice;
|
||||
|
||||
@JsonProperty("isSuccess")
|
||||
private boolean isSuccess;
|
||||
|
||||
private int fullChain;
|
||||
|
||||
private int maxChain;
|
||||
|
||||
private int scoreRank;
|
||||
|
||||
@JsonProperty("isLock")
|
||||
private boolean isLock;
|
||||
|
||||
private int theoryCount;
|
||||
|
||||
private int ext1;
|
||||
|
||||
public UserMusicDetailForAncientChusan(int musicId, int level, int playCount, int scoreMax, int missCount, int maxComboCount, boolean isFullCombo, boolean isAllJustice, int isSuccess, int fullChain, int maxChain, int scoreRank, boolean isLock, int theoryCount, int ext1) {
|
||||
this.musicId = musicId;
|
||||
this.level = level;
|
||||
this.playCount = playCount;
|
||||
this.scoreMax = scoreMax;
|
||||
this.missCount = missCount;
|
||||
this.maxComboCount = maxComboCount;
|
||||
this.isFullCombo = isFullCombo;
|
||||
this.isAllJustice = isAllJustice;
|
||||
this.isSuccess = isSuccess > 0;
|
||||
this.fullChain = fullChain;
|
||||
this.maxChain = maxChain;
|
||||
this.scoreRank = scoreRank;
|
||||
this.isLock = isLock;
|
||||
this.theoryCount = theoryCount;
|
||||
this.ext1 = ext1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package icu.samnyan.aqua.sega.chusan.dto;
|
||||
|
||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserMusicDetail;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserMusicListItemForAncientChusan {
|
||||
private int length;
|
||||
private List<UserMusicDetailForAncientChusan> userMusicDetailList;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package icu.samnyan.aqua.sega.chusan.handler.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import icu.samnyan.aqua.sega.chusan.dto.UserMusicDetailForAncientChusan;
|
||||
import icu.samnyan.aqua.sega.chusan.dto.UserMusicListItemForAncientChusan;
|
||||
import icu.samnyan.aqua.sega.chusan.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.chusan.model.response.data.UserMusicListItem;
|
||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserMusicDetail;
|
||||
@@ -78,13 +80,51 @@ public class GetUserMusicHandler implements BaseHandler {
|
||||
userMusicMap.remove(lastMusicId);
|
||||
}
|
||||
|
||||
String version = (String) request.get("version");
|
||||
Map<Integer, UserMusicListItemForAncientChusan> userMusicMapForAncientChusan = new LinkedHashMap<>();
|
||||
boolean isAncient = false;
|
||||
try {
|
||||
if (Double.parseDouble(version) < 2.15){
|
||||
userMusicMap.forEach((k, v) -> {
|
||||
UserMusicListItemForAncientChusan list = new UserMusicListItemForAncientChusan();
|
||||
list.setLength(v.getLength());
|
||||
List<UserMusicDetailForAncientChusan> userMusicDetailForAncientChusanList = new ArrayList<>();
|
||||
v.getUserMusicDetailList().forEach(userMusicDetail -> {
|
||||
UserMusicDetailForAncientChusan userMusicDetailForAncientChusan = new UserMusicDetailForAncientChusan(
|
||||
userMusicDetail.getMusicId(),
|
||||
userMusicDetail.getLevel(),
|
||||
userMusicDetail.getPlayCount(),
|
||||
userMusicDetail.getScoreMax(),
|
||||
userMusicDetail.getMissCount(),
|
||||
userMusicDetail.getMaxComboCount(),
|
||||
userMusicDetail.isFullCombo(),
|
||||
userMusicDetail.isAllJustice(),
|
||||
userMusicDetail.getIsSuccess(),
|
||||
userMusicDetail.getFullChain(),
|
||||
userMusicDetail.getMaxChain(),
|
||||
userMusicDetail.getScoreRank(),
|
||||
userMusicDetail.isLock(),
|
||||
userMusicDetail.getTheoryCount(),
|
||||
userMusicDetail.getExt1()
|
||||
);
|
||||
userMusicDetailForAncientChusanList.add(userMusicDetailForAncientChusan);
|
||||
});
|
||||
list.setUserMusicDetailList(userMusicDetailForAncientChusanList);
|
||||
userMusicMapForAncientChusan.put(k, list);
|
||||
});
|
||||
isAncient = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error when handling ancient version of chusan", e);
|
||||
}
|
||||
|
||||
long nextIndex = currentIndex + dbPage.getNumberOfElements() - lastListSize;
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
resultMap.put("length", userMusicMap.size());
|
||||
resultMap.put("nextIndex", dbPage.getNumberOfElements() < maxCount ? -1 : nextIndex);
|
||||
resultMap.put("userMusicList", userMusicMap.values());
|
||||
resultMap.put("userMusicList", isAncient ? userMusicMapForAncientChusan.values() : userMusicMap.values());
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
|
||||
@@ -3,6 +3,8 @@ package icu.samnyan.aqua.sega.chusan.model.userdata;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import icu.samnyan.aqua.sega.chusan.util.BooleanToIntegerDeserializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -67,8 +69,9 @@ public class UserMusicDetail implements Serializable {
|
||||
@JsonProperty("isAllJustice")
|
||||
private boolean isAllJustice;
|
||||
|
||||
@JsonDeserialize(using = BooleanToIntegerDeserializer.class)
|
||||
@JsonProperty("isSuccess")
|
||||
private boolean isSuccess;
|
||||
private int isSuccess;
|
||||
|
||||
private int fullChain;
|
||||
|
||||
@@ -87,7 +90,7 @@ public class UserMusicDetail implements Serializable {
|
||||
user = userData;
|
||||
}
|
||||
|
||||
public UserMusicDetail(int musicId, int level, int playCount, int scoreMax, int missCount, int maxComboCount, boolean isFullCombo, boolean isAllJustice, boolean isSuccess, int fullChain, int maxChain, int scoreRank, boolean isLock, int theoryCount, int ext1) {
|
||||
public UserMusicDetail(int musicId, int level, int playCount, int scoreMax, int missCount, int maxComboCount, boolean isFullCombo, boolean isAllJustice, int isSuccess, int fullChain, int maxChain, int scoreRank, boolean isLock, int theoryCount, int ext1) {
|
||||
this.musicId = musicId;
|
||||
this.level = level;
|
||||
this.playCount = playCount;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package icu.samnyan.aqua.sega.chusan.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
public class BooleanToIntegerDeserializer extends JsonDeserializer<Integer> {
|
||||
@Override
|
||||
public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||
return switch (p.getCurrentToken()) {
|
||||
case VALUE_STRING -> {
|
||||
String value = p.getValueAsString();
|
||||
if (value.toLowerCase(Locale.ROOT).equals("true")) {
|
||||
yield 1;
|
||||
} else if (value.toLowerCase(Locale.ROOT).equals("false")) {
|
||||
yield 0;
|
||||
} else {
|
||||
try {
|
||||
yield Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new UnsupportedOperationException("Cannot deserialize to integer field");
|
||||
}
|
||||
}
|
||||
}
|
||||
case VALUE_NUMBER_INT -> p.getIntValue();
|
||||
case VALUE_TRUE -> 1;
|
||||
case VALUE_FALSE -> 0;
|
||||
default -> throw new UnsupportedOperationException("Cannot deserialize to integer field");
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user