fix(c2c-file): rewrite sendC2cFileMessage wire shape per Lagrange.Core V2
The c2c file send path was wrong on three independent axes — every
c2c file the bot tried to deliver was getting rejected by the QQ-NT
server. Aligned to `dev/Lagrange.Core` (V2 branch) which is the only
direct-protocol reference for c2c files; NapCat goes through QQ-NT
IPC and never builds this packet itself.
Three wire-shape fixes:
1. **Routing**: `routingHead.c2c { uin, uid }` → `routingHead.trans0x211
{ ccCmd: 4, uid }`. RoutingHead field 15 is the c2c-file scene's
slot. `MessagePacker.BuildPacketBase` makes this conditional on
`chain.HasTypeOf<FileEntity>()`: when a file is present, C2C goes
nil and Trans0X211 carries the routing.
2. **File payload location**: `messageBody.richText.notOnlineFile {...}`
→ `messageBody.msgContent = serialize(FileExtra{file: NotOnlineFile})`.
The server doesn't read c2c file metadata from `richText` at all —
`MessageBody.cs:12` even has the comment "Offline file is now put
here(?". Confirmed by `FileEntity.PackElement()` returning empty
and `PackMessageContent()` returning the FileExtra wrapper.
3. **contentHead.c2cCmd**: `11` → `0` (default/omitted). `11` was a
stale go-cqhttp value the QQ-NT server doesn't recognise on the
c2c-file dispatcher. Lagrange leaves it at the C# default (0).
Schema fixes (proton + legacy, both directions):
- `RoutingHead` gains `trans0x211?: pb<15, RoutingTrans0x211>`. The
new message has `toUin@1`, `ccCmd@2`, `uid@8`.
- `SendMessageBody` gains `msgContent?: pb<2, bytes>` (the receive-side
`MessageBody` already had it).
- `FileExtraInfo` deleted — was wrong on every tag (fileSize=1,
fileName=2, fileMd5=3, fileUuid=4, fileHash=5, none of which match
the wire). `FileExtra { file: pb<1, NotOnlineFile> }` now wraps the
same `NotOnlineFile` used on the receive path. This is why c2c file
PUSHES were also silently failing the four-field truthy check in
`extractMsgContent` — the schema couldn't decode anything.
- `NotOnlineFile` gains the three intake-validator fields the server
requires on send: `subcmd@9 = 1`, `dangerEvel@50 = 0`, `expireTime@55`
= now+7d.
Receive side (`rich-body-decoder.ts::extractMsgContent`): drop the
"all four fields must be truthy" guard (it was a workaround for the
broken schema) and accept any payload that decodes a fileUuid.
Tests:
- `bridge-private-routing.test.ts`: new regression that round-trips
`sendC2cFileMessage` through `protoDecode` and asserts trans0x211
routing, msgContent FileExtra wrapper, NotOnlineFile field tags,
c2cCmd=0. Catches each of the three wire-shape regressions
independently.
- `send-private-c2c-file.test.ts`: vi.fn arg signatures explicit for
CI typecheck.
647/647 tests pass.
This commit is contained in:
8 files changed
+248
-68
No files matched your search
@@ -48,7 +48,7 @@ describe('send_private_msg with {type:"file"} segment', () => {
|
||||
// Pure-file case — the elems[] path would have dropped this entirely
|
||||
// and shipped "[空消息]". The c2c file route must take over.
|
||||
const sendPrivateMessage_bridge = vi.fn();
|
||||
const sendC2cFileMessage = vi.fn(async () => goodReceipt);
|
||||
const sendC2cFileMessage = vi.fn(async (_uin: number, _uid: string, _info: any) => goodReceipt);
|
||||
const resolveUserUid = vi.fn(async () => 'u_peer');
|
||||
const bridge = fakeBridge({
|
||||
sendPrivateMessage: sendPrivateMessage_bridge,
|
||||
@@ -78,8 +78,8 @@ describe('send_private_msg with {type:"file"} segment', () => {
|
||||
});
|
||||
|
||||
it('mixed file + text splits across two sends (text first, file second)', async () => {
|
||||
const sendPrivateMessage_bridge = vi.fn(async () => goodReceipt);
|
||||
const sendC2cFileMessage = vi.fn(async () => goodReceipt);
|
||||
const sendPrivateMessage_bridge = vi.fn(async (_uin: number, _elements: any[]) => goodReceipt);
|
||||
const sendC2cFileMessage = vi.fn(async (_uin: number, _uid: string, _info: any) => goodReceipt);
|
||||
const resolveUserUid = vi.fn(async () => 'u_peer');
|
||||
const bridge = fakeBridge({
|
||||
sendPrivateMessage: sendPrivateMessage_bridge,
|
||||
@@ -112,7 +112,7 @@ describe('send_private_msg with {type:"file"} segment', () => {
|
||||
// OneBot11 file segments are upload-by-reference — without a
|
||||
// file_id there's nothing to send. Previously these slipped
|
||||
// through to the elems[] path and shipped empty messages.
|
||||
const sendPrivateMessage_bridge = vi.fn(async () => goodReceipt);
|
||||
const sendPrivateMessage_bridge = vi.fn(async (_uin: number, _elements: any[]) => goodReceipt);
|
||||
const sendC2cFileMessage = vi.fn();
|
||||
const bridge = fakeBridge({
|
||||
sendPrivateMessage: sendPrivateMessage_bridge,
|
||||
|
||||
Reference in new issue
Block a user