From eef5293ca0799b3cf882a8f068dcb1ea94fb64fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sat, 12 Oct 2024 22:17:40 +0800 Subject: [PATCH] refactor: Poke --- src/core/apis/group.ts | 20 ++++++++++---- src/core/proto/NapProto.ts | 8 +++--- src/core/proto/OidbBase.ts | 16 +++++++++++ src/core/proto/Poke.ts | 56 +++++++++++++++++++------------------- 4 files changed, 62 insertions(+), 38 deletions(-) create mode 100644 src/core/proto/OidbBase.ts diff --git a/src/core/apis/group.ts b/src/core/apis/group.ts index 307ab3ab..03e5e021 100644 --- a/src/core/apis/group.ts +++ b/src/core/apis/group.ts @@ -12,11 +12,11 @@ import { import { isNumeric, sleep, solveAsyncProblem } from '@/common/helper'; import { LimitedHashTable } from '@/common/message-unique'; import { NTEventWrapper } from '@/common/event'; -import { encodeGroupPoke } from '../proto/Poke'; import { randomUUID } from 'crypto'; import { RequestUtil } from '@/common/request'; -interface recvPacket -{ +import { NapProtoMsg } from '../proto/NapProto'; +import { OidbSvcTrpcTcp0XED3_1, OidbSvcTrpcTcpBaseProto } from '../proto/OidbBase'; +interface recvPacket { type: string,//仅recv trace_id_md5?: string, data: { @@ -65,10 +65,18 @@ export class NTQQGroupApi { //console.log('ret: ', ret); } async sendPacketPoke(group: number, peer: number) { - let data = encodeGroupPoke(group, peer); - let hex = Buffer.from(data).toString('hex'); + let oidb_0xed3 = new NapProtoMsg(OidbSvcTrpcTcp0XED3_1).encode({ + uin: peer, + groupUin: group, + ext: 0 + }); + let oidb_packet = new NapProtoMsg(OidbSvcTrpcTcpBaseProto).encode({ + command: 0xed3, + subCommand: 1, + body: oidb_0xed3 + }); + let hex = Buffer.from(oidb_packet).toString('hex'); let retdata = await this.core.apis.PacketApi.sendPacket('OidbSvcTrpcTcp.0xed3_1', hex, false); - //console.log('sendPacketPoke', retdata); } async fetchGroupEssenceList(groupCode: string) { const pskey = (await this.core.apis.UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com')!; diff --git a/src/core/proto/NapProto.ts b/src/core/proto/NapProto.ts index 0d87fff7..b7ab8396 100644 --- a/src/core/proto/NapProto.ts +++ b/src/core/proto/NapProto.ts @@ -51,9 +51,9 @@ type ProtoMessageType = { [key: string]: ProtoFieldType; }; -function ProtoField(no: number, type: T, repeated?: R, optional?: O): ScalarProtoFieldType; -function ProtoField ProtoMessageType, O extends boolean = false, R extends O extends true ? false : boolean = false>(no: number, type: T, repeated?: R, optional?: O): MessageProtoFieldType; -function ProtoField(no: number, type: ScalarType | (() => ProtoMessageType), repeated?: boolean, optional?: boolean): ProtoFieldType { +export function ProtoField(no: number, type: T, repeated?: R, optional?: O): ScalarProtoFieldType; +export function ProtoField ProtoMessageType, O extends boolean = false, R extends O extends true ? false : boolean = false>(no: number, type: T, repeated?: R, optional?: O): MessageProtoFieldType; +export function ProtoField(no: number, type: ScalarType | (() => ProtoMessageType), repeated?: boolean, optional?: boolean): ProtoFieldType { if (typeof type === 'function') { return { kind: 'message', no: no, type: type, repeated: repeated ?? false, optional: optional ?? false }; } else { @@ -89,7 +89,7 @@ type ProtoStructType = RequiredFieldsType & OptionalFieldsType; const NapProtoMsgCache = new Map>>(); -class NapProtoMsg { +export class NapProtoMsg { private readonly _msg: T; private readonly _field: PartialFieldInfo[]; private readonly _proto_msg: MessageType>; diff --git a/src/core/proto/OidbBase.ts b/src/core/proto/OidbBase.ts new file mode 100644 index 00000000..3f63f898 --- /dev/null +++ b/src/core/proto/OidbBase.ts @@ -0,0 +1,16 @@ +import { ProtoField } from "./NapProto"; +import { ScalarType } from '@protobuf-ts/runtime'; + +export const OidbSvcTrpcTcpBaseProto = { + command: ProtoField(1, ScalarType.UINT32), + subCommand: ProtoField(2, ScalarType.UINT32), + body: ProtoField(4, ScalarType.BYTES), + isReserved: ProtoField(12, ScalarType.UINT32, false, true) +} + +export const OidbSvcTrpcTcp0XED3_1 = { + uin: ProtoField(1, ScalarType.UINT32), + groupUin: ProtoField(2, ScalarType.UINT32, false, true), + friendUin: ProtoField(5, ScalarType.BYTES, false, true), + ext: ProtoField(6, ScalarType.UINT32) +} \ No newline at end of file diff --git a/src/core/proto/Poke.ts b/src/core/proto/Poke.ts index 3829d4ef..262f0e9b 100644 --- a/src/core/proto/Poke.ts +++ b/src/core/proto/Poke.ts @@ -1,31 +1,31 @@ -import { MessageType, ScalarType, BinaryWriter } from '@protobuf-ts/runtime'; +// import { MessageType, ScalarType, BinaryWriter } from '@protobuf-ts/runtime'; -export const OidbSvcTrpcTcpBase = new MessageType("oidb_svc_trpctcp_base", [ - { no: 1, name: "command", kind: "scalar", T: ScalarType.UINT32 }, - { no: 2, name: "subcommand", kind: "scalar", T: ScalarType.UINT32, opt: true }, - { no: 4, name: "body", kind: "scalar", T: ScalarType.BYTES, opt: true }, - { no: 12, name: "isreserved", kind: "scalar", T: ScalarType.INT32, opt: true } -]); +// export const OidbSvcTrpcTcpBase = new MessageType("oidb_svc_trpctcp_base", [ +// { no: 1, name: "command", kind: "scalar", T: ScalarType.UINT32 }, +// { no: 2, name: "subcommand", kind: "scalar", T: ScalarType.UINT32, opt: true }, +// { no: 4, name: "body", kind: "scalar", T: ScalarType.BYTES, opt: true }, +// { no: 12, name: "isreserved", kind: "scalar", T: ScalarType.INT32, opt: true } +// ]); -export const OidbSvcTrpcTcp0XED3_1 = new MessageType("oidb_svc_trpctcp_0xed3_1", [ - { no: 1, name: "uin", kind: "scalar", T: ScalarType.UINT32 }, - { no: 2, name: "groupuin", kind: "scalar", T: ScalarType.UINT32, opt: true }, - { no: 5, name: "frienduin", kind: "scalar", T: ScalarType.UINT32, opt: true }, - { no: 6, name: "ext", kind: "scalar", T: ScalarType.UINT32 } -]); +// export const OidbSvcTrpcTcp0XED3_1 = new MessageType("oidb_svc_trpctcp_0xed3_1", [ +// { no: 1, name: "uin", kind: "scalar", T: ScalarType.UINT32 }, +// { no: 2, name: "groupuin", kind: "scalar", T: ScalarType.UINT32, opt: true }, +// { no: 5, name: "frienduin", kind: "scalar", T: ScalarType.UINT32, opt: true }, +// { no: 6, name: "ext", kind: "scalar", T: ScalarType.UINT32 } +// ]); -export function encodeGroupPoke(groupUin: number, PeerUin: number) { - let Body = OidbSvcTrpcTcp0XED3_1.toBinary - ({ - uin: PeerUin, - groupuin: groupUin, - ext: 0 - }); - //console.log(Body) - return OidbSvcTrpcTcpBase.toBinary - ({ - command: 0xed3, - subcommand: 1, - body: Body - }); -} \ No newline at end of file +// export function encodeGroupPoke(groupUin: number, PeerUin: number) { +// let Body = OidbSvcTrpcTcp0XED3_1.toBinary +// ({ +// uin: PeerUin, +// groupuin: groupUin, +// ext: 0 +// }); +// //console.log(Body) +// return OidbSvcTrpcTcpBase.toBinary +// ({ +// command: 0xed3, +// subcommand: 1, +// body: Body +// }); +// } \ No newline at end of file