improve SoftID handling in ferv conv

This commit is contained in:
zkldi
2021-05-17 09:14:34 +01:00
parent a35de19e32
commit 08db3c58fe
5 changed files with 26 additions and 19 deletions
+2 -2
View File
@@ -2,7 +2,7 @@ import { Router, RequestHandler } from "express";
import { UpdateClassIfGreater } from "../../../common/class";
import { GetUserWithIDGuaranteed } from "../../../common/user";
import { ParseEA3SoftID } from "../../../common/util";
import { INF2_MODEL, REV_2DXBMS } from "../../../constants/ea3id";
import { MODEL_INFINITAS_2, REV_2DXBMS } from "../../../constants/ea3id";
import { RequireLoggedIn } from "../../../middleware/require-logged-in";
import { ExpressWrappedScoreImportMain } from "../../../score-import/framework/express-wrapper";
import { ParseFervidexStatic } from "../../../score-import/import-types/ir/fervidex-static/parser";
@@ -24,7 +24,7 @@ const RequireInf2ModelHeader: RequestHandler = (req, res, next) => {
try {
let softID = ParseEA3SoftID(swModel);
if (softID.model !== INF2_MODEL) {
if (softID.model !== MODEL_INFINITAS_2) {
return res.status(400).send({
success: false,
description: "This endpoint is only available for INF2 clients.",
+5 -3
View File
@@ -1,8 +1,10 @@
// Various EA3-SoftID constants to make code more readable.
export const INF2_MODEL = "P2D";
export const IIDX_AC_MODEL = "LDJ";
export const IIDX_AC_LIGHTNING_MODEL = "TDJ";
export const MODEL_INFINITAS_2 = "P2D";
export const MODEL_IIDX = "LDJ";
export const MODEL_IIDX_LIGHTNING = "TDJ";
export const REV_2DXTRA = "E";
export const REV_2DXBMS = "Z";
export const REV_OMNIMIX = "X";
export const EXT_HEROIC_VERSE = "2020092900";
@@ -4,7 +4,7 @@ import ScoreImportFatalError from "../../../framework/score-importing/score-impo
import { FormatPrError } from "../../../../common/prudence";
import { ConverterIRFervidexStatic } from "./converter";
import { FervidexStaticContext, FervidexStaticScore } from "./types";
import { FerHeaders, ParseSoftwareModel } from "../fervidex/parser";
import { FerHeaders, SoftwareIDToVersion } from "../fervidex/parser";
import { AssertStrAsPositiveInt } from "../../../framework/common/string-asserts";
const PR_FervidexStatic: PrudenceSchema = {
@@ -18,7 +18,7 @@ export function ParseFervidexStatic(
headers: FerHeaders,
logger: KtLogger
): ParserFunctionReturnsSync<FervidexStaticScore, FervidexStaticContext> {
let version = ParseSoftwareModel(headers.model);
let version = SoftwareIDToVersion(headers.model);
let staticScores = body?.scores;
@@ -209,6 +209,7 @@ export const ConverterIRFervidex: ConverterFunction<FervidexScore, FervidexConte
slow: data.slow,
maxCombo: data.max_combo,
gaugeHistory,
scoreHistory: data.ghost,
gauge,
bp: data.bad + data.poor,
comboBreak: data.combo_break,
@@ -4,6 +4,8 @@ import ScoreImportFatalError from "../../../framework/score-importing/score-impo
import { FormatPrError, optNull } from "../../../../common/prudence";
import { FervidexContext, FervidexScore } from "./types";
import { ConverterIRFervidex } from "./converter";
import { ParseEA3SoftID } from "../../../../common/util";
import { EXT_HEROIC_VERSE, MODEL_IIDX, MODEL_INFINITAS_2 } from "../../../../constants/ea3id";
const PR_Fervidex: PrudenceSchema = {
chart: p.isIn("spb", "spn", "dpn", "sph", "dph", "spa", "dpa", "spl", "dpl"),
@@ -58,21 +60,23 @@ const PR_Fervidex: PrudenceSchema = {
* Converts a string of the form LDJ:X:X:X:2020092900 into a game version.
* I don't really understand the software model format, so this is lazy.
*/
export function ParseSoftwareModel(model: string) {
if (model.startsWith("LDJ")) {
// heroic verse
if (model.endsWith("2020092900")) {
return "27";
export function SoftwareIDToVersion(model: string) {
try {
let data = ParseEA3SoftID(model);
if (data.model === MODEL_INFINITAS_2) {
return "inf2020";
} else if (data.model === MODEL_IIDX) {
// only HV. everything else is disabled deliberately.
if (data.ext === EXT_HEROIC_VERSE) {
return "27";
}
}
// i *really* don't care enough to support rootage or cannonballers.
throw new ScoreImportFatalError(400, `Unsupported Software Model ${model}.`);
} else if (model.startsWith("P2D")) {
// accept anything since this will probably change underfoot a lot.
return "inf2020";
} catch (err) {
throw new ScoreImportFatalError(400, `Unsupported Software Model ${model}`);
}
throw new ScoreImportFatalError(400, `Unsupported Software Model ${model}.`);
}
export interface FerHeaders {
@@ -84,7 +88,7 @@ export function ParseFervidexSingle(
headers: FerHeaders,
logger: KtLogger
): ParserFunctionReturnsSync<FervidexScore, FervidexContext> {
let version = ParseSoftwareModel(headers.model);
let version = SoftwareIDToVersion(headers.model);
// more mods may be added in the future, so lets ignore excess keys.
let err = p(body, PR_Fervidex, undefined, { allowExcessKeys: true });