fix(lr2hook): reject BP if user failed

LR2Hook sends invalid BP if the user ends up exiting the song early.
We need to handle this, and not accept it.
This commit is contained in:
zkldi
2022-10-27 19:46:33 +01:00
parent 7f5084b963
commit 7eaa8bc06b
4 changed files with 94 additions and 4 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
import UGPTAddPreferredRanking from "./migrations/add-preferredRanking-to-ugpt";
import UGPTRivalsMigration from "./migrations/add-rivals-to-ugpt";
import NullLR2HookFailedBPs from "./migrations/null-lr2hook-failed-bps";
import RecalcBrokenIIDXNotecounts from "./migrations/recalc-broken-iidx-notecounts";
import RemoveIIDXBeginners from "./migrations/remove-iidx-beginners";
import RemoveMultifolderStats from "./migrations/remove-multifolder-stats";
@@ -44,7 +45,7 @@ if (Environment.nodeEnv !== "test") {
// bokutachi specific migrations
if (TachiConfig.TYPE !== "ktchi") {
// none, currently
REGISTERED_MIGRATIONS.push(NullLR2HookFailedBPs);
}
}
@@ -0,0 +1,31 @@
import db from "external/mongo/db";
import { UpdateAllPBs } from "utils/calculations/recalc-scores";
import type { Migration } from "utils/types";
const migration: Migration = {
id: "null-lr2hook-failed-bps",
up: async () => {
await db.scores.update(
{
importType: "ir/lr2hook",
"scoreMeta.gauge": "HARD",
lamp: { $in: ["FAILED", "NO PLAY"] },
},
{
$set: {
"scoreData.hitMeta.bp": null,
},
},
{
multi: true,
}
);
await UpdateAllPBs(undefined, { game: "bms" });
},
down: () => {
throw new Error(`Unable to revert transaction, some scores may have been nulled.`);
},
};
export default migration;