feat: use mai/chuni/ongeki-encoding when available (#230)

This commit is contained in:
Raymond
2026-06-20 15:57:20 -04:00
committed by GitHub
parent c099a8954e
commit 853abc8867
@@ -39,14 +39,24 @@ class CompressionFilter(
fun truncateVersion(version: Number): Number {
return (floor(version.toFloat() / 5.0) * 5).toInt();
}
fun getVersion(req: HttpServletRequest, game: String): Int {
// NOTE: this should help with some issues regarding mismatched data
val expectedVersion = (req.getHeader("Mai-Encoding") ?:
req.getHeader("Ongeki-Encoding") ?:
req.getHeader("Chuni-Encoding") ?: "0.0").filterNot { it == '.' }.toInt()
val fallbackVersion = req.servletPath.split("/")[3].filterNot { it == '.' }.toInt()
return if (expectedVersion < 100 || keys.none { it.versions.contains(truncateVersion(expectedVersion)) && it.code == game })
fallbackVersion else expectedVersion // Versions below 1.00 are typically invalid
}
var keys = gameData.chu3GameEncryption + gameData.mai2GameEncryption + gameData.ogkGameEncryption
fun getEncryptionKeys(path: String): GameEncryptionKey? {
val endpoint = path.split("/").last()
fun getEncryptionKeys(req: HttpServletRequest): GameEncryptionKey? {
val endpoint = req.servletPath.split("/").last()
if (endpoint.lowercase() != endpoint || endpoint.length != 32) return null
val game = path.split("/")[2]
val version = path.split("/")[3].filterNot { it == '.' }.toInt()
val game = req.servletPath.split("/")[2]
val version = getVersion(req, game)
return keys.find { it.versions.contains(truncateVersion(version)) && it.code == game }
}
@@ -55,7 +65,8 @@ class CompressionFilter(
val isDeflate = req.getHeader("content-encoding") == "deflate"
val isDfi = req.getHeader("pragma") == "DFI"
val keys = getEncryptionKeys(req.servletPath)
val keys = getEncryptionKeys(req)
val game = req.servletPath.split("/")[2]
// Decode input
val reqSrc = try {
@@ -75,7 +86,7 @@ class CompressionFilter(
else it
}
} catch (e: Exception) {
log.error("Failed to decode request from ip ${geoip.getIP(req)}")
log.error("Failed to decode request from ip ${geoip.getIP(req)} (Version ${getVersion(req, game)}")
resp.sendError(400, "Failed to decode request")
return
}