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

@@ -12,7 +12,7 @@ import { describe, expect, it } from 'vitest';
import type { PacketInfo } from '@snowluma/common/protocol-types';
import { protobuf_encode } from '@snowluma/proton';
import type { PushMsg, PushMsgBody } from '@snowluma/proto-defs/message';
import type { GroupChange } from '@snowluma/proto-defs/notify';
import type { GroupChange, OnlineDeviceNotify } from '@snowluma/proto-defs/notify';
import type { IdentityService } from '../../src/identity-service';
import { parseMsgPush, SysMsgDedup } from '../../src/msg-push';
@@ -40,6 +40,18 @@ function memberIncreasePush(opts: { groupId: number; memberUin: number; sequence
});
}
function onlineDevicesPush(deviceName: string): PacketInfo {
return pushPacket({
responseHead: { fromUin: 2000000001, fromUid: '' },
contentHead: { msgType: 528, subType: 349, sequence: 800, timestamp: 1781540572, msgId: 555 },
body: {
msgContent: protobuf_encode<OnlineDeviceNotify>({
devices: [{ appId: 537242075, instanceId: 202, clientType: 1, platform: 3, deviceName }],
}),
},
});
}
describe('SysMsgDedup', () => {
it('flags the second push with the same (msgType, subType, fromUin, seq, msgId)', () => {
const d = new SysMsgDedup();
@@ -115,4 +127,15 @@ describe('parseMsgPush — system-push dedup (#137)', () => {
expect(parseMsgPush(chat(), identity, dedup)).toHaveLength(1);
expect(parseMsgPush(chat(), identity, dedup)).toHaveLength(1);
});
it('does not dedup replacement state snapshots with the same server identity', () => {
const dedup = new SysMsgDedup();
expect(parseMsgPush(onlineDevicesPush('DESKTOP-A'), identity, dedup)).toMatchObject([
{ kind: 'online_devices_changed', devices: [{ deviceName: 'DESKTOP-A' }] },
]);
expect(parseMsgPush(onlineDevicesPush('DESKTOP-B'), identity, dedup)).toMatchObject([
{ kind: 'online_devices_changed', devices: [{ deviceName: 'DESKTOP-B' }] },
]);
});
});