forked from Cookies_Github_mirror/AquaDX
[cardmaker] Add experimental chusan gacha support
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package icu.samnyan.aqua.sega.cardmaker.controller;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import icu.samnyan.aqua.sega.cardmaker.handler.impl.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("CardMakerServlet")
|
||||
public class CardMakerController {
|
||||
private final GetGameSettingHandler getGameSettingHandler;
|
||||
private final GetClientBookkeepingHandler getClientBookkeepingHandler;
|
||||
private final GetGameConnectHandler getGameConnectHandler;
|
||||
|
||||
@Autowired
|
||||
public CardMakerController(GetGameSettingHandler getGameSettingHandler, GetClientBookkeepingHandler getClientBookkeepingHandler, GetGameConnectHandler getGameConnectHandler) {
|
||||
this.getGameSettingHandler = getGameSettingHandler;
|
||||
this.getClientBookkeepingHandler = getClientBookkeepingHandler;
|
||||
this.getGameConnectHandler = getGameConnectHandler;
|
||||
}
|
||||
|
||||
@PostMapping("GetGameSettingApi")
|
||||
public String getGameSetting(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
|
||||
return getGameSettingHandler.handle(request);
|
||||
}
|
||||
|
||||
@PostMapping("GetGameConnectApi")
|
||||
public String getGameConnect(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
|
||||
return getGameConnectHandler.handle(request);
|
||||
}
|
||||
|
||||
@PostMapping("GetClientBookkeepingApi")
|
||||
public String getClientBookkeeping(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
|
||||
return getClientBookkeepingHandler.handle(request);
|
||||
}
|
||||
|
||||
@PostMapping("UpsertClientBookkeepingApi")
|
||||
public String upsertClientBookkeeping(@ModelAttribute Map<String, Object> request) {
|
||||
return "{\"returnCode\":1},\"apiName\":\"upsertClientBookkeeping\"";
|
||||
}
|
||||
|
||||
@PostMapping("UpsertClientSettingApi")
|
||||
public String upsertClientSetting(@ModelAttribute Map<String, Object> request) {
|
||||
return "{\"returnCode\":1,\"apiName\":\"upsertClientSetting\"}";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package icu.samnyan.aqua.sega.cardmaker.controller;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@RestControllerAdvice(basePackages = "icu.samnyan.aqua.sega.cardmaker")
|
||||
public class CardMakerControllerAdvice {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CardMakerControllerAdvice.class);
|
||||
|
||||
|
||||
/**
|
||||
* Get the map object from json string
|
||||
*
|
||||
* @param request HttpServletRequest
|
||||
*/
|
||||
@ModelAttribute
|
||||
public Map<String, Object> preHandle(HttpServletRequest request) throws IOException {
|
||||
byte[] src = request.getInputStream().readAllBytes();
|
||||
String outputString = new String(src, StandardCharsets.UTF_8).trim();
|
||||
logger.info("Request " + request.getRequestURI() + ": " + outputString);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
return mapper.readValue(outputString, new TypeReference<>() {
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package icu.samnyan.aqua.sega.cardmaker.handler;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
public interface BaseHandler {
|
||||
|
||||
String handle(Map<String, Object> request) throws JsonProcessingException;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package icu.samnyan.aqua.sega.cardmaker.handler.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import icu.samnyan.aqua.sega.cardmaker.handler.BaseHandler;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("CardMakerGetClientBookkeepingHandler")
|
||||
public class GetClientBookkeepingHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetClientBookkeepingHandler.class);
|
||||
|
||||
private final BasicMapper mapper;
|
||||
|
||||
@Autowired
|
||||
public GetClientBookkeepingHandler(BasicMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, Object> request) throws JsonProcessingException {
|
||||
long placeId = ((Number) request.get("placeId")).longValue();
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("placeId", placeId);
|
||||
resultMap.put("length", 0);
|
||||
resultMap.put("clientBookkeepingList", List.of());
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package icu.samnyan.aqua.sega.cardmaker.handler.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import icu.samnyan.aqua.sega.cardmaker.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.cardmaker.model.response.data.GameConnect;
|
||||
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.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("CardMakerGetGameConnectHandler")
|
||||
public class GetGameConnectHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetGameConnectHandler.class);
|
||||
|
||||
private final BasicMapper mapper;
|
||||
private final String ALLNET_HOST;
|
||||
private final String ALLNET_PORT;
|
||||
private final String SERVER_PORT;
|
||||
|
||||
@Autowired
|
||||
public GetGameConnectHandler(BasicMapper mapper, @Value("${allnet.server.host:}") String ALLNET_HOST,
|
||||
@Value("${allnet.server.port:}") String ALLNET_PORT, @Value("${server.port:}") String SERVER_PORT) {
|
||||
this.mapper = mapper;
|
||||
this.ALLNET_HOST = ALLNET_HOST;
|
||||
this.ALLNET_PORT = ALLNET_PORT;
|
||||
this.SERVER_PORT = SERVER_PORT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, Object> request) throws JsonProcessingException {
|
||||
int type = ((Number) request.get("type")).intValue(); // Allnet enabled or not
|
||||
long version = ((Number) request.get("version")).longValue(); // Rom version
|
||||
|
||||
// Unless ip and port is explicitly overridden, use the guessed ip and port as same as AllNet Controller does.
|
||||
String localAddr;
|
||||
try {
|
||||
localAddr = InetAddress.getLocalHost().getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
// If above didn't work then how did this run? I really don't know.
|
||||
localAddr = "localhost";
|
||||
}
|
||||
|
||||
String addr = ALLNET_HOST.equals("") ? localAddr : ALLNET_HOST;
|
||||
String port = ALLNET_PORT.equals("") ? SERVER_PORT : ALLNET_PORT;
|
||||
|
||||
List<GameConnect> gameConnectList = new ArrayList<>();
|
||||
GameConnect chuni = new GameConnect(0, 1, "http://" + addr + ":" + port + "/ChusanServlet/");
|
||||
GameConnect mai = new GameConnect(1, 1, "http://" + addr + ":" + port + "/Maimai2Servlet/");
|
||||
GameConnect ongeki = new GameConnect(2, 1, "http://" + addr + ":" + port + "/OngekiServlet/");
|
||||
gameConnectList.add(chuni);
|
||||
gameConnectList.add(mai);
|
||||
gameConnectList.add(ongeki);
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("length", gameConnectList.size());
|
||||
resultMap.put("gameConnectList", gameConnectList);
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package icu.samnyan.aqua.sega.cardmaker.handler.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import icu.samnyan.aqua.sega.cardmaker.handler.BaseHandler;
|
||||
import icu.samnyan.aqua.sega.cardmaker.model.response.GetGameSettingResp;
|
||||
import icu.samnyan.aqua.sega.cardmaker.model.response.data.GameSetting;
|
||||
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.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("CardMakerGetGameSettingHandler")
|
||||
public class GetGameSettingHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GetGameSettingHandler.class);
|
||||
|
||||
private final BasicMapper mapper;
|
||||
|
||||
@Autowired
|
||||
public GetGameSettingHandler(BasicMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, Object> request) throws JsonProcessingException {
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");
|
||||
LocalDateTime rebootStartTime = LocalDateTime.now().minusHours(3);
|
||||
LocalDateTime rebootEndTime = LocalDateTime.now().minusHours(2);
|
||||
|
||||
GameSetting gameSetting = new GameSetting(
|
||||
"1.0.0",
|
||||
"1.32.0",
|
||||
"1.30.0",
|
||||
"1.32.0",
|
||||
false,
|
||||
10,
|
||||
rebootStartTime.format(formatter),
|
||||
rebootEndTime.format(formatter),
|
||||
false,
|
||||
100,
|
||||
100,
|
||||
100,
|
||||
false);
|
||||
|
||||
GetGameSettingResp resp = new GetGameSettingResp(
|
||||
gameSetting,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
String json = mapper.write(resp);
|
||||
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package icu.samnyan.aqua.sega.cardmaker.model.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CodeResp {
|
||||
private int returnCode;
|
||||
private String apiName;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package icu.samnyan.aqua.sega.cardmaker.model.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import icu.samnyan.aqua.sega.cardmaker.model.response.data.GameSetting;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class GetGameSettingResp {
|
||||
private GameSetting gameSetting;
|
||||
@JsonProperty("isDumpUpload")
|
||||
private boolean isDumpUpload;
|
||||
@JsonProperty("isAou")
|
||||
private boolean isAou;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package icu.samnyan.aqua.sega.cardmaker.model.response.data;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class GameConnect {
|
||||
private int modelKind; // 0: chunithm, 1: maimai, 2: ongeki
|
||||
private int type; // 0: LAN, 1: WAN
|
||||
private String titleUri;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package icu.samnyan.aqua.sega.cardmaker.model.response.data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class GameSetting {
|
||||
private String dataVersion;
|
||||
private String ongekiCmVersion;
|
||||
private String chuniCmVersion;
|
||||
private String maimaiCmVersion;
|
||||
@JsonProperty("isMaintenance")
|
||||
private boolean isMaintenance;
|
||||
private int requestInterval;
|
||||
private String rebootStartTime;
|
||||
private String rebootEndTime;
|
||||
@JsonProperty("isBackgroundDistribute")
|
||||
private boolean isBackgroundDistribute;
|
||||
private int maxCountCharacter;
|
||||
private int maxCountItem;
|
||||
private int maxCountCard;
|
||||
private boolean watermark;
|
||||
}
|
||||
Reference in New Issue
Block a user