[O] riik GetGameSetting

matching
Azalea 2024-12-26 07:24:32 -05:00
parent 6938083463
commit 0411505341
5 changed files with 41 additions and 165 deletions

View File

@ -14,6 +14,8 @@ import icu.samnyan.aqua.spring.Metrics
import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletRequest
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.collections.set import kotlin.collections.set
import kotlin.reflect.full.declaredMemberProperties import kotlin.reflect.full.declaredMemberProperties
@ -25,7 +27,6 @@ import kotlin.reflect.full.declaredMemberProperties
@API(value = ["/g/chu3/{version}/ChuniServlet", "/g/chu3/{version}"]) @API(value = ["/g/chu3/{version}/ChuniServlet", "/g/chu3/{version}"])
class ChusanServletController( class ChusanServletController(
val gameLogin: GameLoginHandler, val gameLogin: GameLoginHandler,
val getGameSetting: GetGameSettingHandler,
val getUserCharacter: GetUserCharacterHandler, val getUserCharacter: GetUserCharacterHandler,
val getUserCourse: GetUserCourseHandler, val getUserCourse: GetUserCourseHandler,
val getUserFavoriteItem: GetUserFavoriteItemHandler, val getUserFavoriteItem: GetUserFavoriteItemHandler,
@ -85,7 +86,7 @@ class ChusanServletController(
// Fun! // Fun!
val initH = mutableMapOf<String, SpecialHandler>() val initH = mutableMapOf<String, SpecialHandler>()
infix fun String.special(fn: SpecialHandler) = initH.set(this.lowercase(), fn) infix fun String.special(fn: SpecialHandler) = initH.set(this.lowercase(), fn)
operator fun String.invoke(fn: (Map<String, Any>) -> Any) = this special { fn(it.data) } operator fun String.invoke(fn: (Map<String, Any>) -> Any) = this special { fn(data) }
infix fun String.user(fn: (Map<String, Any>, Long) -> Any) = this { fn(it, parsing { it["userId"]!!.long }) } infix fun String.user(fn: (Map<String, Any>, Long) -> Any) = this { fn(it, parsing { it["userId"]!!.long }) }
infix fun String.static(fn: () -> Any) = mapper.write(fn()).let { resp -> this { resp } } infix fun String.static(fn: () -> Any) = mapper.write(fn()).let { resp -> this { resp } }
val meow = init() val meow = init()
@ -204,6 +205,43 @@ fun ChusanServletController.init() {
} }
} }
// Game settings
"GetGameSetting" special {
val version = data["version"].toString()
// Fixed reboot time triggers chusan maintenance lockout, so let's try minime method which sets it dynamically
// Special thanks to skogaby
// Hardcode so that the reboot time always started 3 hours ago and ended 2 hours ago
val fmt = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss")
// Get the request url as te address
val addr = req.requestURI.removeSuffix("GetGameSettingApi")
mapOf(
"gameSetting" to mapOf(
"romVersion" to "$version.00", // Chusan checks these two versions to determine if it can enable game modes
"dataVersion" to "$version.00",
"isMaintenance" to false,
"requestInterval" to 0,
"rebootStartTime" to LocalDateTime.now().minusHours(3).format(fmt),
"rebootEndTime" to LocalDateTime.now().minusHours(2).format(fmt),
"isBackgroundDistribute" to false,
"maxCountCharacter" to 300,
"maxCountItem" to 300,
"maxCountMusic" to 300,
"matchStartTime" to LocalDateTime.now().minusHours(1).format(fmt),
"matchEndTime" to LocalDateTime.now().plusHours(1).format(fmt),
"matchTimeLimit" to 10,
"matchErrorLimit" to 10,
"matchingUri" to addr,
"matchingUriX" to addr,
"udpHolePunchUri" to addr,
"reflectorUri" to addr
),
"isDumpUpload" to false,
"isAou" to false
)
}
// Static // Static
"GetGameEvent" static { db.gameEvent.findByEnable(true).let { mapOf("type" to 1, "length" to it.size, "gameEventList" to it) } } "GetGameEvent" static { db.gameEvent.findByEnable(true).let { mapOf("type" to 1, "length" to it.size, "gameEventList" to it) } }
"GetGameCharge" static { db.gameCharge.findAll().let { mapOf("length" to it.size, "gameChargeList" to it) } } "GetGameCharge" static { db.gameCharge.findAll().let { mapOf("length" to it.size, "gameChargeList" to it) } }

