Use newer API for Custom MDB, Fix profile bug.

This commit is contained in:
DitFranXX
2020-12-11 17:48:27 +09:00
parent 5d52767f0a
commit 8db9d98b2b
8 changed files with 117 additions and 77 deletions
+17 -21
View File
@@ -1,34 +1,32 @@
import { getVersion } from "../utils";
import { processData as ExchainMusic } from "../data/Exchain"
import { processData as MatixxMusic } from "../data/Matixx"
import { readXML } from "../data/helper";
import * as path from "path";
import { CommonMusicDataField, readJSONOrXML, readXML } from "../data/helper";
export const playableMusic: EPR = async (info, data, send) => {
const version = getVersion(info);
let musicList: any[] = [];
let music: CommonMusicDataField[] = [];
try {
if (U.GetConfig("enable_custom_mdb")) {
const data = await readXML(path.normalize(U.GetConfig("custom_mdb_path")))
const data = await readXML('data/custom_mdb.xml')
const mdb = $(data).elements("mdb.mdb_data");
for (const m of mdb) {
const d = m.numbers("xg_diff_list");
const contain = m.numbers("contain_stat");
const gf = contain[0];
const dm = contain[1];
if (gf == 0 && dm == 0) {
continue;
}
let type = gf;
if (gf == 0) {
type = dm;
}
musicList.push({
music.push({
id: K.ITEM('s32', m.number("music_id")),
cont_gf: K.ITEM('bool', gf == 0 ? 0 : 1),
cont_dm: K.ITEM('bool', dm == 0 ? 0 : 1),
@@ -56,15 +54,16 @@ export const playableMusic: EPR = async (info, data, send) => {
}
}
} catch (e) {
console.log(e.stack);
send.deny();
console.error(e.stack);
console.error("Fallback: Using default MDB method.")
music = [];
}
if (musicList.length == 0) {
if (music.length == 0) {
if (version == 'exchain') {
musicList = _.get(await ExchainMusic(), 'music', []);
music = _.get(await ExchainMusic(), 'music', []);
} else {
musicList = _.get(await MatixxMusic(), 'music', []);
music = _.get(await MatixxMusic(), 'music', []);
}
}
@@ -74,11 +73,8 @@ export const playableMusic: EPR = async (info, data, send) => {
major: K.ITEM('s32', 1),
minor: K.ITEM('s32', 1),
},
musicinfo: {
'@attr': {
nr: musicList.length,
},
'music': musicList,
},
musicinfo: K.ATTR({ nr: `${music.length}` }, {
music,
}),
});
};
+44 -35
View File
@@ -713,16 +713,28 @@ async function registerUser(refid: string, version: string, id = _.random(0, 999
}
}
const defaultScores = (game: 'gf' | 'dm'): Scores => {
return {
collection: 'scores',
version,
pluginVer: PLUGIN_VER,
game,
scores: {}
}
};
const gf = { game: 'gf', version };
const dm = { game: 'dm', version };
await DB.Upsert(refid, { collection: 'playerinfo', version }, defaultInfo)
await DB.Upsert(refid, { collection: 'profile', ...gf }, defaultProfile('gf'))
await DB.Upsert(refid, { collection: 'profile', ...dm }, defaultProfile('dm'))
await DB.Upsert(refid, { collection: 'record', ...gf }, defaultRecord('gf'))
await DB.Upsert(refid, { collection: 'record', ...dm }, defaultRecord('dm'))
await DB.Upsert(refid, { collection: 'extra', ...gf }, defaultExtra('gf'))
await DB.Upsert(refid, { collection: 'extra', ...dm }, defaultExtra('dm'))
await DB.Upsert(refid, { collection: 'playerinfo', version }, defaultInfo);
await DB.Upsert(refid, { collection: 'profile', ...gf }, defaultProfile('gf'));
await DB.Upsert(refid, { collection: 'profile', ...dm }, defaultProfile('dm'));
await DB.Upsert(refid, { collection: 'record', ...gf }, defaultRecord('gf'));
await DB.Upsert(refid, { collection: 'record', ...dm }, defaultRecord('dm'));
await DB.Upsert(refid, { collection: 'extra', ...gf }, defaultExtra('gf'));
await DB.Upsert(refid, { collection: 'extra', ...dm }, defaultExtra('dm'));
await DB.Upsert(refid, { collection: 'scores', ...gf }, defaultScores('gf'));
await DB.Upsert(refid, { collection: 'scores', ...dm }, defaultScores('dm'));
return defaultInfo
}
@@ -868,6 +880,7 @@ export const savePlayer: EPR = async (info, data, send) => {
await DB.Upsert(refid, { collection: 'extra', game, version }, extra)
const stages = $(data).elements('player.stage');
const scores = (await getScore(refid, version, game)).scores;
for (const stage of stages) {
const mid = stage.number('musicid', -1);
const seq = stage.number('seq', -1);
@@ -885,41 +898,31 @@ export const savePlayer: EPR = async (info, data, send) => {
const meter = stage.bigint('meter', BigInt(0));
const prog = stage.number('meter_prog', 0);
const score = (await getScore(refid, version, game)
|| {
collection: 'scores',
game,
version,
pluginVer: PLUGIN_VER,
scores: {}
}).scores;
if(!score[mid]) {
score[mid] = {
update: [0,0],
if(!scores[mid]) {
scores[mid] = {
update: [0, 0],
diffs: {}
}
}
if (newSkill > score.update[1]) {
score.update[0] = seq;
score.update[1] = newSkill;
if (newSkill > scores[mid].update[1]) {
scores[mid].update[0] = seq;
scores[mid].update[1] = newSkill;
}
score.diffs[seq] = {
perc: Math.max(_.get(score.diffs[seq], 'perc', 0), perc),
rank: Math.max(_.get(score.diffs[seq], 'rank', 0), rank),
scores[mid].diffs[seq] = {
perc: Math.max(_.get(scores[mid].diffs[seq], 'perc', 0), perc),
rank: Math.max(_.get(scores[mid].diffs[seq], 'rank', 0), rank),
meter: meter.toString(),
prog: Math.max(_.get(score.diffs[seq], 'prog', 0), prog),
clear: _.get(score.diffs[seq], 'clear') || clear,
fc: _.get(score.diffs[seq], 'fc') || fc,
ex: _.get(score.diffs[seq], 'ex') || ex,
prog: Math.max(_.get(scores[mid].diffs[seq], 'prog', 0), prog),
clear: _.get(scores[mid].diffs[seq], 'clear') || clear,
fc: _.get(scores[mid].diffs[seq], 'fc') || fc,
ex: _.get(scores[mid].diffs[seq], 'ex') || ex,
};
await saveScore(refid, version, game, score);
}
await saveScore(refid, version, game, scores);
await send.object({
player: K.ATTR({ no: `${no}` }, {
skill: { rank: K.ITEM('s32', 1), total_nr: K.ITEM('s32', 1) },
@@ -962,12 +965,18 @@ async function getRecord(refid: string, version: string, game: 'gf' | 'dm') {
})
}
async function getScore(refid: string, version: string, game: 'gf' | 'dm') {
return await DB.FindOne<Scores>(refid, {
async function getScore(refid: string, version: string, game: 'gf' | 'dm'): Promise<Scores> {
return (await DB.FindOne<Scores>(refid, {
collection: 'scores',
version: version,
game: game
})
})) || {
collection: 'scores',
version: version,
pluginVer: PLUGIN_VER,
game: game,
scores: {}
}
}
async function saveScore(refid: string, version: string, game: 'gf' | 'dm', scores: Scores['scores']) {