feat: support client private-message reporting
Handle confirmed private messages sent from the client and preserve account isolation when sessions change. Surface unavailable messages without reporting incomplete content. Refs #528.
This commit is contained in:
12 files changed
+963
-4
No files matched your search
@@ -957,6 +957,17 @@ export class HookSession extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
packet.source === 'client-message' &&
|
||||
(!isRealUin(packet.uin) || packet.uin !== this._uin)
|
||||
) {
|
||||
this.log.warn(
|
||||
'Client message receipt belongs to an inactive account: PID=%d',
|
||||
this.pid,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const uin = packet.uin || this._uin;
|
||||
// Routing requires a real UIN, but even a frame carrying UIN=0 proves the
|
||||
// receive hook is alive. Attribute that evidence to the current epoch
|
||||
@@ -986,6 +997,7 @@ export class HookSession extends EventEmitter {
|
||||
seqId: packet.seq,
|
||||
retCode: packet.error,
|
||||
fromClient: false,
|
||||
...(packet.source ? { source: packet.source } : {}),
|
||||
body: Buffer.from(packet.body),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from '@snowluma/common/logger';
|
||||
import { renderParamsVerbose } from '@snowluma/common/log-summary';
|
||||
import { isRealUin } from '@snowluma/common/uin';
|
||||
import { CLIENT_MESSAGE_RECEIPT_CMD } from '@snowluma/common/protocol-types';
|
||||
import { readdirSync, promises as fs } from 'fs';
|
||||
import net from 'net';
|
||||
import path from 'path';
|
||||
@@ -38,6 +39,8 @@ export enum PipeOp {
|
||||
recvPacket = 6,
|
||||
loginState = 7,
|
||||
loginIdentityHint = 17,
|
||||
clientMessageReceipt = 21,
|
||||
clientMessageState = 22,
|
||||
}
|
||||
|
||||
const PipeFlagWantReply = 1 << 0;
|
||||
@@ -55,6 +58,7 @@ export interface QqHookPacket {
|
||||
cmd: string;
|
||||
uin: string;
|
||||
body: Buffer;
|
||||
source?: 'client-message';
|
||||
}
|
||||
|
||||
export interface QqHookHello {
|
||||
@@ -1369,6 +1373,44 @@ export class QqHookClient extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (frame.op === PipeOp.clientMessageState) {
|
||||
if (frame.status === 1) {
|
||||
runtimeLog.debug('Client private-message reporting is available: PID=%d', this.pid);
|
||||
} else {
|
||||
runtimeLog.warn(
|
||||
'Client private-message reporting is unavailable: PID=%d status=%d',
|
||||
this.pid,
|
||||
frame.status,
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (frame.op === PipeOp.clientMessageReceipt) {
|
||||
if (
|
||||
frame.cmd !== '' ||
|
||||
frame.requestId !== 0 ||
|
||||
frame.flags !== 0 ||
|
||||
frame.value0 <= 0n ||
|
||||
frame.value0 > BigInt(Number.MAX_SAFE_INTEGER) ||
|
||||
!isRealUin(frame.msg)
|
||||
) {
|
||||
runtimeLog.warn('Invalid client message receipt: PID=%d', this.pid);
|
||||
return;
|
||||
}
|
||||
|
||||
this.emit('packet', {
|
||||
seq: Number(frame.value0),
|
||||
error: frame.status,
|
||||
cmd: CLIENT_MESSAGE_RECEIPT_CMD,
|
||||
uin: frame.msg,
|
||||
body: Buffer.from(frame.body),
|
||||
source: 'client-message',
|
||||
} satisfies QqHookPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
if (frame.op !== PipeOp.recvPacket) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user