diff --git a/server/src/lib/score-import/import-types/ir/lr2hook/converter.ts b/server/src/lib/score-import/import-types/ir/lr2hook/converter.ts index 1addeac09..dde272d4a 100644 --- a/server/src/lib/score-import/import-types/ir/lr2hook/converter.ts +++ b/server/src/lib/score-import/import-types/ir/lr2hook/converter.ts @@ -1,6 +1,7 @@ -import { Lamps } from "tachi-common"; +import { Lamps, ScoreDocument } from "tachi-common"; import { InternalFailure, + InvalidScoreFailure, KTDataNotFoundFailure, } from "lib/score-import/framework/common/converter-failures"; import { GenericGetGradeAndPercent } from "lib/score-import/framework/common/score-utils"; @@ -61,6 +62,7 @@ export const ConverterLR2Hook: ConverterFunction = }, }, scoreMeta: { + random: chart.playtype === "7K" ? ConvertRandom(data.playerData.random) : null, client: "LR2", }, }; @@ -68,6 +70,21 @@ export const ConverterLR2Hook: ConverterFunction = return { song, chart, dryScore }; }; +function ConvertRandom( + random: LR2HookScore["playerData"]["random"] +): ScoreDocument<"bms:7K">["scoreMeta"]["random"] { + switch (random) { + case "NONRAN": + return "NONRAN"; + case "MIRROR": + return "MIRROR"; + case "RAN": + return "RANDOM"; + case "S-RAN": + return "S-RANDOM"; + } +} + function ConvertLamp(lamp: LR2HookScore["scoreData"]["lamp"]): Lamps["bms:7K" | "bms:14K"] { switch (lamp) { case "EASY": diff --git a/server/src/lib/score-import/import-types/ir/lr2hook/parser.ts b/server/src/lib/score-import/import-types/ir/lr2hook/parser.ts index 5676497ca..7747a3071 100644 --- a/server/src/lib/score-import/import-types/ir/lr2hook/parser.ts +++ b/server/src/lib/score-import/import-types/ir/lr2hook/parser.ts @@ -5,8 +5,18 @@ import p, { PrudenceSchema } from "prudence"; import ScoreImportFatalError from "lib/score-import/framework/score-importing/score-import-error"; import { FormatPrError } from "utils/prudence"; +const SUPPORTED_RANDOMS = ["NONRAN", "MIRROR", "RAN", "S-RAN"]; + const PR_LR2Hook: PrudenceSchema = { md5: "string", + playerData: { + autoScr: p.is(false), + // don't really need this, but it's + // { "ALL", "SINGLE", "7K", "5K", "DOUBLE", "14K", "10K", "9K" }; + gameMode: p.any, + // ALLSCR and H-RAN may also be sent, but we don't support them. + random: p.isIn(SUPPORTED_RANDOMS), + }, scoreData: { pgreat: p.isPositiveInteger, great: p.isPositiveInteger, @@ -40,7 +50,20 @@ export function ParseLR2Hook( logger: KtLogger ): ParserFunctionReturns { // Ignore excess keys, as lr2hook is likely to add more features in the future. - const err = p(body, PR_LR2Hook, undefined, { allowExcessKeys: true }); + const err = p( + body, + PR_LR2Hook, + { + playerData: { + autoScr: + "Auto Scratch cannot be turned on, as it is treated as an EASY CLEAR by LR2.", + random: `Expected any of ${SUPPORTED_RANDOMS.join( + ", " + )}. Note that ALLSCR and H-RAN are not supported!`, + }, + }, + { allowExcessKeys: true } + ); if (err) { throw new ScoreImportFatalError(400, FormatPrError(err)); diff --git a/server/src/lib/score-import/import-types/ir/lr2hook/types.ts b/server/src/lib/score-import/import-types/ir/lr2hook/types.ts index 59ff88010..cf66aac8c 100644 --- a/server/src/lib/score-import/import-types/ir/lr2hook/types.ts +++ b/server/src/lib/score-import/import-types/ir/lr2hook/types.ts @@ -2,6 +2,11 @@ import { integer } from "tachi-common"; export interface LR2HookScore { md5: string; + playerData: { + autoScr: boolean; + gameMode: unknown; + random: "NONRAN" | "MIRROR" | "RAN" | "S-RAN"; + }; scoreData: { pgreat: integer; great: integer;