mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-12-04 19:20:29 -06:00
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>
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
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)));
|
|
}
|