feat(msg-push): filter C2C control pushes by c2c_cmd, matching QQ NT (#102)
Upgrades the blank-body heuristic to NT's exact discriminator. RE of
wrapper.linux.node (msg_header_codec_helper.cc::DecodeRoutingHead, sub_3B42650)
shows the official client classifies a C2C push by (svr_msg_type, c2c_cmd):
msgType ∈ {141,166,167} with c2c_cmd ∈ {1,73,75,129,131,133,135,192} is routed
through OnRecvSysMsg (long_cnn_msg_mgr.cc) as a system/control signal and never
shown as a chat bubble — the group-invite "[空消息]" phantom is one of these.
- proto-defs: ContentHead field 3 was mislabelled `divSeq`; it is `c2c_cmd`.
Renamed (only other use was forward.ts, which zeroes it on a fake send).
- MsgPushHead now carries c2cCmd; new isC2cControlPush() in blank-filter.ts.
- parseMsgPush + both history fetches drop control pushes by (msgType, c2cCmd)
regardless of body, so a control signal carrying stray content is caught too
(not just the empty case). isBlankMessage stays as the fallback for
content-less pushes we don't yet classify by cmd. Live path debug-logs a
control push that carried elements, in case the table ever eats real content.
NOTE: the c2c_cmd set is taken from NT; we have not captured #24's actual cmd
(our diagnostic never logged field 3), so the blank fallback remains load-bearing
until a live capture confirms which cmd the invite phantom uses.
This commit is contained in:
7 files changed
+79
-14
No files matched your search
@@ -150,7 +150,7 @@ async function buildForwardPushBody(
|
|||||||
msgId: random,
|
msgId: random,
|
||||||
sequence: seq,
|
sequence: seq,
|
||||||
timestamp: now,
|
timestamp: now,
|
||||||
divSeq: 0,
|
c2cCmd: 0,
|
||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
richText: {
|
richText: {
|
||||||
|
|||||||
@@ -28,7 +28,12 @@ export interface ResponseHead {
|
|||||||
export interface ContentHead {
|
export interface ContentHead {
|
||||||
msgType?: pb<1, uint_32>;
|
msgType?: pb<1, uint_32>;
|
||||||
subType?: pb<2, uint_32>;
|
subType?: pb<2, uint_32>;
|
||||||
divSeq?: pb<3, uint_32>;
|
// C2C command / sub-message-type. QQ NT (msg_header_codec_helper.cc::
|
||||||
|
// DecodeRoutingHead) reads this as `c2c_cmd` and uses it to route C2C-family
|
||||||
|
// pushes (msgType 141/166/167) as system/control signals via OnRecvSysMsg
|
||||||
|
// rather than chat bubbles. A fixed set of values is excluded from the chat
|
||||||
|
// list — see `isC2cControlPush` in msg-push/blank-filter.ts.
|
||||||
|
c2cCmd?: pb<3, uint_32>;
|
||||||
msgId?: pb<4, uint_32>;
|
msgId?: pb<4, uint_32>;
|
||||||
sequence?: pb<5, uint_32>;
|
sequence?: pb<5, uint_32>;
|
||||||
timestamp?: pb<6, uint_32>;
|
timestamp?: pb<6, uint_32>;
|
||||||
|
|||||||
@@ -1,4 +1,28 @@
|
|||||||
import type { PushMsgBody } from './context';
|
import type { MsgPushHead, PushMsgBody } from './context';
|
||||||
|
|
||||||
|
// C2C-family message types (private 166, temp 141, and 167) whose pushes QQ NT
|
||||||
|
// classifies by `c2c_cmd`. RE: `long_cnn_msg_mgr.cc::OnRecvSysMsg` gates on
|
||||||
|
// exactly this set (svr_msg_type-141 bitmask 0x6000001 → {141,166,167}).
|
||||||
|
const C2C_CONTROL_TYPES = new Set<number>([141, 166, 167]);
|
||||||
|
|
||||||
|
// `c2c_cmd` values QQ NT routes as system/control signals (via OnRecvSysMsg) and
|
||||||
|
// excludes from the chat list — never shown as a bubble. RE: the static lookup
|
||||||
|
// table @0xA13DF0 consulted by `msg_header_codec_helper.cc::DecodeRoutingHead`
|
||||||
|
// (sub_3B42650). These carry no chat content by design; the group-invite "[空消息]"
|
||||||
|
// phantom (#102) is one of them.
|
||||||
|
const C2C_CONTROL_CMDS = new Set<number>([1, 73, 75, 129, 131, 133, 135, 192]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a push is a C2C control/system signal that QQ NT never renders as a
|
||||||
|
* chat message (it dispatches it through `OnRecvSysMsg` instead). Matched by
|
||||||
|
* `(msgType, c2cCmd)` exactly as the official client's header codec does, so it
|
||||||
|
* catches these even on the rare occasion they carry junk content that would
|
||||||
|
* otherwise decode to a stray element. The precise complement to
|
||||||
|
* {@link isBlankMessage}, which only catches the content-less case.
|
||||||
|
*/
|
||||||
|
export function isC2cControlPush(head: Pick<MsgPushHead, 'msgType' | 'c2cCmd'>): boolean {
|
||||||
|
return C2C_CONTROL_TYPES.has(head.msgType) && C2C_CONTROL_CMDS.has(head.c2cCmd);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether a push body carries anything {@link decodeRichBody} could turn into an
|
* Whether a push body carries anything {@link decodeRichBody} could turn into an
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ export type PushMsgContentHead = ContentHead;
|
|||||||
export interface MsgPushHead {
|
export interface MsgPushHead {
|
||||||
readonly msgType: number;
|
readonly msgType: number;
|
||||||
readonly subType: number;
|
readonly subType: number;
|
||||||
|
/** C2C command (`contentHead` field 3). Discriminates control pushes — see
|
||||||
|
* `isC2cControlPush` in ./blank-filter. */
|
||||||
|
readonly c2cCmd: number;
|
||||||
readonly sequence: number;
|
readonly sequence: number;
|
||||||
readonly timestamp: number;
|
readonly timestamp: number;
|
||||||
readonly msgId: number;
|
readonly msgId: number;
|
||||||
@@ -63,6 +66,7 @@ export function buildContextFromMessage(
|
|||||||
const head: MsgPushHead = {
|
const head: MsgPushHead = {
|
||||||
msgType: msg.contentHead.msgType ?? 0,
|
msgType: msg.contentHead.msgType ?? 0,
|
||||||
subType: msg.contentHead.subType ?? 0,
|
subType: msg.contentHead.subType ?? 0,
|
||||||
|
c2cCmd: msg.contentHead.c2cCmd ?? 0,
|
||||||
sequence: msg.contentHead.sequence ?? 0,
|
sequence: msg.contentHead.sequence ?? 0,
|
||||||
timestamp: msg.contentHead.timestamp ?? 0,
|
timestamp: msg.contentHead.timestamp ?? 0,
|
||||||
msgId: msg.contentHead.msgId ?? 0,
|
msgId: msg.contentHead.msgId ?? 0,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
|||||||
import type { SsoGetC2cMsg, SsoGetC2cMsgResponse } from '@snowluma/proto-defs/get-c2c-msg';
|
import type { SsoGetC2cMsg, SsoGetC2cMsgResponse } from '@snowluma/proto-defs/get-c2c-msg';
|
||||||
import type { QQEventVariant } from '../events';
|
import type { QQEventVariant } from '../events';
|
||||||
import type { IdentityService } from '../identity-service';
|
import type { IdentityService } from '../identity-service';
|
||||||
import { isBlankMessage } from './blank-filter';
|
import { isBlankMessage, isC2cControlPush } from './blank-filter';
|
||||||
import { buildContextFromMessage } from './context';
|
import { buildContextFromMessage } from './context';
|
||||||
import { decodeFriendMessage } from './decoders/friend-message';
|
import { decodeFriendMessage } from './decoders/friend-message';
|
||||||
|
|
||||||
@@ -50,9 +50,10 @@ export async function fetchC2cMessageRange(
|
|||||||
if (!ctx) continue;
|
if (!ctx) continue;
|
||||||
for (const ev of decodeFriendMessage(ctx)) {
|
for (const ev of decodeFriendMessage(ctx)) {
|
||||||
if (ev.kind !== 'friend_message' || ev.msgSeq <= 0) continue;
|
if (ev.kind !== 'friend_message' || ev.msgSeq <= 0) continue;
|
||||||
// Drop content-less control pushes (the "[空消息]" phantom, #102) just as
|
// Drop C2C control/system signals and content-less pushes (the "[空消息]"
|
||||||
// QQ NT does on its roam/history fetch — keep history parity with live.
|
// phantom, #102) just as QQ NT does on its roam/history fetch — keep
|
||||||
if (isBlankMessage(ev.elements, ctx.body)) continue;
|
// history parity with live (parseMsgPush).
|
||||||
|
if (isC2cControlPush(ctx.head) || isBlankMessage(ev.elements, ctx.body)) continue;
|
||||||
out.push(ev);
|
out.push(ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { PacketInfo } from '@snowluma/common/protocol-types';
|
|||||||
import type { Elem } from '@snowluma/proto-defs/element';
|
import type { Elem } from '@snowluma/proto-defs/element';
|
||||||
import type { QQEventVariant } from '../events';
|
import type { QQEventVariant } from '../events';
|
||||||
import type { IdentityService } from '../identity-service';
|
import type { IdentityService } from '../identity-service';
|
||||||
import { bodyHasDecodableContent } from './blank-filter';
|
import { bodyHasDecodableContent, isC2cControlPush } from './blank-filter';
|
||||||
import { buildContext, type PushMsgBody } from './context';
|
import { buildContext, type PushMsgBody } from './context';
|
||||||
import { decodeEvent0x210 } from './decoders/event-0x210';
|
import { decodeEvent0x210 } from './decoders/event-0x210';
|
||||||
import { decodeEvent0x2DC } from './decoders/event-0x2dc';
|
import { decodeEvent0x2DC } from './decoders/event-0x2dc';
|
||||||
@@ -86,13 +86,23 @@ export function parseMsgPush(pkt: PacketInfo, identity: IdentityService): QQEven
|
|||||||
const events = registry.decode(ctx);
|
const events = registry.decode(ctx);
|
||||||
return events.filter((ev) => {
|
return events.filter((ev) => {
|
||||||
if (!MESSAGE_KINDS.has(ev.kind)) return true;
|
if (!MESSAGE_KINDS.has(ev.kind)) return true;
|
||||||
|
// C2C control/system signal (#102): QQ NT routes these via OnRecvSysMsg and
|
||||||
|
// never shows them as a bubble. Drop by (msgType, c2cCmd) regardless of body
|
||||||
|
// — the precise discriminator, the group-invite "[空消息]" phantom being one.
|
||||||
|
if (isC2cControlPush(ctx.head)) {
|
||||||
|
const elemCount = (ev as { elements?: unknown[] }).elements?.length ?? 0;
|
||||||
|
if (elemCount > 0) {
|
||||||
|
log.debug('dropped c2c control push that carried %d element(s) (kind=%s seq=%d from=%d msgType=%d cmd=%d)',
|
||||||
|
elemCount, ev.kind, ctx.head.sequence, ctx.fromUin, ctx.head.msgType, ctx.head.c2cCmd);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if ((ev as { elements?: unknown[] }).elements?.length !== 0) return true;
|
if ((ev as { elements?: unknown[] }).elements?.length !== 0) return true;
|
||||||
// Empty-element message (#102). Drop it when the body is genuinely empty —
|
// Empty-element message that's NOT a known control cmd. Drop it when the body
|
||||||
// QQ emits a content-less c2c push (msgType=166/0) alongside e.g. a group
|
// is genuinely empty (a content-less push we don't yet classify by c2cCmd).
|
||||||
// invite card, which otherwise surfaces to clients as a confusing
|
// If instead the body *had* content we just couldn't decode, keep the
|
||||||
// "[空消息]". If instead the body *had* content we just couldn't decode,
|
// (still-empty) event but warn so the missing decoder gets noticed rather
|
||||||
// keep the (still-empty) event but warn so the missing decoder gets noticed
|
// than silently swallowed.
|
||||||
// rather than silently swallowed.
|
|
||||||
if (bodyHasDecodableContent(ctx.body)) {
|
if (bodyHasDecodableContent(ctx.body)) {
|
||||||
log.warn('message had content but decoded to 0 elements — missing decoder? (kind=%s seq=%d from=%d msgType=%d/%d): %s',
|
log.warn('message had content but decoded to 0 elements — missing decoder? (kind=%s seq=%d from=%d msgType=%d/%d): %s',
|
||||||
ev.kind, ctx.head.sequence, ctx.fromUin, ctx.head.msgType, ctx.head.subType,
|
ev.kind, ctx.head.sequence, ctx.fromUin, ctx.head.msgType, ctx.head.subType,
|
||||||
|
|||||||
@@ -46,6 +46,27 @@ describe('parseMsgPush — empty message drop (#102)', () => {
|
|||||||
expect(out[0]).toMatchObject({ kind: 'friend_message', elements: [{ type: 'text', text: 'hi' }] });
|
expect(out[0]).toMatchObject({ kind: 'friend_message', elements: [{ type: 'text', text: 'hi' }] });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('drops a C2C control push by (msgType, c2cCmd) even when it carries content', () => {
|
||||||
|
// 166 + c2c_cmd ∈ {1,73,75,129,131,133,135,192} is a control/system signal
|
||||||
|
// QQ NT routes via OnRecvSysMsg, never a bubble — drop regardless of body.
|
||||||
|
const out = parseMsgPush(pushPacket({
|
||||||
|
responseHead: { fromUin: 10001, fromUid: 'u_x' },
|
||||||
|
contentHead: { msgType: 166, subType: 0, c2cCmd: 75, sequence: 200, timestamp: 1781540572, msgId: 3 },
|
||||||
|
body: { richText: { elems: [{ text: { str: 'noise' } }] } },
|
||||||
|
}), identity);
|
||||||
|
expect(out).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps a normal 166 message whose c2cCmd is not a control command', () => {
|
||||||
|
const out = parseMsgPush(pushPacket({
|
||||||
|
responseHead: { fromUin: 10001, fromUid: 'u_x' },
|
||||||
|
contentHead: { msgType: 166, subType: 0, c2cCmd: 0, sequence: 201, timestamp: 1781540572, msgId: 4 },
|
||||||
|
body: { richText: { elems: [{ text: { str: 'hi' } }] } },
|
||||||
|
}), identity);
|
||||||
|
expect(out).toHaveLength(1);
|
||||||
|
expect(out[0]).toMatchObject({ kind: 'friend_message', elements: [{ type: 'text', text: 'hi' }] });
|
||||||
|
});
|
||||||
|
|
||||||
it('keeps an empty-decoded message whose body still carried content (missing decoder)', () => {
|
it('keeps an empty-decoded message whose body still carried content (missing decoder)', () => {
|
||||||
// A commonElem service type the rich-body decoder ignores → 0 elements, but
|
// A commonElem service type the rich-body decoder ignores → 0 elements, but
|
||||||
// the body was not empty, so the message must survive (and be warned about),
|
// the body was not empty, so the message must survive (and be warned about),
|
||||||
|
|||||||
Reference in new issue
Block a user