add kxml value helper

This commit is contained in:
GEEKiDoS
2024-03-08 15:40:09 +08:00
parent 08d6d5fa3d
commit fd8db5e74b
4 changed files with 106 additions and 90 deletions
+23 -88
View File
@@ -1,5 +1,6 @@
import { serviceKxml } from "../../decorators/to-kxml.js";
import { Context } from "../../types.js";
import { v } from "../../utils/kxml-value.js";
interface GetPCDataCall {
ccode: string,
@@ -35,14 +36,8 @@ export default class {
cm_movie_info: {
$type: 3,
},
monthly_mranking: {
$__type: 'u16',
__value: [],
},
total_mranking: {
$__type: 'u16',
__value: [],
},
monthly_mranking: v.u16([]),
total_mranking: v.u16([]),
hitchart: [{
$kind: 0,
$period: 0,
@@ -62,98 +57,38 @@ export default class {
pcdata: this.getPlayerPcData(cid),
bind_eaappli: {},
secret: {
flg1: {
$__type: 's64',
__value: [-1, -1, 1048575],
},
flg2: {
$__type: 's64',
__value: [-1, -1, 0],
},
flg3: {
$__type: 's64',
__value: [-1, -1, 0],
},
flg4: {
$__type: 's64',
__value: [-1, -1, 0],
},
flg1: v.s64([-1, -1, 1048575]),
flg2: v.s64([-1, -1, 0]),
flg3: v.s64([-1, -1, 0]),
flg4: v.s64([-1, -1, 0]),
},
favorite: {
sp_mlist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
sp_clist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
dp_mlist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
dp_clist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
sp_mlist: v.bin(Buffer.alloc(1, 0)),
sp_clist: v.bin(Buffer.alloc(1, 0)),
dp_mlist: v.bin(Buffer.alloc(1, 0)),
dp_clist: v.bin(Buffer.alloc(1, 0)),
},
extra_favorite: [{
$folder_id: 0,
sp_mlist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
sp_clist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
dp_mlist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
dp_clist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
sp_mlist: v.bin(Buffer.alloc(1, 0)),
sp_clist: v.bin(Buffer.alloc(1, 0)),
dp_mlist: v.bin(Buffer.alloc(1, 0)),
dp_clist: v.bin(Buffer.alloc(1, 0)),
}, {
$folder_id: 0,
sp_mlist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
sp_clist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
dp_mlist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
dp_clist: {
$__type: 'bin',
__value: Buffer.alloc(1, 0),
},
sp_mlist: v.bin(Buffer.alloc(1, 0)),
sp_clist: v.bin(Buffer.alloc(1, 0)),
dp_mlist: v.bin(Buffer.alloc(1, 0)),
dp_clist: v.bin(Buffer.alloc(1, 0)),
}],
grade: {
$dgid: -1,
$sgid: -1,
g: {
$__type: 'u8',
__value: [0, 13, 3, 58],
}
},
skin: {
$__type: 's16',
__value: new Array(20).fill(0),
},
tdjskin: {
$__type: 's16',
__value: [0, 0, 0, 0],
},
qprodata: {
$__type: 'u32',
__value: [0, 0, 0, 0, 0],
g: v.u8([0, 13, 3, 58]),
},
skin: v.s16(new Array(20).fill(0)),
tdjskin: v.s16([0, 0, 0, 0]),
qprodata: v.s16([0, 0, 0, 0, 0]),
spdp_rival: {
$flg: 1,
},
+11 -2
View File
@@ -11,6 +11,11 @@ interface CardAuth {
refid: string,
}
interface GetRefId {
cardid: string,
passwd: string;
}
const resp = serviceKxml('cardmng');
export default class {
@@ -25,9 +30,13 @@ export default class {
}
@resp('getrefid')
getrefid() {
return {
getrefid(ctx: Context) {
const { cardid, passwd } = ctx.body as GetRefId;
ctx.logger.info('registering %s with passwd %s.', cardid, passwd);
return {
$dataid: cardid,
$refid: cardid,
}
}
+29
View File
@@ -0,0 +1,29 @@
import { serviceKxml } from "../../decorators/to-kxml.js";
import { v } from "../../utils/kxml-value.js";
const resp = serviceKxml('eacoin');
export default class {
@resp('checkin')
checkin() {
return {
$status: 0,
balance: v.s32(114514),
sessid: v.str('0000000000000000'),
acstatus: v.u8(0),
sequence: v.s16(1),
acid: v.str('0000000000000000'),
acname: v.str('0000000000000000'),
}
}
@resp('consume')
consume() {
return {
$status: 0,
autocharge: v.u8(0),
acstatus: v.u8(0),
balance: v.u8(114514),
}
}
}
+43
View File
@@ -0,0 +1,43 @@
export type ValueTypes = 's8' |
'u8' |
's16' |
'u16' |
's32' |
'u32' |
's64' |
'u64' |
'float' |
'double' |
'b' | 'bool' |
'bin' | 'binary' |
'ip4' |
'str' | 'string' |
'time';
function vg(type: ValueTypes) {
return (value: unknown) => ({
$__type: type,
__value: value,
});
}
export const v: Record<ValueTypes, (value: unknown) => object> = {
s8: vg('s8'),
u8: vg('u8'),
s16: vg('s16'),
u16: vg('u16'),
s32: vg('s32'),
u32: vg('u32'),
s64: vg('s64'),
u64: vg('u64'),
float: vg('float'),
double: vg('double'),
b: vg('b'),
bool: vg('bool'),
bin: vg('bin'),
binary: vg('binary'),
ip4: vg('ip4'),
str: vg('str'),
string: vg('string'),
time: vg('time'),
}