mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-12-05 03:30:23 -06:00
jubeat: split versions into modules with shared player and scores
Each version (prop, Qubell, clan, festo) is now a module under versions/ with its own route table and model date range. All jubeat versions call the same method names, so versions/index.ts registers one route per method and picks the version from the model date. - handlers/player.ts: one jubeat ID and name per card, in the existing festo `profile` document - handlers/scores.ts: one score store for every version; prop, Qubell and clan only see normal-mode charts of songs up to their own - handlers/version_data.ts: per-version fields, course and league results, keyed by version id (7 prop, 8 Qubell, 9 clan, 10 festo) - V2.1.0 Qubell saves move to the shared profile and scores on first login; the old documents are kept and marked `migrated` - festo moves to versions/festo with the same requests and responses; records without a ghost now get an empty one instead of a broken node - builds older than prop are refused instead of answered as Qubell Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
43
jubeat@asphyxia/DEV.md
Normal file
43
jubeat@asphyxia/DEV.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# Jubeat Plugin: Development Notes
|
||||
|
||||
## Code layout
|
||||
|
||||
Each supported version is a module under `versions/` that owns its routes. All versions call the same
|
||||
method names, so `versions/index.ts` picks the version from the date in the model string
|
||||
(`L44:J:A:A:2015100000`) and calls that version's handler.
|
||||
|
||||
- `versions/prop/`, `qubell/`, `clan/`, `festo/`
|
||||
- `index.ts` the version's route table and model date range
|
||||
- the rest: that version's info node, profile format and features (prop: `course.ts`, `league.ts`)
|
||||
- `handlers/` shared building blocks the versions wire up
|
||||
- `player.ts` the shared profile (jubeat ID, name), and the move of V2.1.0 Qubell saves
|
||||
- `scores.ts` the shared score records, single-play saving, and the pre-festo `mdata_list`
|
||||
- `version_data.ts` per-version fields, course results and league results, keyed by version id
|
||||
- `common.ts`, `lobby.ts` replies several versions share
|
||||
- `models/` stored documents; `data/` per-version tables
|
||||
|
||||
## Versions and stored data
|
||||
|
||||
Version ids are the game's number in the series (7 prop, 8 Qubell, 9 clan, 10 festo), which are also
|
||||
the first digits of the music ids each version added; a version is only sent songs up to its own.
|
||||
|
||||
| Version | Model dates | Version id |
|
||||
| ------- | ------------------------- | ---------- |
|
||||
| prop | 2015022000 - 2016032999 | 7 |
|
||||
| Qubell | 2016033000 - 2017062599 | 8 |
|
||||
| clan | 2017062600 - 2018089999 | 9 |
|
||||
| festo | 2018090000 and later | 10 |
|
||||
|
||||
A model string without a date is answered as festo; builds older than prop are refused.
|
||||
|
||||
- `profile`: the shared profile. `jubeatId` and `name` are used by every version; the other fields are festo's.
|
||||
- `score`: one record per chart, shared by every version. `clear` holds the game's clear flags, which every
|
||||
version numbers the same way. Versions before festo only read and write normal-mode records (`isHardMode: false`).
|
||||
- `version_data`, `version_course`, `version_league`: fields and results of versions before festo, keyed by
|
||||
version id, so other versions never receive them.
|
||||
- `qubell_profile` / `qubell_score`: V2.1.0 Qubell saves, moved to the above on the card's first login and
|
||||
kept, marked `migrated`.
|
||||
|
||||
## Adding a version
|
||||
|
||||
Copy the closest module, change what differs, and list it in `versions/index.ts`.
|
||||
@@ -4,9 +4,13 @@ Jubeat Plugin for Asphyxia Core
|
||||
|
||||
# Supported Versions
|
||||
|
||||
- prop
|
||||
- Qubell (tested with L44:J:B:A:2017062001)
|
||||
- clan (answered with Qubell's handlers, untested)
|
||||
- Festo
|
||||
- prop (model dates 2015022000 - 2016032999; profile, scores, course mode, league, shop info)
|
||||
- Qubell (tested with L44:J:B:A:2017062001; prop and clan are routed to the same handlers but untested)
|
||||
|
||||
Scores are shared by every version (a version only sees the songs and charts it has). The jubeat ID and name
|
||||
are shared; each version keeps its own settings, items and progress.
|
||||
|
||||
# Versions
|
||||
|
||||
@@ -23,14 +27,19 @@ Jubeat Plugin for Asphyxia Core
|
||||
- Older builds (model date < 2018090000) use the Qubell handlers; festo behaviour is unchanged
|
||||
|
||||
- V2.2.0 (2026/11/27)
|
||||
- Add jubeat prop support via version-split handlers in `prop/`
|
||||
- Add jubeat prop support
|
||||
- Profile load/save in the prop layout (career, league class, jbox, items, navi, events)
|
||||
- Score list (`gametop.get_mdata`, split over its 3 requests) and score saving with ghosts
|
||||
- Course mode (`gametop.get_course`) with the Saucer Fulfill base courses and the 5th KAC prop courses
|
||||
- Weekly league (`gametop.get_league`): 3 songs per week, top 30% promoted and bottom 30% demoted, absent players demoted every 2 weeks
|
||||
- Daily FC challenge songs and a hit chart from local plays
|
||||
- prop data is stored in its own collections (`prop_profile`, `prop_score`, `prop_course`, `prop_league`); a card that already has a Qubell or festo profile gets a new prop profile with the same name
|
||||
- All secret songs are unlocked
|
||||
- Daily FC challenge songs
|
||||
- One jubeat ID and name per card in every version
|
||||
- Scores are shared by every version; prop, Qubell and clan only see normal-mode charts of the songs they have
|
||||
- Qubell saves from V2.1.0 are moved over on the card's first login
|
||||
- clan has its own entry (still answered with Qubell's handlers) and keeps its own data
|
||||
- Hit charts list the most played songs on the server
|
||||
- Builds older than prop are now refused instead of being answered as Qubell
|
||||
- All secret songs are unlocked on prop and Qubell
|
||||
- The WebUI profile pages still only show festo data
|
||||
|
||||
# TODO
|
||||
|
||||
44
jubeat@asphyxia/handlers/common.ts
Normal file
44
jubeat@asphyxia/handlers/common.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { VersionInfo } from "../versions/types";
|
||||
import { mostPlayed } from "./scores";
|
||||
|
||||
// Replies that versions before festo share.
|
||||
|
||||
export const news: EamusePluginRoute = (info, data, send) =>
|
||||
send.object({ data: { officialnews: K.ATTR({ count: "0" }) } }, { compress: true });
|
||||
|
||||
/** Top 10 songs by plays on this server, limited to the version's songs. */
|
||||
export const hitchart = (version: VersionInfo): EamusePluginRoute => async (info, data, send) => {
|
||||
const now = new Date();
|
||||
const pad = (n: number) => (n < 10 ? "0" : "") + n;
|
||||
const top = await mostPlayed(version, 10);
|
||||
return send.object({
|
||||
data: {
|
||||
update: K.ITEM("str", `${pad(now.getDate())}/${pad(now.getMonth() + 1)}/${now.getFullYear()}`),
|
||||
hitchart_lic: K.ATTR({ count: "0" }),
|
||||
hitchart_org: K.ATTR({ count: String(top.length) }, {
|
||||
rankdata: top.map((id, i) => ({
|
||||
music_id: K.ITEM("s32", id),
|
||||
rank: K.ITEM("s16", i + 1),
|
||||
prev: K.ITEM("s16", i + 1),
|
||||
})),
|
||||
}),
|
||||
},
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const meeting: EamusePluginRoute = (info, data, send) =>
|
||||
send.object({
|
||||
data: {
|
||||
meeting: { single: K.ATTR({ count: "0" }), tag: K.ATTR({ count: "0" }) },
|
||||
reward: { total: K.ITEM("s32", -1), point: K.ITEM("s32", -1) },
|
||||
},
|
||||
}, { compress: true });
|
||||
|
||||
export const lobbyCheck: EamusePluginRoute = (info, data, send) =>
|
||||
send.object({
|
||||
data: {
|
||||
interval: K.ITEM("s16", 0),
|
||||
entry_timeout: K.ITEM("s16", 0),
|
||||
entrant_nr: K.ITEM("u32", 0, { time: "0" }),
|
||||
},
|
||||
}, { compress: true });
|
||||
@@ -1,3 +1,5 @@
|
||||
// Lobby replies (festo's layout). Every version uses entry / refresh / report; festo also uses check.
|
||||
|
||||
export const Check = (req, reqData, send) => {
|
||||
const { data } = reqData;
|
||||
const enter = $(data).content("enter");
|
||||
84
jubeat@asphyxia/handlers/player.ts
Normal file
84
jubeat@asphyxia/handlers/player.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import Profile from "../models/profile";
|
||||
import { mergeRecord } from "./scores";
|
||||
import { loadVersionData, saveVersionData } from "./version_data";
|
||||
|
||||
/** The player's shared profile (jubeat ID, name), after moving any old Qubell save over. */
|
||||
export async function findPlayer(refid: string): Promise<Profile | null> {
|
||||
await migrateQubell(refid);
|
||||
return DB.FindOne<Profile>(refid, { collection: "profile" });
|
||||
}
|
||||
|
||||
export function playerByJid(jid: number) {
|
||||
return DB.FindOne<Profile>(null, { collection: "profile", jubeatId: jid });
|
||||
}
|
||||
|
||||
/** An unused 8-digit jubeat ID. */
|
||||
export async function newJubeatId(): Promise<number> {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const jid = 10000000 + Math.floor(Math.random() * 89999999);
|
||||
if (!(await playerByJid(jid))) return jid;
|
||||
}
|
||||
return 10000000 + Math.floor(Math.random() * 89999999);
|
||||
}
|
||||
|
||||
/** Creates the shared profile, in the shape festo loads. */
|
||||
export async function createPlayer(refid: string, name: string, jubeatId?: number): Promise<Profile> {
|
||||
const profile: Profile = {
|
||||
collection: "profile",
|
||||
jubeatId: jubeatId || await newJubeatId(),
|
||||
eventFlag: 0,
|
||||
name,
|
||||
isFirstplay: true,
|
||||
emo: [],
|
||||
lastShopname: "",
|
||||
lastAreaname: "",
|
||||
};
|
||||
await DB.Upsert<Profile>(refid, { collection: "profile" }, profile);
|
||||
return DB.FindOne<Profile>(refid, { collection: "profile" });
|
||||
}
|
||||
|
||||
/**
|
||||
* The player's profile, created when missing. Versions before festo use this
|
||||
* in get_pdata too: CORE already reports a card as registered for L44 once any
|
||||
* version made a profile for it, so the game skips gametop.regist.
|
||||
*/
|
||||
export async function loadPlayer(refid: string, name?: string): Promise<Profile> {
|
||||
return (await findPlayer(refid)) || createPlayer(refid, name || "なし");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Qubell saves from plugin v2.1.0 (qubell_profile / qubell_score)
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
const QUBELL = 8;
|
||||
|
||||
/**
|
||||
* Moves a v2.1.0 Qubell save into the shared profile, Qubell's version data
|
||||
* and the shared scores, once. The old documents are kept, marked `migrated`.
|
||||
*/
|
||||
async function migrateQubell(refid: string) {
|
||||
const old: any = await DB.FindOne<any>(refid, { collection: "qubell_profile" });
|
||||
if (!old || old.migrated) return;
|
||||
|
||||
if (!(await DB.FindOne<Profile>(refid, { collection: "profile" }))) {
|
||||
const taken = old.jid && await playerByJid(old.jid);
|
||||
await createPlayer(refid, old.name || "なし", taken ? undefined : old.jid);
|
||||
}
|
||||
|
||||
if (Object.keys(await loadVersionData(refid, QUBELL)).length === 0) {
|
||||
const { _id, __refid, createdAt, updatedAt, collection, jid, name, migrated, ...fields } = old;
|
||||
await saveVersionData(refid, QUBELL, fields);
|
||||
}
|
||||
|
||||
let scores = 0;
|
||||
for (const s of await DB.Find<any>(refid, { collection: "qubell_score" })) {
|
||||
await mergeRecord(refid, {
|
||||
musicId: s.musicId, seq: s.seq, score: s.score, clear: s.clear, bar: s.bar,
|
||||
playCount: s.playCnt, clearCount: s.clearCnt, fullcomboCount: s.fcCnt, excellentCount: s.exCnt,
|
||||
});
|
||||
scores++;
|
||||
}
|
||||
|
||||
await DB.Update<any>(refid, { collection: "qubell_profile" }, { $set: { migrated: true } } as any);
|
||||
console.log(`[jubeat] moved Qubell save of ${old.name} (${scores} records) to the shared profile`);
|
||||
}
|
||||
127
jubeat@asphyxia/handlers/scores.ts
Normal file
127
jubeat@asphyxia/handlers/scores.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
import { Score } from "../models/score";
|
||||
import { VersionInfo } from "../versions/types";
|
||||
|
||||
/** Clear flags, numbered the same way by every version. */
|
||||
export const Flag = {
|
||||
PLAYED: 0x1,
|
||||
CLEARED: 0x2,
|
||||
FULL_COMBO: 0x4,
|
||||
EXCELLENT: 0x8,
|
||||
};
|
||||
|
||||
const fix = (v: any, n: number, def: number): number[] => {
|
||||
const a = Array.isArray(v) ? v.slice(0, n) : [];
|
||||
while (a.length < n) a.push(def);
|
||||
return a;
|
||||
};
|
||||
|
||||
/** Every record a version can show: its songs, normal mode, basic to extreme. */
|
||||
export async function versionScores(refid: string, version: VersionInfo): Promise<Score[]> {
|
||||
const all = await DB.Find<Score>(refid, { collection: "score" });
|
||||
return all.filter(s => !s.isHardMode && s.seq >= 0 && s.seq <= 2 &&
|
||||
(version.maxMusicId === undefined || s.musicId <= version.maxMusicId));
|
||||
}
|
||||
|
||||
const chart = (musicId: number, seq: number) => ({ collection: "score" as const, musicId, seq, isHardMode: false });
|
||||
|
||||
/**
|
||||
* Saves one normal-mode play from a version that reports single plays (prop,
|
||||
* Qubell, clan): counts go up by the play's flags, the best score and its
|
||||
* ghost are kept, and clear flags accumulate.
|
||||
*/
|
||||
export async function addPlay(refid: string, musicId: number, seq: number, score: number, clear: number, bar?: number[]) {
|
||||
const old = await DB.FindOne<Score>(refid, chart(musicId, seq));
|
||||
const best = old ? old.score | 0 : 0;
|
||||
await DB.Upsert<Score>(refid, chart(musicId, seq), {
|
||||
$set: {
|
||||
score: Math.max(best, score),
|
||||
clear: (old ? old.clear | 0 : 0) | clear,
|
||||
bar: bar && bar.length && (score >= best || !(old && old.bar && old.bar.length)) ? bar : (old && old.bar) || [],
|
||||
playCount: (old ? old.playCount | 0 : 0) + 1,
|
||||
clearCount: (old ? old.clearCount | 0 : 0) + (clear & Flag.CLEARED ? 1 : 0),
|
||||
fullcomboCount: (old ? old.fullcomboCount | 0 : 0) + (clear & Flag.FULL_COMBO ? 1 : 0),
|
||||
excellentCount: (old ? old.excellentCount | 0 : 0) + (clear & Flag.EXCELLENT ? 1 : 0),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** Adds records kept elsewhere (an old save) to the shared ones: best of both, counts summed. */
|
||||
export async function mergeRecord(refid: string, r: {
|
||||
musicId: number; seq: number; score: number; clear: number; bar?: number[];
|
||||
playCount: number; clearCount: number; fullcomboCount: number; excellentCount: number;
|
||||
}) {
|
||||
const old = await DB.FindOne<Score>(refid, chart(r.musicId, r.seq));
|
||||
const better = !old || (r.score | 0) > (old.score | 0);
|
||||
await DB.Upsert<Score>(refid, chart(r.musicId, r.seq), {
|
||||
$set: {
|
||||
score: Math.max(old ? old.score | 0 : 0, r.score | 0),
|
||||
clear: (old ? old.clear | 0 : 0) | (r.clear | 0),
|
||||
bar: (better && r.bar && r.bar.length) ? r.bar : (old && old.bar) || r.bar || [],
|
||||
playCount: (old ? old.playCount | 0 : 0) + (r.playCount | 0),
|
||||
clearCount: (old ? old.clearCount | 0 : 0) + (r.clearCount | 0),
|
||||
fullcomboCount: (old ? old.fullcomboCount | 0 : 0) + (r.fullcomboCount | 0),
|
||||
excellentCount: (old ? old.excellentCount | 0 : 0) + (r.excellentCount | 0),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the `data.result.tune` plays of a prop / Qubell / clan `gameend.regist`.
|
||||
* Returns the saved plays in order, for the profile's last-played song.
|
||||
*/
|
||||
export async function saveResultTunes(refid: string, d: KDataReader) {
|
||||
const saved: { musicId: number; seq: number }[] = [];
|
||||
for (const tune of d.elements("data.result.tune") || []) {
|
||||
const musicId = tune.number("music");
|
||||
const attr = tune.attr("player.score") || {};
|
||||
const seq = parseInt(attr.seq);
|
||||
if (!musicId || isNaN(seq)) continue;
|
||||
await addPlay(refid, musicId, seq, tune.number("player.score") | 0, parseInt(attr.clear) | 0, tune.numbers("player.mbar"));
|
||||
saved.push({ musicId, seq });
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
/**
|
||||
* `mdata_list` for versions before festo. The game asks three times
|
||||
* (mdata_ver 1 to 3); songs are split by music id so each answer stays small.
|
||||
*/
|
||||
export function legacyMdata(scores: Score[], part: number) {
|
||||
const byMusic: { [id: string]: Score[] } = {};
|
||||
for (const s of scores) (byMusic[String(s.musicId)] = byMusic[String(s.musicId)] || []).push(s);
|
||||
const ids = Object.keys(byMusic).sort((a, b) => parseInt(a) - parseInt(b));
|
||||
const per = Math.ceil(ids.length / 3);
|
||||
const mine = ids.length < 50 ? (part === 1 ? ids : []) : ids.slice((part - 1) * per, part * per);
|
||||
|
||||
return mine.map(id => {
|
||||
const play = [0, 0, 0], clr = [0, 0, 0], fc = [0, 0, 0], ex = [0, 0, 0], pts = [0, 0, 0], flags = [0, 0, 0];
|
||||
const bars: any[] = [];
|
||||
for (const s of byMusic[id]) {
|
||||
play[s.seq] = s.playCount | 0; clr[s.seq] = s.clearCount | 0;
|
||||
fc[s.seq] = s.fullcomboCount | 0; ex[s.seq] = s.excellentCount | 0;
|
||||
pts[s.seq] = s.score | 0;
|
||||
let f = Flag.PLAYED;
|
||||
if (s.clearCount > 0 || (s.clear & Flag.CLEARED)) f |= Flag.CLEARED;
|
||||
if (s.fullcomboCount > 0 || (s.clear & Flag.FULL_COMBO)) f |= Flag.FULL_COMBO;
|
||||
if (s.excellentCount > 0 || (s.clear & Flag.EXCELLENT)) f |= Flag.EXCELLENT;
|
||||
flags[s.seq] = f;
|
||||
if (s.bar && s.bar.length) bars.push(K.ARRAY("u8", fix(s.bar, 30, 0), { seq: String(s.seq) }));
|
||||
}
|
||||
return K.ATTR({ music_id: id }, {
|
||||
play_cnt: K.ARRAY("s32", play), clear_cnt: K.ARRAY("s32", clr),
|
||||
fc_cnt: K.ARRAY("s32", fc), ex_cnt: K.ARRAY("s32", ex),
|
||||
score: K.ARRAY("s32", pts), clear: K.ARRAY("s8", flags),
|
||||
...(bars.length ? { bar: bars } : {}),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** Music ids by total plays across all players, most played first. */
|
||||
export async function mostPlayed(version: VersionInfo, count: number): Promise<number[]> {
|
||||
const plays: { [id: string]: number } = {};
|
||||
for (const s of await DB.Find<Score>(null, { collection: "score" })) {
|
||||
if (version.maxMusicId !== undefined && s.musicId > version.maxMusicId) continue;
|
||||
plays[String(s.musicId)] = (plays[String(s.musicId)] || 0) + (s.playCount | 0);
|
||||
}
|
||||
return Object.keys(plays).sort((a, b) => plays[b] - plays[a]).slice(0, count).map(id => parseInt(id));
|
||||
}
|
||||
46
jubeat@asphyxia/handlers/version_data.ts
Normal file
46
jubeat@asphyxia/handlers/version_data.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { VersionCourse, VersionData, VersionLeague } from "../models/version_data";
|
||||
|
||||
const META = ["_id", "__refid", "createdAt", "updatedAt", "collection", "version"];
|
||||
const strip = (doc: any) => {
|
||||
const out: Record<string, any> = {};
|
||||
for (const key of Object.keys(doc || {})) if (!META.includes(key)) out[key] = doc[key];
|
||||
return out;
|
||||
};
|
||||
|
||||
/** A player's fields for one version (`{}` until the version saves something). */
|
||||
export async function loadVersionData(refid: string, version: number): Promise<Record<string, any>> {
|
||||
return strip(await DB.FindOne<VersionData>(refid, { collection: "version_data", version }));
|
||||
}
|
||||
|
||||
export async function saveVersionData(refid: string, version: number, fields: Record<string, any>) {
|
||||
await DB.Upsert<VersionData>(refid, { collection: "version_data", version }, { $set: strip(fields) });
|
||||
}
|
||||
|
||||
export function versionCourses(refid: string, version: number) {
|
||||
return DB.Find<VersionCourse>(refid, { collection: "version_course", version });
|
||||
}
|
||||
|
||||
export function findVersionCourse(refid: string, version: number, courseId: number) {
|
||||
return DB.FindOne<VersionCourse>(refid, { collection: "version_course", version, courseId });
|
||||
}
|
||||
|
||||
export async function saveVersionCourse(refid: string, version: number, courseId: number, rating: number, scores: number[]) {
|
||||
await DB.Upsert<VersionCourse>(refid, { collection: "version_course", version, courseId }, { $set: { rating, scores } });
|
||||
}
|
||||
|
||||
export function findLeague(refid: string, version: number, leagueId: number) {
|
||||
return DB.FindOne<VersionLeague>(refid, { collection: "version_league", version, leagueId });
|
||||
}
|
||||
|
||||
/** Every player's result in one league, for promotions. */
|
||||
export function leagueResults(version: number, leagueId: number) {
|
||||
return DB.Find<VersionLeague>(null, { collection: "version_league", version, leagueId });
|
||||
}
|
||||
|
||||
export function playerLeagues(refid: string, version: number) {
|
||||
return DB.Find<VersionLeague>(refid, { collection: "version_league", version });
|
||||
}
|
||||
|
||||
export async function saveLeague(refid: string, version: number, leagueId: number, score: number[], clear: number[]) {
|
||||
await DB.Upsert<VersionLeague>(refid, { collection: "version_league", version, leagueId }, { $set: { score, clear } });
|
||||
}
|
||||
@@ -1,79 +1,13 @@
|
||||
import ShopInfo from "./routes/shopinfo";
|
||||
import {getProfile, Getinfo, loadScore, Meeting} from "./routes/gametop";
|
||||
import {saveProfile} from "./routes/gameend";
|
||||
import {Check, Entry, Refresh, Report} from "./routes/lobby";
|
||||
import * as Q from "./qubell/qubell";
|
||||
import * as P from "./prop/prop";
|
||||
|
||||
// Version split: the original handlers target festo (2018-09 onward). prop builds
|
||||
// (2015022000 - 2016032999) are answered by ./prop, other older builds (Qubell / clan) by the
|
||||
// Qubell handlers in ./qubell. The model string looks like "L44:J:B:A:2017062001".
|
||||
const modelDate = (info: EamuseInfo): number => parseInt((info.model || "").split(":")[4]);
|
||||
const isProp = (info: EamuseInfo): boolean => {
|
||||
const date = modelDate(info);
|
||||
return !isNaN(date) && date >= 2015022000 && date < 2016033000;
|
||||
};
|
||||
const isPreFesto = (info: EamuseInfo): boolean => {
|
||||
const date = modelDate(info);
|
||||
return !isNaN(date) && date < 2018090000;
|
||||
};
|
||||
|
||||
// Never let a handler exception surface as an HTTP error: log it and deny instead.
|
||||
const guard = (name: string, fn: EamusePluginRoute): EamusePluginRoute =>
|
||||
async (info, data, send) => {
|
||||
try {
|
||||
return await fn(info, data, send);
|
||||
} catch (e) {
|
||||
console.error(`[jubeat] ${name} failed: ${e && e.stack ? e.stack : e}`);
|
||||
return send.deny();
|
||||
}
|
||||
};
|
||||
|
||||
type Handler = EamusePluginRoute | boolean;
|
||||
const run = (h: Handler, info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
if (h === true) return send.success();
|
||||
if (h === false) return send.deny();
|
||||
return guard(`${info.module}.${info.method}`, h as EamusePluginRoute)(info, data, send);
|
||||
};
|
||||
|
||||
const split = (prop: Handler, qubell: Handler, festo: Handler): EamusePluginRoute =>
|
||||
(info, data, send) => {
|
||||
if (isProp(info)) return run(prop, info, data, send);
|
||||
if (isPreFesto(info)) return run(qubell, info, data, send);
|
||||
if (festo === true || festo === false) return run(festo, info, data, send);
|
||||
return (festo as EamusePluginRoute)(info, data, send);
|
||||
};
|
||||
import { registerVersions } from "./versions";
|
||||
|
||||
export async function register() {
|
||||
if (CORE_VERSION_MAJOR <= 1 && CORE_VERSION_MINOR < 31) {
|
||||
console.error("The current version of Asphyxia Core is not supported. Requires version '1.31' or later.");
|
||||
return;
|
||||
}
|
||||
R.GameCode("L44");
|
||||
R.Contributor("yuanqiuye", "https://github.com/yuanqiuye")
|
||||
|
||||
R.Route("gametop.regist", split(P.gametopRegist, Q.gametopRegist, getProfile));
|
||||
R.Route("gametop.get_info", split(P.gametopGetInfo, Q.gametopGetInfo, Getinfo));
|
||||
R.Route("gametop.get_pdata", split(P.gametopGetPdata, Q.gametopGetPdata, getProfile));
|
||||
R.Route("gametop.get_mdata", split(P.gametopGetMdata, Q.gametopGetMdata, loadScore));
|
||||
R.Route("gametop.get_meeting", split(P.gametopGetMeeting, Q.gametopGetMeeting, Meeting));
|
||||
R.Route("gametop.get_course", split(P.gametopGetCourse, true, true));
|
||||
R.Route("gametop.get_league", split(P.gametopGetLeague, true, true));
|
||||
|
||||
R.Route("gameend.final", split(true, Q.gameendFinal, true));
|
||||
R.Route("gameend.regist", split(P.gameendRegist, Q.gameendRegist, saveProfile));
|
||||
|
||||
R.Route("shopinfo.regist", split(P.shopinfoRegist, Q.shopinfoRegist, ShopInfo));
|
||||
R.Route("lobby.check", split(P.lobbyCheck, Q.lobbyCheck, Check));
|
||||
R.Route("lobby.entry", Entry);
|
||||
R.Route("lobby.refresh", Refresh);
|
||||
R.Route("lobby.report", Report);
|
||||
|
||||
R.Route("demodata.get_news", split(P.demodataGetNews, Q.demodataGetNews, true));
|
||||
R.Route("demodata.get_hitchart", split(P.demodataGetHitchart, Q.demodataGetHitchart, true));
|
||||
R.Route("recommend.get_recommend", split(true, Q.recommendGetRecommend, true));
|
||||
|
||||
R.Route("netlog.send", true);
|
||||
R.Route("logger.report", true);
|
||||
R.Unhandled();
|
||||
if (CORE_VERSION_MAJOR <= 1 && CORE_VERSION_MINOR < 31) {
|
||||
console.error("The current version of Asphyxia Core is not supported. Requires version '1.31' or later.");
|
||||
return;
|
||||
}
|
||||
R.GameCode("L44");
|
||||
R.Contributor("yuanqiuye", "https://github.com/yuanqiuye");
|
||||
|
||||
registerVersions();
|
||||
R.Unhandled();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* The shared player profile. `jubeatId` and `name` are used by every version;
|
||||
* the other fields are festo's (older versions keep theirs in version data).
|
||||
*/
|
||||
export default interface Profile {
|
||||
collection: "profile";
|
||||
navi?: number,
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
/**
|
||||
* One chart's record, shared by every version.
|
||||
*
|
||||
* `clear` holds the game's clear flags, which every version numbers the same
|
||||
* way (see `Flag` in handlers/scores.ts). Versions before festo only have
|
||||
* normal mode, so they only read and write records with `isHardMode: false`.
|
||||
*/
|
||||
export interface Score {
|
||||
collection: "score";
|
||||
|
||||
musicId: number;
|
||||
seq: number;
|
||||
score: number;
|
||||
clear: number;
|
||||
musicRate: number;
|
||||
bar: number[];
|
||||
playCount: number;
|
||||
clearCount: number;
|
||||
fullcomboCount: number;
|
||||
excellentCount: number;
|
||||
isHardMode: boolean;
|
||||
}
|
||||
collection: "score";
|
||||
|
||||
musicId: number;
|
||||
seq: number;
|
||||
score: number;
|
||||
clear: number;
|
||||
/** festo only. */
|
||||
musicRate?: number;
|
||||
bar?: number[];
|
||||
playCount: number;
|
||||
clearCount: number;
|
||||
fullcomboCount: number;
|
||||
excellentCount: number;
|
||||
isHardMode: boolean;
|
||||
}
|
||||
|
||||
31
jubeat@asphyxia/models/version_data.ts
Normal file
31
jubeat@asphyxia/models/version_data.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Per-version player data for versions before festo.
|
||||
*
|
||||
* The shared `profile` keeps the jubeat ID and name (and festo's own fields);
|
||||
* anything an older version defines its own way lives here, keyed by version
|
||||
* id, so other versions never receive it.
|
||||
*/
|
||||
export interface VersionData {
|
||||
collection: "version_data";
|
||||
version: number;
|
||||
[field: string]: any;
|
||||
}
|
||||
|
||||
/** A course result in one version (prop's course mode). */
|
||||
export interface VersionCourse {
|
||||
collection: "version_course";
|
||||
version: number;
|
||||
courseId: number;
|
||||
/** The game's rating: 1 failed, 2 bronze, 3 silver, 4 gold. */
|
||||
rating: number;
|
||||
scores: number[];
|
||||
}
|
||||
|
||||
/** A player's result in one weekly league (prop). */
|
||||
export interface VersionLeague {
|
||||
collection: "version_league";
|
||||
version: number;
|
||||
leagueId: number;
|
||||
score: number[];
|
||||
clear: number[];
|
||||
}
|
||||
@@ -1,788 +0,0 @@
|
||||
declare const BigInt: any; // CORE typecheck targets es2017
|
||||
// jubeat prop (L44, model dates 2015022000 - 2016032999) handlers for Asphyxia CORE.
|
||||
//
|
||||
// Request/response layout follows bemaniutils' bemani/backend/jubeat/prop.py, and was checked
|
||||
// against the property paths referenced by prop's jubeat.dll / course_db.dll / league_db.dll
|
||||
// (data/player/{info,last,item,history,fc_challenge,news,rivallist,lab_edit_seq,free_first_play,
|
||||
// event_info,jbox,career,league,new_music,eapass_privilege,bonus_music,bistro,navi,cabinet_survey,
|
||||
// kaitou_bisco,gift_list}, data/course_list, data/league_list, ...).
|
||||
//
|
||||
// Storage (separate from the festo and qubell collections):
|
||||
// prop_profile one per card
|
||||
// prop_score one per (musicId, seq)
|
||||
// prop_course one per course id
|
||||
// prop_league one per weekly league id
|
||||
|
||||
import { PROP_COURSES } from "./courses";
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// helpers
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
const fill = (n: number, v: number): number[] => new Array(n).fill(v);
|
||||
const s32a = (v: number[]) => K.ARRAY("s32", v);
|
||||
const fix = (v: any, n: number, def: number): number[] => {
|
||||
const a = Array.isArray(v) ? v.slice(0, n) : [];
|
||||
while (a.length < n) a.push(def);
|
||||
return a;
|
||||
};
|
||||
const ok = (v: any): boolean => v !== undefined && v !== null && !(typeof v === "number" && isNaN(v));
|
||||
|
||||
const FLAG_PLAYED = 0x1, FLAG_CLEARED = 0x2, FLAG_FC = 0x4, FLAG_EX = 0x8;
|
||||
|
||||
// Course ratings as the game sends/expects them.
|
||||
const COURSE_RATING_FAILED = 1;
|
||||
|
||||
const WEEK = 604800, DAY = 86400;
|
||||
const nowSec = () => Math.floor(Date.now() / 1000);
|
||||
|
||||
// Deterministic PRNG so every cabinet agrees on the weekly league / daily FC challenge songs.
|
||||
const mulberry32 = (seed: number) => () => {
|
||||
seed |= 0; seed = (seed + 0x6d2b79f5) | 0;
|
||||
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
|
||||
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
// Songs known to exist in prop: everything referenced by the course list.
|
||||
const SONG_POOL: number[] = Array.from(new Set(
|
||||
PROP_COURSES.reduce((a, c) => a.concat(c.music.map(m => m[0])), [] as number[]))).sort((a, b) => a - b);
|
||||
const pickSongs = (seed: number, n: number): number[] => {
|
||||
const rnd = mulberry32(seed), pool = SONG_POOL.slice(), out: number[] = [];
|
||||
while (out.length < n && pool.length) out.push(pool.splice(Math.floor(rnd() * pool.length), 1)[0]);
|
||||
return out;
|
||||
};
|
||||
|
||||
const currentLeagueId = () => Math.floor(nowSec() / WEEK);
|
||||
const leagueSongs = (leagueId: number) => pickSongs(leagueId * 7919 + 1, 3);
|
||||
const currentDayId = () => Math.floor(nowSec() / DAY);
|
||||
const fcChallenge = (dayId: number) => { const s = pickSongs(dayId * 104729 + 2, 2); return { today: s[0], whim: s[1] }; };
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// models
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
export interface PProfile {
|
||||
collection: "prop_profile";
|
||||
jid: number;
|
||||
name: string;
|
||||
saved: boolean;
|
||||
jubility: number; jubility_yday: number;
|
||||
tune_cnt: number; save_cnt: number; saved_cnt: number; fc_cnt: number; ex_cnt: number;
|
||||
pf_cnt: number; clear_cnt: number; match_cnt: number; beat_cnt: number; mynews_cnt: number;
|
||||
total_best_score: number;
|
||||
bonus_tune_points: number; is_bonus_tune_played: boolean;
|
||||
last: {
|
||||
play_time: number; shopname: string; areaname: string;
|
||||
music_id: number; seq_id: number; sort: number; category: number; expert_option: number;
|
||||
marker: number; theme: number; title: number; parts: number;
|
||||
rank_sort: number; combo_disp: number; matching: number; hazard: number; hard: number;
|
||||
emblem: number[];
|
||||
last_course_id: number;
|
||||
league_class: number; league_subclass: number;
|
||||
};
|
||||
music_list: number[]; theme_list: number; marker_list: number[];
|
||||
title_list: number[]; parts_list: number[]; emblem_list: number[];
|
||||
theme_list_new: number; marker_list_new: number[];
|
||||
career: { level: number; point: number; param: number[]; is_unlocked: boolean };
|
||||
jbox_point: number; jbox_normal_index: number; jbox_premium_index: number;
|
||||
navi_flag: number; kaitou_bisco_read_flag: number;
|
||||
events: { [type: string]: boolean };
|
||||
league_class: number; league_subclass: number;
|
||||
league_is_checked: boolean; league_is_first_play: boolean;
|
||||
league_eval_id: number; // last league week that promotion/demotion was applied for
|
||||
fc_day: number; fc_played: number[]; // FC challenge [today, whim] played on fc_day
|
||||
}
|
||||
|
||||
export interface PScore {
|
||||
collection: "prop_score";
|
||||
musicId: number; seq: number;
|
||||
score: number; clear: number; combo: number;
|
||||
playCnt: number; clearCnt: number; fcCnt: number; exCnt: number;
|
||||
bar: number[];
|
||||
time: number;
|
||||
}
|
||||
|
||||
export interface PCourse {
|
||||
collection: "prop_course";
|
||||
courseId: number;
|
||||
rating: number;
|
||||
scores: number[];
|
||||
}
|
||||
|
||||
export interface PLeague {
|
||||
collection: "prop_league";
|
||||
leagueId: number;
|
||||
score: number[];
|
||||
clear: number[];
|
||||
}
|
||||
|
||||
const newProfile = (name: string, jid: number): PProfile => ({
|
||||
collection: "prop_profile",
|
||||
jid, name, saved: false,
|
||||
jubility: 0, jubility_yday: 0,
|
||||
tune_cnt: 0, save_cnt: 0, saved_cnt: 0, fc_cnt: 0, ex_cnt: 0,
|
||||
pf_cnt: 0, clear_cnt: 0, match_cnt: 0, beat_cnt: 0, mynews_cnt: 0, total_best_score: 0,
|
||||
bonus_tune_points: 0, is_bonus_tune_played: false,
|
||||
last: {
|
||||
play_time: 0, shopname: "", areaname: "",
|
||||
music_id: 0, seq_id: 0, sort: 0, category: 0, expert_option: 0,
|
||||
marker: 0, theme: 0, title: 0, parts: 0, rank_sort: 0, combo_disp: 0,
|
||||
matching: 0, hazard: 0, hard: 0, emblem: [0, 0, 0, 0, 0],
|
||||
last_course_id: -1, league_class: 1, league_subclass: 5,
|
||||
},
|
||||
music_list: fill(32, -1), theme_list: -1, marker_list: fill(2, -1),
|
||||
title_list: fill(160, -1), parts_list: fill(160, -1), emblem_list: fill(96, 0),
|
||||
theme_list_new: -1, marker_list_new: fill(2, -1),
|
||||
career: { level: 1, point: 0, param: fill(10, -1), is_unlocked: false },
|
||||
jbox_point: 0, jbox_normal_index: 2, jbox_premium_index: 1,
|
||||
navi_flag: 0, kaitou_bisco_read_flag: 0,
|
||||
events: {},
|
||||
league_class: 1, league_subclass: 5, league_is_checked: true, league_is_first_play: true,
|
||||
league_eval_id: 0,
|
||||
fc_day: 0, fc_played: [0, 0],
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// global "info" node (shopinfo.regist, gametop.get_info, and inside every profile)
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
const EVENTS = [5, 6, 9, 14, 15, 16, 17, 18, 19];
|
||||
|
||||
export const propInfo = () => ({
|
||||
event_info: {
|
||||
event: EVENTS.map(e => K.ATTR({ type: String(e) }, { state: K.ITEM("u8", 0) })),
|
||||
},
|
||||
share_music: {},
|
||||
bonus_music: {},
|
||||
only_now_music: {},
|
||||
fc_challenge: { today: { music_id: K.ITEM("s32", fcChallenge(currentDayId()).today) } },
|
||||
white_music_list: s32a(fill(32, -1)),
|
||||
open_music_list: s32a(fill(32, -1)),
|
||||
cabinet_survey: { id: K.ITEM("s32", -1), status: K.ITEM("s32", 0) },
|
||||
kaitou_bisco: { remaining_days: K.ITEM("s32", 0) },
|
||||
league: { status: K.ITEM("u8", 1) },
|
||||
bistro: { bistro_id: K.ITEM("u16", 0) },
|
||||
jbox: {
|
||||
point: K.ITEM("s32", 0),
|
||||
emblem: {
|
||||
normal: { index: K.ITEM("s16", 2) },
|
||||
premium: { index: K.ITEM("s16", 1) },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// league promotion / demotion
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Class 1-4 (Amateur, Regular, Master, Legend), subclass 5 (lowest) .. 1 (highest); Legend has
|
||||
// only subclass 1. Rank 0..15 is the linear order of those.
|
||||
const classToRank = (c: number, s: number): number => {
|
||||
c = Math.min(4, Math.max(1, c | 0)); s = Math.min(5, Math.max(1, s | 0));
|
||||
return c === 4 ? 15 : (c - 1) * 5 + (5 - s);
|
||||
};
|
||||
const rankToClass = (r: number): [number, number] => {
|
||||
r = Math.min(15, Math.max(0, r | 0));
|
||||
return r === 15 ? [4, 1] : [Math.floor(r / 5) + 1, 5 - (r % 5)];
|
||||
};
|
||||
|
||||
const shiftClass = (p: PProfile, delta: number) => {
|
||||
const [nc, ns] = rankToClass(classToRank(p.league_class, p.league_subclass) + delta);
|
||||
if (nc === p.league_class && ns === p.league_subclass) return;
|
||||
// Remember the class the player last saw, so the game can show the change.
|
||||
if (p.league_is_checked) {
|
||||
p.last.league_class = p.league_class;
|
||||
p.last.league_subclass = p.league_subclass;
|
||||
}
|
||||
p.league_class = nc; p.league_subclass = ns;
|
||||
p.league_is_checked = false;
|
||||
};
|
||||
|
||||
const leagueTotal = (l: PLeague) => fix(l.score, 3, 0).reduce((a, b) => a + b, 0);
|
||||
|
||||
// Lazily apply the weekly league evaluation (bemaniutils does this from a weekly cron job):
|
||||
// top 30% of last week's participants are promoted, the bottom ~30% demoted, and players who
|
||||
// have been absent for every second week since they last played are demoted.
|
||||
const evaluateLeague = async (refid: string, p: PProfile): Promise<boolean> => {
|
||||
const cur = currentLeagueId();
|
||||
if ((p.league_eval_id | 0) >= cur) return false;
|
||||
const mine = await DB.Find<PLeague>(refid, { collection: "prop_league" });
|
||||
const played = new Set(mine.map(l => l.leagueId));
|
||||
const from = Math.max((p.league_eval_id | 0) + 1, cur - 52);
|
||||
for (let w = from; w <= cur; w++) {
|
||||
const prev = w - 1;
|
||||
let lastPlayed = 0;
|
||||
played.forEach(id => { if (id < w && id > lastPlayed) lastPlayed = id; });
|
||||
if (lastPlayed === 0) continue; // never played a league before this week
|
||||
if (played.has(prev)) {
|
||||
const all = await DB.Find<PLeague>(null, { collection: "prop_league", leagueId: prev });
|
||||
const sorted = all.map(l => ({ refid: (l as any).__refid, total: leagueTotal(l) }))
|
||||
.sort((a, b) => b.total - a.total);
|
||||
const promoted = Math.ceil(sorted.length * 0.3);
|
||||
const rest = sorted.slice(promoted);
|
||||
const demoted = Math.ceil(rest.length * 0.42);
|
||||
const idx = sorted.findIndex(x => x.refid === refid);
|
||||
if (idx >= 0 && idx < promoted) shiftClass(p, +1);
|
||||
else if (idx >= promoted && demoted > 0 && idx >= sorted.length - demoted) shiftClass(p, -1);
|
||||
} else {
|
||||
const weeksDifferent = (w - lastPlayed) - 1;
|
||||
if (weeksDifferent >= 2 && weeksDifferent % 2 === 0) shiftClass(p, -1);
|
||||
}
|
||||
}
|
||||
p.league_eval_id = cur;
|
||||
return true;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// profile -> response
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
const formatProfile = (p: PProfile) => {
|
||||
const l = p.last;
|
||||
const emblem = fix(l.emblem, 5, 0);
|
||||
if (emblem[1] === 0) emblem[1] = 2; // default main part, as bemaniutils does
|
||||
const career = p.career || { level: 1, point: 0, param: fill(10, -1), is_unlocked: false };
|
||||
const fc = fcChallenge(currentDayId());
|
||||
const fcPlayed = p.fc_day === currentDayId() ? fix(p.fc_played, 2, 0) : [0, 0];
|
||||
|
||||
return {
|
||||
data: {
|
||||
info: propInfo(),
|
||||
player: {
|
||||
name: K.ITEM("str", p.name),
|
||||
jid: K.ITEM("s32", p.jid),
|
||||
session_id: K.ITEM("s32", 1),
|
||||
event_flag: K.ITEM("u64", BigInt(0)),
|
||||
info: {
|
||||
jubility: K.ITEM("s16", p.jubility | 0),
|
||||
jubility_yday: K.ITEM("s16", p.jubility_yday | 0),
|
||||
tune_cnt: K.ITEM("s32", p.tune_cnt | 0),
|
||||
save_cnt: K.ITEM("s32", p.save_cnt | 0),
|
||||
saved_cnt: K.ITEM("s32", p.saved_cnt | 0),
|
||||
fc_cnt: K.ITEM("s32", p.fc_cnt | 0),
|
||||
ex_cnt: K.ITEM("s32", p.ex_cnt | 0),
|
||||
clear_cnt: K.ITEM("s32", p.clear_cnt | 0),
|
||||
pf_cnt: K.ITEM("s32", p.pf_cnt | 0),
|
||||
match_cnt: K.ITEM("s32", p.match_cnt | 0),
|
||||
beat_cnt: K.ITEM("s32", p.beat_cnt | 0),
|
||||
mynews_cnt: K.ITEM("s32", p.mynews_cnt | 0),
|
||||
bonus_tune_points: K.ITEM("s32", p.bonus_tune_points | 0),
|
||||
is_bonus_tune_played: K.ITEM("bool", !!p.is_bonus_tune_played),
|
||||
// true would mark this as a carried-over profile and skip the tutorial; there is no
|
||||
// older-version data to inherit from here.
|
||||
inherit: K.ITEM("bool", false),
|
||||
mtg_entry_cnt: K.ITEM("s32", 123),
|
||||
mtg_hold_cnt: K.ITEM("s32", 456),
|
||||
mtg_result: K.ITEM("u8", 10),
|
||||
},
|
||||
last: {
|
||||
play_time: K.ITEM("s64", BigInt(l.play_time || 0)),
|
||||
shopname: K.ITEM("str", l.shopname || ""),
|
||||
areaname: K.ITEM("str", l.areaname || ""),
|
||||
expert_option: K.ITEM("s8", l.expert_option | 0),
|
||||
category: K.ITEM("s8", l.category | 0),
|
||||
sort: K.ITEM("s8", l.sort | 0),
|
||||
music_id: K.ITEM("s32", l.music_id | 0),
|
||||
seq_id: K.ITEM("s8", l.seq_id | 0),
|
||||
settings: {
|
||||
marker: K.ITEM("s8", l.marker | 0),
|
||||
theme: K.ITEM("s8", l.theme | 0),
|
||||
title: K.ITEM("s16", l.title | 0),
|
||||
parts: K.ITEM("s16", l.parts | 0),
|
||||
rank_sort: K.ITEM("s8", l.rank_sort | 0),
|
||||
combo_disp: K.ITEM("s8", l.combo_disp | 0),
|
||||
matching: K.ITEM("s8", l.matching | 0),
|
||||
hazard: K.ITEM("s8", l.hazard | 0),
|
||||
hard: K.ITEM("s8", l.hard | 0),
|
||||
emblem: K.ARRAY("s16", emblem),
|
||||
},
|
||||
},
|
||||
item: {
|
||||
music_list: s32a(fix(p.music_list, 32, -1)),
|
||||
secret_list: s32a(fill(32, -1)), // force-unlock all secret songs
|
||||
theme_list: K.ITEM("s16", ok(p.theme_list) ? p.theme_list : -1),
|
||||
marker_list: s32a(fix(p.marker_list, 2, -1)),
|
||||
title_list: s32a(fix(p.title_list, 160, -1)),
|
||||
parts_list: s32a(fix(p.parts_list, 160, -1)),
|
||||
emblem_list: s32a(fix(p.emblem_list, 96, 0)),
|
||||
new: {
|
||||
secret_list: s32a(fill(32, -1)),
|
||||
theme_list: K.ITEM("s16", ok(p.theme_list_new) ? p.theme_list_new : -1),
|
||||
marker_list: s32a(fix(p.marker_list_new, 2, -1)),
|
||||
},
|
||||
},
|
||||
history: K.ATTR({ count: "0" }),
|
||||
lab_edit_seq: K.ATTR({ count: "0" }),
|
||||
cabinet_survey: { read_flag: K.ITEM("u32", 0) },
|
||||
kaitou_bisco: { read_flag: K.ITEM("u32", p.kaitou_bisco_read_flag | 0) },
|
||||
navi: { flag: K.ITEM("u32", p.navi_flag | 0) },
|
||||
event_info: {
|
||||
event: Object.keys(p.events || {}).map(t =>
|
||||
K.ATTR({ type: t }, { state: K.ITEM("u8", p.events[t] ? 0x2 : 0x0) })),
|
||||
},
|
||||
fc_challenge: {
|
||||
today: { music_id: K.ITEM("s32", fc.today), state: K.ITEM("u8", fcPlayed[0] ? 0x40 : 0) },
|
||||
whim: { music_id: K.ITEM("s32", fc.whim), state: K.ITEM("u8", fcPlayed[1] ? 0x40 : 0) },
|
||||
},
|
||||
news: { checked: K.ITEM("s16", 0), checked_flag: K.ITEM("u32", 0) },
|
||||
rivallist: K.ATTR({ count: "0" }),
|
||||
free_first_play: {
|
||||
is_available: K.ITEM("bool", false),
|
||||
point: K.ITEM("s32", 0),
|
||||
point_used: K.ITEM("s32", 0),
|
||||
come_come_jbox: {
|
||||
is_valid: K.ITEM("bool", false),
|
||||
end_time_if_paired: K.ITEM("s64", BigInt(0)),
|
||||
},
|
||||
},
|
||||
jbox: {
|
||||
point: K.ITEM("s32", p.jbox_point | 0),
|
||||
emblem: {
|
||||
normal: { index: K.ITEM("s16", p.jbox_normal_index || 2) },
|
||||
premium: { index: K.ITEM("s16", p.jbox_premium_index || 1) },
|
||||
},
|
||||
},
|
||||
career: {
|
||||
level: K.ITEM("s16", career.level || 1),
|
||||
point: K.ITEM("s32", career.point | 0),
|
||||
param: s32a(fix(career.param, 10, -1)),
|
||||
is_unlocked: K.ITEM("bool", !!career.is_unlocked),
|
||||
},
|
||||
league: {
|
||||
is_first_play: K.ITEM("bool", p.league_is_first_play !== false),
|
||||
class: K.ITEM("s32", p.league_class || 1),
|
||||
subclass: K.ITEM("s32", p.league_subclass || 5),
|
||||
},
|
||||
new_music: {},
|
||||
eapass_privilege: { emblem_list: {} },
|
||||
bonus_music: {
|
||||
music: {},
|
||||
event_id: K.ITEM("s32", -1),
|
||||
till_time: K.ITEM("str", ""),
|
||||
},
|
||||
bistro: {
|
||||
chef: { id: K.ITEM("s32", 1) },
|
||||
carry_over: K.ITEM("s32", 0),
|
||||
route_list: { route_count: K.ITEM("u8", 0) },
|
||||
extension: K.ITEM("bool", false),
|
||||
},
|
||||
gift_list: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// DB access
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
const findProfile = (refid: string) =>
|
||||
DB.FindOne<PProfile>(refid, { collection: "prop_profile" });
|
||||
|
||||
const saveProfile = async (refid: string, p: PProfile) => {
|
||||
const { __refid, _id, createdAt, updatedAt, ...plain } = p as any;
|
||||
await DB.Update<PProfile>(refid, { collection: "prop_profile" }, { $set: plain });
|
||||
};
|
||||
|
||||
const nextJid = async (): Promise<number> => {
|
||||
// 8-digit id, unique across every jubeat collection this plugin keeps
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const jid = 10000000 + Math.floor(Math.random() * 89999999);
|
||||
const hit = await DB.FindOne<PProfile>(null, { collection: "prop_profile", jid });
|
||||
if (!hit) return jid;
|
||||
}
|
||||
return 10000000 + Math.floor(Math.random() * 89999999);
|
||||
};
|
||||
|
||||
const createProfile = async (refid: string, name: string) => {
|
||||
await DB.Upsert<PProfile>(refid, { collection: "prop_profile" }, newProfile(name, await nextJid()));
|
||||
return findProfile(refid);
|
||||
};
|
||||
|
||||
// Profile lookups by jid, also used for get_mdata / get_course / get_league.
|
||||
const profileByJid = (jid: number) => DB.FindOne<PProfile>(null, { collection: "prop_profile", jid });
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// routes
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
export const shopinfoRegist = (info: EamuseInfo, data: any, send: EamuseSend) =>
|
||||
send.object({
|
||||
data: {
|
||||
cabid: K.ITEM("u32", 1),
|
||||
locationid: K.ITEM("str", $(data).str("shop.locationid") || "nowhere"),
|
||||
tax_phase: K.ITEM("u8", 1),
|
||||
facility: { exist: K.ITEM("u32", 1) },
|
||||
info: propInfo(),
|
||||
},
|
||||
}, { compress: true });
|
||||
|
||||
export const gametopGetInfo = (info: EamuseInfo, data: any, send: EamuseSend) =>
|
||||
send.object({ data: { info: propInfo() } }, { compress: true });
|
||||
|
||||
export const gametopRegist = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
const name = $(data).str("data.player.name") || "なし";
|
||||
if (!refid) return send.deny();
|
||||
let p = await findProfile(refid);
|
||||
if (!p) p = await createProfile(refid, name);
|
||||
console.log(`[jubeat/prop] gametop.regist -> jid ${p.jid} name ${p.name}`);
|
||||
return send.object(formatProfile(p), { compress: true });
|
||||
};
|
||||
|
||||
export const gametopGetPdata = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
if (!refid) return send.deny();
|
||||
let p = await findProfile(refid);
|
||||
if (!p) {
|
||||
// CORE already reports this card as registered for L44 when it has a festo or qubell
|
||||
// profile, so prop never calls gametop.regist for it. Create the prop profile here,
|
||||
// reusing the name from the other version.
|
||||
const q: any = await DB.FindOne<any>(refid, { collection: "qubell_profile" });
|
||||
const f: any = await DB.FindOne<any>(refid, { collection: "profile" });
|
||||
const name = (q && q.name) || (f && f.name) || "なし";
|
||||
p = await createProfile(refid, String(name));
|
||||
console.log(`[jubeat/prop] gametop.get_pdata: created profile, name=${p.name} jid=${p.jid}`);
|
||||
}
|
||||
if (await evaluateLeague(refid, p)) await saveProfile(refid, p);
|
||||
return send.object(formatProfile(p), { compress: true });
|
||||
};
|
||||
|
||||
export const gametopGetMdata = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const jid = $(data).number("data.player.jid");
|
||||
const part = Math.min(3, Math.max(1, $(data).number("data.player.mdata_ver", 1)));
|
||||
if (!jid) return send.deny();
|
||||
const p = await profileByJid(jid);
|
||||
if (!p) return send.status(109);
|
||||
|
||||
// The game fetches scores in three parts (mdata_ver 1..3). Split songs deterministically by
|
||||
// sorted music id so each response stays small.
|
||||
const scores = await DB.Find<PScore>(p.__refid, { collection: "prop_score" });
|
||||
const byMusic: { [id: string]: PScore[] } = {};
|
||||
for (const s of scores) {
|
||||
if (s.seq < 0 || s.seq > 2) continue; // prop only has basic/advanced/extreme
|
||||
(byMusic[String(s.musicId)] = byMusic[String(s.musicId)] || []).push(s);
|
||||
}
|
||||
const ids = Object.keys(byMusic).sort((a, b) => parseInt(a) - parseInt(b));
|
||||
const per = Math.ceil(ids.length / 3);
|
||||
const mine = ids.length < 50 ? (part === 1 ? ids : []) : ids.slice((part - 1) * per, part * per);
|
||||
|
||||
const musicdata = mine.map(id => {
|
||||
const play = [0, 0, 0], clr = [0, 0, 0], fc = [0, 0, 0], ex = [0, 0, 0], pts = [0, 0, 0], flags = [0, 0, 0];
|
||||
const bars: any[] = [];
|
||||
for (const s of byMusic[id]) {
|
||||
play[s.seq] = s.playCnt | 0; clr[s.seq] = s.clearCnt | 0; fc[s.seq] = s.fcCnt | 0; ex[s.seq] = s.exCnt | 0;
|
||||
pts[s.seq] = s.score | 0;
|
||||
let f = FLAG_PLAYED;
|
||||
if (s.clearCnt > 0) f |= FLAG_CLEARED;
|
||||
if (s.fcCnt > 0) f |= FLAG_FC;
|
||||
if (s.exCnt > 0) f |= FLAG_EX;
|
||||
flags[s.seq] = f;
|
||||
if (s.bar && s.bar.length) bars.push(K.ARRAY("u8", s.bar, { seq: String(s.seq) }));
|
||||
}
|
||||
return K.ATTR({ music_id: id }, {
|
||||
play_cnt: s32a(play), clear_cnt: s32a(clr), fc_cnt: s32a(fc), ex_cnt: s32a(ex),
|
||||
score: s32a(pts), clear: K.ARRAY("s8", flags),
|
||||
...(bars.length ? { bar: bars } : {}),
|
||||
});
|
||||
});
|
||||
|
||||
return send.object({
|
||||
data: { player: { jid: K.ITEM("s32", jid), mdata_list: { musicdata } } },
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const gametopGetCourse = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const jid = $(data).number("data.player.jid");
|
||||
const p = jid ? await profileByJid(jid) : null;
|
||||
const results = p ? await DB.Find<PCourse>(p.__refid, { collection: "prop_course" }) : [];
|
||||
const valid = new Set(PROP_COURSES.map(c => c.id));
|
||||
|
||||
const course = PROP_COURSES.map(c => {
|
||||
const ids = [0, 0, 0], bronze = [0, 0, 0], silver = [0, 0, 0], gold = [0, 0, 0];
|
||||
c.norma.slice(0, 3).forEach((n, i) => { ids[i] = n[0]; bronze[i] = n[1]; silver[i] = n[2]; gold[i] = n[3]; });
|
||||
return {
|
||||
id: K.ITEM("s32", c.id),
|
||||
name: K.ITEM("str", c.name),
|
||||
level: K.ITEM("u8", c.level),
|
||||
norma: {
|
||||
norma_id: s32a(ids),
|
||||
bronze_value: s32a(bronze),
|
||||
silver_value: s32a(silver),
|
||||
gold_value: s32a(gold),
|
||||
},
|
||||
music_list: {
|
||||
music: c.music.map((m, i) => K.ATTR({ index: String(i) }, {
|
||||
music_id: K.ITEM("s32", m[0]),
|
||||
seq: K.ITEM("u8", m[1]),
|
||||
})),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
return send.object({
|
||||
data: {
|
||||
course_list: { course },
|
||||
player_list: {
|
||||
player: {
|
||||
jid: K.ITEM("s32", jid | 0),
|
||||
result_list: {
|
||||
result: results.filter(r => valid.has(r.courseId)).map(r => ({
|
||||
id: K.ITEM("s32", r.courseId),
|
||||
rating: K.ITEM("u8", r.rating | 0),
|
||||
score: s32a(fix(r.scores, 5, 0)),
|
||||
})),
|
||||
},
|
||||
},
|
||||
},
|
||||
last_course_id: K.ITEM("s32", p && ok(p.last.last_course_id) ? p.last.last_course_id : -1),
|
||||
},
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const gametopGetLeague = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const jid = $(data).number("data.player.jid");
|
||||
const p = jid ? await profileByJid(jid) : null;
|
||||
if (p && await evaluateLeague(p.__refid, p)) await saveProfile(p.__refid, p);
|
||||
|
||||
const leagueId = currentLeagueId();
|
||||
const mine = p ? await DB.FindOne<PLeague>(p.__refid, { collection: "prop_league", leagueId }) : null;
|
||||
const cls = p ? (p.league_class || 1) : 1;
|
||||
|
||||
return send.object({
|
||||
data: {
|
||||
league_list: {
|
||||
league: K.ATTR({ index: "0" }, {
|
||||
id: K.ITEM("s32", leagueId),
|
||||
stime: K.ITEM("u64", BigInt(leagueId * WEEK * 1000)),
|
||||
etime: K.ITEM("u64", BigInt((leagueId + 1) * WEEK * 1000)),
|
||||
music_list: {
|
||||
music: leagueSongs(leagueId).map((m, i) => K.ATTR({ index: String(i) }, {
|
||||
music_id: K.ITEM("s32", m),
|
||||
seq: K.ITEM("u8", cls === 1 ? 1 : 2),
|
||||
})),
|
||||
},
|
||||
player_list: {
|
||||
player: {
|
||||
jid: K.ITEM("s32", jid | 0),
|
||||
result: {
|
||||
score: s32a(fix(mine && mine.score, 3, 0)),
|
||||
clear: K.ARRAY("s8", fix(mine && mine.clear, 3, 0)),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
last_class: K.ITEM("s32", p ? (p.last.league_class || 1) : 1),
|
||||
last_subclass: K.ITEM("s32", p ? (p.last.league_subclass || 5) : 5),
|
||||
is_checked: K.ITEM("bool", p ? p.league_is_checked !== false : true),
|
||||
},
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const gametopGetMeeting = (info: EamuseInfo, data: any, send: EamuseSend) =>
|
||||
send.object({
|
||||
data: {
|
||||
meeting: { single: K.ATTR({ count: "0" }), tag: K.ATTR({ count: "0" }) },
|
||||
reward: { total: K.ITEM("s32", -1), point: K.ITEM("s32", -1) },
|
||||
},
|
||||
}, { compress: true });
|
||||
|
||||
export const gameendRegist = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
if (!refid) return send.deny();
|
||||
const p = await findProfile(refid);
|
||||
if (!p) return send.deny();
|
||||
const d = $(data);
|
||||
const num = (path: string, def: number) => { const v = d.number(path); return ok(v) ? v : def; };
|
||||
const nums = (path: string, n: number, cur: number[], def: number) => {
|
||||
const v = d.numbers(path); return (v && v.length) ? fix(v, n, def) : cur;
|
||||
};
|
||||
|
||||
p.saved = true;
|
||||
p.last.play_time = num("data.info.time_gameend", p.last.play_time);
|
||||
p.last.shopname = d.str("data.info.shopname") || p.last.shopname;
|
||||
p.last.areaname = d.str("data.info.areaname") || p.last.areaname;
|
||||
|
||||
if (d.element("data.player.info")) {
|
||||
const I = "data.player.info.";
|
||||
p.jubility = num(I + "jubility", p.jubility); p.jubility_yday = num(I + "jubility_yday", p.jubility_yday);
|
||||
p.tune_cnt = num(I + "tune_cnt", p.tune_cnt); p.save_cnt = num(I + "save_cnt", p.save_cnt);
|
||||
p.saved_cnt = num(I + "saved_cnt", p.saved_cnt); p.fc_cnt = num(I + "fc_cnt", p.fc_cnt);
|
||||
p.ex_cnt = num(I + "ex_cnt", p.ex_cnt); p.pf_cnt = num(I + "pf_cnt", p.pf_cnt);
|
||||
p.clear_cnt = num(I + "clear_cnt", p.clear_cnt); p.match_cnt = num(I + "match_cnt", p.match_cnt);
|
||||
p.beat_cnt = num(I + "beat_cnt", p.beat_cnt); p.mynews_cnt = num(I + "mynews_cnt", p.mynews_cnt);
|
||||
p.total_best_score = num(I + "total_best_score", p.total_best_score);
|
||||
p.bonus_tune_points = num(I + "bonus_tune_points", p.bonus_tune_points);
|
||||
p.is_bonus_tune_played = d.bool(I + "is_bonus_tune_played");
|
||||
}
|
||||
|
||||
if (d.element("data.player.last")) {
|
||||
const L = "data.player.last.";
|
||||
p.last.expert_option = num(L + "expert_option", p.last.expert_option);
|
||||
p.last.sort = num(L + "sort", p.last.sort);
|
||||
p.last.category = num(L + "category", p.last.category);
|
||||
const S = L + "settings.";
|
||||
p.last.matching = num(S + "matching", p.last.matching); p.last.hazard = num(S + "hazard", p.last.hazard);
|
||||
p.last.hard = num(S + "hard", p.last.hard); p.last.marker = num(S + "marker", p.last.marker);
|
||||
p.last.theme = num(S + "theme", p.last.theme); p.last.title = num(S + "title", p.last.title);
|
||||
p.last.parts = num(S + "parts", p.last.parts); p.last.rank_sort = num(S + "rank_sort", p.last.rank_sort);
|
||||
p.last.combo_disp = num(S + "combo_disp", p.last.combo_disp);
|
||||
p.last.emblem = nums(S + "emblem", 5, fix(p.last.emblem, 5, 0), 0);
|
||||
}
|
||||
|
||||
if (d.element("data.player.item")) {
|
||||
// secret_list is not stored: it is force-unlocked on load, so the game echoes all bits back.
|
||||
const T = "data.player.item.";
|
||||
p.music_list = nums(T + "music_list", 32, p.music_list, -1);
|
||||
p.theme_list = num(T + "theme_list", p.theme_list);
|
||||
p.marker_list = nums(T + "marker_list", 2, p.marker_list, -1);
|
||||
p.title_list = nums(T + "title_list", 160, p.title_list, -1);
|
||||
p.parts_list = nums(T + "parts_list", 160, p.parts_list, -1);
|
||||
p.emblem_list = nums(T + "emblem_list", 96, p.emblem_list, 0);
|
||||
p.theme_list_new = num(T + "new.theme_list", p.theme_list_new);
|
||||
p.marker_list_new = nums(T + "new.marker_list", 2, p.marker_list_new, -1);
|
||||
}
|
||||
|
||||
if (d.element("data.player.career")) {
|
||||
const C = "data.player.career.";
|
||||
const c = p.career || { level: 1, point: 0, param: fill(10, -1), is_unlocked: false };
|
||||
c.level = num(C + "level", c.level);
|
||||
c.point = num(C + "point", c.point);
|
||||
c.param = nums(C + "param", 10, c.param, -1);
|
||||
c.is_unlocked = d.bool(C + "is_unlocked");
|
||||
p.career = c;
|
||||
}
|
||||
|
||||
if (d.element("data.player.jbox")) {
|
||||
p.jbox_point = num("data.player.jbox.point", p.jbox_point);
|
||||
const jbType = num("data.player.jbox.emblem.type", 0), jbIndex = num("data.player.jbox.emblem.index", 0);
|
||||
if (jbType === 1) p.jbox_normal_index = jbIndex;
|
||||
else if (jbType === 2) p.jbox_premium_index = jbIndex;
|
||||
}
|
||||
|
||||
p.events = p.events || {};
|
||||
for (const ev of d.elements("data.player.event_info.event") || []) {
|
||||
const t = ev.attr("").type;
|
||||
if (t !== undefined) p.events[String(t)] = ev.bool("is_completed");
|
||||
}
|
||||
|
||||
p.navi_flag = num("data.player.navi.flag", p.navi_flag);
|
||||
p.kaitou_bisco_read_flag = num("data.player.kaitou_bisco.read_flag", p.kaitou_bisco_read_flag);
|
||||
|
||||
// scores
|
||||
const fc = fcChallenge(currentDayId());
|
||||
if (p.fc_day !== currentDayId()) { p.fc_day = currentDayId(); p.fc_played = [0, 0]; }
|
||||
let saved = 0;
|
||||
for (const tune of d.elements("data.result.tune") || []) {
|
||||
const musicId = tune.number("music");
|
||||
const sa = tune.attr("player.score") || {};
|
||||
const seq = parseInt(sa.seq), flags = parseInt(sa.clear) | 0, combo = parseInt(sa.combo) | 0;
|
||||
const points = tune.number("player.score") | 0;
|
||||
const bar = tune.numbers("player.mbar");
|
||||
if (!musicId || isNaN(seq)) continue;
|
||||
p.last.music_id = musicId; p.last.seq_id = seq;
|
||||
if (musicId === fc.today) p.fc_played[0] = 1;
|
||||
if (musicId === fc.whim) p.fc_played[1] = 1;
|
||||
|
||||
const old = await DB.FindOne<PScore>(refid, { collection: "prop_score", musicId, seq });
|
||||
const ns: PScore = old || {
|
||||
collection: "prop_score", musicId, seq, score: 0, clear: 0, combo: 0,
|
||||
playCnt: 0, clearCnt: 0, fcCnt: 0, exCnt: 0, bar: [], time: 0,
|
||||
};
|
||||
ns.playCnt = (ns.playCnt | 0) + 1;
|
||||
if (flags & FLAG_CLEARED) ns.clearCnt = (ns.clearCnt | 0) + 1;
|
||||
if (flags & FLAG_FC) ns.fcCnt = (ns.fcCnt | 0) + 1;
|
||||
if (flags & FLAG_EX) ns.exCnt = (ns.exCnt | 0) + 1;
|
||||
// keep the ghost of the best score
|
||||
if (bar && bar.length && (points >= (ns.score | 0) || !(ns.bar && ns.bar.length))) ns.bar = bar;
|
||||
ns.score = Math.max(ns.score | 0, points);
|
||||
ns.clear = (ns.clear | 0) | flags;
|
||||
ns.combo = Math.max(ns.combo | 0, combo);
|
||||
await DB.Upsert<PScore>(refid, { collection: "prop_score", musicId, seq }, {
|
||||
$set: {
|
||||
musicId, seq, score: ns.score, clear: ns.clear, combo: ns.combo,
|
||||
playCnt: ns.playCnt, clearCnt: ns.clearCnt, fcCnt: ns.fcCnt, exCnt: ns.exCnt,
|
||||
bar: ns.bar, time: Date.now(),
|
||||
},
|
||||
});
|
||||
saved++;
|
||||
}
|
||||
|
||||
// course save
|
||||
if (d.element("data.player.course")) {
|
||||
const courseId = d.number("data.player.course.course_id");
|
||||
const rating = num("data.player.course.rating", COURSE_RATING_FAILED);
|
||||
const scores = [0, 0, 0, 0, 0];
|
||||
for (const m of d.elements("data.player.course.music") || []) {
|
||||
const idx = parseInt(m.attr("").index);
|
||||
if (!isNaN(idx) && idx >= 0 && idx < 5) scores[idx] = m.number("score") | 0;
|
||||
}
|
||||
if (ok(courseId)) {
|
||||
const old = await DB.FindOne<PCourse>(refid, { collection: "prop_course", courseId });
|
||||
const sum = (a: number[]) => fix(a, 5, 0).reduce((x, y) => x + y, 0);
|
||||
const better = !old || rating > (old.rating | 0) || (rating === (old.rating | 0) && sum(scores) > sum(old.scores));
|
||||
if (better) {
|
||||
await DB.Upsert<PCourse>(refid, { collection: "prop_course", courseId }, {
|
||||
$set: { courseId, rating: Math.max(rating, old ? old.rating | 0 : 0), scores },
|
||||
});
|
||||
}
|
||||
p.last.last_course_id = courseId;
|
||||
}
|
||||
}
|
||||
|
||||
// league save
|
||||
if (d.element("data.player.league")) {
|
||||
const leagueId = d.number("data.player.league.league_id");
|
||||
p.league_is_checked = d.bool("data.player.league.is_checked");
|
||||
p.league_is_first_play = d.bool("data.player.league.is_first_play");
|
||||
const score = [0, 0, 0], clear = [0, 0, 0];
|
||||
for (const m of d.elements("data.player.league.music") || []) {
|
||||
const idx = parseInt(m.attr("").index);
|
||||
if (isNaN(idx) || idx < 0 || idx > 2) continue;
|
||||
score[idx] = m.number("score") | 0;
|
||||
clear[idx] = parseInt((m.attr("score") || {}).clear) | 0;
|
||||
}
|
||||
if (ok(leagueId)) {
|
||||
const old = await DB.FindOne<PLeague>(refid, { collection: "prop_league", leagueId });
|
||||
if (!old || leagueTotal(old) < score.reduce((a, b) => a + b, 0)) {
|
||||
await DB.Upsert<PLeague>(refid, { collection: "prop_league", leagueId }, { $set: { leagueId, score, clear } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await saveProfile(refid, p);
|
||||
console.log(`[jubeat/prop] gameend.regist jid ${p.jid}: ${saved} tune(s) saved`);
|
||||
return send.object({
|
||||
data: { player: { session_id: K.ITEM("s32", 1), end_final_session_id: K.ITEM("s32", 1) } },
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const lobbyCheck = (info: EamuseInfo, data: any, send: EamuseSend) =>
|
||||
send.object({
|
||||
data: {
|
||||
interval: K.ITEM("s16", 0),
|
||||
entry_timeout: K.ITEM("s16", 0),
|
||||
entrant_nr: K.ITEM("u32", 0, { time: "0" }),
|
||||
},
|
||||
}, { compress: true });
|
||||
|
||||
export const demodataGetNews = (info: EamuseInfo, data: any, send: EamuseSend) =>
|
||||
send.object({ data: { officialnews: K.ATTR({ count: "0" }) } }, { compress: true });
|
||||
|
||||
export const demodataGetHitchart = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const now = new Date();
|
||||
const pad = (n: number) => (n < 10 ? "0" : "") + n;
|
||||
// Top 10 songs by total plays across all prop players.
|
||||
const plays: { [id: string]: number } = {};
|
||||
for (const s of await DB.Find<PScore>(null, { collection: "prop_score" })) {
|
||||
plays[String(s.musicId)] = (plays[String(s.musicId)] || 0) + (s.playCnt | 0);
|
||||
}
|
||||
const top = Object.keys(plays).sort((a, b) => plays[b] - plays[a]).slice(0, 10);
|
||||
return send.object({
|
||||
data: {
|
||||
update: K.ITEM("str", `${pad(now.getDate())}/${pad(now.getMonth() + 1)}/${now.getFullYear()}`),
|
||||
hitchart_lic: K.ATTR({ count: "0" }),
|
||||
hitchart_org: K.ATTR({ count: String(top.length) }, {
|
||||
rankdata: top.map((id, i) => ({
|
||||
music_id: K.ITEM("s32", parseInt(id)),
|
||||
rank: K.ITEM("s16", i + 1),
|
||||
prev: K.ITEM("s16", i + 1),
|
||||
})),
|
||||
}),
|
||||
},
|
||||
}, { compress: true });
|
||||
};
|
||||
12
jubeat@asphyxia/versions/clan/index.ts
Normal file
12
jubeat@asphyxia/versions/clan/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { GameVersion, VersionInfo } from "../types";
|
||||
import { qubellRoutes } from "../qubell";
|
||||
|
||||
const version: VersionInfo = {
|
||||
id: 9, name: "clan", from: 2017062600, until: 2018090000, maxMusicId: 99999999,
|
||||
};
|
||||
|
||||
/**
|
||||
* clan is answered with Qubell's handlers for now (its own layout is in
|
||||
* bemaniutils' clan.py), but keeps its own version data.
|
||||
*/
|
||||
export const Clan: GameVersion = { ...version, routes: qubellRoutes(version) };
|
||||
40
jubeat@asphyxia/versions/festo/index.ts
Normal file
40
jubeat@asphyxia/versions/festo/index.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { GameVersion, VersionInfo } from "../types";
|
||||
import * as lobby from "../../handlers/lobby";
|
||||
import { getProfile, Getinfo, loadScore, Meeting } from "./load";
|
||||
import { saveProfile } from "./save";
|
||||
import { shopInfo } from "./shopinfo";
|
||||
|
||||
/** festo and later. Model strings without a date are answered as festo too. */
|
||||
const version: VersionInfo = { id: 10, name: "festo", from: 2018090000, until: Infinity };
|
||||
|
||||
export const Festo: GameVersion = {
|
||||
...version,
|
||||
routes: {
|
||||
"shopinfo.regist": shopInfo,
|
||||
"gametop.get_info": Getinfo,
|
||||
|
||||
// Profile
|
||||
"gametop.regist": getProfile,
|
||||
"gametop.get_pdata": getProfile,
|
||||
"gameend.regist": saveProfile,
|
||||
"gameend.final": true,
|
||||
|
||||
// Scores
|
||||
"gametop.get_mdata": loadScore,
|
||||
|
||||
// Matching
|
||||
"gametop.get_meeting": Meeting,
|
||||
"lobby.check": lobby.Check,
|
||||
"lobby.entry": lobby.Entry,
|
||||
"lobby.refresh": lobby.Refresh,
|
||||
"lobby.report": lobby.Report,
|
||||
|
||||
// Attract
|
||||
"demodata.get_news": true,
|
||||
"demodata.get_hitchart": true,
|
||||
"recommend.get_recommend": true,
|
||||
|
||||
"netlog.send": true,
|
||||
"logger.report": true,
|
||||
},
|
||||
};
|
||||
@@ -1,4 +1,7 @@
|
||||
import {emoList, shopList, FestoCourse, courseCategories} from "../static/data"
|
||||
// festo's global "info" node (shopinfo.regist, gametop.get_info, and inside every profile).
|
||||
import {emoList, shopList, FestoCourse, courseCategories} from "../../data/festo"
|
||||
|
||||
declare const BigInt: any; // CORE typecheck targets es2017
|
||||
|
||||
/*
|
||||
if pos_index is not (1230 ~ 1236 or 1204 ~ 1205) and pos_index > 1200:
|
||||
@@ -11,7 +14,7 @@ for(var i=0; i<=36; i++){
|
||||
pick_up_array[37] = -3211264;
|
||||
pick_up_array[38] = -2080769;
|
||||
|
||||
module.exports = () => ({
|
||||
export const festoInfo = () => ({
|
||||
info: {
|
||||
white_music_list: K.ARRAY("s32", new Array(64).fill(-1)),
|
||||
white_marker_list: K.ARRAY("s32", new Array(16).fill(-1)),
|
||||
@@ -1,5 +1,9 @@
|
||||
import Profile from '../models/profile';
|
||||
import { Score } from '../models/score';
|
||||
import { Score } from '../../models/score';
|
||||
import { createPlayer, findPlayer, playerByJid } from '../../handlers/player';
|
||||
import { festoInfo } from './info';
|
||||
import { profileData } from './profile_data';
|
||||
|
||||
declare const BigInt: any; // CORE typecheck targets es2017
|
||||
|
||||
export const getProfile = async (
|
||||
info: EamuseInfo,
|
||||
@@ -13,23 +17,10 @@ export const getProfile = async (
|
||||
console.log(data, { depth: null });
|
||||
if (!refId) return send.deny();
|
||||
|
||||
let profile = await DB.FindOne<Profile>(refId, { collection: 'profile' });
|
||||
let profile = await findPlayer(refId);
|
||||
|
||||
if (!profile && name) {
|
||||
const newProfile: Profile = {
|
||||
collection: 'profile',
|
||||
jubeatId: Math.round(Math.random() * 99999999),
|
||||
eventFlag: 0,
|
||||
name: name,
|
||||
isFirstplay: true,
|
||||
emo: [],
|
||||
lastShopname: '',
|
||||
lastAreaname: '',
|
||||
};
|
||||
|
||||
await DB.Upsert<Profile>(refId, { collection: 'profile' }, newProfile);
|
||||
|
||||
profile = newProfile;
|
||||
profile = await createPlayer(refId, name);
|
||||
} else if (!profile && !name) {
|
||||
return send.deny();
|
||||
}
|
||||
@@ -37,7 +28,7 @@ export const getProfile = async (
|
||||
return send.object(
|
||||
{
|
||||
data: {
|
||||
...require('../templates/gameInfos.ts')(),
|
||||
...festoInfo(),
|
||||
|
||||
player: {
|
||||
jid: K.ITEM('s32', profile.jubeatId),
|
||||
@@ -45,7 +36,7 @@ export const getProfile = async (
|
||||
name: K.ITEM('str', profile.name),
|
||||
event_flag: K.ITEM('u64', BigInt(profile.eventFlag || 0)),
|
||||
|
||||
...(await require('../templates/profiles.ts')(profile)),
|
||||
...(await profileData(profile)),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -56,7 +47,7 @@ export const getProfile = async (
|
||||
export const Getinfo = (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
console.log(data, { depth: null });
|
||||
return send.object(
|
||||
{ data: require('../templates/gameInfos')() },
|
||||
{ data: festoInfo() },
|
||||
{ compress: true }
|
||||
);
|
||||
};
|
||||
@@ -68,10 +59,7 @@ export const loadScore = async (info, data, send) => {
|
||||
const jubeatId = $(data).number('data.player.jid');
|
||||
if (!jubeatId) return send.deny();
|
||||
|
||||
const profile = await DB.FindOne<Profile>(null, {
|
||||
collection: 'profile',
|
||||
jubeatId,
|
||||
});
|
||||
const profile = await playerByJid(jubeatId);
|
||||
if (!profile) return send.deny();
|
||||
|
||||
const scores = await DB.Find<Score>(profile.__refid, { collection: 'score' });
|
||||
@@ -108,14 +96,15 @@ export const loadScore = async (info, data, send) => {
|
||||
}
|
||||
|
||||
const data = scoreData[score.musicId][score.isHardMode ? 1 : 0];
|
||||
data.musicRate[score.seq] = score.musicRate;
|
||||
data.playCnt[score.seq] = score.playCount;
|
||||
data.clearCnt[score.seq] = score.clearCount;
|
||||
data.fcCnt[score.seq] = score.fullcomboCount;
|
||||
data.exCnt[score.seq] = score.excellentCount;
|
||||
data.clear[score.seq] = score.clear;
|
||||
data.score[score.seq] = score.score;
|
||||
data.bar[score.seq] = score.bar;
|
||||
// Records saved by older versions have no music rate, and may have no ghost.
|
||||
data.musicRate[score.seq] = score.musicRate || 0;
|
||||
data.playCnt[score.seq] = score.playCount || 0;
|
||||
data.clearCnt[score.seq] = score.clearCount || 0;
|
||||
data.fcCnt[score.seq] = score.fullcomboCount || 0;
|
||||
data.exCnt[score.seq] = score.excellentCount || 0;
|
||||
data.clear[score.seq] = score.clear || 0;
|
||||
data.score[score.seq] = score.score || 0;
|
||||
if (score.bar && score.bar.length) data.bar[score.seq] = score.bar;
|
||||
}
|
||||
|
||||
var sendobj = {
|
||||
@@ -1,8 +1,11 @@
|
||||
import Profile from "../models/profile";
|
||||
import {Course} from "../models/course";
|
||||
import {emoList, shopList, FestoCourse, courseCategories, COURSE_STATUS} from "../static/data"
|
||||
// festo's player node, built from the shared profile (festo keeps its fields there).
|
||||
import Profile from "../../models/profile";
|
||||
import {Course} from "../../models/course";
|
||||
import {emoList, shopList, FestoCourse, courseCategories, COURSE_STATUS} from "../../data/festo"
|
||||
|
||||
module.exports = async (data: Profile) => ({
|
||||
declare const BigInt: any; // CORE typecheck targets es2017
|
||||
|
||||
export const profileData = async (data: Profile & { __refid?: string }) => ({
|
||||
info: {
|
||||
tune_cnt: K.ITEM("s32", data?.tuneCount || 0),
|
||||
save_cnt: K.ITEM("s32", data?.saveCount || 0),
|
||||
@@ -18,11 +21,11 @@ module.exports = async (data: Profile) => ({
|
||||
mtg_result: K.ITEM("u8", 0),
|
||||
bonus_tune_points: K.ITEM("s32", data?.bonusPoints || 0),
|
||||
is_bonus_tune_played: K.ITEM("bool", data?.isBonusPlayed || false),
|
||||
last_play_time: K.ITEM("s64", data?.lastPlayTime || 0),
|
||||
last_play_time: (K.ITEM as any)("s64", data?.lastPlayTime || 0),
|
||||
},
|
||||
|
||||
last: {
|
||||
play_time: K.ITEM("s64", data?.lastPlayTime || 0),
|
||||
play_time: (K.ITEM as any)("s64", data?.lastPlayTime || 0),
|
||||
shopname: K.ITEM("str", data.lastShopname),
|
||||
areaname: K.ITEM("str", data.lastAreaname),
|
||||
music_id: K.ITEM("s32", data.musicId || 0),
|
||||
@@ -1,7 +1,8 @@
|
||||
import {Score} from "../models/score"
|
||||
import Profile from "../models/profile";
|
||||
import { Course } from "../models/course";
|
||||
import { COURSE_STATUS } from "../static/data";
|
||||
import {Score} from "../../models/score"
|
||||
import Profile from "../../models/profile";
|
||||
import { Course } from "../../models/course";
|
||||
import { COURSE_STATUS } from "../../data/festo";
|
||||
import { findPlayer } from "../../handlers/player";
|
||||
|
||||
export const saveProfile = async (info, {data}, send) => {
|
||||
console.log("gameend.regist");
|
||||
@@ -9,7 +10,7 @@ export const saveProfile = async (info, {data}, send) => {
|
||||
const refId = $(data).str("player.refid");
|
||||
if (!refId) return send.deny();
|
||||
|
||||
const profile = await DB.FindOne<Profile>(refId, { collection: "profile" });
|
||||
const profile = await findPlayer(refId);
|
||||
if (!profile) return send.deny();
|
||||
|
||||
let lastMarker = 0;
|
||||
@@ -1,7 +1,9 @@
|
||||
export default (_: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
import { festoInfo } from "./info";
|
||||
|
||||
export const shopInfo = (_: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
|
||||
const locId = $(data).element("shop").content("locationid");
|
||||
console.log({...require("../templates/gameInfos.ts")()}, {depth:null});
|
||||
console.log({...festoInfo()}, {depth:null});
|
||||
return send.object(
|
||||
{
|
||||
data: {
|
||||
@@ -12,7 +14,7 @@ export default (_: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
exist: K.ITEM("u32", 0),
|
||||
},
|
||||
|
||||
...require("../templates/gameInfos.ts")(),
|
||||
...festoInfo(),
|
||||
},
|
||||
},
|
||||
{ compress: true }
|
||||
52
jubeat@asphyxia/versions/index.ts
Normal file
52
jubeat@asphyxia/versions/index.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { GameVersion } from "./types";
|
||||
import { Prop } from "./prop";
|
||||
import { Qubell } from "./qubell";
|
||||
import { Clan } from "./clan";
|
||||
import { Festo } from "./festo";
|
||||
|
||||
/**
|
||||
* Supported game versions, oldest first. Each one owns its routes, so a
|
||||
* version can change without touching the others.
|
||||
*
|
||||
* To add a version, copy the closest module, change what differs, and list it here.
|
||||
*/
|
||||
export const VERSIONS: GameVersion[] = [Prop, Qubell, Clan, Festo];
|
||||
|
||||
/**
|
||||
* The version a cabinet runs, from the date in its model string. A model
|
||||
* without a date is answered as festo, as before the split.
|
||||
*/
|
||||
export function versionFor(model: string): GameVersion | undefined {
|
||||
const date = parseInt((model || "").split(":")[4]);
|
||||
if (isNaN(date)) return Festo;
|
||||
return VERSIONS.find(v => date >= v.from && date < v.until);
|
||||
}
|
||||
|
||||
const dispatch = (method: string): EamusePluginRoute => async (info, data, send) => {
|
||||
const version = versionFor(info.model);
|
||||
if (!version) {
|
||||
console.warn(`[jubeat] unsupported version ${info.model} (${method})`);
|
||||
return send.deny();
|
||||
}
|
||||
const handler = version.routes[method];
|
||||
if (handler === undefined) {
|
||||
console.warn(`[jubeat] ${version.name}: unhandled method ${method}`);
|
||||
return send.success();
|
||||
}
|
||||
if (handler === true) return send.success();
|
||||
if (handler === false) return send.deny();
|
||||
// Never let a handler exception surface as an HTTP error: log it and deny instead.
|
||||
try {
|
||||
return await handler(info, data, send);
|
||||
} catch (e) {
|
||||
console.error(`[jubeat] ${version.name} ${method} failed: ${e && e.stack ? e.stack : e}`);
|
||||
return send.deny();
|
||||
}
|
||||
};
|
||||
|
||||
/** Registers one route per method any version handles, dispatched by version. */
|
||||
export function registerVersions() {
|
||||
const methods = new Set<string>();
|
||||
for (const version of VERSIONS) Object.keys(version.routes).forEach(m => methods.add(m));
|
||||
methods.forEach(method => R.Route(method, dispatch(method)));
|
||||
}
|
||||
83
jubeat@asphyxia/versions/prop/course.ts
Normal file
83
jubeat@asphyxia/versions/prop/course.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
// prop's course mode: the course list, the player's results, and saving a course play.
|
||||
|
||||
import { PROP_COURSES } from "../../data/prop_courses";
|
||||
import { playerByJid } from "../../handlers/player";
|
||||
import { findVersionCourse, saveVersionCourse, versionCourses } from "../../handlers/version_data";
|
||||
import { PROP, PropData, loadProp } from "./data";
|
||||
|
||||
const fix = (v: any, n: number, def: number): number[] => {
|
||||
const a = Array.isArray(v) ? v.slice(0, n) : [];
|
||||
while (a.length < n) a.push(def);
|
||||
return a;
|
||||
};
|
||||
|
||||
const COURSE_RATING_FAILED = 1;
|
||||
|
||||
export const getCourse: EamusePluginRoute = async (info, data, send) => {
|
||||
const jid = $(data).number("data.player.jid");
|
||||
const player = jid ? await playerByJid(jid) : null;
|
||||
const results = player ? await versionCourses(player.__refid, PROP) : [];
|
||||
const p = player ? await loadProp(player.__refid) : null;
|
||||
const valid = new Set(PROP_COURSES.map(c => c.id));
|
||||
|
||||
const course = PROP_COURSES.map(c => {
|
||||
const ids = [0, 0, 0], bronze = [0, 0, 0], silver = [0, 0, 0], gold = [0, 0, 0];
|
||||
c.norma.slice(0, 3).forEach((n, i) => { ids[i] = n[0]; bronze[i] = n[1]; silver[i] = n[2]; gold[i] = n[3]; });
|
||||
return {
|
||||
id: K.ITEM("s32", c.id),
|
||||
name: K.ITEM("str", c.name),
|
||||
level: K.ITEM("u8", c.level),
|
||||
norma: {
|
||||
norma_id: K.ARRAY("s32", ids),
|
||||
bronze_value: K.ARRAY("s32", bronze),
|
||||
silver_value: K.ARRAY("s32", silver),
|
||||
gold_value: K.ARRAY("s32", gold),
|
||||
},
|
||||
music_list: {
|
||||
music: c.music.map((m, i) => K.ATTR({ index: String(i) }, {
|
||||
music_id: K.ITEM("s32", m[0]),
|
||||
seq: K.ITEM("u8", m[1]),
|
||||
})),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
return send.object({
|
||||
data: {
|
||||
course_list: { course },
|
||||
player_list: {
|
||||
player: {
|
||||
jid: K.ITEM("s32", jid | 0),
|
||||
result_list: {
|
||||
result: results.filter(r => valid.has(r.courseId)).map(r => ({
|
||||
id: K.ITEM("s32", r.courseId),
|
||||
rating: K.ITEM("u8", r.rating | 0),
|
||||
score: K.ARRAY("s32", fix(r.scores, 5, 0)),
|
||||
})),
|
||||
},
|
||||
},
|
||||
},
|
||||
last_course_id: K.ITEM("s32", p ? p.last.last_course_id : -1),
|
||||
},
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
/** Saves the `data.player.course` part of gameend.regist, keeping the best rating. */
|
||||
export async function saveCourseResult(refid: string, d: KDataReader, p: PropData) {
|
||||
if (!d.element("data.player.course")) return;
|
||||
const courseId = d.number("data.player.course.course_id");
|
||||
if (courseId === undefined || courseId === null || isNaN(courseId)) return;
|
||||
const rawRating = d.number("data.player.course.rating");
|
||||
const rating = isNaN(rawRating) ? COURSE_RATING_FAILED : rawRating;
|
||||
const scores = [0, 0, 0, 0, 0];
|
||||
for (const m of d.elements("data.player.course.music") || []) {
|
||||
const idx = parseInt(m.attr("").index);
|
||||
if (!isNaN(idx) && idx >= 0 && idx < 5) scores[idx] = m.number("score") | 0;
|
||||
}
|
||||
const old = await findVersionCourse(refid, PROP, courseId);
|
||||
const sum = (a: number[]) => fix(a, 5, 0).reduce((x, y) => x + y, 0);
|
||||
if (!old || rating > (old.rating | 0) || (rating === (old.rating | 0) && sum(scores) > sum(old.scores))) {
|
||||
await saveVersionCourse(refid, PROP, courseId, Math.max(rating, old ? old.rating | 0 : 0), scores);
|
||||
}
|
||||
p.last.last_course_id = courseId;
|
||||
}
|
||||
73
jubeat@asphyxia/versions/prop/data.ts
Normal file
73
jubeat@asphyxia/versions/prop/data.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
// prop's player data, kept in version data. The jubeat ID and name are the shared profile's.
|
||||
|
||||
import { loadVersionData, saveVersionData } from "../../handlers/version_data";
|
||||
|
||||
export const PROP = 7;
|
||||
|
||||
const fill = (n: number, v: number): number[] => new Array(n).fill(v);
|
||||
|
||||
export interface PropData {
|
||||
saved: boolean;
|
||||
jubility: number; jubility_yday: number;
|
||||
tune_cnt: number; save_cnt: number; saved_cnt: number; fc_cnt: number; ex_cnt: number;
|
||||
pf_cnt: number; clear_cnt: number; match_cnt: number; beat_cnt: number; mynews_cnt: number;
|
||||
total_best_score: number;
|
||||
bonus_tune_points: number; is_bonus_tune_played: boolean;
|
||||
last: {
|
||||
play_time: number; shopname: string; areaname: string;
|
||||
music_id: number; seq_id: number; sort: number; category: number; expert_option: number;
|
||||
marker: number; theme: number; title: number; parts: number;
|
||||
rank_sort: number; combo_disp: number; matching: number; hazard: number; hard: number;
|
||||
emblem: number[];
|
||||
last_course_id: number;
|
||||
/** The league class the player last saw, so the game can show a change. */
|
||||
league_class: number; league_subclass: number;
|
||||
};
|
||||
music_list: number[]; theme_list: number; marker_list: number[];
|
||||
title_list: number[]; parts_list: number[]; emblem_list: number[];
|
||||
theme_list_new: number; marker_list_new: number[];
|
||||
career: { level: number; point: number; param: number[]; is_unlocked: boolean };
|
||||
jbox_point: number; jbox_normal_index: number; jbox_premium_index: number;
|
||||
navi_flag: number; kaitou_bisco_read_flag: number;
|
||||
events: { [type: string]: boolean };
|
||||
league_class: number; league_subclass: number;
|
||||
league_is_checked: boolean; league_is_first_play: boolean;
|
||||
/** Last league week that promotions were applied for. */
|
||||
league_eval_id: number;
|
||||
/** FC challenge [today, whim] played on `fc_day`. */
|
||||
fc_day: number; fc_played: number[];
|
||||
}
|
||||
|
||||
const defaults = (): PropData => ({
|
||||
saved: false,
|
||||
jubility: 0, jubility_yday: 0,
|
||||
tune_cnt: 0, save_cnt: 0, saved_cnt: 0, fc_cnt: 0, ex_cnt: 0,
|
||||
pf_cnt: 0, clear_cnt: 0, match_cnt: 0, beat_cnt: 0, mynews_cnt: 0, total_best_score: 0,
|
||||
bonus_tune_points: 0, is_bonus_tune_played: false,
|
||||
last: {
|
||||
play_time: 0, shopname: "", areaname: "",
|
||||
music_id: 0, seq_id: 0, sort: 0, category: 0, expert_option: 0,
|
||||
marker: 0, theme: 0, title: 0, parts: 0, rank_sort: 0, combo_disp: 0,
|
||||
matching: 0, hazard: 0, hard: 0, emblem: [0, 0, 0, 0, 0],
|
||||
last_course_id: -1, league_class: 1, league_subclass: 5,
|
||||
},
|
||||
music_list: fill(32, -1), theme_list: -1, marker_list: fill(2, -1),
|
||||
title_list: fill(160, -1), parts_list: fill(160, -1), emblem_list: fill(96, 0),
|
||||
theme_list_new: -1, marker_list_new: fill(2, -1),
|
||||
career: { level: 1, point: 0, param: fill(10, -1), is_unlocked: false },
|
||||
jbox_point: 0, jbox_normal_index: 2, jbox_premium_index: 1,
|
||||
navi_flag: 0, kaitou_bisco_read_flag: 0,
|
||||
events: {},
|
||||
league_class: 1, league_subclass: 5, league_is_checked: true, league_is_first_play: true,
|
||||
league_eval_id: 0,
|
||||
fc_day: 0, fc_played: [0, 0],
|
||||
});
|
||||
|
||||
export async function loadProp(refid: string): Promise<PropData> {
|
||||
const d: any = { ...defaults(), ...(await loadVersionData(refid, PROP)) };
|
||||
d.last = { ...defaults().last, ...(d.last || {}) };
|
||||
d.career = { ...defaults().career, ...(d.career || {}) };
|
||||
return d;
|
||||
}
|
||||
|
||||
export const saveProp = (refid: string, p: PropData) => saveVersionData(refid, PROP, p);
|
||||
59
jubeat@asphyxia/versions/prop/index.ts
Normal file
59
jubeat@asphyxia/versions/prop/index.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { GameVersion, VersionInfo } from "../types";
|
||||
import * as common from "../../handlers/common";
|
||||
import * as lobby from "../../handlers/lobby";
|
||||
import { info as globalInfo } from "./info";
|
||||
import * as profile from "./profile";
|
||||
import { getCourse } from "./course";
|
||||
import { getLeague } from "./league";
|
||||
|
||||
const version: VersionInfo = {
|
||||
id: 7, name: "prop", from: 2015022000, until: 2016033000, maxMusicId: 79999999,
|
||||
};
|
||||
|
||||
export const Prop: GameVersion = {
|
||||
...version,
|
||||
routes: {
|
||||
"shopinfo.regist": (info, data, send) => send.object({
|
||||
data: {
|
||||
cabid: K.ITEM("u32", 1),
|
||||
locationid: K.ITEM("str", $(data).str("shop.locationid") || "nowhere"),
|
||||
tax_phase: K.ITEM("u8", 1),
|
||||
facility: { exist: K.ITEM("u32", 1) },
|
||||
info: globalInfo(),
|
||||
},
|
||||
}, { compress: true }),
|
||||
"gametop.get_info": (info, data, send) => send.object({ data: { info: globalInfo() } }, { compress: true }),
|
||||
|
||||
// Profile
|
||||
"gametop.regist": profile.regist,
|
||||
"gametop.get_pdata": profile.getPdata,
|
||||
"gameend.regist": profile.gameendRegist,
|
||||
|
||||
// Scores
|
||||
"gametop.get_mdata": profile.getMdata(version),
|
||||
|
||||
// Course mode and league
|
||||
"gametop.get_course": getCourse,
|
||||
"gametop.get_league": getLeague,
|
||||
|
||||
// Matching
|
||||
"gametop.get_meeting": common.meeting,
|
||||
"lobby.check": common.lobbyCheck,
|
||||
"lobby.entry": lobby.Entry,
|
||||
"lobby.refresh": lobby.Refresh,
|
||||
"lobby.report": lobby.Report,
|
||||
|
||||
// Attract
|
||||
"demodata.get_news": common.news,
|
||||
"demodata.get_hitchart": common.hitchart(version),
|
||||
|
||||
"netlog.send": true,
|
||||
"logger.report": true,
|
||||
|
||||
// Referenced by jubeat.dll but not handled by bemaniutils either: acknowledged, nothing stored
|
||||
"gametop.get_event": true,
|
||||
"gametop.get_collabo": true,
|
||||
"gameend.set_event": true,
|
||||
"gameend.set_collabo": true,
|
||||
},
|
||||
};
|
||||
65
jubeat@asphyxia/versions/prop/info.ts
Normal file
65
jubeat@asphyxia/versions/prop/info.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
// prop's global "info" node (shopinfo.regist, gametop.get_info, and inside every profile),
|
||||
// and the songs picked for the weekly league and the daily FC challenge.
|
||||
// Layout from bemaniutils' bemani/backend/jubeat/prop.py (__get_global_info).
|
||||
|
||||
import { PROP_COURSES } from "../../data/prop_courses";
|
||||
|
||||
const fill = (n: number, v: number): number[] => new Array(n).fill(v);
|
||||
const s32a = (v: number[]) => K.ARRAY("s32", v);
|
||||
|
||||
export const WEEK = 604800;
|
||||
const DAY = 86400;
|
||||
const nowSec = () => Math.floor(Date.now() / 1000);
|
||||
|
||||
// Deterministic PRNG so every cabinet agrees on the weekly league / daily FC challenge songs.
|
||||
const mulberry32 = (seed: number) => () => {
|
||||
seed |= 0; seed = (seed + 0x6d2b79f5) | 0;
|
||||
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
|
||||
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
|
||||
// Songs known to exist in prop: everything its course list uses.
|
||||
const SONG_POOL: number[] = Array.from(new Set(
|
||||
PROP_COURSES.reduce((a, c) => a.concat(c.music.map(m => m[0])), [] as number[]))).sort((a, b) => a - b);
|
||||
|
||||
const pickSongs = (seed: number, n: number): number[] => {
|
||||
const rnd = mulberry32(seed), pool = SONG_POOL.slice(), out: number[] = [];
|
||||
while (out.length < n && pool.length) out.push(pool.splice(Math.floor(rnd() * pool.length), 1)[0]);
|
||||
return out;
|
||||
};
|
||||
|
||||
/** League ids are week numbers since the epoch. */
|
||||
export const currentLeagueId = () => Math.floor(nowSec() / WEEK);
|
||||
export const leagueSongs = (leagueId: number) => pickSongs(leagueId * 7919 + 1, 3);
|
||||
|
||||
export const currentDayId = () => Math.floor(nowSec() / DAY);
|
||||
export const fcChallenge = (dayId: number) => {
|
||||
const s = pickSongs(dayId * 104729 + 2, 2);
|
||||
return { today: s[0], whim: s[1] };
|
||||
};
|
||||
|
||||
const EVENTS = [5, 6, 9, 14, 15, 16, 17, 18, 19];
|
||||
|
||||
export const info = () => ({
|
||||
event_info: {
|
||||
event: EVENTS.map(e => K.ATTR({ type: String(e) }, { state: K.ITEM("u8", 0) })),
|
||||
},
|
||||
share_music: {},
|
||||
bonus_music: {},
|
||||
only_now_music: {},
|
||||
fc_challenge: { today: { music_id: K.ITEM("s32", fcChallenge(currentDayId()).today) } },
|
||||
white_music_list: s32a(fill(32, -1)),
|
||||
open_music_list: s32a(fill(32, -1)),
|
||||
cabinet_survey: { id: K.ITEM("s32", -1), status: K.ITEM("s32", 0) },
|
||||
kaitou_bisco: { remaining_days: K.ITEM("s32", 0) },
|
||||
league: { status: K.ITEM("u8", 1) },
|
||||
bistro: { bistro_id: K.ITEM("u16", 0) },
|
||||
jbox: {
|
||||
point: K.ITEM("s32", 0),
|
||||
emblem: {
|
||||
normal: { index: K.ITEM("s16", 2) },
|
||||
premium: { index: K.ITEM("s16", 1) },
|
||||
},
|
||||
},
|
||||
});
|
||||
126
jubeat@asphyxia/versions/prop/league.ts
Normal file
126
jubeat@asphyxia/versions/prop/league.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
declare const BigInt: any; // CORE typecheck targets es2017
|
||||
// prop's weekly league: three songs a week; the top 30% of a week's players move up a class,
|
||||
// the bottom 30% move down, and players who stay away drop one class every two weeks.
|
||||
// bemaniutils runs this from a weekly job; here it is applied when a player next logs in.
|
||||
|
||||
import { VersionLeague } from "../../models/version_data";
|
||||
import { playerByJid } from "../../handlers/player";
|
||||
import { findLeague, leagueResults, playerLeagues, saveLeague } from "../../handlers/version_data";
|
||||
import { PROP, PropData, loadProp, saveProp } from "./data";
|
||||
import { WEEK, currentLeagueId, leagueSongs } from "./info";
|
||||
|
||||
const fix = (v: any, n: number, def: number): number[] => {
|
||||
const a = Array.isArray(v) ? v.slice(0, n) : [];
|
||||
while (a.length < n) a.push(def);
|
||||
return a;
|
||||
};
|
||||
|
||||
// Class 1-4 (Amateur, Regular, Master, Legend), subclass 5 (lowest) .. 1 (highest); Legend has
|
||||
// only subclass 1. Rank 0..15 is the linear order of those.
|
||||
const classToRank = (c: number, s: number): number => {
|
||||
c = Math.min(4, Math.max(1, c | 0)); s = Math.min(5, Math.max(1, s | 0));
|
||||
return c === 4 ? 15 : (c - 1) * 5 + (5 - s);
|
||||
};
|
||||
const rankToClass = (r: number): [number, number] => {
|
||||
r = Math.min(15, Math.max(0, r | 0));
|
||||
return r === 15 ? [4, 1] : [Math.floor(r / 5) + 1, 5 - (r % 5)];
|
||||
};
|
||||
|
||||
const shiftClass = (p: PropData, delta: number) => {
|
||||
const [nc, ns] = rankToClass(classToRank(p.league_class, p.league_subclass) + delta);
|
||||
if (nc === p.league_class && ns === p.league_subclass) return;
|
||||
if (p.league_is_checked) {
|
||||
p.last.league_class = p.league_class;
|
||||
p.last.league_subclass = p.league_subclass;
|
||||
}
|
||||
p.league_class = nc; p.league_subclass = ns;
|
||||
p.league_is_checked = false;
|
||||
};
|
||||
|
||||
const total = (l: VersionLeague) => fix(l.score, 3, 0).reduce((a, b) => a + b, 0);
|
||||
|
||||
/** Applies the weeks since the last evaluation. Returns whether `p` changed. */
|
||||
export async function evaluateLeague(refid: string, p: PropData): Promise<boolean> {
|
||||
const cur = currentLeagueId();
|
||||
if ((p.league_eval_id | 0) >= cur) return false;
|
||||
const played = new Set((await playerLeagues(refid, PROP)).map(l => l.leagueId));
|
||||
for (let w = Math.max((p.league_eval_id | 0) + 1, cur - 52); w <= cur; w++) {
|
||||
let lastPlayed = 0;
|
||||
played.forEach(id => { if (id < w && id > lastPlayed) lastPlayed = id; });
|
||||
if (lastPlayed === 0) continue; // no league before this week
|
||||
if (played.has(w - 1)) {
|
||||
const ranked = (await leagueResults(PROP, w - 1))
|
||||
.map(l => ({ refid: (l as any).__refid, total: total(l) }))
|
||||
.sort((a, b) => b.total - a.total);
|
||||
const promoted = Math.ceil(ranked.length * 0.3);
|
||||
const demoted = Math.ceil((ranked.length - promoted) * 0.42);
|
||||
const idx = ranked.findIndex(x => x.refid === refid);
|
||||
if (idx >= 0 && idx < promoted) shiftClass(p, +1);
|
||||
else if (idx >= promoted && demoted > 0 && idx >= ranked.length - demoted) shiftClass(p, -1);
|
||||
} else {
|
||||
const weeksAway = (w - lastPlayed) - 1;
|
||||
if (weeksAway >= 2 && weeksAway % 2 === 0) shiftClass(p, -1);
|
||||
}
|
||||
}
|
||||
p.league_eval_id = cur;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Saves the `data.player.league` part of gameend.regist, keeping the best total. */
|
||||
export async function saveLeagueResult(refid: string, d: KDataReader, p: PropData) {
|
||||
if (!d.element("data.player.league")) return;
|
||||
const leagueId = d.number("data.player.league.league_id");
|
||||
p.league_is_checked = d.bool("data.player.league.is_checked");
|
||||
p.league_is_first_play = d.bool("data.player.league.is_first_play");
|
||||
const score = [0, 0, 0], clear = [0, 0, 0];
|
||||
for (const m of d.elements("data.player.league.music") || []) {
|
||||
const idx = parseInt(m.attr("").index);
|
||||
if (isNaN(idx) || idx < 0 || idx > 2) continue;
|
||||
score[idx] = m.number("score") | 0;
|
||||
clear[idx] = parseInt((m.attr("score") || {}).clear) | 0;
|
||||
}
|
||||
if (leagueId === undefined || leagueId === null || isNaN(leagueId)) return;
|
||||
const old = await findLeague(refid, PROP, leagueId);
|
||||
if (!old || total(old) < score.reduce((a, b) => a + b, 0)) await saveLeague(refid, PROP, leagueId, score, clear);
|
||||
}
|
||||
|
||||
export const getLeague: EamusePluginRoute = async (info, data, send) => {
|
||||
const jid = $(data).number("data.player.jid");
|
||||
const player = jid ? await playerByJid(jid) : null;
|
||||
const p = player ? await loadProp(player.__refid) : null;
|
||||
if (p && await evaluateLeague(player.__refid, p)) await saveProp(player.__refid, p);
|
||||
|
||||
const leagueId = currentLeagueId();
|
||||
const mine = player ? await findLeague(player.__refid, PROP, leagueId) : null;
|
||||
const cls = p ? p.league_class || 1 : 1;
|
||||
|
||||
return send.object({
|
||||
data: {
|
||||
league_list: {
|
||||
league: K.ATTR({ index: "0" }, {
|
||||
id: K.ITEM("s32", leagueId),
|
||||
stime: K.ITEM("u64", BigInt(leagueId * WEEK * 1000)),
|
||||
etime: K.ITEM("u64", BigInt((leagueId + 1) * WEEK * 1000)),
|
||||
music_list: {
|
||||
music: leagueSongs(leagueId).map((m, i) => K.ATTR({ index: String(i) }, {
|
||||
music_id: K.ITEM("s32", m),
|
||||
seq: K.ITEM("u8", cls === 1 ? 1 : 2),
|
||||
})),
|
||||
},
|
||||
player_list: {
|
||||
player: {
|
||||
jid: K.ITEM("s32", jid | 0),
|
||||
result: {
|
||||
score: K.ARRAY("s32", fix(mine && mine.score, 3, 0)),
|
||||
clear: K.ARRAY("s8", fix(mine && mine.clear, 3, 0)),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
last_class: K.ITEM("s32", p ? p.last.league_class || 1 : 1),
|
||||
last_subclass: K.ITEM("s32", p ? p.last.league_subclass || 5 : 5),
|
||||
is_checked: K.ITEM("bool", p ? p.league_is_checked !== false : true),
|
||||
},
|
||||
}, { compress: true });
|
||||
};
|
||||
293
jubeat@asphyxia/versions/prop/profile.ts
Normal file
293
jubeat@asphyxia/versions/prop/profile.ts
Normal file
@@ -0,0 +1,293 @@
|
||||
declare const BigInt: any; // CORE typecheck targets es2017
|
||||
// prop's profile, in the layout of bemaniutils' bemani/backend/jubeat/prop.py (format_profile,
|
||||
// unformat_profile), checked against the property paths prop's jubeat.dll reads
|
||||
// (data/player/{info,last,item,history,fc_challenge,news,rivallist,lab_edit_seq,free_first_play,
|
||||
// event_info,jbox,career,league,new_music,eapass_privilege,bonus_music,bistro,navi,cabinet_survey,
|
||||
// kaitou_bisco,gift_list}).
|
||||
|
||||
import Profile from "../../models/profile";
|
||||
import { VersionInfo } from "../types";
|
||||
import { findPlayer, loadPlayer, playerByJid } from "../../handlers/player";
|
||||
import { legacyMdata, saveResultTunes, versionScores } from "../../handlers/scores";
|
||||
import { PropData, loadProp, saveProp } from "./data";
|
||||
import { currentDayId, fcChallenge, info as globalInfo } from "./info";
|
||||
import { evaluateLeague, saveLeagueResult } from "./league";
|
||||
import { saveCourseResult } from "./course";
|
||||
|
||||
const fill = (n: number, v: number): number[] => new Array(n).fill(v);
|
||||
const s32a = (v: number[]) => K.ARRAY("s32", v);
|
||||
const fix = (v: any, n: number, def: number): number[] => {
|
||||
const a = Array.isArray(v) ? v.slice(0, n) : [];
|
||||
while (a.length < n) a.push(def);
|
||||
return a;
|
||||
};
|
||||
const ok = (v: any): boolean => v !== undefined && v !== null && !(typeof v === "number" && isNaN(v));
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// profile -> response
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
const format = (player: Profile, p: PropData) => {
|
||||
const l = p.last;
|
||||
const emblem = fix(l.emblem, 5, 0);
|
||||
if (emblem[1] === 0) emblem[1] = 2; // default main part, as bemaniutils does
|
||||
const career = p.career;
|
||||
const fc = fcChallenge(currentDayId());
|
||||
const fcPlayed = p.fc_day === currentDayId() ? fix(p.fc_played, 2, 0) : [0, 0];
|
||||
|
||||
return {
|
||||
data: {
|
||||
info: globalInfo(),
|
||||
player: {
|
||||
name: K.ITEM("str", player.name),
|
||||
jid: K.ITEM("s32", player.jubeatId),
|
||||
session_id: K.ITEM("s32", 1),
|
||||
event_flag: K.ITEM("u64", BigInt(0)),
|
||||
info: {
|
||||
jubility: K.ITEM("s16", p.jubility | 0),
|
||||
jubility_yday: K.ITEM("s16", p.jubility_yday | 0),
|
||||
tune_cnt: K.ITEM("s32", p.tune_cnt | 0),
|
||||
save_cnt: K.ITEM("s32", p.save_cnt | 0),
|
||||
saved_cnt: K.ITEM("s32", p.saved_cnt | 0),
|
||||
fc_cnt: K.ITEM("s32", p.fc_cnt | 0),
|
||||
ex_cnt: K.ITEM("s32", p.ex_cnt | 0),
|
||||
clear_cnt: K.ITEM("s32", p.clear_cnt | 0),
|
||||
pf_cnt: K.ITEM("s32", p.pf_cnt | 0),
|
||||
match_cnt: K.ITEM("s32", p.match_cnt | 0),
|
||||
beat_cnt: K.ITEM("s32", p.beat_cnt | 0),
|
||||
mynews_cnt: K.ITEM("s32", p.mynews_cnt | 0),
|
||||
bonus_tune_points: K.ITEM("s32", p.bonus_tune_points | 0),
|
||||
is_bonus_tune_played: K.ITEM("bool", !!p.is_bonus_tune_played),
|
||||
// true would mark this as a carried-over profile and skip the tutorial; there is no
|
||||
// older-version data to inherit from here.
|
||||
inherit: K.ITEM("bool", false),
|
||||
mtg_entry_cnt: K.ITEM("s32", 123),
|
||||
mtg_hold_cnt: K.ITEM("s32", 456),
|
||||
mtg_result: K.ITEM("u8", 10),
|
||||
},
|
||||
last: {
|
||||
play_time: K.ITEM("s64", BigInt(l.play_time || 0)),
|
||||
shopname: K.ITEM("str", l.shopname || ""),
|
||||
areaname: K.ITEM("str", l.areaname || ""),
|
||||
expert_option: K.ITEM("s8", l.expert_option | 0),
|
||||
category: K.ITEM("s8", l.category | 0),
|
||||
sort: K.ITEM("s8", l.sort | 0),
|
||||
music_id: K.ITEM("s32", l.music_id | 0),
|
||||
seq_id: K.ITEM("s8", l.seq_id | 0),
|
||||
settings: {
|
||||
marker: K.ITEM("s8", l.marker | 0),
|
||||
theme: K.ITEM("s8", l.theme | 0),
|
||||
title: K.ITEM("s16", l.title | 0),
|
||||
parts: K.ITEM("s16", l.parts | 0),
|
||||
rank_sort: K.ITEM("s8", l.rank_sort | 0),
|
||||
combo_disp: K.ITEM("s8", l.combo_disp | 0),
|
||||
matching: K.ITEM("s8", l.matching | 0),
|
||||
hazard: K.ITEM("s8", l.hazard | 0),
|
||||
hard: K.ITEM("s8", l.hard | 0),
|
||||
emblem: K.ARRAY("s16", emblem),
|
||||
},
|
||||
},
|
||||
item: {
|
||||
music_list: s32a(fix(p.music_list, 32, -1)),
|
||||
secret_list: s32a(fill(32, -1)), // force-unlock all secret songs
|
||||
theme_list: K.ITEM("s16", ok(p.theme_list) ? p.theme_list : -1),
|
||||
marker_list: s32a(fix(p.marker_list, 2, -1)),
|
||||
title_list: s32a(fix(p.title_list, 160, -1)),
|
||||
parts_list: s32a(fix(p.parts_list, 160, -1)),
|
||||
emblem_list: s32a(fix(p.emblem_list, 96, 0)),
|
||||
new: {
|
||||
secret_list: s32a(fill(32, -1)),
|
||||
theme_list: K.ITEM("s16", ok(p.theme_list_new) ? p.theme_list_new : -1),
|
||||
marker_list: s32a(fix(p.marker_list_new, 2, -1)),
|
||||
},
|
||||
},
|
||||
history: K.ATTR({ count: "0" }),
|
||||
lab_edit_seq: K.ATTR({ count: "0" }),
|
||||
cabinet_survey: { read_flag: K.ITEM("u32", 0) },
|
||||
kaitou_bisco: { read_flag: K.ITEM("u32", p.kaitou_bisco_read_flag | 0) },
|
||||
navi: { flag: K.ITEM("u32", p.navi_flag | 0) },
|
||||
event_info: {
|
||||
event: Object.keys(p.events || {}).map(t =>
|
||||
K.ATTR({ type: t }, { state: K.ITEM("u8", p.events[t] ? 0x2 : 0x0) })),
|
||||
},
|
||||
fc_challenge: {
|
||||
today: { music_id: K.ITEM("s32", fc.today), state: K.ITEM("u8", fcPlayed[0] ? 0x40 : 0) },
|
||||
whim: { music_id: K.ITEM("s32", fc.whim), state: K.ITEM("u8", fcPlayed[1] ? 0x40 : 0) },
|
||||
},
|
||||
news: { checked: K.ITEM("s16", 0), checked_flag: K.ITEM("u32", 0) },
|
||||
rivallist: K.ATTR({ count: "0" }),
|
||||
free_first_play: {
|
||||
is_available: K.ITEM("bool", false),
|
||||
point: K.ITEM("s32", 0),
|
||||
point_used: K.ITEM("s32", 0),
|
||||
come_come_jbox: {
|
||||
is_valid: K.ITEM("bool", false),
|
||||
end_time_if_paired: K.ITEM("s64", BigInt(0)),
|
||||
},
|
||||
},
|
||||
jbox: {
|
||||
point: K.ITEM("s32", p.jbox_point | 0),
|
||||
emblem: {
|
||||
normal: { index: K.ITEM("s16", p.jbox_normal_index || 2) },
|
||||
premium: { index: K.ITEM("s16", p.jbox_premium_index || 1) },
|
||||
},
|
||||
},
|
||||
career: {
|
||||
level: K.ITEM("s16", career.level || 1),
|
||||
point: K.ITEM("s32", career.point | 0),
|
||||
param: s32a(fix(career.param, 10, -1)),
|
||||
is_unlocked: K.ITEM("bool", !!career.is_unlocked),
|
||||
},
|
||||
league: {
|
||||
is_first_play: K.ITEM("bool", p.league_is_first_play !== false),
|
||||
class: K.ITEM("s32", p.league_class || 1),
|
||||
subclass: K.ITEM("s32", p.league_subclass || 5),
|
||||
},
|
||||
new_music: {},
|
||||
eapass_privilege: { emblem_list: {} },
|
||||
bonus_music: {
|
||||
music: {},
|
||||
event_id: K.ITEM("s32", -1),
|
||||
till_time: K.ITEM("str", ""),
|
||||
},
|
||||
bistro: {
|
||||
chef: { id: K.ITEM("s32", 1) },
|
||||
carry_over: K.ITEM("s32", 0),
|
||||
route_list: { route_count: K.ITEM("u8", 0) },
|
||||
extension: K.ITEM("bool", false),
|
||||
},
|
||||
gift_list: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// request -> profile (gameend.regist)
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
const unformat = (d: KDataReader, p: PropData) => {
|
||||
const num = (path: string, def: number) => { const v = d.number(path); return ok(v) ? v : def; };
|
||||
const nums = (path: string, n: number, cur: number[], def: number) => {
|
||||
const v = d.numbers(path); return (v && v.length) ? fix(v, n, def) : cur;
|
||||
};
|
||||
|
||||
p.saved = true;
|
||||
p.last.play_time = num("data.info.time_gameend", p.last.play_time);
|
||||
p.last.shopname = d.str("data.info.shopname") || p.last.shopname;
|
||||
p.last.areaname = d.str("data.info.areaname") || p.last.areaname;
|
||||
|
||||
if (d.element("data.player.info")) {
|
||||
const I = "data.player.info.";
|
||||
p.jubility = num(I + "jubility", p.jubility); p.jubility_yday = num(I + "jubility_yday", p.jubility_yday);
|
||||
p.tune_cnt = num(I + "tune_cnt", p.tune_cnt); p.save_cnt = num(I + "save_cnt", p.save_cnt);
|
||||
p.saved_cnt = num(I + "saved_cnt", p.saved_cnt); p.fc_cnt = num(I + "fc_cnt", p.fc_cnt);
|
||||
p.ex_cnt = num(I + "ex_cnt", p.ex_cnt); p.pf_cnt = num(I + "pf_cnt", p.pf_cnt);
|
||||
p.clear_cnt = num(I + "clear_cnt", p.clear_cnt); p.match_cnt = num(I + "match_cnt", p.match_cnt);
|
||||
p.beat_cnt = num(I + "beat_cnt", p.beat_cnt); p.mynews_cnt = num(I + "mynews_cnt", p.mynews_cnt);
|
||||
p.total_best_score = num(I + "total_best_score", p.total_best_score);
|
||||
p.bonus_tune_points = num(I + "bonus_tune_points", p.bonus_tune_points);
|
||||
p.is_bonus_tune_played = d.bool(I + "is_bonus_tune_played");
|
||||
}
|
||||
|
||||
if (d.element("data.player.last")) {
|
||||
const L = "data.player.last.";
|
||||
p.last.expert_option = num(L + "expert_option", p.last.expert_option);
|
||||
p.last.sort = num(L + "sort", p.last.sort);
|
||||
p.last.category = num(L + "category", p.last.category);
|
||||
const S = L + "settings.";
|
||||
p.last.matching = num(S + "matching", p.last.matching); p.last.hazard = num(S + "hazard", p.last.hazard);
|
||||
p.last.hard = num(S + "hard", p.last.hard); p.last.marker = num(S + "marker", p.last.marker);
|
||||
p.last.theme = num(S + "theme", p.last.theme); p.last.title = num(S + "title", p.last.title);
|
||||
p.last.parts = num(S + "parts", p.last.parts); p.last.rank_sort = num(S + "rank_sort", p.last.rank_sort);
|
||||
p.last.combo_disp = num(S + "combo_disp", p.last.combo_disp);
|
||||
p.last.emblem = nums(S + "emblem", 5, fix(p.last.emblem, 5, 0), 0);
|
||||
}
|
||||
|
||||
if (d.element("data.player.item")) {
|
||||
// secret_list is not stored: it is force-unlocked on load, so the game echoes all bits back.
|
||||
const T = "data.player.item.";
|
||||
p.music_list = nums(T + "music_list", 32, p.music_list, -1);
|
||||
p.theme_list = num(T + "theme_list", p.theme_list);
|
||||
p.marker_list = nums(T + "marker_list", 2, p.marker_list, -1);
|
||||
p.title_list = nums(T + "title_list", 160, p.title_list, -1);
|
||||
p.parts_list = nums(T + "parts_list", 160, p.parts_list, -1);
|
||||
p.emblem_list = nums(T + "emblem_list", 96, p.emblem_list, 0);
|
||||
p.theme_list_new = num(T + "new.theme_list", p.theme_list_new);
|
||||
p.marker_list_new = nums(T + "new.marker_list", 2, p.marker_list_new, -1);
|
||||
}
|
||||
|
||||
if (d.element("data.player.career")) {
|
||||
const C = "data.player.career.";
|
||||
p.career.level = num(C + "level", p.career.level);
|
||||
p.career.point = num(C + "point", p.career.point);
|
||||
p.career.param = nums(C + "param", 10, p.career.param, -1);
|
||||
p.career.is_unlocked = d.bool(C + "is_unlocked");
|
||||
}
|
||||
|
||||
if (d.element("data.player.jbox")) {
|
||||
p.jbox_point = num("data.player.jbox.point", p.jbox_point);
|
||||
const jbType = num("data.player.jbox.emblem.type", 0), jbIndex = num("data.player.jbox.emblem.index", 0);
|
||||
if (jbType === 1) p.jbox_normal_index = jbIndex;
|
||||
else if (jbType === 2) p.jbox_premium_index = jbIndex;
|
||||
}
|
||||
|
||||
p.events = p.events || {};
|
||||
for (const ev of d.elements("data.player.event_info.event") || []) {
|
||||
const t = ev.attr("").type;
|
||||
if (t !== undefined) p.events[String(t)] = ev.bool("is_completed");
|
||||
}
|
||||
|
||||
p.navi_flag = num("data.player.navi.flag", p.navi_flag);
|
||||
p.kaitou_bisco_read_flag = num("data.player.kaitou_bisco.read_flag", p.kaitou_bisco_read_flag);
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// routes
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
export const regist: EamusePluginRoute = async (info, data, send) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
if (!refid) return send.deny();
|
||||
const player = await loadPlayer(refid, $(data).str("data.player.name"));
|
||||
const p = await loadProp(refid);
|
||||
if (await evaluateLeague(refid, p)) await saveProp(refid, p);
|
||||
return send.object(format(player, p), { compress: true });
|
||||
};
|
||||
|
||||
// Same as regist: the game skips regist for cards CORE already knows.
|
||||
export const getPdata = regist;
|
||||
|
||||
export const getMdata = (version: VersionInfo): EamusePluginRoute => async (info, data, send) => {
|
||||
const jid = $(data).number("data.player.jid");
|
||||
if (!jid) return send.deny();
|
||||
const player = await playerByJid(jid);
|
||||
if (!player) return send.status(109);
|
||||
const part = Math.min(3, Math.max(1, $(data).number("data.player.mdata_ver", 1)));
|
||||
const musicdata = legacyMdata(await versionScores(player.__refid, version), part);
|
||||
return send.object({
|
||||
data: { player: { jid: K.ITEM("s32", jid), mdata_list: { musicdata } } },
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const gameendRegist: EamusePluginRoute = async (info, data, send) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
if (!refid || !(await findPlayer(refid))) return send.deny();
|
||||
const d = $(data);
|
||||
const p = await loadProp(refid);
|
||||
unformat(d, p);
|
||||
|
||||
const plays = await saveResultTunes(refid, d);
|
||||
const fc = fcChallenge(currentDayId());
|
||||
if (p.fc_day !== currentDayId()) { p.fc_day = currentDayId(); p.fc_played = [0, 0]; }
|
||||
for (const play of plays) {
|
||||
p.last.music_id = play.musicId; p.last.seq_id = play.seq;
|
||||
if (play.musicId === fc.today) p.fc_played[0] = 1;
|
||||
if (play.musicId === fc.whim) p.fc_played[1] = 1;
|
||||
}
|
||||
|
||||
await saveCourseResult(refid, d, p);
|
||||
await saveLeagueResult(refid, d, p);
|
||||
await saveProp(refid, p);
|
||||
console.log(`[jubeat] prop gameend.regist: ${plays.length} tune(s) saved`);
|
||||
return send.object({
|
||||
data: { player: { session_id: K.ITEM("s32", 1), end_final_session_id: K.ITEM("s32", 1) } },
|
||||
}, { compress: true });
|
||||
};
|
||||
50
jubeat@asphyxia/versions/qubell/index.ts
Normal file
50
jubeat@asphyxia/versions/qubell/index.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { GameVersion, VersionInfo } from "../types";
|
||||
import * as common from "../../handlers/common";
|
||||
import * as lobby from "../../handlers/lobby";
|
||||
import { info as globalInfo } from "./info";
|
||||
import * as profile from "./profile";
|
||||
|
||||
const version: VersionInfo = {
|
||||
id: 8, name: "Qubell", from: 2016033000, until: 2017062600, maxMusicId: 89999999,
|
||||
};
|
||||
|
||||
/** Qubell's route table. Clan answers with the same handlers under its own version. */
|
||||
export const qubellRoutes = (version: VersionInfo): GameVersion["routes"] => ({
|
||||
"shopinfo.regist": (info, data, send) => send.object({
|
||||
data: {
|
||||
cabid: K.ITEM("u32", 1),
|
||||
locationid: K.ITEM("str", $(data).str("data.shop.locationid", "nowhere") || "nowhere"),
|
||||
tax_phase: K.ITEM("u8", 1),
|
||||
facility: { exist: K.ITEM("u32", 1) },
|
||||
info: globalInfo(),
|
||||
},
|
||||
}, { compress: true }),
|
||||
"gametop.get_info": (info, data, send) => send.object({ data: { info: globalInfo() } }, { compress: true }),
|
||||
|
||||
// Profile
|
||||
"gametop.regist": profile.regist(version),
|
||||
"gametop.get_pdata": profile.getPdata(version),
|
||||
"gameend.regist": profile.gameendRegist(version),
|
||||
"gameend.final": profile.gameendFinal(version),
|
||||
|
||||
// Scores
|
||||
"gametop.get_mdata": profile.getMdata(version),
|
||||
|
||||
// Matching
|
||||
"gametop.get_meeting": common.meeting,
|
||||
"lobby.check": common.lobbyCheck,
|
||||
"lobby.entry": lobby.Entry,
|
||||
"lobby.refresh": lobby.Refresh,
|
||||
"lobby.report": lobby.Report,
|
||||
|
||||
// Attract
|
||||
"demodata.get_news": common.news,
|
||||
"demodata.get_hitchart": common.hitchart(version),
|
||||
"recommend.get_recommend": (info, data, send) =>
|
||||
send.object({ data: { player: { music_list: {} } } }, { compress: true }),
|
||||
|
||||
"netlog.send": true,
|
||||
"logger.report": true,
|
||||
});
|
||||
|
||||
export const Qubell: GameVersion = { ...version, routes: qubellRoutes(version) };
|
||||
41
jubeat@asphyxia/versions/qubell/info.ts
Normal file
41
jubeat@asphyxia/versions/qubell/info.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
// Qubell's global "info" node (shopinfo.regist, gametop.get_info, and inside every profile).
|
||||
// Layout from bemaniutils' bemani/backend/jubeat/qubell.py (__get_global_info).
|
||||
|
||||
const fill = (n: number, v: number): number[] => new Array(n).fill(v);
|
||||
const s32a = (v: number[]) => K.ARRAY("s32", v);
|
||||
|
||||
const EVENTS = [5, 6, 15, 19];
|
||||
|
||||
export const info = () => ({
|
||||
event_info: {
|
||||
event: EVENTS.map(e => K.ATTR({ type: String(e) }, { state: K.ITEM("u8", 0) })),
|
||||
},
|
||||
share_music: {},
|
||||
bonus_music: {},
|
||||
white_music_list: s32a(fill(64, -1)),
|
||||
white_marker_list: s32a(fill(16, -1)),
|
||||
white_theme_list: s32a(fill(16, -1)),
|
||||
open_music_list: s32a(fill(64, -1)),
|
||||
shareable_music_list: s32a(fill(64, -1)),
|
||||
jbox: {
|
||||
point: K.ITEM("s32", 0),
|
||||
emblem: {
|
||||
normal: { index: K.ITEM("s16", 2) },
|
||||
premium: { index: K.ITEM("s16", 1) },
|
||||
},
|
||||
},
|
||||
born: { status: K.ITEM("s8", 0), year: K.ITEM("s16", 0) },
|
||||
digdig: {
|
||||
stage_list: {
|
||||
stage: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13].map(n =>
|
||||
K.ATTR({ number: String(n) }, { state: K.ITEM("u8", 1) })),
|
||||
},
|
||||
},
|
||||
collection: { rating_s: {} },
|
||||
generic_dig: { map_list: {} },
|
||||
expert_option: { is_available: K.ITEM("bool", true) },
|
||||
tsumtsum: { is_available: K.ITEM("bool", true) },
|
||||
nagatanien: { is_available: K.ITEM("bool", true) },
|
||||
all_music_matching: { is_available: K.ITEM("bool", true) },
|
||||
question_list: {},
|
||||
});
|
||||
@@ -1,13 +1,17 @@
|
||||
declare const BigInt: any; // CORE typecheck targets es2017
|
||||
// jubeat Qubell (L44 2016-2017) handlers for Asphyxia CORE.
|
||||
// Response layout follows bemaniutils' bemani/backend/jubeat/qubell.py (format_profile,
|
||||
// format_scores, unformat_profile, __get_global_info) so the game accepts it.
|
||||
// Profiles live in collection "qubell_profile", scores in "qubell_score" (separate from the
|
||||
// festo collections used by the original plugin code).
|
||||
// Qubell's profile, in the layout of bemaniutils' bemani/backend/jubeat/qubell.py
|
||||
// (format_profile, unformat_profile). Clan reuses it under its own version id.
|
||||
//
|
||||
// The jubeat ID and name come from the shared profile; everything else is the
|
||||
// version's own data (handlers/version_data.ts).
|
||||
|
||||
import Profile from "../../models/profile";
|
||||
import { VersionInfo } from "../types";
|
||||
import { loadPlayer, findPlayer, playerByJid } from "../../handlers/player";
|
||||
import { loadVersionData, saveVersionData } from "../../handlers/version_data";
|
||||
import { legacyMdata, saveResultTunes, versionScores } from "../../handlers/scores";
|
||||
import { info as globalInfo } from "./info";
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// helpers
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
const fill = (n: number, v: number): number[] => new Array(n).fill(v);
|
||||
const s32a = (v: number[]) => K.ARRAY("s32", v);
|
||||
const fix = (v: any, n: number, def: number): number[] => {
|
||||
@@ -16,12 +20,8 @@ const fix = (v: any, n: number, def: number): number[] => {
|
||||
return a;
|
||||
};
|
||||
|
||||
const FLAG_PLAYED = 0x1, FLAG_CLEARED = 0x2, FLAG_FC = 0x4, FLAG_EX = 0x8;
|
||||
|
||||
export interface QProfile {
|
||||
collection: "qubell_profile";
|
||||
jid: number;
|
||||
name: string;
|
||||
/** Qubell's player data, kept in version data. */
|
||||
export interface QubellData {
|
||||
saved: boolean;
|
||||
jubility: number; jubility_yday: number;
|
||||
tune_cnt: number; save_cnt: number; saved_cnt: number; fc_cnt: number; ex_cnt: number;
|
||||
@@ -36,8 +36,8 @@ export interface QProfile {
|
||||
emblem: number[];
|
||||
};
|
||||
music_list: number[]; theme_list: number[]; marker_list: number[];
|
||||
title_list: number[]; parts_list: number[]; emblem_list: number[]; secret_list: number[];
|
||||
theme_list_new: number[]; marker_list_new: number[]; secret_list_new: number[];
|
||||
title_list: number[]; parts_list: number[]; emblem_list: number[];
|
||||
theme_list_new: number[]; marker_list_new: number[];
|
||||
jbox_point: number; jbox_normal_index: number; jbox_premium_index: number;
|
||||
navi_flag: number;
|
||||
born_status: number; born_year: number;
|
||||
@@ -46,17 +46,8 @@ export interface QProfile {
|
||||
stages: { [num: string]: number };
|
||||
}
|
||||
|
||||
export interface QScore {
|
||||
collection: "qubell_score";
|
||||
musicId: number; seq: number;
|
||||
score: number; clear: number;
|
||||
playCnt: number; clearCnt: number; fcCnt: number; exCnt: number;
|
||||
bar: number[];
|
||||
}
|
||||
|
||||
const newProfile = (name: string, jid: number): QProfile => ({
|
||||
collection: "qubell_profile",
|
||||
jid, name, saved: false,
|
||||
const defaults = (): QubellData => ({
|
||||
saved: false,
|
||||
jubility: 0, jubility_yday: 0,
|
||||
tune_cnt: 0, save_cnt: 0, saved_cnt: 0, fc_cnt: 0, ex_cnt: 0,
|
||||
clear_cnt: 0, match_cnt: 0, beat_cnt: 0, mynews_cnt: 0,
|
||||
@@ -69,56 +60,22 @@ const newProfile = (name: string, jid: number): QProfile => ({
|
||||
},
|
||||
music_list: fill(64, -1), theme_list: fill(16, -1), marker_list: fill(16, -1),
|
||||
title_list: fill(160, -1), parts_list: fill(160, -1), emblem_list: fill(96, -1),
|
||||
secret_list: fill(64, -1),
|
||||
theme_list_new: fill(16, -1), marker_list_new: fill(16, -1), secret_list_new: fill(64, -1),
|
||||
theme_list_new: fill(16, -1), marker_list_new: fill(16, -1),
|
||||
jbox_point: 0, jbox_normal_index: 2, jbox_premium_index: 1,
|
||||
navi_flag: 0, born_status: 0, born_year: 0,
|
||||
events: {}, digdig: {}, stages: {},
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// global "info" node (shopinfo.regist, gametop.get_info, and inside every profile)
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
const EVENTS = [5, 6, 15, 19];
|
||||
|
||||
export const qubellInfo = () => ({
|
||||
event_info: {
|
||||
event: EVENTS.map(e => K.ATTR({ type: String(e) }, { state: K.ITEM("u8", 0) })),
|
||||
},
|
||||
share_music: {},
|
||||
bonus_music: {},
|
||||
white_music_list: s32a(fill(64, -1)),
|
||||
white_marker_list: s32a(fill(16, -1)),
|
||||
white_theme_list: s32a(fill(16, -1)),
|
||||
open_music_list: s32a(fill(64, -1)),
|
||||
shareable_music_list: s32a(fill(64, -1)),
|
||||
jbox: {
|
||||
point: K.ITEM("s32", 0),
|
||||
emblem: {
|
||||
normal: { index: K.ITEM("s16", 2) },
|
||||
premium: { index: K.ITEM("s16", 1) },
|
||||
},
|
||||
},
|
||||
born: { status: K.ITEM("s8", 0), year: K.ITEM("s16", 0) },
|
||||
digdig: {
|
||||
stage_list: {
|
||||
stage: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13].map(n =>
|
||||
K.ATTR({ number: String(n) }, { state: K.ITEM("u8", 1) })),
|
||||
},
|
||||
},
|
||||
collection: { rating_s: {} },
|
||||
generic_dig: { map_list: {} },
|
||||
expert_option: { is_available: K.ITEM("bool", true) },
|
||||
tsumtsum: { is_available: K.ITEM("bool", true) },
|
||||
nagatanien: { is_available: K.ITEM("bool", true) },
|
||||
all_music_matching: { is_available: K.ITEM("bool", true) },
|
||||
question_list: {},
|
||||
});
|
||||
const load = async (refid: string, version: VersionInfo): Promise<QubellData> => {
|
||||
const d: any = { ...defaults(), ...(await loadVersionData(refid, version.id)) };
|
||||
d.last = { ...defaults().last, ...(d.last || {}) };
|
||||
return d;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// profile -> response
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
const formatProfile = (p: QProfile) => {
|
||||
const format = (player: Profile, p: QubellData) => {
|
||||
const l = p.last;
|
||||
const emblem = fix(l.emblem, 5, 0);
|
||||
if (emblem[1] === 0) emblem[1] = 2; // default main part, as bemaniutils does
|
||||
@@ -126,11 +83,11 @@ const formatProfile = (p: QProfile) => {
|
||||
const et = dd.eternal || {};
|
||||
return {
|
||||
data: {
|
||||
info: qubellInfo(),
|
||||
info: globalInfo(),
|
||||
player: {
|
||||
server: {},
|
||||
name: K.ITEM("str", p.name),
|
||||
jid: K.ITEM("s32", p.jid),
|
||||
name: K.ITEM("str", player.name),
|
||||
jid: K.ITEM("s32", player.jubeatId),
|
||||
session_id: K.ITEM("s32", 1),
|
||||
event_flag: K.ITEM("u64", BigInt(0)),
|
||||
info: {
|
||||
@@ -258,129 +215,9 @@ const formatProfile = (p: QProfile) => {
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// DB access
|
||||
// request -> profile (gameend.regist)
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
const findProfile = (refid: string) =>
|
||||
DB.FindOne<QProfile>(refid, { collection: "qubell_profile" });
|
||||
|
||||
const nextJid = async (): Promise<number> => {
|
||||
// 8-digit id, retried until unused
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const jid = 10000000 + Math.floor(Math.random() * 89999999);
|
||||
const hit = await DB.FindOne<QProfile>(null, { collection: "qubell_profile", jid });
|
||||
if (!hit) return jid;
|
||||
}
|
||||
return 10000000 + Math.floor(Math.random() * 89999999);
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// routes
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
export const shopinfoRegist = (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const locId = $(data).str("data.shop.locationid", "nowhere");
|
||||
return send.object({
|
||||
data: {
|
||||
cabid: K.ITEM("u32", 1),
|
||||
locationid: K.ITEM("str", locId || "nowhere"),
|
||||
tax_phase: K.ITEM("u8", 1),
|
||||
facility: { exist: K.ITEM("u32", 1) },
|
||||
info: qubellInfo(),
|
||||
},
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const gametopGetInfo = (info: EamuseInfo, data: any, send: EamuseSend) =>
|
||||
send.object({ data: { info: qubellInfo() } }, { compress: true });
|
||||
|
||||
export const gametopGetMeeting = (info: EamuseInfo, data: any, send: EamuseSend) =>
|
||||
send.object({
|
||||
data: {
|
||||
meeting: { single: K.ATTR({ count: "0" }), tag: K.ATTR({ count: "0" }) },
|
||||
reward: { total: K.ITEM("s32", -1), point: K.ITEM("s32", -1) },
|
||||
},
|
||||
}, { compress: true });
|
||||
|
||||
export const gametopRegist = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
const name = $(data).str("data.player.name") || "なし";
|
||||
if (!refid) return send.deny();
|
||||
let p = await findProfile(refid);
|
||||
if (!p) {
|
||||
const np = newProfile(name, await nextJid());
|
||||
await DB.Upsert<QProfile>(refid, { collection: "qubell_profile" }, np);
|
||||
p = await findProfile(refid);
|
||||
}
|
||||
console.log(`[qubell] gametop.regist -> jid ${p.jid} name ${p.name}`);
|
||||
return send.object(formatProfile(p), { compress: true });
|
||||
};
|
||||
|
||||
export const gametopGetPdata = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
if (!refid) return send.deny();
|
||||
let p = await findProfile(refid);
|
||||
if (!p) {
|
||||
// The card is already bound to this game on the CORE side (it went through registration
|
||||
// once with the festo-format code), so Qubell never calls gametop.regist again and treats a
|
||||
// "no profile" status as a login failure. Create the Qubell profile here instead, reusing
|
||||
// the name from the old festo-format profile if one exists.
|
||||
const old: any = await DB.FindOne<any>(refid, { collection: "profile" });
|
||||
const name = (old && old.name) ? String(old.name) : "なし";
|
||||
await DB.Upsert<QProfile>(refid, { collection: "qubell_profile" }, newProfile(name, await nextJid()));
|
||||
p = await findProfile(refid);
|
||||
console.log(`[qubell] gametop.get_pdata: created profile on the fly, name=${name} jid=${p.jid}`);
|
||||
}
|
||||
console.log(`[qubell] gametop.get_pdata -> jid ${p.jid} name ${p.name}`);
|
||||
return send.object(formatProfile(p), { compress: true });
|
||||
};
|
||||
|
||||
export const gametopGetMdata = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const jid = $(data).number("data.player.jid");
|
||||
const mdataVer = $(data).number("data.player.mdata_ver", 1);
|
||||
if (!jid) return send.deny();
|
||||
const p = await DB.FindOne<QProfile>(null, { collection: "qubell_profile", jid });
|
||||
if (!p) return send.status(109);
|
||||
|
||||
// all scores go out in partition 1; later partitions are empty
|
||||
const scores = mdataVer === 1
|
||||
? await DB.Find<QScore>(p.__refid, { collection: "qubell_score" })
|
||||
: [];
|
||||
|
||||
const byMusic: { [id: string]: QScore[] } = {};
|
||||
for (const s of scores) (byMusic[String(s.musicId)] = byMusic[String(s.musicId)] || []).push(s);
|
||||
|
||||
const musicdata = Object.keys(byMusic).map(id => {
|
||||
const play = [0, 0, 0], clr = [0, 0, 0], fc = [0, 0, 0], ex = [0, 0, 0], pts = [0, 0, 0], flags = [0, 0, 0];
|
||||
const bars: any[] = [];
|
||||
for (const s of byMusic[id]) {
|
||||
if (s.seq < 0 || s.seq > 2) continue;
|
||||
play[s.seq] = s.playCnt | 0; clr[s.seq] = s.clearCnt | 0; fc[s.seq] = s.fcCnt | 0; ex[s.seq] = s.exCnt | 0;
|
||||
pts[s.seq] = s.score | 0;
|
||||
let f = FLAG_PLAYED;
|
||||
if (s.clearCnt > 0) f |= FLAG_CLEARED;
|
||||
if (s.fcCnt > 0) f |= FLAG_FC;
|
||||
if (s.exCnt > 0) f |= FLAG_EX;
|
||||
flags[s.seq] = f;
|
||||
if (s.bar && s.bar.length) bars.push(K.ARRAY("u8", fix(s.bar, 30, 0), { seq: String(s.seq) }));
|
||||
}
|
||||
return K.ATTR({ music_id: id }, {
|
||||
play_cnt: s32a(play), clear_cnt: s32a(clr), fc_cnt: s32a(fc), ex_cnt: s32a(ex),
|
||||
score: s32a(pts), clear: K.ARRAY("s8", flags),
|
||||
...(bars.length ? { bar: bars } : {}),
|
||||
});
|
||||
});
|
||||
|
||||
console.log(`[qubell] gametop.get_mdata jid ${jid} ver ${mdataVer} -> ${musicdata.length} songs`);
|
||||
return send.object({
|
||||
data: { player: { jid: K.ITEM("s32", jid), mdata_list: { musicdata } } },
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const gameendRegist = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
if (!refid) return send.deny();
|
||||
const p = await findProfile(refid);
|
||||
if (!p) return send.deny();
|
||||
const d = $(data);
|
||||
const unformat = (d: KDataReader, p: QubellData) => {
|
||||
const num = (path: string, def: number) => { const v = d.number(path); return (v === undefined || v === null || isNaN(v)) ? def : v; };
|
||||
const nums = (path: string, n: number, cur: number[]) => { const v = d.numbers(path); return (v && v.length) ? fix(v, n, -1) : cur; };
|
||||
|
||||
@@ -431,11 +268,13 @@ export const gameendRegist = async (info: EamuseInfo, data: any, send: EamuseSen
|
||||
p.born_status = num("data.player.born.status", p.born_status);
|
||||
p.born_year = num("data.player.born.year", p.born_year);
|
||||
|
||||
p.events = p.events || {};
|
||||
for (const ev of d.elements("data.player.event_info.event") || []) {
|
||||
const t = ev.attr("").type;
|
||||
if (t !== undefined) p.events[String(t)] = ev.bool("is_completed");
|
||||
}
|
||||
|
||||
p.stages = p.stages || {};
|
||||
const dd = p.digdig || {};
|
||||
if (d.element("data.player.digdig")) {
|
||||
dd.flag = num("data.player.digdig.flag", dd.flag | 0);
|
||||
@@ -473,81 +312,65 @@ export const gameendRegist = async (info: EamuseInfo, data: any, send: EamuseSen
|
||||
}
|
||||
}
|
||||
p.digdig = dd;
|
||||
};
|
||||
|
||||
// scores
|
||||
let saved = 0;
|
||||
for (const tune of d.elements("data.result.tune") || []) {
|
||||
const musicId = tune.number("music");
|
||||
const sa = tune.attr("player.score") || {};
|
||||
const seq = parseInt(sa.seq), flags = parseInt(sa.clear) | 0;
|
||||
const points = tune.number("player.score") | 0;
|
||||
const bar = tune.numbers("player.mbar");
|
||||
if (!musicId || isNaN(seq)) continue;
|
||||
p.last.music_id = musicId; p.last.seq_id = seq;
|
||||
const old = await DB.FindOne<QScore>(refid, { collection: "qubell_score", musicId, seq });
|
||||
const ns: QScore = old || { collection: "qubell_score", musicId, seq, score: 0, clear: 0, playCnt: 0, clearCnt: 0, fcCnt: 0, exCnt: 0, bar: [] };
|
||||
ns.playCnt++;
|
||||
if (flags & FLAG_CLEARED) ns.clearCnt++;
|
||||
if (flags & FLAG_FC) ns.fcCnt++;
|
||||
if (flags & FLAG_EX) ns.exCnt++;
|
||||
ns.score = Math.max(ns.score | 0, points);
|
||||
ns.clear = (ns.clear | 0) | flags;
|
||||
if (bar && bar.length) ns.bar = bar;
|
||||
await DB.Upsert<QScore>(refid, { collection: "qubell_score", musicId, seq }, {
|
||||
$set: { musicId, seq, score: ns.score, clear: ns.clear, playCnt: ns.playCnt, clearCnt: ns.clearCnt, fcCnt: ns.fcCnt, exCnt: ns.exCnt, bar: ns.bar },
|
||||
});
|
||||
saved++;
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// routes
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
export const regist = (version: VersionInfo): EamusePluginRoute => async (info, data, send) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
if (!refid) return send.deny();
|
||||
const player = await loadPlayer(refid, $(data).str("data.player.name"));
|
||||
return send.object(format(player, await load(refid, version)), { compress: true });
|
||||
};
|
||||
|
||||
// Same as regist: the game skips regist for cards CORE already knows.
|
||||
export const getPdata = regist;
|
||||
|
||||
export const getMdata = (version: VersionInfo): EamusePluginRoute => async (info, data, send) => {
|
||||
const jid = $(data).number("data.player.jid");
|
||||
if (!jid) return send.deny();
|
||||
const player = await playerByJid(jid);
|
||||
if (!player) return send.status(109);
|
||||
const part = Math.min(3, Math.max(1, $(data).number("data.player.mdata_ver", 1)));
|
||||
const musicdata = legacyMdata(await versionScores(player.__refid, version), part);
|
||||
return send.object({
|
||||
data: { player: { jid: K.ITEM("s32", jid), mdata_list: { musicdata } } },
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const gameendRegist = (version: VersionInfo): EamusePluginRoute => async (info, data, send) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
if (!refid || !(await findPlayer(refid))) return send.deny();
|
||||
const d = $(data);
|
||||
const p = await load(refid, version);
|
||||
unformat(d, p);
|
||||
|
||||
const plays = await saveResultTunes(refid, d);
|
||||
if (plays.length) {
|
||||
p.last.music_id = plays[plays.length - 1].musicId;
|
||||
p.last.seq_id = plays[plays.length - 1].seq;
|
||||
}
|
||||
|
||||
const { __refid, _id, createdAt, updatedAt, ...plain } = p as any;
|
||||
await DB.Update<QProfile>(refid, { collection: "qubell_profile" }, { $set: plain });
|
||||
console.log(`[qubell] gameend.regist jid ${p.jid}: ${saved} tune(s) saved`);
|
||||
await saveVersionData(refid, version.id, p);
|
||||
console.log(`[jubeat] ${version.name} gameend.regist: ${plays.length} tune(s) saved`);
|
||||
return send.object({
|
||||
data: { player: { session_id: K.ITEM("s32", 1), end_final_session_id: K.ITEM("s32", 1) } },
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const gameendFinal = async (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
export const gameendFinal = (version: VersionInfo): EamusePluginRoute => async (info, data, send) => {
|
||||
const refid = $(data).str("data.player.refid");
|
||||
if (refid) {
|
||||
const p = await findProfile(refid);
|
||||
if (p) {
|
||||
const d = $(data);
|
||||
const jbType = d.number("data.player.jbox.emblem.type"), jbIndex = d.number("data.player.jbox.emblem.index");
|
||||
const upd: any = {};
|
||||
const pt = d.number("data.player.jbox.point"); if (pt !== undefined && !isNaN(pt)) upd.jbox_point = pt;
|
||||
if (jbType === 1) upd.jbox_normal_index = jbIndex; else if (jbType === 2) upd.jbox_premium_index = jbIndex;
|
||||
const bs = d.number("data.player.born.status"); if (bs !== undefined && !isNaN(bs)) upd.born_status = bs;
|
||||
const by = d.number("data.player.born.year"); if (by !== undefined && !isNaN(by)) upd.born_year = by;
|
||||
if (Object.keys(upd).length) await DB.Update<QProfile>(refid, { collection: "qubell_profile" }, { $set: upd });
|
||||
}
|
||||
if (refid && (await findPlayer(refid))) {
|
||||
const d = $(data);
|
||||
const ok = (v: number) => v !== undefined && v !== null && !isNaN(v);
|
||||
const upd: any = {};
|
||||
const pt = d.number("data.player.jbox.point"); if (ok(pt)) upd.jbox_point = pt;
|
||||
const jbType = d.number("data.player.jbox.emblem.type"), jbIndex = d.number("data.player.jbox.emblem.index");
|
||||
if (jbType === 1) upd.jbox_normal_index = jbIndex; else if (jbType === 2) upd.jbox_premium_index = jbIndex;
|
||||
const bs = d.number("data.player.born.status"); if (ok(bs)) upd.born_status = bs;
|
||||
const by = d.number("data.player.born.year"); if (ok(by)) upd.born_year = by;
|
||||
if (Object.keys(upd).length) await saveVersionData(refid, version.id, upd);
|
||||
}
|
||||
return send.success();
|
||||
};
|
||||
|
||||
export const lobbyCheck = (info: EamuseInfo, data: any, send: EamuseSend) =>
|
||||
send.object({
|
||||
data: {
|
||||
interval: K.ITEM("s16", 0),
|
||||
entry_timeout: K.ITEM("s16", 0),
|
||||
entrant_nr: K.ITEM("u32", 0, { time: "0" }),
|
||||
},
|
||||
}, { compress: true });
|
||||
|
||||
export const demodataGetNews = (info: EamuseInfo, data: any, send: EamuseSend) =>
|
||||
send.object({ data: { officialnews: K.ATTR({ count: "0" }) } }, { compress: true });
|
||||
|
||||
export const demodataGetHitchart = (info: EamuseInfo, data: any, send: EamuseSend) => {
|
||||
const now = new Date();
|
||||
const pad = (n: number) => (n < 10 ? "0" : "") + n;
|
||||
return send.object({
|
||||
data: {
|
||||
update: K.ITEM("str", `${pad(now.getDate())}/${pad(now.getMonth() + 1)}/${now.getFullYear()}`),
|
||||
hitchart_lic: K.ATTR({ count: "0" }),
|
||||
hitchart_org: K.ATTR({ count: "0" }),
|
||||
},
|
||||
}, { compress: true });
|
||||
};
|
||||
|
||||
export const recommendGetRecommend = (info: EamuseInfo, data: any, send: EamuseSend) =>
|
||||
send.object({ data: { player: { music_list: {} } } }, { compress: true });
|
||||
31
jubeat@asphyxia/versions/types.ts
Normal file
31
jubeat@asphyxia/versions/types.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Identity of a supported game version.
|
||||
*
|
||||
* Every jubeat version calls the same method names (`gametop.get_pdata`, ...),
|
||||
* so the version is picked from the date in the model string
|
||||
* (`L44:J:A:A:2015100000`) instead of from the method name.
|
||||
*/
|
||||
export interface VersionInfo {
|
||||
/**
|
||||
* The game's number in the series (7 prop, 8 Qubell, 9 clan, 10 festo).
|
||||
* Also the key of per-version records, and the first digits of the music
|
||||
* ids the version added.
|
||||
*/
|
||||
readonly id: number;
|
||||
/** Display name. */
|
||||
readonly name: string;
|
||||
/** First model date the version answers (inclusive). */
|
||||
readonly from: number;
|
||||
/** First model date it no longer answers (exclusive). */
|
||||
readonly until: number;
|
||||
/**
|
||||
* Highest music id the version can have. Records are shared by all
|
||||
* versions; songs added later are not sent. Undefined: no limit.
|
||||
*/
|
||||
readonly maxMusicId?: number;
|
||||
}
|
||||
|
||||
export interface GameVersion extends VersionInfo {
|
||||
/** Handlers by full method name (`gametop.get_pdata`). */
|
||||
readonly routes: Readonly<Record<string, EamusePluginRoute | boolean>>;
|
||||
}
|
||||
Reference in New Issue
Block a user