View File

@ -1,105 +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.response.GetGameSettingResp;
import icu.samnyan.aqua.sega.chusan.model.response.data.GameSetting;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
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.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component("ChusanGetGameSettingHandler")
public class GetGameSettingHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetGameSettingHandler.class);
private final StringMapper mapper;
private final String ALLNET_HOST;
private final String ALLNET_PORT;
private final String SERVER_PORT;
private final String ROM_VERSION;
private final String GAME_VERSION;
@Autowired
public GetGameSettingHandler(StringMapper mapper, @Value("${allnet.server.host:}") String ALLNET_HOST, @Value("${allnet.server.port:}") String ALLNET_PORT, @Value("${server.port:}") String SERVER_PORT, @Value("${game.chusan.version:2.00.00}") String GAME_VERSION, @Value("${game.chusan.rom-version:2.00.01}") String ROM_VERSION) {
this.mapper = mapper;
this.ALLNET_HOST = ALLNET_HOST;
this.ALLNET_PORT = ALLNET_PORT;
this.SERVER_PORT = SERVER_PORT;
this.GAME_VERSION = GAME_VERSION;
this.ROM_VERSION = ROM_VERSION;
}
@Override
public String handle(Map<String, ?> request) throws JsonProcessingException {
// Fixed reboot time triggers chusan maintenance lockout, so let's try minime method which sets it dynamically
// Special thanks to skogaby
// Hardcode so that the reboot time always started 3 hours ago and ended 2 hours ago
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");
LocalDateTime rebootStartTime = LocalDateTime.now().minusHours(3);
LocalDateTime rebootEndTime = LocalDateTime.now().minusHours(2);
LocalDateTime matchingStartTime = LocalDateTime.now().minusHours(1);
LocalDateTime matchingEndTime = LocalDateTime.now().plusHours(1);
// 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.isEmpty() ? localAddr : ALLNET_HOST;
String port = ALLNET_PORT.isEmpty() ? SERVER_PORT : ALLNET_PORT;
GameSetting gameSetting = new GameSetting(
ROM_VERSION, // Chusan checks these two versions to determine if it can enable game modes
GAME_VERSION,
false,
0,
rebootStartTime.format(formatter),
rebootEndTime.format(formatter),
false,
300,
300,
300,
matchingStartTime.format(formatter),
matchingEndTime.format(formatter),
10,
10,
"http://" + addr + ":" + port + "/ChusanServlet/",
"http://" + addr + ":" + port + "/ChusanServlet/",
"http://" + addr + ":" + port + "/ChusanServlet/",
"http://" + addr + ":" + port + "/ChusanServlet/"
);
GetGameSettingResp resp = new GetGameSettingResp(
gameSetting,
false,
false
);
String json = mapper.write(resp);
logger.info("Response: " + json);
return json;
}
}

View File

@ -1,22 +0,0 @@
package icu.samnyan.aqua.sega.chusan.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
import icu.samnyan.aqua.sega.chusan.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;
}

View File

@ -1,35 +0,0 @@
package icu.samnyan.aqua.sega.chusan.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 romVersion;
private String dataVersion;
@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 maxCountMusic;
private String matchStartTime;
private String matchEndTime;
private int matchTimeLimit;
private int matchErrorLimit;
private String matchingUri;
private String matchingUriX;
private String udpHolePunchUri;
private String reflectorUri;
}

View File

@ -16,5 +16,5 @@ data class RequestContext(
val data: Map<String, Any>, val data: Map<String, Any>,
) )
typealias SpecialHandler = (RequestContext) -> Any? typealias SpecialHandler = RequestContext.() -> Any?
fun BaseHandler.toSpecial() = { ctx: RequestContext -> handle(ctx.data) } fun BaseHandler.toSpecial() = { ctx: RequestContext -> handle(ctx.data) }