mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: 一些异常类型
This commit is contained in:
parent
479b971b0c
commit
f7c1951191
@ -65,7 +65,7 @@ export abstract class PacketClient {
|
||||
}): Promise<RecvPacketData> {
|
||||
return new Promise<RecvPacketData>((resolve, reject) => {
|
||||
if (!this.isAvailable) {
|
||||
throw new Error("WebSocket is not connected");
|
||||
throw new Error("Packet Service is not available");
|
||||
}
|
||||
this.sendCommandImpl(cmd, data, trace_id);
|
||||
if (rsp) {
|
||||
|
@ -3,14 +3,17 @@ import { NapCatCore } from "@/core";
|
||||
import path, { dirname } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import fs from "fs";
|
||||
import { console } from "inspector";
|
||||
import { PacketClient } from "@/core/packet/client/client";
|
||||
import { constants, platform, type } from "node:os";
|
||||
import { constants } from "node:os";
|
||||
import { LogWrapper } from "@/common/log";
|
||||
|
||||
export interface NativePacketExportType {
|
||||
InitHook: (recv: string, send: string, callback: (type: number, uin: string, seq: number, cmd: string, hex_data: string) => void) => boolean;
|
||||
SendPacket: (cmd: string, data: string, trace_id: string) => void;
|
||||
}
|
||||
export class NativePacketClient extends PacketClient {
|
||||
static supportedPlatforms = ['win32.x64'];
|
||||
private MoeHooExport: any = { exports: {} };
|
||||
private MoeHooExport: { exports?: NativePacketExportType } = { exports: undefined };
|
||||
|
||||
protected constructor(core: NapCatCore) {
|
||||
super(core);
|
||||
@ -42,22 +45,20 @@ export class NativePacketClient extends PacketClient {
|
||||
const platform = process.platform + '.' + process.arch;
|
||||
const moehoo_path = path.join(dirname(fileURLToPath(import.meta.url)), './moehoo/moehoo.' + platform + '.node');
|
||||
process.dlopen(this.MoeHooExport, moehoo_path, constants.dlopen.RTLD_LAZY);
|
||||
this.MoeHooExport.exports.InitHook(pid, recv, send, (type: number, uin: string, seq: number, cmd: string, hex_data: string) => {
|
||||
this.MoeHooExport.exports?.InitHook(recv, send, (type: number, uin: string, seq: number, cmd: string, hex_data: string) => {
|
||||
const callback = this.cb.get(createHash('md5').update(Buffer.from(hex_data, 'hex')).digest('hex') + (type === 0 ? 'send' : 'recv'));
|
||||
if (callback) {
|
||||
callback({ seq, cmd, hex_data });
|
||||
} else {
|
||||
this.logger.logError(`Callback not found for hex_data: ${hex_data}`);
|
||||
}
|
||||
// TODO: cannot use console.log here, fxxk tx
|
||||
// Error [ERR_INSPECTOR_NOT_AVAILABLE]: Inspector is not available
|
||||
// console.log('type:', type, 'uin:', uin, 'seq:', seq, 'cmd:', cmd, 'hex_data:', hex_data);
|
||||
console.log('type:', type, 'uin:', uin, 'seq:', seq, 'cmd:', cmd, 'hex_data:', hex_data);
|
||||
});
|
||||
this.isAvailable = true;
|
||||
}
|
||||
|
||||
sendCommandImpl(cmd: string, data: string, trace_id: string): void {
|
||||
this.MoeHooExport.exports.SendPacket(cmd, data, crypto.createHash('md5').update(trace_id).digest('hex'));
|
||||
this.MoeHooExport.exports?.SendPacket(cmd, data, crypto.createHash('md5').update(trace_id).digest('hex'));
|
||||
}
|
||||
|
||||
connect(cb: () => void): Promise<void> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user