[allnet] Add support for v2 power on response

This commit is contained in:
samnyan
2020-12-14 17:02:44 +08:00
parent be5d241565
commit b3a8e80399
4 changed files with 171 additions and 70 deletions

View File

@@ -2,6 +2,8 @@ package icu.samnyan.aqua.sega.allnet;
import com.fasterxml.jackson.databind.ObjectMapper;
import icu.samnyan.aqua.sega.allnet.model.response.PowerOnResponse;
import icu.samnyan.aqua.sega.allnet.model.response.PowerOnResponseV2;
import icu.samnyan.aqua.sega.allnet.model.response.PowerOnResponseV3;
import icu.samnyan.aqua.sega.allnet.util.Decoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.io.InputStream;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.zip.DataFormatException;
@@ -24,6 +27,7 @@ public class AllNetController {
private static final Logger logger = LoggerFactory.getLogger(AllNetController.class);
private final ObjectMapper mapper = new ObjectMapper();
private final String HOST;
private final String PORT;
@@ -53,27 +57,56 @@ public class AllNetController {
// TODO: Verify KeyChip id
String gameId = reqMap.getOrDefault("game_id", "");
PowerOnResponse resp = new PowerOnResponse(
1,
switchUri(gameId),
switchHost(gameId),
"123",
"",
"",
"1",
"W",
"X",
"Y",
"Z",
"JPN",
"456",
"+0900",
Instant.now().toString().substring(0, 19).concat("Z"),
"",
"3",
reqMap.get("token")
);
logger.info("Response: " + new ObjectMapper().writeValueAsString(resp));
String format_ver = reqMap.getOrDefault("format_ver", "");
PowerOnResponse resp;
if (format_ver.startsWith("2")) {
var now = LocalDateTime.now();
resp = new PowerOnResponseV2(
1,
switchUri(gameId),
switchHost(gameId),
"123",
"",
"",
"1",
"W",
"X",
"Y",
"Z",
"JPN",
now.getYear(),
now.getMonth().getValue(),
now.getDayOfMonth(),
now.getHour(),
now.getMinute(),
now.getSecond(),
"1",
"+09:00",
"PowerOnResponseV2"
);
} else {
resp = new PowerOnResponseV3(
1,
switchUri(gameId),
switchHost(gameId),
"123",
"",
"",
"1",
"W",
"X",
"Y",
"Z",
"JPN",
"456",
"+0900",
Instant.now().toString().substring(0, 19).concat("Z"),
"",
"3",
reqMap.get("token")
);
}
logger.info("Response: " + mapper.writeValueAsString(resp));
return resp.toString().concat("\n");
}