feat: add new NapCat config key: packetBackend

- Acceptable values: `native`, `frida`, `auto`, `disable`
- Default value is set to `auto`
This commit is contained in:
pk5ls20 committed 2024-11-05 14:45:02 +08:00
1 parent ad6f21980c
commit e46d274a75
5 files changed
+25 -5

No files matched your search

+16 -1
View File
@@ -23,11 +23,26 @@ export class PacketSession {
constructor(core: NapCatCore) {
this.logger = core.context.logger;
this.client = this.judgeClient(core);
this.client = this.newClient(core);
this.packer = new PacketPacker(this.logger, this.client);
this.highwaySession = new PacketHighwaySession(this.logger, this.client, this.packer);
}
private newClient(core: NapCatCore): PacketClient {
const prefer = core.configLoader.configData.packetBackend;
switch (prefer) {
case "native":
return new NativePacketClient(core);
case "frida":
return new wsPacketClient(core);
case "auto":
case undefined:
return this.judgeClient(core);
default:
throw new Error(`[Core] [Packet] 未知的Packet后端类型 ${prefer},请检查配置文件!`);
}
}
private judgeClient(core: NapCatCore): PacketClient {
const sortedClients = Object.entries(clientPriority)
.map(([priority, clientFactory]) => {