Skip to content

Commit 1cabb85

Browse files
committed
merge from master
2 parents 2221520 + 4cb1980 commit 1cabb85

File tree

16 files changed

+1541
-2947
lines changed

16 files changed

+1541
-2947
lines changed

package-lock.json

Lines changed: 345 additions & 380 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"license": "MIT",
4848
"dependencies": {
4949
"@cordisjs/logger": "^0.1.3",
50-
"@kamyu/kbinxml": "^2.0.2",
50+
"@geekidos/kbinxml": "^2.0.4",
51+
"@kamyu/lz77": "^1.0.0",
5152
"@koa/cors": "^5.0.0",
5253
"@koa/router": "^12.0.1",
5354
"arc4": "^2.1.4",
@@ -59,6 +60,7 @@
5960
"koa-bodyparser": "^4.4.1",
6061
"lodash": "^4.17.21",
6162
"mongodb": "^6.4.0",
63+
"node-cache": "^5.1.2",
6264
"pug": "^3.0.2",
6365
"reflect-metadata": "^0.2.1",
6466
"tslib": "~2.6",

src/apis/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import Router from "@koa/router";
22
import { p2dRoutes } from "./p2d/index.js";
33
import { DefaultContext, DefaultState, ParameterizedContext } from "koa";
44
import { ILaochanContext } from "../types.js";
5+
import { sdvxRoutes } from './sdvx/index.js';
56

67
const router = new Router({
78
prefix: '/api',
89
})
9-
.use(p2dRoutes);
10+
.use(p2dRoutes)
11+
.use(sdvxRoutes);
1012

1113
export const apiRoutes = router.routes();
1214
export type Context = ParameterizedContext<DefaultState, ILaochanContext & Router.RouterParamContext<DefaultState, DefaultContext>, any>;

src/apis/sdvx/index.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import Router from '@koa/router';
2+
import { Context } from '../index.js';
3+
import {UserService} from '../../services/sdvx/user.js';
4+
import { SaveData } from '../../types/sdvx/savedata.js';
5+
import { PlayerMusicData } from '../../types/sdvx/index.js';
6+
import { tokenToCardNumber } from '../../utils/laochan-id.js';
7+
import { toObject } from '../../utils/kbinxml.js';
8+
import { Serializable } from '../../utils/kxml-value.js';
9+
10+
interface SdvxDataExport {
11+
sdvx_profile: {
12+
"1": {
13+
card: string;
14+
pin: "0000";
15+
sdvx_id: string;
16+
version: {
17+
"6": SaveData;
18+
}
19+
}
20+
}
21+
sdvx_scores_best: Record<string, PlayerMusicData>;
22+
skill_scores_best: {};
23+
}
24+
25+
const router = new Router({
26+
prefix: '/sdvx',
27+
})
28+
.get('/data_export/:token', async (ctx: Context) => {
29+
const { token } = ctx.params;
30+
31+
if (!token) {
32+
ctx.status = 400;
33+
return;
34+
}
35+
36+
const userService = ctx.resolve(UserService);
37+
38+
if (!await userService.hasPlayerData(token)){
39+
ctx.status = 404;
40+
return;
41+
}
42+
43+
const [playerData, musicDatas] = await Promise.all([
44+
userService.getPlayerData(token),
45+
userService.getPlayerMusicDatas(token),
46+
]);
47+
48+
const scoreBests: Record<string, PlayerMusicData> = {};
49+
musicDatas.forEach((m, i) => {
50+
scoreBests[i.toString()] = m;
51+
})
52+
53+
ctx.status = 200;
54+
ctx.body = {
55+
sdvx_profile: {
56+
"1": {
57+
card: tokenToCardNumber(token),
58+
pin: '0000',
59+
sdvx_id: playerData.sdvx_id.__value as string,
60+
version:{
61+
"6": toObject(playerData as unknown as Serializable),
62+
}
63+
}
64+
},
65+
sdvx_scores_best: scoreBests,
66+
skill_scores_best: {}
67+
} as SdvxDataExport;
68+
})
69+
70+
export const sdvxRoutes = router.routes();

src/controllers/default.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export class DefaultService {
2525
};
2626

2727
// handle ac relay
28-
if (ctx.eacnetRequest) {
28+
if (ctx.acRelayInfo) {
2929
result['xrpc_status_code'] = v.s32(0);
3030
result['xrpc_fault_code'] = v.s32(0);
3131
result['response'] = {
32-
[ctx.eacnetRequest.module]: {
32+
[ctx.acRelayInfo.module]: {
3333
$status: 0,
3434
}
3535
}

src/controllers/eac-generic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class EacGeneric {
147147
service: [
148148
{
149149
service_name: v.str('acRelay'),
150-
url: v.str(`${config.selfUrl}/need_auth/AcRelay`),
150+
url: v.str(`https://p.eagate.573.jp/game/konasteapp/APIEX/servletex/need_auth/AcRelay`),
151151
},
152152
{
153153
service_name: v.str('cancelReserveConsumeItem'),
@@ -203,7 +203,7 @@ export class EacGeneric {
203203
},
204204
{
205205
service_name: v.str('getUserIDs'),
206-
url: v.str(`${config.selfUrl}/need_auth/GetUserId`),
206+
url: v.str(`https://p.eagate.573.jp/game/konasteapp/APIEX/servletex/need_auth/GetUserId`),
207207
},
208208
{
209209
service_name: v.str('heartbeat'),

src/controllers/sdvx/ac-relay.ts

Lines changed: 54 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,100 +2,75 @@ import { generic } from "../../decorators/eacnet.js";
22
import { Context } from "../../types.js";
33
import { Serializable, v } from "../../utils/kxml-value.js";
44
import * as data from '../../datas/sdvx.js';
5+
import { requestEa3 } from "../../utils/ea3.js";
6+
import { SDVX_AC_MODEL } from "./index.js";
7+
import { tokenToCardNumber } from '../../utils/laochan-id.js';
8+
import { cache } from '../../decorators/cache.js';
59

610
export class AcRelay {
711
@generic()
8-
async sv6_play_e(): Promise<Serializable> {
12+
async acRelayCommon(ctx: Context): Promise<Serializable> {
13+
const { status, response } = await requestEa3(ctx.acRelayInfo, SDVX_AC_MODEL, ctx.token);
14+
915
return {
1016
status: v.s32(0),
1117
error_code: v.s32(0),
12-
xrpc_status_code: v.s32(0),
13-
xrpc_fault_code: v.s32(0),
14-
response: {
15-
game: {
16-
$status: 0,
17-
},
18-
}
18+
xrpc_status_code: v.s32(status),
19+
xrpc_fault_code: v.s32(status),
20+
response,
1921
};
2022
}
2123

22-
@generic()
23-
async sv6_play_s(): Promise<Serializable> {
24-
return {
25-
status: v.s32(0),
26-
error_code: v.s32(0),
27-
xrpc_status_code: v.s32(0),
28-
xrpc_fault_code: v.s32(0),
29-
response: {
30-
game: {
31-
$status: 0,
32-
play_id: v.u32(Math.floor(new Date().valueOf() / 6e4)),
33-
},
34-
}
35-
};
24+
async sv6_play_e(ctx: Context): Promise<Serializable> {
25+
return this.acRelayCommon(ctx);
3626
}
3727

38-
@generic()
39-
async sv6_hiscore() {
40-
return {
41-
status: v.s32(0),
42-
error_code: v.s32(0),
43-
xrpc_status_code: v.s32(0),
44-
xrpc_fault_code: v.s32(0),
45-
response: {
46-
game: {
47-
$status: 0,
48-
sc: {},
49-
}
50-
}
51-
};
28+
async sv6_play_s(ctx: Context): Promise<Serializable> {
29+
return this.acRelayCommon(ctx);
5230
}
5331

54-
@generic()
55-
async sv6_log(): Promise<Serializable> {
56-
return {
57-
status: v.s32(0),
58-
error_code: v.s32(0),
59-
xrpc_status_code: v.s32(0),
60-
xrpc_fault_code: v.s32(0),
61-
response: {
62-
game: {
63-
$status: 0,
64-
}
65-
}
66-
};
32+
async sv6_hiscore(ctx: Context) {
33+
return this.acRelayCommon(ctx);
6734
}
6835

69-
@generic()
70-
async sv6_common(): Promise<Serializable> {
71-
return {
72-
status: v.s32(0),
73-
error_code: v.s32(0),
74-
xrpc_status_code: v.s32(0),
75-
xrpc_fault_code: v.s32(0),
76-
response: {
77-
game: {
78-
$status: 0,
79-
music: {},
80-
event: {
81-
info: data.eventList.map(id => ({
82-
event_id: v.str(id),
83-
}))
84-
},
85-
extend: {
86-
info: data.extendInfos,
87-
},
88-
music_limited: {
89-
info: data.musicInfos,
90-
},
91-
skill_course: {
92-
info: data.skillCourses,
93-
},
94-
appealcard: {},
95-
valgene: {},
96-
}
97-
}
98-
}
36+
async sv6_log(ctx: Context): Promise<Serializable> {
37+
return this.acRelayCommon(ctx);
38+
}
39+
40+
@cache('sv6_common')
41+
async sv6_common(ctx: Context): Promise<Serializable> {
42+
return this.acRelayCommon(ctx);
43+
}
44+
45+
async sv6_save_m(ctx: Context): Promise<Serializable> {
46+
return this.acRelayCommon(ctx);
47+
}
48+
49+
async sv6_load_r(ctx: Context): Promise<Serializable> {
50+
return this.acRelayCommon(ctx);
51+
}
52+
53+
async sv6_load_m(ctx: Context): Promise<Serializable> {
54+
return this.acRelayCommon(ctx);
55+
}
56+
57+
async sv6_save_c(ctx: Context): Promise<Serializable> {
58+
return this.acRelayCommon(ctx);
59+
}
60+
61+
async sv6_save(ctx: Context): Promise<Serializable> {
62+
return this.acRelayCommon(ctx);
63+
}
64+
65+
async sv6_new(ctx: Context): Promise<Serializable> {
66+
return this.acRelayCommon(ctx);
67+
}
68+
69+
async sv6_load(ctx: Context): Promise<Serializable> {
70+
// hack for maomani
71+
// chou xiang amao
72+
ctx.acRelayInfo.request['cardid'] = v.str(tokenToCardNumber(ctx.token));
73+
return this.acRelayCommon(ctx);
9974
}
10075

10176
@generic()

0 commit comments

Comments
 (0)