feat(protocol): decode online device snapshots

Decode Event 0x210 subtype 349 into typed online-device snapshots, including QQ-compatible low-byte client type normalization and one-entry-per-device-category projection.

Keep replacement snapshots outside system-message deduplication, reject malformed device identities observably, and add wire-level regressions for complete, packed, repeated, and invalid payloads. Live verification covered mobile account switching without requiring native changes.
This commit is contained in:
DrSmoothl committed 2026-07-19 19:19:58 +08:00
1 parent e6a69b05a7
commit b92c8ad881
8 files changed
+279 -3

No files matched your search

+126 -1
View File
@@ -15,7 +15,7 @@ import type { GroupMemberInfo, QQGroupInfo } from '@snowluma/protocol/qq-info';
import type {
GroupChange, NewFriend, FriendRecall, OperatorInfo, SelfJoinInGroup, GroupAdmin,
InputStatusNotify, NotifyMessageBody, GroupNameChange, GroupSpecialTitleChange,
ProfileLikeTip,
OnlineDeviceNotify, ProfileLikeTip,
} from '@snowluma/proto-defs/notify';
import type { PushMsg } from '@snowluma/proto-defs/message';
import type {
@@ -449,6 +449,131 @@ describe('parseMsgPush Event0x210 subType=277 (input status → 对方正在输
});
});
describe('parseMsgPush Event0x210 subType=349 (online-device snapshot)', () => {
it('decodes the complete device fields recovered from the QQ wire handler', () => {
const content = protobuf_encode<OnlineDeviceNotify>({
appId: 537242075,
instanceId: 101,
clientType: 1,
platform: 3,
devices: [
{
appId: 537242075,
instanceId: 202,
clientType: 1,
platform: 3,
deviceName: 'DESKTOP-TEST',
},
{
appId: 537242075,
instanceId: 203,
clientType: 5,
platform: 3,
deviceName: 'DESKTOP-DUPLICATE',
},
{
appId: 537242075,
instanceId: 303,
clientType: 4,
platform: 2,
deviceName: 'Pixel 9',
},
],
});
const events = parseMsgPush(
makeEvent0x210PacketAny(349, content),
makeIdentity(),
);
expect(events).toEqual([{
kind: 'online_devices_changed',
time: 1710000000,
selfUin: Number(SELF_UIN),
devices: [
{
appId: 537242075,
instanceId: 202,
clientType: 1,
platform: 3,
deviceName: 'DESKTOP-TEST',
deviceKind: 'computer',
},
{
appId: 537242075,
instanceId: 303,
clientType: 4,
platform: 2,
deviceName: 'Pixel 9',
deviceKind: 'phone',
},
],
}]);
});
it('normalizes packed wire client types before classification and deduplication', () => {
const content = protobuf_encode<OnlineDeviceNotify>({
devices: [
{
appId: 1001,
instanceId: 202,
clientType: 83714, // 0x14702 -> phone client type 2
platform: 3,
deviceName: 'BOT-HOST',
},
{
appId: 1001,
instanceId: 203,
clientType: 65799, // 0x10107 -> phone client type 7
platform: 2,
deviceName: 'MOBILE-DUPLICATE',
},
],
});
const events = parseMsgPush(
makeEvent0x210PacketAny(349, content),
makeIdentity(),
);
expect(events).toEqual([{
kind: 'online_devices_changed',
time: 1710000000,
selfUin: Number(SELF_UIN),
devices: [{
appId: 1001,
instanceId: 202,
clientType: 2,
platform: 3,
deviceName: 'BOT-HOST',
deviceKind: 'phone',
}],
}]);
});
it('rejects entries that omit required identity fields', () => {
const content = protobuf_encode<OnlineDeviceNotify>({
devices: [{ instanceId: 202, platform: 3, deviceName: 'BROKEN' }],
});
const captured: string[] = [];
const unsubscribe = subscribeLogs((entry) => {
if (entry.scope === 'MsgPush' && /online-device entry 0/.test(entry.message)) {
captured.push(entry.message);
}
});
try {
expect(parseMsgPush(
makeEvent0x210PacketAny(349, content),
makeIdentity(),
)).toEqual([]);
expect(captured).toHaveLength(1);
expect(captured[0]).toMatch(/appIdPresent=false clientTypePresent=false/);
} finally {
unsubscribe();
}
});
});
describe('parseMsgPush Event0x210 subType=39 (profile like → 名片赞)', () => {
// 0x210/39 is multiplexed; body.msgContent decodes as ProfileLikeTip and is a
// like only when inner msgType==0 && subType==203. Proto shape from NapCat's