From 064838bca92a38f7c431e0934ca48364cf7f2abf Mon Sep 17 00:00:00 2001 From: duel0213 Date: Wed, 31 Jul 2024 06:40:27 +0900 Subject: [PATCH] IIDX: Added experimental badge save/load support --- iidx@asphyxia/README.md | 1 + iidx@asphyxia/handlers/grade.ts | 18 +++ iidx@asphyxia/handlers/music.ts | 64 +++++++++- iidx@asphyxia/handlers/pc.ts | 199 ++++++++++++++++++++++++++------ iidx@asphyxia/models/badge.ts | 8 ++ 5 files changed, 248 insertions(+), 42 deletions(-) create mode 100644 iidx@asphyxia/models/badge.ts diff --git a/iidx@asphyxia/README.md b/iidx@asphyxia/README.md index 64c51ee..44fe8a2 100644 --- a/iidx@asphyxia/README.md +++ b/iidx@asphyxia/README.md @@ -135,6 +135,7 @@ Changelogs **v0.1.15** - Added Initial support for GOLD - Added Disable Beginner Option + - Added Experimental Badge saving support - Fixed where plugin may fail to register due to missing types in dev mode - Fixed where pacemaker isn't working as intended due to malformed ghost data on music.appoint response (~ DJ TROOPERS) - Fixed where unable to login after first-play (SPADA, SINOBUZ, Rootage) diff --git a/iidx@asphyxia/handlers/grade.ts b/iidx@asphyxia/handlers/grade.ts index f5716f8..563f97d 100644 --- a/iidx@asphyxia/handlers/grade.ts +++ b/iidx@asphyxia/handlers/grade.ts @@ -2,6 +2,7 @@ import { pcdata } from "../models/pcdata"; import { grade } from "../models/grade"; import { IDtoRef, GetVersion } from "../util"; import { eisei_grade } from "../models/lightning"; +import { badge } from "../models/badge"; export const graderaised: EPR = async (info, data, send) => { const version = GetVersion(info); @@ -153,6 +154,23 @@ export const graderaised: EPR = async (info, data, send) => { ); } + if (!_.isNil($(data).element("badge"))) { + await DB.Upsert( + refid, + { + collection: "badge", + version: version, + category_name: "grade", + flg_id: parseInt($(data).attr("badge").badge_flg_id), + }, + { + $set: { + flg: parseInt($(data).attr("badge").badge_flg), + } + } + ); + } + let gradeUser = await DB.Find(null, { collection: "grade", version: version, diff --git a/iidx@asphyxia/handlers/music.ts b/iidx@asphyxia/handlers/music.ts index c27371d..4c8bc07 100644 --- a/iidx@asphyxia/handlers/music.ts +++ b/iidx@asphyxia/handlers/music.ts @@ -3,6 +3,7 @@ import { score, score_top } from "../models/score"; import { profile } from "../models/profile"; import { shop_data } from "../models/shop"; import { tutorial } from "../models/tutorial"; +import { badge } from "../models/badge"; export const musicgetrank: EPR = async (info, data, send) => { const version = GetVersion(info); @@ -435,12 +436,16 @@ export const musicappoint: EPR = async (info, data, send) => { export const musicreg: EPR = async (info, data, send) => { const version = GetVersion(info); + const refid = await IDtoRef(parseInt($(data).attr().iidxid)); + const shop_data = await DB.FindOne({ collection: "shop_data", }); + const profile = await DB.FindOne(refid, { + collection: "profile", + }); // wid, oppid, opname, opt, opt2, pside, nocnt, anum // - const refid = await IDtoRef(parseInt($(data).attr().iidxid)); const pgnum = parseInt($(data).attr().pgnum); const gnum = parseInt($(data).attr().gnum); const mnum = parseInt($(data).attr().mnum); @@ -470,10 +475,6 @@ export const musicreg: EPR = async (info, data, send) => { mid: mid, }); - const profile = await DB.FindOne(refid, { - collection: "profile", - }); - // SPN -> DPA [0~5] -> LINCLE // // SPB -> DPL [0~9] -> Heroic Verse // let pgArray = Array(10).fill(0); // PGREAT // @@ -618,6 +619,59 @@ export const musicreg: EPR = async (info, data, send) => { } ); + if (!_.isNil($(data).element("badge"))) { + if (!_.isNil($(data).attr("badge").djLevel_badge_flg_id)) { + await DB.Upsert( + refid, + { + collection: "badge", + version: version, + category_name: "djLevel", + flg_id: parseInt($(data).attr("badge").djLevel_badge_flg_id), + }, + { + $set: { + flg: parseInt($(data).attr("badge").djLevel_badge_flg), + } + } + ); + } + + if (!_.isNil($(data).attr("badge").clear_badge_flg_id)) { + await DB.Upsert( + refid, + { + collection: "badge", + version: version, + category_name: "clear", + flg_id: parseInt($(data).attr("badge").clear_badge_flg_id), + }, + { + $set: { + flg: parseInt($(data).attr("badge").clear_badge_flg), + } + } + ); + } + + if (!_.isNil($(data).attr("badge").rivalChallenge_badge_flg)) { + await DB.Upsert( + refid, + { + collection: "badge", + version: version, + category_name: "rivalChallenge", + flg_id: 0, + }, + { + $set: { + flg: parseInt($(data).attr("badge").rivalChallenge_badge_flg), + } + } + ); + } + } + let shop_rank = -1, shop_rank_data = []; let scores: any[][]; scores = ( diff --git a/iidx@asphyxia/handlers/pc.ts b/iidx@asphyxia/handlers/pc.ts index 942ae0c..e5d2745 100644 --- a/iidx@asphyxia/handlers/pc.ts +++ b/iidx@asphyxia/handlers/pc.ts @@ -10,6 +10,7 @@ import { shop_data } from "../models/shop"; import { tutorial } from "../models/tutorial"; import { expert } from "../models/ranking"; import { blueboss } from "../models/event"; +import { badge } from "../models/badge"; export const pccommon: EPR = async (info, data, send) => { const version = GetVersion(info); @@ -469,14 +470,16 @@ export const pcget: EPR = async (info, data, send) => { const custom = await DB.FindOne(refid, { collection: "custom", version: version }); const grade = await DB.Find(refid, { collection: "grade", version: version }); const rivals = await DB.Find(refid, { collection: "rival" }); + const shop_data = await DB.FindOne({ collection: "shop_data" }); + const expert = await DB.Find(refid, { collection: "expert", version: version }); const world_tourism = await DB.Find(refid, { collection: "world_tourism", version: version }); + const badge = await DB.Find(refid, { collection: "badge", version: version }); + const lm_settings = await DB.FindOne(refid, { collection: "lightning_settings", version: version }); const lm_playdata = await DB.FindOne(refid, { collection: "lightning_playdata", version: version }); const lm_eisei_grade = await DB.Find(refid, { collection: "eisei_grade", version: version }); const lm_music_memo = await DB.Find(refid, { collection: "lightning_musicmemo", version: version }); const lm_music_memo_new = await DB.Find(refid, { collection: "lightning_musicmemo_new", version: version }); - const shop_data = await DB.FindOne({ collection: "shop_data" }); - const expert = await DB.Find(refid, { collection: "expert", version: version }); if (_.isNil(pcdata)) return send.deny(); @@ -900,43 +903,54 @@ export const pcget: EPR = async (info, data, send) => { badge_flg ***/ - if (version >= 30) { - for (let a = 0; a < 13; a++) { - if (a == 0 || a == 1) { - for (let b = 0; b < 24; b++) { - bArray.push({ - id: a, - flg_id: b, - flg: -1, - }); - } - continue; - } else if (a == 9) { - for (let b = 0; b < 10; b++) { - bArray.push({ - id: a, - flg_id: b, - flg: -1, - }); - } - continue; - } else if (a == 7 || a == 10) { - for (let b = 0; b < 2; b++) { - bArray.push({ - id: a, - flg_id: b, - flg: -1, - }); - } - continue; - } - + if (version >= 30 && badge.length > 0) { + let djLevel, clear, visitor, notes_radar, event1; + djLevel = badge.filter((res) => res.category_name === "djLevel"); + djLevel.forEach((res) => { bArray.push({ - id: a, - flg_id: 0, - flg: -1, + id: 0, + flg_id: res.flg_id, + flg: res.flg, }); - } + }); + + clear = badge.filter((res) => res.category_name === "clear"); + clear.forEach((res) => { + bArray.push({ + id: 1, + flg_id: res.flg_id, + flg: res.flg, + }); + }); + + // this keep sending back on save // + // possibly wrong category_id but at least doesn't show as new badges // + visitor = badge.filter((res) => res.category_name === "visitor"); + visitor.forEach((res) => { + bArray.push({ + id: 6, + flg_id: res.flg_id, + flg: res.flg, + }); + }); + + notes_radar = badge.filter((res) => res.category_name === "notes_radar"); + notes_radar.forEach((res) => { + bArray.push({ + id: 7, + flg_id: res.flg_id, + flg: res.flg, + }); + }); + + event1 = badge.filter((res) => res.category_name === "event1"); + event1.forEach((res) => { + bArray.push({ + id: 9, + flg_id: res.flg_id, + flg: res.flg, + }); + }); } if (version == 24) { // migration // @@ -1211,6 +1225,7 @@ export const pcsave: EPR = async (info, data, send) => { const hasWorldTourism = !(_.isNil($(data).element("world_tourism_data"))); const hasMusicMemo = !(_.isNil($(data).element("music_memo"))); const hasTowerData = !(_.isNil($(data).element("tower_data"))); + const hasBadgeData = !(_.isNil($(data).element("badge"))); if (cltype == 0) pcdata.spnum += 1; else pcdata.dpnum += 1; @@ -3515,6 +3530,116 @@ export const pcsave: EPR = async (info, data, send) => { profile.total_kbd += parseInt($(data).attr("tower_data").keyboard); profile.total_scr += parseInt($(data).attr("tower_data").scratch); } + + // saving for future purpose // + if (hasBadgeData) { + let badge_data = []; + let badge = $(data).element("badge"); + + if (!(_.isNil(badge.element("today_recommend")))) { + let badgeInfo = { + category_id: "today_recommend", + flg_id: 0, + flg: parseInt(badge.element("today_recommend").attr().flg), + }; + + badge_data.push(badgeInfo); + } + + if (!(_.isNil(badge.element("weekly_ranking")))) { + let badgeInfo = { + category_id: "weekly_ranking", + flg_id: 0, + flg: parseInt(badge.element("weekly_ranking").attr().flg), + }; + + badge_data.push(badgeInfo); + } + + if (!(_.isNil(badge.element("visitor")))) { + badge.elements("visitor").forEach((res) => { + let badgeInfo = { + category_id: "visitor", + flg_id: parseInt(res.attr().flg_id), + flg: parseInt(res.attr().flg), + }; + + badge_data.push(badgeInfo); + }); + } + + if (!(_.isNil(badge.element("notes_radar")))) { + badge.elements("notes_radar").forEach((res) => { + let badgeInfo = { + category_id: "notes_radar", + flg_id: parseInt(res.attr().flg_id), + flg: parseInt(res.attr().flg), + }; + + badge_data.push(badgeInfo); + }); + } + + if (!(_.isNil(badge.element("world_tourism")))) { + let badgeInfo = { + category_id: "world_tourism", + flg_id: 0, + flg: parseInt(badge.element("world_tourism").attr().flg), + }; + + badge_data.push(badgeInfo); + } + + if (!(_.isNil(badge.element("event1")))) { + badge.elements("event1").forEach((res) => { + let badgeInfo = { + category_id: "event1", + flg_id: parseInt(res.attr().flg_id), + flg: parseInt(res.attr().flg), + }; + + badge_data.push(badgeInfo); + }); + } + + if (!(_.isNil(badge.element("arena")))) { + badge.elements("arena").forEach((res) => { + let badgeInfo = { + category_id: "arena", + flg_id: parseInt(res.attr().flg_id), + flg: parseInt(res.attr().flg), + }; + + badge_data.push(badgeInfo); + }); + } + + if (!(_.isNil(badge.element("iidx_exam")))) { + let badgeInfo = { + category_id: "iidx_exam", + flg_id: 0, + flg: parseInt(badge.element("iidx_exam").attr().flg), + }; + + badge_data.push(badgeInfo); + } + + badge_data.forEach((res) => { + DB.Upsert( + refid, + { + collection: "badge", + version: version, + category_name: res.category_id, + flg_id: res.flg_id, + }, + { + $set: { + flg: res.flg, + } + }); + }); + } } await DB.Upsert( diff --git a/iidx@asphyxia/models/badge.ts b/iidx@asphyxia/models/badge.ts new file mode 100644 index 0000000..2683b26 --- /dev/null +++ b/iidx@asphyxia/models/badge.ts @@ -0,0 +1,8 @@ +export interface badge { + collection: "badge"; + version: number; + + category_name: string; + flg_id: number; + flg: number; +}