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.
95 lines
3.0 KiB
TypeScript
95 lines
3.0 KiB
TypeScript
import { protobuf_decode } from '@snowluma/proton';
|
|
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
|
import type { IdentityService } from '../identity-service';
|
|
import type { ContentHead, MessageBody, PushMsg, PushMsgBody as ProtoMessage, ResponseHead } from '@snowluma/proto-defs/message';
|
|
|
|
export type PushMsgBody = MessageBody;
|
|
export type PushMsgResponseHead = ResponseHead;
|
|
export type PushMsgContentHead = ContentHead;
|
|
|
|
export interface MsgPushHead {
|
|
readonly msgType: number;
|
|
readonly subType: number;
|
|
/** C2C command (`contentHead` field 3). Discriminates control pushes — see
|
|
* `isC2cControlPush` in ./blank-filter. */
|
|
readonly c2cCmd: number;
|
|
readonly sequence: number;
|
|
readonly timestamp: number;
|
|
readonly msgId: number;
|
|
}
|
|
|
|
export interface MsgPushContext {
|
|
readonly head: MsgPushHead;
|
|
readonly fromUin: number;
|
|
readonly fromUid: string;
|
|
readonly selfUin: number;
|
|
readonly content: Uint8Array;
|
|
readonly body: PushMsgBody | undefined;
|
|
readonly responseHead: PushMsgResponseHead | undefined;
|
|
readonly identity: IdentityService;
|
|
}
|
|
|
|
export function buildContext(pkt: PacketInfo, identity: IdentityService): MsgPushContext | null {
|
|
if (pkt.body.length === 0) return null;
|
|
|
|
// `pkt.body` is already a `Uint8Array` (see `PacketInfo` in
|
|
// @snowluma/common/protocol-types). The legacy `Buffer.from(uint8)`
|
|
// wrap was a no-op copy — Buffer is a Uint8Array subclass and
|
|
// proton's decoder accepts the parent type directly. Dropping the
|
|
// wrap saves one allocation per incoming push packet.
|
|
const push = protobuf_decode<PushMsg>(pkt.body);
|
|
if (!push?.message) return null;
|
|
|
|
let selfUin = 0;
|
|
if (pkt.uin) {
|
|
const n = parseInt(pkt.uin, 10);
|
|
if (!isNaN(n)) selfUin = n;
|
|
}
|
|
|
|
return buildContextFromMessage(push.message, selfUin, identity);
|
|
}
|
|
|
|
/**
|
|
* Build a push context from an already-extracted per-message struct (the same
|
|
* `PushMsgBody` shape that `PushMsg.message` carries). Used both by
|
|
* {@link buildContext} (live OlPush) and by the group-history fetch, whose
|
|
* `SsoGetGroupMsgResponse.body.messages` are these same structs — so the
|
|
* regular msg-push decoders parse fetched history unchanged.
|
|
*/
|
|
export function buildContextFromMessage(
|
|
msg: ProtoMessage,
|
|
selfUin: number,
|
|
identity: IdentityService,
|
|
): MsgPushContext | null {
|
|
if (!msg.contentHead) return null;
|
|
|
|
const head: MsgPushHead = {
|
|
msgType: msg.contentHead.msgType ?? 0,
|
|
subType: msg.contentHead.subType ?? 0,
|
|
c2cCmd: msg.contentHead.c2cCmd ?? 0,
|
|
sequence: msg.contentHead.sequence ?? 0,
|
|
timestamp: msg.contentHead.timestamp ?? 0,
|
|
msgId: msg.contentHead.msgId ?? 0,
|
|
};
|
|
|
|
let fromUin = 0;
|
|
let fromUid = '';
|
|
if (msg.responseHead) {
|
|
fromUin = msg.responseHead.fromUin ?? 0;
|
|
fromUid = msg.responseHead.fromUid ?? '';
|
|
}
|
|
|
|
const content = msg.body?.msgContent ?? new Uint8Array(0);
|
|
|
|
return {
|
|
head,
|
|
fromUin,
|
|
fromUid,
|
|
selfUin,
|
|
content,
|
|
body: msg.body,
|
|
responseHead: msg.responseHead,
|
|
identity,
|
|
};
|
|
}
|