Make sure that do not pass invaild value to client

This commit is contained in:
DitFranXX 2020-12-26 15:16:23 +09:00
parent 7ab416c917
commit f63ee8aae8
4 changed files with 16 additions and 7 deletions

View File

@ -1,12 +1,12 @@
import { CommonMusicDataField, readB64JSON, readXML } from "./helper";
export async function processData() {
export async function processData(): Promise<CommonMusicData> {
if (IO.Exists("data/forte_mdb.json.b64")) {
return await readB64JSON("data/forte_mdb.json.b64");
}
const data = await readJSONOrXML("data/forte_mdb.json", "data/forte_mdb.xml")
// await IO.WriteFile("data/forte_mdb.json.b64", Buffer.from(JSON.stringify(data)).toString("base64"))
return data
return data;
}
export async function processMdbData(path: string): Promise<CommonMusicData> {

View File

@ -99,10 +99,18 @@ export const get_music_info: EPR = async (info, data, send) => {
}));
}
const music_list = async () => {
const music_list = await processData()
music_list.music_spec = music_list.music_spec.filter( (v) =>
parseInt(v["@attr"].index, 10) <= version.getMusicMaxIndex()
)
return music_list;
}
const versionObject = version.isFirstOrForte()
? {
permitted_list: forte_permitted_list,
music_list: await processData()
music_list: await music_list()
}
: {
permitted_list,

View File

@ -51,7 +51,7 @@ const getPlayerData = async (refid: string, info: EamuseInfo, name?: string) =>
const brooch: any[] = [];
for (const b in p.brooches) {
if (parseInt(b, 10) > version.getBroochMaxIndex()) continue; // Forte Brooch is ~147.
if (parseInt(b, 10) > version.getBroochMaxIndex()) continue;
const bData = p.brooches[b];
brooch.push(K.ATTR({ index: b }, {
watch_count: K.ITEM('s32', bData.watch),
@ -63,6 +63,7 @@ const getPlayerData = async (refid: string, info: EamuseInfo, name?: string) =>
// Unlock brooches
for (let i = 101; i <= 124; ++i) {
if (i > version.getBroochMaxIndex()) continue;
brooch.push(K.ATTR({ index: `${i}` }, {
'watch_count': K.ITEM('s32', 0),
'level': K.ITEM('s8', 1),

View File

@ -1,14 +1,14 @@
type NostalgiaVersions = 'First' | 'Forte' | 'Op2' | 'Op3'
type NostalgiaNumericTypes = 'music_index' | 'sheet_type' | 'brooch_index'
type NostalgiaNumericTypes = 'music_index' | 'sheet_type' | 'brooch_index' | 'event_index'
export class NosVersionHelper {
public version: NostalgiaVersions
private table = { // FIXME: Op3 is placeholder
private table = { // FIXME: All of Op3 values are placeholder
music_index: { First: 87, Forte: 195, Op2: 315, Op3: 500 },
brooch_index: { First: 120, Forte: 147, Op2: 148, Op3: 200 },
sheet_type: { First: 2, Forte: 2, Op2: 3, Op3: 3 },
event_index: { First: 5, Forte: 10, Op2: 17, Op3: 20 } // FIXME: First And Op3 is placeholder
event_index: { First: 10, Forte: 10, Op2: 17, Op3: 20 }
}
constructor (info: EamuseInfo) {