diff --git a/client/pb/msg/msg.pb.go b/client/pb/msg/msg.pb.go index 6e68441d..d8685f1d 100644 --- a/client/pb/msg/msg.pb.go +++ b/client/pb/msg/msg.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.11.4 +// protoc v3.13.0 // source: msg.proto package msg @@ -6018,6 +6018,61 @@ func (x *PbMultiMsgTransmit) GetPbItemList() []*PbMultiMsgItem { return nil } +type MsgElemInfoServtype3 struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FlashTroopPic *CustomFace `protobuf:"bytes,1,opt,name=flash_troop_pic,json=flashTroopPic,proto3" json:"flash_troop_pic,omitempty"` + FlashC2CPic *NotOnlineImage `protobuf:"bytes,2,opt,name=flash_c2c_pic,json=flashC2cPic,proto3" json:"flash_c2c_pic,omitempty"` +} + +func (x *MsgElemInfoServtype3) Reset() { + *x = MsgElemInfoServtype3{} + if protoimpl.UnsafeEnabled { + mi := &file_msg_proto_msgTypes[56] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgElemInfoServtype3) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgElemInfoServtype3) ProtoMessage() {} + +func (x *MsgElemInfoServtype3) ProtoReflect() protoreflect.Message { + mi := &file_msg_proto_msgTypes[56] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MsgElemInfoServtype3.ProtoReflect.Descriptor instead. +func (*MsgElemInfoServtype3) Descriptor() ([]byte, []int) { + return file_msg_proto_rawDescGZIP(), []int{56} +} + +func (x *MsgElemInfoServtype3) GetFlashTroopPic() *CustomFace { + if x != nil { + return x.FlashTroopPic + } + return nil +} + +func (x *MsgElemInfoServtype3) GetFlashC2CPic() *NotOnlineImage { + if x != nil { + return x.FlashC2CPic + } + return nil +} + var File_msg_proto protoreflect.FileDescriptor var file_msg_proto_rawDesc = []byte{ @@ -6969,11 +7024,19 @@ var file_msg_proto_rawDesc = []byte{ 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x2f, 0x0a, 0x0a, 0x70, 0x62, 0x49, 0x74, 0x65, 0x6d, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x50, 0x62, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x4d, 0x73, 0x67, 0x49, 0x74, 0x65, 0x6d, 0x52, - 0x0a, 0x70, 0x62, 0x49, 0x74, 0x65, 0x6d, 0x4c, 0x69, 0x73, 0x74, 0x2a, 0x2e, 0x0a, 0x08, 0x53, - 0x79, 0x6e, 0x63, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x54, 0x41, 0x52, 0x54, - 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x4f, 0x4e, 0x54, 0x49, 0x4e, 0x55, 0x4d, 0x45, 0x10, - 0x01, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x54, 0x4f, 0x50, 0x10, 0x02, 0x42, 0x07, 0x5a, 0x05, 0x2e, - 0x3b, 0x6d, 0x73, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x0a, 0x70, 0x62, 0x49, 0x74, 0x65, 0x6d, 0x4c, 0x69, 0x73, 0x74, 0x22, 0x81, 0x01, 0x0a, 0x15, + 0x4d, 0x73, 0x67, 0x45, 0x6c, 0x65, 0x6d, 0x49, 0x6e, 0x66, 0x6f, 0x5f, 0x73, 0x65, 0x72, 0x76, + 0x74, 0x79, 0x70, 0x65, 0x33, 0x12, 0x33, 0x0a, 0x0f, 0x66, 0x6c, 0x61, 0x73, 0x68, 0x5f, 0x74, + 0x72, 0x6f, 0x6f, 0x70, 0x5f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, + 0x2e, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x46, 0x61, 0x63, 0x65, 0x52, 0x0d, 0x66, 0x6c, 0x61, + 0x73, 0x68, 0x54, 0x72, 0x6f, 0x6f, 0x70, 0x50, 0x69, 0x63, 0x12, 0x33, 0x0a, 0x0d, 0x66, 0x6c, + 0x61, 0x73, 0x68, 0x5f, 0x63, 0x32, 0x63, 0x5f, 0x70, 0x69, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0f, 0x2e, 0x4e, 0x6f, 0x74, 0x4f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x49, 0x6d, 0x61, + 0x67, 0x65, 0x52, 0x0b, 0x66, 0x6c, 0x61, 0x73, 0x68, 0x43, 0x32, 0x63, 0x50, 0x69, 0x63, 0x2a, + 0x2e, 0x0a, 0x08, 0x53, 0x79, 0x6e, 0x63, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x09, 0x0a, 0x05, 0x53, + 0x54, 0x41, 0x52, 0x54, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x4f, 0x4e, 0x54, 0x49, 0x4e, + 0x55, 0x4d, 0x45, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x54, 0x4f, 0x50, 0x10, 0x02, 0x42, + 0x07, 0x5a, 0x05, 0x2e, 0x3b, 0x6d, 0x73, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -6989,7 +7052,7 @@ func file_msg_proto_rawDescGZIP() []byte { } var file_msg_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 56) +var file_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 57) var file_msg_proto_goTypes = []interface{}{ (SyncFlag)(0), // 0: SyncFlag (*GetMessageRequest)(nil), // 1: GetMessageRequest @@ -7048,6 +7111,7 @@ var file_msg_proto_goTypes = []interface{}{ (*PbMultiMsgItem)(nil), // 54: PbMultiMsgItem (*PbMultiMsgNew)(nil), // 55: PbMultiMsgNew (*PbMultiMsgTransmit)(nil), // 56: PbMultiMsgTransmit + (*MsgElemInfoServtype3)(nil), // 57: MsgElemInfo_servtype3 } var file_msg_proto_depIdxs = []int32{ 0, // 0: GetMessageRequest.syncFlag:type_name -> SyncFlag @@ -7109,11 +7173,13 @@ var file_msg_proto_depIdxs = []int32{ 17, // 56: PbMultiMsgNew.msg:type_name -> Message 17, // 57: PbMultiMsgTransmit.msg:type_name -> Message 54, // 58: PbMultiMsgTransmit.pbItemList:type_name -> PbMultiMsgItem - 59, // [59:59] is the sub-list for method output_type - 59, // [59:59] is the sub-list for method input_type - 59, // [59:59] is the sub-list for extension type_name - 59, // [59:59] is the sub-list for extension extendee - 0, // [0:59] is the sub-list for field type_name + 41, // 59: MsgElemInfo_servtype3.flash_troop_pic:type_name -> CustomFace + 31, // 60: MsgElemInfo_servtype3.flash_c2c_pic:type_name -> NotOnlineImage + 61, // [61:61] is the sub-list for method output_type + 61, // [61:61] is the sub-list for method input_type + 61, // [61:61] is the sub-list for extension type_name + 61, // [61:61] is the sub-list for extension extendee + 0, // [0:61] is the sub-list for field type_name } func init() { file_msg_proto_init() } @@ -7794,6 +7860,18 @@ func file_msg_proto_init() { return nil } } + file_msg_proto_msgTypes[56].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgElemInfoServtype3); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -7801,7 +7879,7 @@ func file_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_msg_proto_rawDesc, NumEnums: 1, - NumMessages: 56, + NumMessages: 57, NumExtensions: 0, NumServices: 0, }, diff --git a/client/pb/msg/msg.proto b/client/pb/msg/msg.proto index a7aec253..ceda05e1 100644 --- a/client/pb/msg/msg.proto +++ b/client/pb/msg/msg.proto @@ -698,6 +698,11 @@ message PbMultiMsgTransmit { repeated PbMultiMsgItem pbItemList = 2; } +message MsgElemInfo_servtype3{ + CustomFace flash_troop_pic = 1; + NotOnlineImage flash_c2c_pic = 2; +} + enum SyncFlag { START = 0; CONTINUME = 1; diff --git a/message/elements.go b/message/elements.go index a6466e0a..d1593d17 100644 --- a/message/elements.go +++ b/message/elements.go @@ -107,6 +107,14 @@ type RedBagElement struct { Title string } +type GroupFlashPicElement struct { + GroupImageElement +} + +type FriendFlashPicElement struct{ + FriendImageElement +} + type RedBagMessageType int const ( diff --git a/message/message.go b/message/message.go index c9e9821a..1a4cabce 100644 --- a/message/message.go +++ b/message/message.go @@ -78,6 +78,10 @@ type ( Type() ElementType } + IRichMessageElement interface { + Pack() []*msg.Elem + } + ElementType int GroupGift int @@ -271,123 +275,9 @@ func ToProtoElems(elems []IMessageElement, generalFlags bool) (r []*msg.Elem) { }) } } - imgOld := []byte{0x15, 0x36, 0x20, 0x39, 0x32, 0x6B, 0x41, 0x31, 0x00, 0x38, 0x37, 0x32, 0x66, 0x30, 0x36, 0x36, 0x30, 0x33, 0x61, 0x65, 0x31, 0x30, 0x33, 0x62, 0x37, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x35, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x30, 0x31, 0x45, 0x39, 0x34, 0x35, 0x31, 0x42, 0x2D, 0x37, 0x30, 0x45, 0x44, - 0x2D, 0x45, 0x41, 0x45, 0x33, 0x2D, 0x42, 0x33, 0x37, 0x43, 0x2D, 0x31, 0x30, 0x31, 0x46, 0x31, 0x45, 0x45, 0x42, 0x46, 0x35, 0x42, 0x35, 0x7D, 0x2E, 0x70, 0x6E, 0x67, 0x41} for _, elem := range elems { - switch e := elem.(type) { - case *TextElement: - r = append(r, &msg.Elem{ - Text: &msg.Text{ - Str: e.Content, - }, - }) - case *FaceElement: - r = append(r, &msg.Elem{ - Face: &msg.Face{ - Index: e.Index, - Old: binary.ToBytes(int16(0x1445 - 4 + e.Index)), - Buf: []byte{0x00, 0x01, 0x00, 0x04, 0x52, 0xCC, 0xF5, 0xD0}, - }, - }) - case *AtElement: - r = append(r, &msg.Elem{ - Text: &msg.Text{ - Str: e.Display, - Attr6Buf: binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(1) - w.WriteUInt16(0) - w.WriteUInt16(uint16(len([]rune(e.Display)))) - w.WriteByte(func() byte { - if e.Target == 0 { - return 1 - } - return 0 - }()) - w.WriteUInt32(uint32(e.Target)) - w.WriteUInt16(0) - }), - }, - }) - r = append(r, &msg.Elem{Text: &msg.Text{Str: " "}}) - case *ImageElement: - r = append(r, &msg.Elem{ - CustomFace: &msg.CustomFace{ - FilePath: e.Filename, - Md5: e.Md5, - Size: e.Size, - Flag: make([]byte, 4), - OldData: imgOld, - }, - }) - case *GroupImageElement: - r = append(r, &msg.Elem{ - CustomFace: &msg.CustomFace{ - FileType: 66, - Useful: 1, - Origin: 1, - FileId: int32(e.FileId), - FilePath: e.ImageId, - Size: e.Size, - Md5: e.Md5[:], - Flag: make([]byte, 4), - //OldData: imgOld, - }, - }) - case *FriendImageElement: - r = append(r, &msg.Elem{ - NotOnlineImage: &msg.NotOnlineImage{ - FilePath: e.ImageId, - ResId: e.ImageId, - OldPicMd5: false, - PicMd5: e.Md5, - DownloadPath: e.ImageId, - Original: 1, - PbReserve: []byte{0x78, 0x02}, - }, - }) - case *ServiceElement: - if e.Id == 35 { - r = append(r, &msg.Elem{ - RichMsg: &msg.RichMsg{ - Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), - ServiceId: e.Id, - MsgResId: []byte{}, - }, - }) - r = append(r, &msg.Elem{ - Text: &msg.Text{ - Str: "你的QQ暂不支持查看[转发多条消息],请期待后续版本。", - }, - }) - continue - } - if e.Id == 33 { - r = append(r, &msg.Elem{ - Text: &msg.Text{Str: e.ResId}, - }) - r = append(r, &msg.Elem{ - RichMsg: &msg.RichMsg{ - Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), - ServiceId: e.Id, - MsgResId: []byte{}, - }, - }) - continue - } - r = append(r, &msg.Elem{ - RichMsg: &msg.RichMsg{ - Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), - ServiceId: e.Id, - }, - }) - case *LightAppElement: - r = append(r, &msg.Elem{ - LightApp: &msg.LightAppElem{ - Data: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), - MsgResid: []byte{1}, - }, - }) + if e,ok := elem.(IRichMessageElement);ok{ + r = append(r, e.Pack()...) } } if generalFlags { @@ -584,6 +474,29 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement { if elem.Face != nil { res = append(res, NewFace(elem.Face.Index)) } + if elem.CommonElem != nil { + switch elem.CommonElem.ServiceType { + case 3: + flash := &msg.MsgElemInfoServtype3{} + _ = proto.Unmarshal(elem.CommonElem.PbElem, flash) + if flash.FlashTroopPic != nil { + res = append(res, &ImageElement{ + Filename: flash.FlashTroopPic.FilePath, + Size: flash.FlashTroopPic.Size, + Width: flash.FlashTroopPic.Width, + Height: flash.FlashTroopPic.Height, + Md5: flash.FlashTroopPic.Md5, + }) + } + if flash.FlashC2CPic != nil { + res = append(res, &ImageElement{ + Filename: flash.FlashC2CPic.FilePath, + Size: flash.FlashC2CPic.FileLen, + Md5: flash.FlashC2CPic.PicMd5, + }) + } + } + } } return res } diff --git a/message/pack.go b/message/pack.go new file mode 100644 index 00000000..1da01041 --- /dev/null +++ b/message/pack.go @@ -0,0 +1,211 @@ +package message + +import ( + "github.com/Mrs4s/MiraiGo/binary" + "github.com/Mrs4s/MiraiGo/client/pb/msg" + "github.com/golang/protobuf/proto" +) + +var imgOld = []byte{0x15, 0x36, 0x20, 0x39, 0x32, 0x6B, 0x41, 0x31, 0x00, 0x38, 0x37, 0x32, 0x66, 0x30, 0x36, 0x36, 0x30, 0x33, 0x61, 0x65, 0x31, 0x30, 0x33, 0x62, 0x37, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x35, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x30, 0x31, 0x45, 0x39, 0x34, 0x35, 0x31, 0x42, 0x2D, 0x37, 0x30, 0x45, 0x44, + 0x2D, 0x45, 0x41, 0x45, 0x33, 0x2D, 0x42, 0x33, 0x37, 0x43, 0x2D, 0x31, 0x30, 0x31, 0x46, 0x31, 0x45, 0x45, 0x42, 0x46, 0x35, 0x42, 0x35, 0x7D, 0x2E, 0x70, 0x6E, 0x67, 0x41} + +func (e *TextElement) Pack() (r []*msg.Elem) { + r = append(r, &msg.Elem{ + Text: &msg.Text{ + Str: e.Content, + }, + }) + return +} + +func (e *FaceElement) Pack() (r []*msg.Elem) { + r = []*msg.Elem{} + r = append(r, &msg.Elem{ + Face: &msg.Face{ + Index: e.Index, + Old: binary.ToBytes(int16(0x1445 - 4 + e.Index)), + Buf: []byte{0x00, 0x01, 0x00, 0x04, 0x52, 0xCC, 0xF5, 0xD0}, + }, + }) + return +} + +func (e *AtElement) Pack() (r []*msg.Elem) { + r = []*msg.Elem{} + r = append(r, &msg.Elem{ + Text: &msg.Text{ + Str: e.Display, + Attr6Buf: binary.NewWriterF(func(w *binary.Writer) { + w.WriteUInt16(1) + w.WriteUInt16(0) + w.WriteUInt16(uint16(len([]rune(e.Display)))) + w.WriteByte(func() byte { + if e.Target == 0 { + return 1 + } + return 0 + }()) + w.WriteUInt32(uint32(e.Target)) + w.WriteUInt16(0) + }), + }, + }) + r = append(r, &msg.Elem{Text: &msg.Text{Str: " "}}) + return +} + +func (e *ImageElement) Pack() (r []*msg.Elem) { + r = []*msg.Elem{} + r = append(r, &msg.Elem{ + CustomFace: &msg.CustomFace{ + FilePath: e.Filename, + Md5: e.Md5, + Size: e.Size, + Flag: make([]byte, 4), + OldData: imgOld, + }, + }) + return +} + +func (e *GroupImageElement) Pack(r []*msg.Elem) { + r = []*msg.Elem{} + r = append(r, &msg.Elem{ + CustomFace: &msg.CustomFace{ + FileType: 66, + Useful: 1, + Origin: 1, + FileId: int32(e.FileId), + FilePath: e.ImageId, + Size: e.Size, + Md5: e.Md5[:], + Flag: make([]byte, 4), + //OldData: imgOld, + }, + }) + return +} + +func (e *FriendImageElement) Pack() (r []*msg.Elem) { + r = []*msg.Elem{} + r = append(r, &msg.Elem{ + NotOnlineImage: &msg.NotOnlineImage{ + FilePath: e.ImageId, + ResId: e.ImageId, + OldPicMd5: false, + PicMd5: e.Md5, + DownloadPath: e.ImageId, + Original: 1, + PbReserve: []byte{0x78, 0x02}, + }, + }) + return +} + +func (e *ServiceElement) Pack() (r []*msg.Elem) { + r = []*msg.Elem{} + if e.Id == 35 { + r = append(r, &msg.Elem{ + RichMsg: &msg.RichMsg{ + Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), + ServiceId: e.Id, + MsgResId: []byte{}, + }, + }) + r = append(r, &msg.Elem{ + Text: &msg.Text{ + Str: "你的QQ暂不支持查看[转发多条消息],请期待后续版本。", + }, + }) + return + } + if e.Id == 33 { + r = append(r, &msg.Elem{ + Text: &msg.Text{Str: e.ResId}, + }) + r = append(r, &msg.Elem{ + RichMsg: &msg.RichMsg{ + Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), + ServiceId: e.Id, + MsgResId: []byte{}, + }, + }) + return + } + r = append(r, &msg.Elem{ + RichMsg: &msg.RichMsg{ + Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), + ServiceId: e.Id, + }, + }) + return +} + +func (e *LightAppElement) Pack() (r []*msg.Elem) { + r = []*msg.Elem{} + r = append(r, &msg.Elem{ + LightApp: &msg.LightAppElem{ + Data: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), + MsgResid: []byte{1}, + }, + }) + return +} + +func (e *FriendFlashPicElement) Pack() (r []*msg.Elem) { + r = []*msg.Elem{} + flash := &msg.MsgElemInfoServtype3{ + FlashC2CPic: &msg.NotOnlineImage{ + FilePath: e.ImageId, + ResId: e.ImageId, + OldPicMd5: false, + PicMd5: e.Md5, + DownloadPath: e.ImageId, + Original: 1, + PbReserve: []byte{0x78, 0x02}, + }, + } + data, _ := proto.Marshal(flash) + r = append(r, &msg.Elem{ + CommonElem: &msg.CommonElem{ + ServiceType: 3, + PbElem: data, + }, + }) + r = append(r, &msg.Elem{ + Text: &msg.Text{ + Str: "[闪照]请使用新版手机QQ查看闪照。", + }, + }) + return +} + +func (e *GroupFlashPicElement) Pack() (r []*msg.Elem) { + r = []*msg.Elem{} + flash := &msg.MsgElemInfoServtype3{ + FlashTroopPic: &msg.CustomFace{ + FileType: 66, + Useful: 1, + Origin: 1, + FileId: int32(e.FileId), + FilePath: e.ImageId, + Size: e.Size, + Md5: e.Md5[:], + Flag: make([]byte, 4), + }, + } + data, _ := proto.Marshal(flash) + r = append(r, &msg.Elem{ + CommonElem: &msg.CommonElem{ + ServiceType: 3, + PbElem: data, + }, + }) + r = append(r, &msg.Elem{ + Text: &msg.Text{ + Str: "[闪照]请使用新版手机QQ查看闪照。", + }, + }) + return +} \ No newline at end of file