diff --git a/packages/core/src/bridge/proto/proton/action.ts b/packages/core/src/bridge/proto/proton/action.ts index 0a44d8b8..fbd94d9e 100644 --- a/packages/core/src/bridge/proto/proton/action.ts +++ b/packages/core/src/bridge/proto/proton/action.ts @@ -1,11 +1,7 @@ -// Proton (compile-time) form of bridge/proto/action.ts. -// One-to-one mirror; legacy `*Schema` constants stay alongside for back-compat. - import type { pb, pb_repeated, int_32, uint_32, uint_64, bytes } from '@snowluma/proton'; import type { Elem } from './element'; -// ── Routing ───────────────────────────────────────────────────────── - +// Routing export interface RoutingC2C { uin?: pb<1, uint_32>; uid?: pb<2, string>; @@ -15,14 +11,10 @@ export interface RoutingGroup { groupCode?: pb<1, uint_64>; } -// `Trans0x211` is the c2c-file scene's routing header. The server -// rejects c2c file messages routed through `RoutingC2C` — instead it -// expects `trans0x211 { ccCmd: 4, uid: }`. Confirmed against -// `dev/Lagrange.Core/Lagrange.Core/Internal/Packets/Message/ -// Routing/Trans0X211.cs` + `RoutingHead.cs` (Trans0X211 sits at -// field 15) + `MessagePacker.BuildPacketBase` (`Trans0X211 = -// !chain.HasTypeOf() ? null : new Trans0X211 { CcCmd = 4, -// Uid = chain.Uid }`). +// 服务器限制 C2C 文件消息必须使用 Trans0x211 路由头(RoutingHead 字段 15) +// 若误用常规 RoutingC2C 会被服务器拒绝。 +// 仅在包含 FileEntity 时触发,且 CcCmd 固定为 4。 + export interface RoutingTrans0x211 { toUin?: pb<1, uint_64>; ccCmd?: pb<2, uint_32>; @@ -35,39 +27,32 @@ export interface RoutingHead { trans0x211?: pb<15, RoutingTrans0x211>; } -// ── Content Head (for send) ───────────────────────────────────────── - +// Content Head for send export interface SendContentHead { type?: pb<1, uint_32>; subType?: pb<2, uint_32>; c2cCmd?: pb<3, uint_32>; } -// ── Message Control ───────────────────────────────────────────────── - +// Message Control export interface MessageControl { msgFlag?: pb<1, int_32>; } -// ── RichText (for send — only elems) ──────────────────────────────── - +// RichText (for send — only elems) export interface SendRichText { elems?: pb_repeated<2, Elem>; } -// ── MessageBody (for send) ────────────────────────────────────────── - +// MessageBody (for send) export interface SendMessageBody { richText?: pb<1, SendRichText>; - // C2C file payload — serialised `FileExtra { file: NotOnlineFile }` - // bytes. The server reads c2c file metadata from this slot, NOT - // from `richText.notOnlineFile`. Confirmed against `dev/Lagrange.Core/ - // .../MessageBody.cs:12` (commented "Offline file is now put here"). + // C2C 离线文件元数据(NotOnlineFile)必须序列化后塞入此字段 + // 服务器不会读取 richText.notOnlineFile。 msgContent?: pb<2, bytes>; } -// ── SendMessageRequest ────────────────────────────────────────────── - +// SendMessageRequest export interface SendMessageRequest { routingHead?: pb<1, RoutingHead>; contentHead?: pb<2, SendContentHead>; @@ -81,8 +66,7 @@ export interface SendMessageRequest { multiSendSeq?: pb<14, uint_32>; } -// ── SendMessageResponse ───────────────────────────────────────────── - +// SendMessageResponse export interface SendMessageResponse { result?: pb<1, int_32>; errMsg?: pb<2, string>; @@ -93,12 +77,7 @@ export interface SendMessageResponse { privateSequence?: pb<14, uint_32>; } -// ── MentionExtra (for building @mention text element) ─────────────── -// -// Same wire shape as element.ts's MentionExtra (which is used for decoding -// inbound mentions) — kept under a distinct name to mark the send-side -// usage, matching the legacy convention. - +// MentionExtra (for building @mention text element) export interface MentionExtraSend { type?: pb<3, int_32>; uin?: pb<4, uint_32>; @@ -106,8 +85,7 @@ export interface MentionExtraSend { uid?: pb<9, string>; } -// ── MarkdownData ──────────────────────────────────────────────────── - +// MarkdownData export interface MarkdownData { content?: pb<1, string>; } diff --git a/packages/core/src/bridge/proto/proton/element.ts b/packages/core/src/bridge/proto/proton/element.ts index 304cd08e..07512392 100644 --- a/packages/core/src/bridge/proto/proton/element.ts +++ b/packages/core/src/bridge/proto/proton/element.ts @@ -1,13 +1,6 @@ -// Proton (compile-time) form of bridge/proto/element.ts. -// -// One-to-one mirror of every schema in element.ts. The legacy `*Schema` -// constants stay in place for back-compat; both forms produce wire-equivalent -// output (modulo the proto3 default-value omission — see README). - import type { pb, pb_repeated, int_32, uint_32, uint_64, bool, bytes } from '@snowluma/proton'; -// ── Nested / helper schemas ───────────────────────────────────────── - +// Nested / helper schemas export interface CustomFacePbReserve { subType?: pb<1, int_32>; summary?: pb<9, string>; @@ -33,8 +26,7 @@ export interface NotOnlineImagePbReserve { md5Str?: pb<31, string>; } -// ── Core element schemas ──────────────────────────────────────────── - +// Core element schemas export interface TextElem { str?: pb<1, string>; link?: pb<2, string>; @@ -238,7 +230,7 @@ export interface GeneralFlags { longTextResId?: pb<7, string>; } -// ── Elem (union of all element types) ─────────────────────────────── +// Elem (union of all element types) export interface Elem { text?: pb<1, TextElem>; @@ -258,7 +250,7 @@ export interface Elem { commonElem?: pb<53, CommonElem>; } -// ── Extra decode types (for CommonElem.pbElem sub-messages) ───────── +// Extra decode types (for CommonElem.pbElem sub-messages) export interface MentionExtra { type?: pb<3, int_32>; @@ -284,7 +276,7 @@ export interface QSmallFaceExtra { preview2?: pb<3, string>; } -// ── NTQQ MsgInfo types (CommonElem service_type 48) ───────────────── +// NTQQ MsgInfo types (CommonElem service_type 48) export interface FileType { type?: pb<1, uint_32>; @@ -391,24 +383,15 @@ export interface MsgInfo { extBizInfo?: pb<2, ExtBizInfo>; } -// ── GroupFileExtra (TransElem type=24) ────────────────────────────── -// -// Sourced from NapCat's `GroupFileExtraInfo` (component.ts:146-155) -// cross-checked against acidify's `GroupFileExtra.Inner.Info` -// (proto/message/extra/GroupFileExtra.kt). Field numbers had been -// shifted by one in the previous schema (fileSha at 5, ext at 6, -// fileMd5 at 7) which caused the server to reject group-file chat -// posts with `result=79` — the server saw fileSha bytes where it -// expected a uint32 placeholder (field 5) and silently dropped the -// rest. Field 5 is a uint32 placeholder both refs label `field5`; -// fileSha is at 6, extInfoString at 7, fileMd5 at 8. - +// 群文件附加信息 (TransElem type=24) +// 旧版 Schema 字段 5-7 错位曾导致服务器返回 result=79 并拒收消息。 +// 字段 5 为 uint32 占位符。 export interface GroupFileInfo { busId?: pb<1, uint_32>; fileId?: pb<2, string>; fileSize?: pb<3, uint_64>; fileName?: pb<4, string>; - field5?: pb<5, uint_32>; + field5?: pb<5, uint_32>; // 关键:必须是 uint32 占位符,错位会导致 SHA 字节流污染此字段 fileSha?: pb<6, bytes>; extInfoString?: pb<7, string>; fileMd5?: pb<8, bytes>; @@ -418,24 +401,18 @@ export interface GroupFileExtraInner { info?: pb<2, GroupFileInfo>; } -// Outer wrapper carries three additional fields the server expects: -// field1 (uint32, NapCat hardcodes to 6 — "magic op tag"), fileName -// (string mirror of the inner info.fileName), display (optional UI -// preview string, NapCat leaves empty but writes the slot). Without -// these the server still recognized the message in older builds but -// rejects it in the current rollout. +// 新版服务器强校验外层结构。缺少 field1 (Magic Tag)、fileName 或 display 槽位,消息将被直接拒绝。 export interface GroupFileExtra { - field1?: pb<1, uint_32>; - fileName?: pb<2, string>; - display?: pb<3, string>; + field1?: pb<1, uint_32>; // NapCat 硬编码固定为 6 (Magic Op Tag) + fileName?: pb<2, string>; // 镜像同步内部的 info.fileName + display?: pb<3, string>; // UI 预览槽位,可留空但必须声明 inner?: pb<7, GroupFileExtraInner>; } -// ── Preserve (for message receipt info) ───────────────────────────── - +// 消息回执保留信息 export interface Preserve { messageId?: pb<3, uint_64>; senderUid?: pb<6, string>; receiverUid?: pb<7, string>; clientSequence?: pb<8, uint_32>; -} +} \ No newline at end of file diff --git a/packages/core/src/bridge/proto/proton/highway.ts b/packages/core/src/bridge/proto/proton/highway.ts index eef6ee84..d6e39377 100644 --- a/packages/core/src/bridge/proto/proton/highway.ts +++ b/packages/core/src/bridge/proto/proton/highway.ts @@ -1,6 +1,3 @@ -// Proton (compile-time) form of bridge/proto/highway.ts. -// One-to-one mirror; legacy `*Schema` constants stay alongside for back-compat. - import type { pb, pb_repeated, int_32, uint_32, uint_64, bool, bytes } from '@snowluma/proton'; import type { IndexNode, @@ -11,7 +8,7 @@ import type { PttExtBizInfo, } from './element'; -// ── DataHighwayHead ───────────────────────────────────────────────── +// DataHighwayHead export interface DataHighwayHead { version?: pb<1, uint_32>; @@ -57,7 +54,7 @@ export interface RespDataHighwayHead { errorCode?: pb<3, uint_32>; } -// ── Highway extend (NTV2RichMediaHighwayExt) ──────────────────────── +// Highway extend (NTV2RichMediaHighwayExt) export interface HighwayDomain { isEnable?: pb<1, bool>; @@ -93,7 +90,7 @@ export interface NTV2RichMediaHighwayExt { hash?: pb<11, HighwayHash>; } -// ── File upload extend (group/private file highway) ───────────────── +// File upload extend (group/private file highway) export interface FileUploadUrl { unknown?: pb<1, int_32>; @@ -153,7 +150,7 @@ export interface FileUploadExt { unknown200?: pb<200, int_32>; } -// ── Encodable MsgInfo (for embedding in message element) ──────────── +// Encodable MsgInfo (for embedding in message element) export interface EncodableMediaExtBizInfo { pic?: pb<1, PicExtBizInfo>; @@ -167,7 +164,7 @@ export interface EncodableMediaMsgInfo { extBizInfo?: pb<2, EncodableMediaExtBizInfo>; } -// ── HttpConn.0x6ff_501 (highway session) ──────────────────────────── +// HttpConn.0x6ff_501 (highway session) export interface HttpConn { field1?: pb<1, int_32>; @@ -208,7 +205,7 @@ export interface HttpConn0x6FF501Response { httpConn?: pb<0x501, HttpConnResponse>; } -// ── NTV2 Upload Request (for OIDB 0x11C4/0x11C5) ──────────────────── +// NTV2 Upload Request (for OIDB 0x11C4/0x11C5) export interface NTV2FileType { type?: pb<1, uint_32>; @@ -234,10 +231,8 @@ export interface NTV2UploadInfo { subFileType?: pb<2, uint_32>; } -// The NTV2 upload request + response carry the same ExtBizInfo shape that -// element-side incoming-message decoding uses. See bridge/proto/highway.ts -// for the rationale (the video fromScene/toScene drop was responsible for -// c2c result=79 rejections on send_private_msg [{type:'video'}]). +// NTV2 上传请求/响应扩展信息(与消息解码结构共用,参考 bridge/proto/highway.ts) +// 必须包含 video.fromScene 和 toScene 字段,否则私聊发送视频时会被服务器返回 result=79 拒绝。 export interface NTV2ExtBizInfo { pic?: pb<1, PicExtBizInfo>; video?: pb<2, VideoExtBizInfo>; @@ -293,8 +288,7 @@ export interface NTV2UploadRichMediaReq { upload?: pb<2, NTV2UploadReq>; } -// ── NTV2 Upload Response ──────────────────────────────────────────── - +// NTV2 Upload Response export interface NTV2IPv4 { outIp?: pb<1, uint_32>; outPort?: pb<2, uint_32>; diff --git a/packages/core/src/bridge/proto/proton/longmsg.ts b/packages/core/src/bridge/proto/proton/longmsg.ts index ef634a96..040d622b 100644 --- a/packages/core/src/bridge/proto/proton/longmsg.ts +++ b/packages/core/src/bridge/proto/proton/longmsg.ts @@ -1,10 +1,3 @@ -// Proton (compile-time) form of the long-message schemas. -// -// One-to-one mirror of `bridge/proto/longmsg.ts`. All 12 schemas are now -// migrated — the three (`LongMsgContent` / `LongMsgAction` / `LongMsgResult`) -// that reach into `PushMsgBody` resolve via the proton-form `message.ts` -// migration alongside this file. - import type { pb, pb_repeated, uint_32, bool, bytes } from '@snowluma/proton'; import type { PushMsgBody } from './message'; @@ -61,8 +54,7 @@ export interface RecvLongMsgResp { settings?: pb<15, LongMsgSettings>; } -// ── Schemas that reach into PushMsgBody (via message.ts) ──────────── - +// Schemas that reach into PushMsgBody export interface LongMsgContent { msgBody?: pb_repeated<1, PushMsgBody>; } diff --git a/packages/core/src/bridge/proto/proton/message.ts b/packages/core/src/bridge/proto/proton/message.ts index 8f31ab6b..26a8c5a6 100644 --- a/packages/core/src/bridge/proto/proton/message.ts +++ b/packages/core/src/bridge/proto/proton/message.ts @@ -1,11 +1,7 @@ -// Proton (compile-time) form of bridge/proto/message.ts. -// One-to-one mirror; legacy `*Schema` constants stay alongside for back-compat. - import type { pb, pb_repeated, int_32, uint_32, uint_64, bytes } from '@snowluma/proton'; import type { Elem } from './element'; -// ── ResponseHead.Grp ──────────────────────────────────────────────── - +// ResponseHead.Grp export interface ResponseGrp { groupUin?: pb<1, uint_32>; memberName?: pb<2, string>; @@ -16,8 +12,7 @@ export interface ResponseForward { friendName?: pb<6, string>; } -// ── ResponseHead ──────────────────────────────────────────────────── - +// ResponseHead export interface ResponseHead { fromUin?: pb<1, uint_32>; fromUid?: pb<2, string>; @@ -29,8 +24,7 @@ export interface ResponseHead { grp?: pb<8, ResponseGrp>; } -// ── ContentHead ───────────────────────────────────────────────────── - +// ContentHead export interface ContentHead { msgType?: pb<1, uint_32>; subType?: pb<2, uint_32>; @@ -42,8 +36,7 @@ export interface ContentHead { newId?: pb<12, uint_64>; } -// ── Ptt (voice) ───────────────────────────────────────────────────── - +// Ptt (voice) export interface Ptt { fileType?: pb<1, uint_32>; fileId?: pb<2, uint_64>; @@ -57,69 +50,48 @@ export interface Ptt { format?: pb<29, uint_32>; } -// ── NotOnlineFile (C2C file) ──────────────────────────────────────── -// -// Field numbers cross-checked against `dev/Lagrange.Core/.../Component/ -// NotOnlineFile.cs`. This same shape is what gets serialised inside -// `FileExtra` (below) and ridden as `MessageBody.msgContent` for c2c -// file sends — fields 9/50/55 are required on send (subcmd=1, -// dangerEvel=0, expireTime=now+7d), the receiver only reads the -// identification slots. - +// C2C 离线文件结构 +// 1. 发送端必填:字段 9/50/55(subcmd=1, dangerEvel=0, expireTime=当前时间+7天)。 +// 2. 接收端只读:核心标识槽位(Uuid/Md5/Name/Size/Hash)。 export interface NotOnlineFile { fileType?: pb<1, uint_32>; fileUuid?: pb<3, string>; fileMd5?: pb<4, bytes>; fileName?: pb<5, string>; fileSize?: pb<6, uint_64>; - subcmd?: pb<9, uint_32>; - dangerEvel?: pb<50, uint_32>; - expireTime?: pb<55, uint_32>; + subcmd?: pb<9, uint_32>; // 发送必填:固定为 1 + dangerEvel?: pb<50, uint_32>; // 发送必填:固定为 0 + expireTime?: pb<55, uint_32>; // 发送必填:过期时间戳(now + 7 days) fileHash?: pb<57, string>; } -// ── RichText ──────────────────────────────────────────────────────── - +// RichText export interface RichText { elems?: pb_repeated<2, Elem>; notOnlineFile?: pb<3, NotOnlineFile>; ptt?: pb<4, Ptt>; } -// ── MessageBody ───────────────────────────────────────────────────── - +// MessageBody export interface MessageBody { richText?: pb<1, RichText>; msgContent?: pb<2, bytes>; } -// ── FileExtra (for C2C file in msg_content) ───────────────────────── -// -// `FileExtra { file: NotOnlineFile }` is the wrapper the server expects -// at `MessageBody.msgContent` (per `dev/Lagrange.Core/.../FileExtra.cs`). -// Old code had a parallel `FileExtraInfo` with fileSize=1, fileName=2, -// fileMd5=3, fileUuid=4, fileHash=5 — that schema didn't match the -// wire shape at all (every field was at the wrong tag), which is why -// c2c file messages we received via msgContent silently failed to -// parse, and c2c file messages we sent through `richText.notOnlineFile` -// (also wrong — see SendMessageBody) shipped a payload the recipient -// couldn't render. Consolidating to a single shared `NotOnlineFile` -// (identification fields 1/3/4/5/6/57) fixes both directions. - +// C2C 文件附加信息 +// 统一使用与线上数据对齐的 NotOnlineFile 结构,修复收发双向的解析问题。 export interface FileExtra { file?: pb<1, NotOnlineFile>; } -// ── PushMsgBody ───────────────────────────────────────────────────── - +// PushMsgBody export interface PushMsgBody { responseHead?: pb<1, ResponseHead>; contentHead?: pb<2, ContentHead>; body?: pb<3, MessageBody>; } -// ── PushMsg (top-level) ───────────────────────────────────────────── - +// PushMsg (top-level) export interface PushMsg { message?: pb<1, PushMsgBody>; status?: pb<3, int_32>; diff --git a/packages/core/src/bridge/proto/proton/notify.ts b/packages/core/src/bridge/proto/proton/notify.ts index 4a916290..68903cb2 100644 --- a/packages/core/src/bridge/proto/proton/notify.ts +++ b/packages/core/src/bridge/proto/proton/notify.ts @@ -1,6 +1,3 @@ -// Proton (compile-time) form of bridge/proto/notify.ts. -// One-to-one mirror; legacy `*Schema` constants stay alongside for back-compat. - import type { pb, pb_repeated, int_32, uint_32, uint_64, bool, bytes } from '@snowluma/proton'; export interface OperatorField1 { @@ -122,18 +119,12 @@ export interface FriendRecall { reserved?: pb<5, bytes>; } -// ── NewFriend (0x210 subType 179 + 226) ─────────────────────────── -// -// Mutual-accept friend notice. Fires when: -// - bot sent a friend request and the other side accepted (179), or -// - the other side sent a request and bot accepted it (226). -// Both subTypes share this wire shape; field semantics follow -// `LagrangeDev/LagrangeGo` client/packets/pb/message/notify.proto. - +// 新好友通知 (0x210 子类型 179 / 226) +// 触发场景:双向同意好友申请(179:对方同意 Bot;226:Bot 同意对方)。 export interface NewFriendInfo { uid?: pb<1, string>; field2?: pb<2, uint_32>; - time?: pb<3, uint_32>; // fixed32 on wire; uint_32 decoded value is the unix epoch + time?: pb<3, uint_32>; // Unix 时间戳 (Wire 层为 fixed32) message?: pb<4, string>; nickName?: pb<5, string>; field6?: pb<6, uint_32>; @@ -146,16 +137,12 @@ export interface NewFriend { info?: pb<2, NewFriendInfo>; } -// ── SelfJoinInGroup (PkgType 85) ────────────────────────────────── -// -// Fired when the bot itself was admitted into a group — typically the -// completion of an admin-approved join request or an accepted invite. -// Ported from `lagrange-python/pb/status/group.py:170 PBSelfJoinInGroup`. - +// Bot 自身进群通知 (PkgType 85) +// 触发场景:Bot 成功加入群聊(管理员通过申请 或 接受邀请进群)。 export interface SelfJoinInGroup { groupUin?: pb<1, uint_64>; field2?: pb<2, uint_32>; - operatorUid?: pb<3, string>; + operatorUid?: pb<3, string>; // 操作人 UID (如批准申请的管理员) field4?: pb<4, uint_32>; field6?: pb<6, uint_32>; field7?: pb<7, string>; @@ -245,8 +232,7 @@ export interface NotifyMessageBody { field39?: pb<39, uint_32>; } -// ─── Event0x2DC subType=16: GroupMsgEmojiLike ──────────────────────── - +// Event0x2DC subType=16: GroupMsgEmojiLike export interface GroupReactionDataInnerDataTarget { seq?: pb<1, uint_64>; }