mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: packet send/recv
This commit is contained in:
parent
bb8b06c044
commit
cdd00d665d
@ -24,7 +24,9 @@ export class LRUCache<K, V> {
|
|||||||
} else if (this.cache.size >= this.capacity) {
|
} else if (this.cache.size >= this.capacity) {
|
||||||
// If the cache is full, remove the least recently used key (the first one in the map)
|
// If the cache is full, remove the least recently used key (the first one in the map)
|
||||||
const firstKey = this.cache.keys().next().value;
|
const firstKey = this.cache.keys().next().value;
|
||||||
this.cache.delete(firstKey);
|
if (firstKey !== undefined) {
|
||||||
|
this.cache.delete(firstKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.cache.set(key, value);
|
this.cache.set(key, value);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,16 @@ import { NTEventWrapper } from '@/common/event';
|
|||||||
import { encodeGroupPoke } from '../proto/Poke';
|
import { encodeGroupPoke } from '../proto/Poke';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { RequestUtil } from '@/common/request';
|
import { RequestUtil } from '@/common/request';
|
||||||
|
interface recvPacket
|
||||||
|
{
|
||||||
|
type: string,//仅recv
|
||||||
|
trace_id_md5?: string,
|
||||||
|
data: {
|
||||||
|
seq: number,
|
||||||
|
hex_data: string,
|
||||||
|
cmd: string
|
||||||
|
}
|
||||||
|
}
|
||||||
export class NTQQGroupApi {
|
export class NTQQGroupApi {
|
||||||
context: InstanceContext;
|
context: InstanceContext;
|
||||||
core: NapCatCore;
|
core: NapCatCore;
|
||||||
@ -39,12 +48,9 @@ export class NTQQGroupApi {
|
|||||||
this.context.logger.logDebug(`加载${this.groups.length}个群组缓存完成`);
|
this.context.logger.logDebug(`加载${this.groups.length}个群组缓存完成`);
|
||||||
console.log('pid', process.pid);
|
console.log('pid', process.pid);
|
||||||
// this.session = await frida.attach(process.pid);
|
// this.session = await frida.attach(process.pid);
|
||||||
// setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
// let data = Buffer.from('089601', 'hex').toString('utf-8');//optional int32 a = 1;
|
this.sendPocketRkey();
|
||||||
// console.log('data', Buffer.from(data).toString('hex'));
|
}, 10000);
|
||||||
// let ret = await this.core.context.session.getMsgService().sendSsoCmdReqByContend("OidbSvcTrpcTcp.0xfe1_2", data);
|
|
||||||
// console.log('sendSsoCmdReqByContend', ret);
|
|
||||||
// }, 20000);
|
|
||||||
}
|
}
|
||||||
async getCoreAndBaseInfo(uids: string[]) {
|
async getCoreAndBaseInfo(uids: string[]) {
|
||||||
return await this.core.eventWrapper.callNoListenerEvent(
|
return await this.core.eventWrapper.callNoListenerEvent(
|
||||||
@ -53,6 +59,11 @@ export class NTQQGroupApi {
|
|||||||
uids,
|
uids,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
async sendPocketRkey() {
|
||||||
|
let hex = '08E7A00210CA01221D0A130A05080110CA011206A80602B006011A0208022206080A081408022A006001';
|
||||||
|
let ret = await this.core.apis.PacketApi.sendPacket('OidbSvcTrpcTcp.0x9067_202', hex, true);
|
||||||
|
console.log('ret: ', ret);
|
||||||
|
}
|
||||||
async sendPacketPoke(group: number, peer: number) {
|
async sendPacketPoke(group: number, peer: number) {
|
||||||
let data = encodeGroupPoke(group, peer);
|
let data = encodeGroupPoke(group, peer);
|
||||||
let hex = Buffer.from(data).toString('hex');
|
let hex = Buffer.from(data).toString('hex');
|
||||||
|
@ -53,16 +53,7 @@ export class NTQQPacketApi {
|
|||||||
async sendPacket(cmd: string, data: string, rsp = false) {
|
async sendPacket(cmd: string, data: string, rsp = false) {
|
||||||
// wtfk tx
|
// wtfk tx
|
||||||
// 校验失败和异常 可能返回undefined
|
// 校验失败和异常 可能返回undefined
|
||||||
return new Promise<undefined | {
|
return new Promise((resolve, reject) => {
|
||||||
type: string,//仅recv含有data
|
|
||||||
trace_id: string,
|
|
||||||
data: {
|
|
||||||
trace_id: string,
|
|
||||||
seq: number,
|
|
||||||
hex_data: string,
|
|
||||||
cmd: string
|
|
||||||
}
|
|
||||||
}>((resolve, reject) => {
|
|
||||||
if (!this.isInit || !this.PacketClient?.isConnected) {
|
if (!this.isInit || !this.PacketClient?.isConnected) {
|
||||||
this.core.context.logger.logError('PacketClient is not init');
|
this.core.context.logger.logError('PacketClient is not init');
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
import { LogWrapper } from "@/common/log";
|
import { LogWrapper } from "@/common/log";
|
||||||
import { LRUCache } from "@/common/lru-cache";
|
import { LRUCache } from "@/common/lru-cache";
|
||||||
import WebSocket from "ws";
|
import WebSocket from "ws";
|
||||||
|
import { createHash } from "crypto";
|
||||||
|
|
||||||
export class PacketClient {
|
export class PacketClient {
|
||||||
private websocket: WebSocket | undefined;
|
private websocket: WebSocket | undefined;
|
||||||
public isConnected: boolean = false;
|
public isConnected: boolean = false;
|
||||||
private reconnectAttempts: number = 0;
|
private reconnectAttempts: number = 0;
|
||||||
private maxReconnectAttempts: number = 5;
|
private maxReconnectAttempts: number = 5;
|
||||||
private cb = new LRUCache<string, { type: string, callback: any }>(500);
|
//trace_id-type callback
|
||||||
|
private cb = new LRUCache<string, any>(500);
|
||||||
constructor(private url: string, public logger: LogWrapper) { }
|
constructor(private url: string, public logger: LogWrapper) { }
|
||||||
|
|
||||||
connect(): Promise<void> {
|
connect(): Promise<void> {
|
||||||
@ -51,7 +53,7 @@ export class PacketClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async registerCallback(trace_id: string, type: string, callback: any): Promise<void> {
|
async registerCallback(trace_id: string, type: string, callback: any): Promise<void> {
|
||||||
this.cb.put(trace_id, { type: type, callback: callback });
|
this.cb.put(createHash('md5').update(trace_id).digest('hex') + type, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(pid: number, recv: string, send: string): Promise<void> {
|
async init(pid: number, recv: string, send: string): Promise<void> {
|
||||||
@ -79,7 +81,6 @@ export class PacketClient {
|
|||||||
data: data,
|
data: data,
|
||||||
trace_id: trace_id
|
trace_id: trace_id
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.send(JSON.stringify(commandMessage));
|
this.websocket.send(JSON.stringify(commandMessage));
|
||||||
if (rsp) {
|
if (rsp) {
|
||||||
this.registerCallback(trace_id, 'recv', (json: any) => {
|
this.registerCallback(trace_id, 'recv', (json: any) => {
|
||||||
@ -103,10 +104,11 @@ export class PacketClient {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
let json = JSON.parse(message.toString());
|
let json = JSON.parse(message.toString());
|
||||||
let trace_id = json.trace_id;
|
let trace_id_md5 = json.trace_id_md5;
|
||||||
let event = this.cb.get(trace_id);
|
let action = json?.type ?? 'init';
|
||||||
if (event?.type == 'all' || event?.type == json.type) {
|
let event = this.cb.get(trace_id_md5 + action);
|
||||||
await event?.callback(json.data);
|
if (event) {
|
||||||
|
await event(json.data);
|
||||||
}
|
}
|
||||||
//console.log("Received message:", json);
|
//console.log("Received message:", json);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user