1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-06-19 14:05:04 +08:00

convert msg to proto2.

This commit is contained in:
Mrs4s 2020-11-18 21:22:21 +08:00
parent 9891871259
commit 03652b0425
10 changed files with 1765 additions and 1759 deletions

View File

@ -483,22 +483,22 @@ func (c *QQClient) buildGetMessageRequestPacket(flag msg.SyncFlag, msgTime int64
cook := c.syncCookie
if cook == nil {
cook, _ = proto.Marshal(&msg.SyncCookie{
Time: msgTime,
Ran1: 758330138,
Ran2: 2480149246,
Const1: 1167238020,
Const2: 3913056418,
Const3: 0x1D,
Time: &msgTime,
Ran1: proto.Int64(758330138),
Ran2: proto.Int64(2480149246),
Const1: proto.Int64(1167238020),
Const2: proto.Int64(3913056418),
Const3: proto.Int64(0x1D),
})
}
req := &msg.GetMessageRequest{
SyncFlag: flag,
SyncFlag: &flag,
SyncCookie: cook,
LatestRambleNumber: 20,
OtherRambleNumber: 3,
OnlineSyncFlag: 1,
ContextFlag: 1,
MsgReqType: 1,
LatestRambleNumber: proto.Int32(20),
OtherRambleNumber: proto.Int32(3),
OnlineSyncFlag: proto.Int32(1),
ContextFlag: proto.Int32(1),
MsgReqType: proto.Int32(1),
PubaccountCookie: []byte{},
MsgCtrlBuf: []byte{},
ServerBuf: []byte{},
@ -561,8 +561,8 @@ func (c *QQClient) buildGroupSendingPacket(groupCode int64, r, pkgNum, pkgIndex,
}
}
req := &msg.SendMessageRequest{
RoutingHead: &msg.RoutingHead{Grp: &msg.Grp{GroupCode: groupCode}},
ContentHead: &msg.ContentHead{PkgNum: pkgNum, PkgIndex: pkgIndex, DivSeq: pkgDiv},
RoutingHead: &msg.RoutingHead{Grp: &msg.Grp{GroupCode: &groupCode}},
ContentHead: &msg.ContentHead{PkgNum: &pkgNum, PkgIndex: &pkgIndex, DivSeq: &pkgDiv},
MsgBody: &msg.MessageBody{
RichText: &msg.RichText{
Elems: message.ToProtoElems(m, true),
@ -574,13 +574,13 @@ func (c *QQClient) buildGroupSendingPacket(groupCode int64, r, pkgNum, pkgIndex,
}(),
},
},
MsgSeq: c.nextGroupSeq(),
MsgRand: r,
MsgSeq: proto.Int32(c.nextGroupSeq()),
MsgRand: &r,
SyncCookie: EmptyBytes,
MsgVia: 1,
MsgVia: proto.Int32(1),
MsgCtrl: func() *msg.MsgCtrl {
if forward {
return &msg.MsgCtrl{MsgFlag: 4}
return &msg.MsgCtrl{MsgFlag: proto.Int32(4)}
}
return nil
}(),
@ -601,24 +601,24 @@ func (c *QQClient) buildFriendSendingPacket(target int64, msgSeq, r, pkgNum, pkg
}
}
req := &msg.SendMessageRequest{
RoutingHead: &msg.RoutingHead{C2C: &msg.C2C{ToUin: target}},
ContentHead: &msg.ContentHead{PkgNum: pkgNum, PkgIndex: pkgIndex, DivSeq: pkgDiv},
RoutingHead: &msg.RoutingHead{C2C: &msg.C2C{ToUin: &target}},
ContentHead: &msg.ContentHead{PkgNum: &pkgNum, PkgIndex: &pkgIndex, DivSeq: &pkgDiv},
MsgBody: &msg.MessageBody{
RichText: &msg.RichText{
Elems: message.ToProtoElems(m, false),
Ptt: ptt,
},
},
MsgSeq: msgSeq,
MsgRand: r,
MsgSeq: &msgSeq,
MsgRand: &r,
SyncCookie: func() []byte {
cookie := &msg.SyncCookie{
Time: time,
Ran1: rand.Int63(),
Ran2: rand.Int63(),
Const1: syncConst1,
Const2: syncConst2,
Const3: 0x1d,
Time: &time,
Ran1: proto.Int64(rand.Int63()),
Ran2: proto.Int64(rand.Int63()),
Const1: &syncConst1,
Const2: &syncConst2,
Const3: proto.Int64(0x1d),
}
b, _ := proto.Marshal(cookie)
return b
@ -634,25 +634,25 @@ func (c *QQClient) buildTempSendingPacket(groupUin, target int64, msgSeq, r int3
seq := c.nextSeq()
req := &msg.SendMessageRequest{
RoutingHead: &msg.RoutingHead{GrpTmp: &msg.GrpTmp{
GroupUin: groupUin,
ToUin: target,
GroupUin: &groupUin,
ToUin: &target,
}},
ContentHead: &msg.ContentHead{PkgNum: 1},
ContentHead: &msg.ContentHead{PkgNum: proto.Int32(1)},
MsgBody: &msg.MessageBody{
RichText: &msg.RichText{
Elems: message.ToProtoElems(m.Elements, false),
},
},
MsgSeq: msgSeq,
MsgRand: r,
MsgSeq: &msgSeq,
MsgRand: &r,
SyncCookie: func() []byte {
cookie := &msg.SyncCookie{
Time: time,
Ran1: rand.Int63(),
Ran2: rand.Int63(),
Const1: syncConst1,
Const2: syncConst2,
Const3: 0x1d,
Time: &time,
Ran1: proto.Int64(rand.Int63()),
Ran2: proto.Int64(rand.Int63()),
Const1: &syncConst1,
Const2: &syncConst2,
Const3: proto.Int64(0x1d),
}
b, _ := proto.Marshal(cookie)
return b

View File

@ -560,14 +560,14 @@ func (c *QQClient) GetForwardMessage(resId string) *message.ForwardMessage {
ret := &message.ForwardMessage{}
for _, m := range multiMsg.Msg {
ret.Nodes = append(ret.Nodes, &message.ForwardNode{
SenderId: m.Head.FromUin,
SenderId: m.Head.GetFromUin(),
SenderName: func() string {
if m.Head.MsgType == 82 && m.Head.GroupInfo != nil {
return m.Head.GroupInfo.GroupCard
if m.Head.GetMsgType() == 82 && m.Head.GroupInfo != nil {
return m.Head.GroupInfo.GetGroupCard()
}
return m.Head.FromNick
return m.Head.GetFromNick()
}(),
Time: m.Head.MsgTime,
Time: m.Head.GetMsgTime(),
Message: message.ParseMessageElems(m.Body.RichText.Elems),
})
}

View File

@ -250,7 +250,7 @@ func decodeMessageSvcPacket(c *QQClient, _ uint16, payload []byte) (interface{},
if err != nil {
return nil, err
}
if rsp.Result != 0 {
if rsp.GetResult() != 0 {
return nil, errors.New("message svc result unsuccessful")
}
c.syncCookie = rsp.SyncCookie
@ -264,17 +264,17 @@ func decodeMessageSvcPacket(c *QQClient, _ uint16, payload []byte) (interface{},
for _, message := range pairMsg.Messages {
// delete message
delItem := &pb.MessageItem{
FromUin: message.Head.FromUin,
ToUin: message.Head.ToUin,
FromUin: message.Head.GetFromUin(),
ToUin: message.Head.GetToUin(),
MsgType: 187,
MsgSeq: message.Head.MsgSeq,
MsgUid: message.Head.MsgUid,
MsgSeq: message.Head.GetMsgSeq(),
MsgUid: message.Head.GetMsgUid(),
}
delItems = append(delItems, delItem)
if message.Head.ToUin != c.Uin {
if message.Head.GetToUin() != c.Uin {
continue
}
if (int64(pairMsg.LastReadTime) & 4294967295) > int64(message.Head.MsgTime) {
if (int64(pairMsg.GetLastReadTime()) & 4294967295) > int64(message.Head.GetMsgTime()) {
continue
}
strKey := fmt.Sprintf("%d%d%d%d", message.Head.FromUin, message.Head.ToUin, message.Head.MsgSeq, message.Head.MsgUid)
@ -282,23 +282,23 @@ func decodeMessageSvcPacket(c *QQClient, _ uint16, payload []byte) (interface{},
continue
}
c.msgSvcCache.Add(strKey, "", time.Minute)
switch message.Head.MsgType {
switch message.Head.GetMsgType() {
case 33: // 加群同步
groupJoinLock.Lock()
group := c.FindGroupByUin(message.Head.FromUin)
if message.Head.AuthUin == c.Uin {
group := c.FindGroupByUin(message.Head.GetFromUin())
if message.Head.GetAuthUin() == c.Uin {
if group == nil && c.ReloadGroupList() == nil {
c.dispatchJoinGroupEvent(c.FindGroupByUin(message.Head.FromUin))
c.dispatchJoinGroupEvent(c.FindGroupByUin(message.Head.GetFromUin()))
}
} else {
if group != nil && group.FindMember(message.Head.AuthUin) == nil {
if group != nil && group.FindMember(message.Head.GetAuthUin()) == nil {
mem := &GroupMemberInfo{
Uin: message.Head.AuthUin,
Uin: message.Head.GetAuthUin(),
Nickname: func() string {
if message.Head.AuthNick == "" {
return message.Head.FromNick
if message.Head.GetAuthNick() == "" {
return message.Head.GetFromNick()
}
return message.Head.AuthNick
return message.Head.GetAuthNick()
}(),
JoinTime: time.Now().Unix(),
Permission: Member,
@ -320,20 +320,20 @@ func decodeMessageSvcPacket(c *QQClient, _ uint16, payload []byte) (interface{},
if message.Head.C2CTmpMsgHead == nil {
continue
}
group := c.FindGroupByUin(message.Head.C2CTmpMsgHead.GroupUin)
group := c.FindGroupByUin(message.Head.C2CTmpMsgHead.GetGroupUin())
if group == nil {
continue
}
if message.Head.FromUin == c.Uin {
if message.Head.GetFromUin() == c.Uin {
continue
}
c.dispatchTempMessage(c.parseTempMessage(message))
case 166: // 好友消息
if message.Head.FromUin == c.Uin {
if message.Head.GetFromUin() == c.Uin {
for {
frdSeq := atomic.LoadInt32(&c.friendSeq)
if frdSeq < message.Head.MsgSeq {
if atomic.CompareAndSwapInt32(&c.friendSeq, frdSeq, message.Head.MsgSeq) {
if frdSeq < message.Head.GetMsgSeq() {
if atomic.CompareAndSwapInt32(&c.friendSeq, frdSeq, message.Head.GetMsgSeq()) {
break
}
} else {
@ -361,8 +361,8 @@ func decodeMessageSvcPacket(c *QQClient, _ uint16, payload []byte) (interface{},
}
c.dispatchOfflineFileEvent(&OfflineFileEvent{
FileName: string(sub4.NotOnlineFile.FileName),
FileSize: sub4.NotOnlineFile.FileSize,
Sender: message.Head.FromUin,
FileSize: sub4.NotOnlineFile.GetFileSize(),
Sender: message.Head.GetFromUin(),
DownloadUrl: rsp.(string),
})
}
@ -370,9 +370,9 @@ func decodeMessageSvcPacket(c *QQClient, _ uint16, payload []byte) (interface{},
}
}
_, _ = c.sendAndWait(c.buildDeleteMessageRequestPacket(delItems))
if rsp.SyncFlag != msg.SyncFlag_STOP {
if rsp.GetSyncFlag() != msg.SyncFlag_STOP {
c.Debug("continue sync with flag: %v", rsp.SyncFlag.String())
_, _ = c.sendAndWait(c.buildGetMessageRequestPacket(rsp.SyncFlag, time.Now().Unix()))
_, _ = c.sendAndWait(c.buildGetMessageRequestPacket(rsp.GetSyncFlag(), time.Now().Unix()))
}
return nil, err
}
@ -384,15 +384,15 @@ func decodeGroupMessagePacket(c *QQClient, _ uint16, payload []byte) (interface{
if err != nil {
return nil, err
}
if pkt.Message.Head.FromUin == c.Uin {
if pkt.Message.Head.GetFromUin() == c.Uin {
c.dispatchGroupMessageReceiptEvent(&groupMessageReceiptEvent{
Rand: pkt.Message.Body.RichText.Attr.Random,
Seq: pkt.Message.Head.MsgSeq,
Rand: pkt.Message.Body.RichText.Attr.GetRandom(),
Seq: pkt.Message.Head.GetMsgSeq(),
Msg: c.parseGroupMessage(pkt.Message),
})
return nil, nil
}
if pkt.Message.Content != nil && pkt.Message.Content.PkgNum > 1 {
if pkt.Message.Content != nil && pkt.Message.Content.GetPkgNum() > 1 {
var builder *groupMessageBuilder // TODO: 支持多SEQ
i, ok := c.groupMsgBuilders.Load(pkt.Message.Content.DivSeq)
if !ok {
@ -402,7 +402,7 @@ func decodeGroupMessagePacket(c *QQClient, _ uint16, payload []byte) (interface{
builder = i.(*groupMessageBuilder)
}
builder.MessageSlices = append(builder.MessageSlices, pkt.Message)
if int32(len(builder.MessageSlices)) >= pkt.Message.Content.PkgNum {
if int32(len(builder.MessageSlices)) >= pkt.Message.Content.GetPkgNum() {
c.groupMsgBuilders.Delete(pkt.Message.Content.DivSeq)
c.dispatchGroupMessage(c.parseGroupMessage(builder.build()))
}
@ -418,7 +418,7 @@ func decodeMsgSendResponse(c *QQClient, _ uint16, payload []byte) (interface{},
if err := proto.Unmarshal(payload, &rsp); err != nil {
return nil, err
}
if rsp.Result != 0 {
if rsp.GetResult() != 0 {
c.Error("send msg error: %v %v", rsp.Result, rsp.ErrMsg)
}
return nil, nil
@ -835,18 +835,18 @@ func decodeOnlinePushTransPacket(c *QQClient, _ uint16, payload []byte) (interfa
return nil, err
}
data := binary.NewReader(info.MsgData)
idStr := strconv.FormatInt(info.MsgUid, 10)
idStr := strconv.FormatInt(info.GetMsgUid(), 10)
if _, ok := c.transCache.Get(idStr); ok {
return nil, nil
}
c.transCache.Add(idStr, "", time.Second*15)
if info.MsgType == 34 {
if info.GetMsgType() == 34 {
data.ReadInt32()
data.ReadByte()
target := int64(uint32(data.ReadInt32()))
typ := int32(data.ReadByte())
operator := int64(uint32(data.ReadInt32()))
if g := c.FindGroupByUin(info.FromUin); g != nil {
if g := c.FindGroupByUin(info.GetFromUin()); g != nil {
groupLeaveLock.Lock()
defer groupLeaveLock.Unlock()
switch typ {
@ -901,7 +901,7 @@ func decodeOnlinePushTransPacket(c *QQClient, _ uint16, payload []byte) (interfa
}
}
}
if info.MsgType == 44 {
if info.GetMsgType() == 44 {
data.ReadBytes(5)
var4 := int32(data.ReadByte())
var var5 int64 = 0
@ -909,7 +909,7 @@ func decodeOnlinePushTransPacket(c *QQClient, _ uint16, payload []byte) (interfa
if var4 != 0 && var4 != 1 {
var5 = int64(uint32(data.ReadInt32()))
}
if g := c.FindGroupByUin(info.FromUin); g != nil {
if g := c.FindGroupByUin(info.GetFromUin()); g != nil {
if var5 == 0 && data.Len() == 1 {
newPermission := func() MemberPermission {
if data.ReadByte() == 1 {

View File

@ -352,12 +352,12 @@ func qualityTest(addr *net.TCPAddr) (int64, error) {
}
func (c *QQClient) parsePrivateMessage(msg *msg.Message) *message.PrivateMessage {
friend := c.FindFriend(msg.Head.FromUin)
friend := c.FindFriend(msg.Head.GetFromUin())
var sender *message.Sender
if friend == nil {
sender = &message.Sender{
Uin: msg.Head.FromUin,
Nickname: msg.Head.FromNick,
Uin: msg.Head.GetFromUin(),
Nickname: msg.Head.GetFromNick(),
IsFriend: false,
}
} else {
@ -367,23 +367,23 @@ func (c *QQClient) parsePrivateMessage(msg *msg.Message) *message.PrivateMessage
}
}
ret := &message.PrivateMessage{
Id: msg.Head.MsgSeq,
Id: msg.Head.GetMsgSeq(),
Target: c.Uin,
Time: msg.Head.MsgTime,
Time: msg.Head.GetMsgTime(),
Sender: sender,
Elements: message.ParseMessageElems(msg.Body.RichText.Elems),
}
if msg.Body.RichText.Attr != nil {
ret.InternalId = msg.Body.RichText.Attr.Random
ret.InternalId = msg.Body.RichText.Attr.GetRandom()
}
return ret
}
func (c *QQClient) parseTempMessage(msg *msg.Message) *message.TempMessage {
group := c.FindGroupByUin(msg.Head.C2CTmpMsgHead.GroupUin)
mem := group.FindMember(msg.Head.FromUin)
group := c.FindGroupByUin(msg.Head.C2CTmpMsgHead.GetGroupUin())
mem := group.FindMember(msg.Head.GetFromUin())
sender := &message.Sender{
Uin: msg.Head.FromUin,
Uin: msg.Head.GetFromUin(),
Nickname: "Unknown",
IsFriend: false,
}
@ -392,7 +392,7 @@ func (c *QQClient) parseTempMessage(msg *msg.Message) *message.TempMessage {
sender.CardName = mem.CardName
}
return &message.TempMessage{
Id: msg.Head.MsgSeq,
Id: msg.Head.GetMsgSeq(),
GroupCode: group.Code,
GroupName: group.Name,
Sender: sender,
@ -401,10 +401,10 @@ func (c *QQClient) parseTempMessage(msg *msg.Message) *message.TempMessage {
}
func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage {
group := c.FindGroup(m.Head.GroupInfo.GroupCode)
group := c.FindGroup(m.Head.GroupInfo.GetGroupCode())
if group == nil {
c.Debug("sync group %v.", m.Head.GroupInfo.GroupCode)
info, err := c.GetGroupInfo(m.Head.GroupInfo.GroupCode)
info, err := c.GetGroupInfo(m.Head.GroupInfo.GetGroupCode())
if err != nil {
c.Error("error to sync group %v : %v", m.Head.GroupInfo.GroupCode, err)
return nil
@ -434,9 +434,9 @@ func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage {
IsFriend: false,
}
} else {
mem := group.FindMember(m.Head.FromUin)
mem := group.FindMember(m.Head.GetFromUin())
if mem == nil {
info, _ := c.getMemberInfo(group.Code, m.Head.FromUin)
info, _ := c.getMemberInfo(group.Code, m.Head.GetFromUin())
if info == nil {
return nil
}
@ -456,25 +456,25 @@ func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage {
}
var g *message.GroupMessage
g = &message.GroupMessage{
Id: m.Head.MsgSeq,
Id: m.Head.GetMsgSeq(),
GroupCode: group.Code,
GroupName: string(m.Head.GroupInfo.GroupName),
Sender: sender,
Time: m.Head.MsgTime,
Time: m.Head.GetMsgTime(),
Elements: message.ParseMessageElems(m.Body.RichText.Elems),
}
var extInfo *msg.ExtraInfo
// pre parse
for _, elem := range m.Body.RichText.Elems {
// is rich long msg
if elem.GeneralFlags != nil && elem.GeneralFlags.LongTextResid != "" {
if f := c.GetForwardMessage(elem.GeneralFlags.LongTextResid); f != nil && len(f.Nodes) == 1 {
if elem.GeneralFlags != nil && elem.GeneralFlags.GetLongTextResid() != "" {
if f := c.GetForwardMessage(elem.GeneralFlags.GetLongTextResid()); f != nil && len(f.Nodes) == 1 {
g = &message.GroupMessage{
Id: m.Head.MsgSeq,
Id: m.Head.GetMsgSeq(),
GroupCode: group.Code,
GroupName: string(m.Head.GroupInfo.GroupName),
Sender: sender,
Time: m.Head.MsgTime,
Time: m.Head.GetMsgTime(),
Elements: f.Nodes[0].Message,
}
}
@ -484,8 +484,8 @@ func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage {
}
}
if !sender.IsAnonymous() {
mem := group.FindMember(m.Head.FromUin)
groupCard := m.Head.GroupInfo.GroupCard
mem := group.FindMember(m.Head.GetFromUin())
groupCard := m.Head.GroupInfo.GetGroupCard()
if extInfo != nil && len(extInfo.GroupCard) > 0 && extInfo.GroupCard[0] == 0x0A {
buf := oidb.D8FCCommCardNameBuf{}
if err := proto.Unmarshal(extInfo.GroupCard, &buf); err == nil && len(buf.RichCardName) > 0 {
@ -514,22 +514,22 @@ func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage {
if m.Body.RichText.Ptt != nil {
g.Elements = []message.IMessageElement{
&message.VoiceElement{
Name: m.Body.RichText.Ptt.FileName,
Name: m.Body.RichText.Ptt.GetFileName(),
Md5: m.Body.RichText.Ptt.FileMd5,
Size: m.Body.RichText.Ptt.FileSize,
Size: m.Body.RichText.Ptt.GetFileSize(),
Url: "http://grouptalk.c2c.qq.com" + string(m.Body.RichText.Ptt.DownPara),
},
}
}
if m.Body.RichText.Attr != nil {
g.InternalId = m.Body.RichText.Attr.Random
g.InternalId = m.Body.RichText.Attr.GetRandom()
}
return g
}
func (b *groupMessageBuilder) build() *msg.Message {
sort.Slice(b.MessageSlices, func(i, j int) bool {
return b.MessageSlices[i].Content.PkgIndex < b.MessageSlices[j].Content.PkgIndex
return b.MessageSlices[i].Content.GetPkgIndex() < b.MessageSlices[j].Content.GetPkgIndex()
})
base := b.MessageSlices[0]
for _, m := range b.MessageSlices[1:] {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -42,13 +42,13 @@ func (c *QQClient) UploadGroupPtt(groupCode int64, voice []byte) (*message.Group
ok:
return &message.GroupVoiceElement{
Ptt: &msg.Ptt{
FileType: 4,
SrcUin: c.Uin,
FileType: proto.Int32(4),
SrcUin: &c.Uin,
FileMd5: h[:],
FileName: hex.EncodeToString(h[:]) + ".amr",
FileSize: int32(len(voice)),
FileName: proto.String(hex.EncodeToString(h[:]) + ".amr"),
FileSize: proto.Int32(int32(len(voice))),
GroupFileKey: rsp.FileKey,
BoolValid: true,
BoolValid: proto.Bool(true),
PbReserve: []byte{8, 0, 40, 0, 56, 0},
}}, nil
}
@ -75,13 +75,13 @@ func (c *QQClient) UploadPrivatePtt(target int64, voice []byte) (*message.Privat
ok:
return &message.PrivateVoiceElement{
Ptt: &msg.Ptt{
FileType: 4,
SrcUin: c.Uin,
FileType: proto.Int32(4),
SrcUin: &c.Uin,
FileMd5: h[:],
FileName: hex.EncodeToString(h[:]) + ".amr",
FileSize: int32(len(voice)),
FileName: proto.String(hex.EncodeToString(h[:]) + ".amr"),
FileSize: proto.Int32(int32(len(voice))),
FileKey: rsp.FileKey,
BoolValid: true,
BoolValid: proto.Bool(true),
PbReserve: []byte{8, 0, 40, 0, 56, 0},
}}, nil
}

View File

@ -24,13 +24,13 @@ func (c *QQClient) buildGroupRecallPacket(groupCode int64, msgSeq, msgRan int32)
req := &msg.MsgWithDrawReq{
GroupWithDraw: []*msg.GroupMsgWithDrawReq{
{
SubCmd: 1,
GroupCode: groupCode,
SubCmd: proto.Int32(1),
GroupCode: &groupCode,
MsgList: []*msg.GroupMsgInfo{
{
MsgSeq: msgSeq,
MsgRandom: msgRan,
MsgType: 0,
MsgSeq: &msgSeq,
MsgRandom: &msgRan,
MsgType: proto.Int32(0),
},
},
UserDef: []byte{0x08, 0x00},
@ -48,16 +48,16 @@ func (c *QQClient) buildPrivateRecallPacket(uin, ts int64, msgSeq, random int32)
{
MsgInfo: []*msg.C2CMsgInfo{
{
FromUin: c.Uin,
ToUin: uin,
MsgTime: ts,
MsgUid: int64(random),
MsgSeq: msgSeq,
MsgRandom: random,
FromUin: &c.Uin,
ToUin: &uin,
MsgTime: &ts,
MsgUid: proto.Int64(int64(random)),
MsgSeq: &msgSeq,
MsgRandom: &random,
},
},
Reserved: []byte{0x08, 0x00},
SubCmd: 1,
SubCmd: proto.Int32(1),
},
}}
payload, _ := proto.Marshal(req)

View File

@ -275,9 +275,9 @@ func ToProtoElems(elems []IMessageElement, generalFlags bool) (r []*msg.Elem) {
r = append(r, &msg.Elem{
SrcMsg: &msg.SourceMsg{
OrigSeqs: []int32{reply.ReplySeq},
SenderUin: reply.Sender,
Time: reply.Time,
Flag: 1,
SenderUin: &reply.Sender,
Time: &reply.Time,
Flag: proto.Int32(1),
Elems: ToSrcProtoElems(reply.Elements),
RichMsg: []byte{},
PbReserve: []byte{},
@ -300,8 +300,8 @@ func ToProtoElems(elems []IMessageElement, generalFlags bool) (r []*msg.Elem) {
if e.SubType == "Long" {
r = append(r, &msg.Elem{
GeneralFlags: &msg.GeneralFlags{
LongTextFlag: 1,
LongTextResid: e.ResId,
LongTextFlag: proto.Int32(1),
LongTextResid: &e.ResId,
PbReserve: []byte{0x78, 0x00, 0xF8, 0x01, 0x00, 0xC8, 0x02, 0x00},
},
})
@ -331,7 +331,7 @@ func ToSrcProtoElems(elems []IMessageElement) (r []*msg.Elem) {
case *ImageElement, *GroupImageElement, *FriendImageElement:
r = append(r, &msg.Elem{
Text: &msg.Text{
Str: "[图片]",
Str: proto.String("[图片]"),
},
})
default:
@ -348,8 +348,8 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
if len(elem.SrcMsg.OrigSeqs) != 0 {
r := &ReplyElement{
ReplySeq: elem.SrcMsg.OrigSeqs[0],
Time: elem.SrcMsg.Time,
Sender: elem.SrcMsg.SenderUin,
Time: elem.SrcMsg.GetTime(),
Sender: elem.SrcMsg.GetSenderUin(),
Elements: ParseMessageElems(elem.SrcMsg.Elems),
}
res = append(res, r)
@ -357,7 +357,7 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
continue
}
if elem.TransElemInfo != nil {
if elem.TransElemInfo.ElemType == 24 { // QFile
if elem.TransElemInfo.GetElemType() == 24 { // QFile
i3 := len(elem.TransElemInfo.ElemValue)
r := binary.NewReader(elem.TransElemInfo.ElemValue)
if i3 > 3 {
@ -394,7 +394,7 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
return append(res, &ShortVideoElement{
Name: string(elem.VideoFile.FileName),
Uuid: elem.VideoFile.FileUuid,
Size: elem.VideoFile.FileSize,
Size: elem.VideoFile.GetFileSize(),
Md5: elem.VideoFile.FileMd5,
})
}
@ -402,16 +402,16 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
if len(elem.Text.Attr6Buf) == 0 {
res = append(res, NewText(func() string {
// 这么处理应该没问题
if strings.Contains(elem.Text.Str, "\r") && !strings.Contains(elem.Text.Str, "\r\n") {
return strings.ReplaceAll(elem.Text.Str, "\r", "\r\n")
if strings.Contains(elem.Text.GetStr(), "\r") && !strings.Contains(elem.Text.GetStr(), "\r\n") {
return strings.ReplaceAll(elem.Text.GetStr(), "\r", "\r\n")
}
return elem.Text.Str
return elem.Text.GetStr()
}()))
} else {
att6 := binary.NewReader(elem.Text.Attr6Buf)
att6.ReadBytes(7)
target := int64(uint32(att6.ReadInt32()))
res = append(res, NewAt(target, elem.Text.Str))
res = append(res, NewAt(target, elem.Text.GetStr()))
}
}
if elem.RichMsg != nil {
@ -423,16 +423,16 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
content = string(binary.ZlibUncompress(elem.RichMsg.Template1[1:]))
}
if content != "" {
if elem.RichMsg.ServiceId == 35 {
if elem.RichMsg.GetServiceId() == 35 {
reg := regexp.MustCompile(`m_resid="(\w+?.*?)"`)
res = append(res, &ForwardElement{ResId: reg.FindAllStringSubmatch(content, -1)[0][1]})
continue
}
if elem.RichMsg.ServiceId == 33 {
if elem.RichMsg.GetServiceId() == 33 {
continue // 前面一个 elem 已经解析到链接
}
if isOk := strings.Contains(content, "<?xml"); isOk {
res = append(res, NewRichXml(content, int64(elem.RichMsg.ServiceId)))
res = append(res, NewRichXml(content, int64(elem.RichMsg.GetServiceId())))
continue
} else {
if gjson.Valid(content) {
@ -448,59 +448,59 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
continue
}
res = append(res, &ImageElement{
Filename: elem.CustomFace.FilePath,
Size: elem.CustomFace.Size,
Width: elem.CustomFace.Width,
Height: elem.CustomFace.Height,
Filename: elem.CustomFace.GetFilePath(),
Size: elem.CustomFace.GetSize(),
Width: elem.CustomFace.GetWidth(),
Height: elem.CustomFace.GetHeight(),
Url: func() string {
if elem.CustomFace.OrigUrl == "" {
if elem.CustomFace.GetOrigUrl() == "" {
return "http://gchat.qpic.cn/gchatpic_new/0/0-0-" + strings.ReplaceAll(binary.CalculateImageResourceId(elem.CustomFace.Md5)[1:37], "-", "") + "/0?term=2"
}
return "http://gchat.qpic.cn" + elem.CustomFace.OrigUrl
return "http://gchat.qpic.cn" + elem.CustomFace.GetOrigUrl()
}(),
Md5: elem.CustomFace.Md5,
})
}
if elem.NotOnlineImage != nil {
var img string
if elem.NotOnlineImage.OrigUrl != "" {
img = "http://c2cpicdw.qpic.cn" + elem.NotOnlineImage.OrigUrl
if elem.NotOnlineImage.GetOrigUrl() != "" {
img = "http://c2cpicdw.qpic.cn" + elem.NotOnlineImage.GetOrigUrl()
} else {
img = "http://c2cpicdw.qpic.cn/offpic_new/0/" + elem.NotOnlineImage.ResId + "/0?term=2"
img = "http://c2cpicdw.qpic.cn/offpic_new/0/" + elem.NotOnlineImage.GetResId() + "/0?term=2"
}
res = append(res, &ImageElement{
Filename: elem.NotOnlineImage.FilePath,
Size: elem.NotOnlineImage.FileLen,
Filename: elem.NotOnlineImage.GetFilePath(),
Size: elem.NotOnlineImage.GetFileLen(),
Url: img,
Md5: elem.NotOnlineImage.PicMd5,
})
}
if elem.QQWalletMsg != nil && elem.QQWalletMsg.AioBody != nil {
msgType := elem.QQWalletMsg.AioBody.MsgType
msgType := elem.QQWalletMsg.AioBody.GetMsgType()
if msgType == 2 || msgType == 3 || msgType == 6 {
return []IMessageElement{
&RedBagElement{
MsgType: RedBagMessageType(msgType),
Title: elem.QQWalletMsg.AioBody.Receiver.Title,
Title: elem.QQWalletMsg.AioBody.Receiver.GetTitle(),
},
}
}
}
if elem.Face != nil {
res = append(res, NewFace(elem.Face.Index))
res = append(res, NewFace(elem.Face.GetIndex()))
}
if elem.CommonElem != nil {
switch elem.CommonElem.ServiceType {
switch elem.CommonElem.GetServiceType() {
case 3:
flash := &msg.MsgElemInfoServtype3{}
_ = proto.Unmarshal(elem.CommonElem.PbElem, flash)
if flash.FlashTroopPic != nil {
res = append(res, &GroupFlashImgElement{
ImageElement{
Filename: flash.FlashTroopPic.FilePath,
Size: flash.FlashTroopPic.Size,
Width: flash.FlashTroopPic.Width,
Height: flash.FlashTroopPic.Height,
Filename: flash.FlashTroopPic.GetFilePath(),
Size: flash.FlashTroopPic.GetSize(),
Width: flash.FlashTroopPic.GetWidth(),
Height: flash.FlashTroopPic.GetHeight(),
Md5: flash.FlashTroopPic.Md5,
},
})
@ -509,8 +509,8 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
if flash.FlashC2CPic != nil {
res = append(res, &GroupFlashImgElement{
ImageElement{
Filename: flash.FlashC2CPic.FilePath,
Size: flash.FlashC2CPic.FileLen,
Filename: flash.FlashC2CPic.GetFilePath(),
Size: flash.FlashC2CPic.GetFileLen(),
Md5: flash.FlashC2CPic.PicMd5,
},
})
@ -519,7 +519,7 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
case 33:
newSysFaceMsg := &msg.MsgElemInfoServtype33{}
_ = proto.Unmarshal(elem.CommonElem.PbElem, newSysFaceMsg)
res = append(res, NewFace(int32(newSysFaceMsg.Index)))
res = append(res, NewFace(int32(newSysFaceMsg.GetIndex())))
}
}
}
@ -531,19 +531,19 @@ func (forMsg *ForwardMessage) CalculateValidationData(seq, random int32, groupCo
for _, node := range forMsg.Nodes {
msgs = append(msgs, &msg.Message{
Head: &msg.MessageHead{
FromUin: node.SenderId,
MsgSeq: seq,
MsgTime: node.Time,
MsgUid: 0x01000000000000000 | (int64(random) & 0xFFFFFFFF),
FromUin: &node.SenderId,
MsgSeq: &seq,
MsgTime: &node.Time,
MsgUid: proto.Int64(0x01000000000000000 | (int64(random) & 0xFFFFFFFF)),
MutiltransHead: &msg.MutilTransHead{
MsgId: 1,
MsgId: proto.Int32(1),
},
MsgType: 82,
MsgType: proto.Int32(82),
GroupInfo: &msg.GroupInfo{
GroupCode: groupCode,
GroupCode: &groupCode,
GroupRank: []byte{},
GroupName: []byte{},
GroupCard: node.SenderName,
GroupCard: &node.SenderName,
},
},
Body: &msg.MessageBody{
@ -556,7 +556,7 @@ func (forMsg *ForwardMessage) CalculateValidationData(seq, random int32, groupCo
buf, _ := proto.Marshal(&msg.PbMultiMsgNew{Msg: msgs})
trans := &msg.PbMultiMsgTransmit{Msg: msgs, PbItemList: []*msg.PbMultiMsgItem{
{
FileName: "MultiMsg",
FileName: proto.String("MultiMsg"),
Buffer: buf,
},
}}

View File

@ -13,7 +13,7 @@ var imgOld = []byte{0x15, 0x36, 0x20, 0x39, 0x32, 0x6B, 0x41, 0x31, 0x00, 0x38,
func (e *TextElement) Pack() (r []*msg.Elem) {
r = append(r, &msg.Elem{
Text: &msg.Text{
Str: e.Content,
Str: &e.Content,
},
})
return
@ -23,22 +23,22 @@ func (e *FaceElement) Pack() (r []*msg.Elem) {
r = []*msg.Elem{}
if e.NewSysFace {
elem := &msg.MsgElemInfoServtype33{
Index: uint32(e.Index),
Index: proto.Uint32(uint32(e.Index)),
Text: []byte("/" + e.Name),
Compat: []byte("/" + e.Name),
}
b, _ := proto.Marshal(elem)
r = append(r, &msg.Elem{
CommonElem: &msg.CommonElem{
ServiceType: 33,
ServiceType: proto.Int32(33),
PbElem: b,
BusinessType: 1,
BusinessType: proto.Int32(1),
},
})
} else {
r = append(r, &msg.Elem{
Face: &msg.Face{
Index: e.Index,
Index: &e.Index,
Old: binary.ToBytes(int16(0x1445 - 4 + e.Index)),
Buf: []byte{0x00, 0x01, 0x00, 0x04, 0x52, 0xCC, 0xF5, 0xD0},
},
@ -51,7 +51,7 @@ func (e *AtElement) Pack() (r []*msg.Elem) {
r = []*msg.Elem{}
r = append(r, &msg.Elem{
Text: &msg.Text{
Str: e.Display,
Str: &e.Display,
Attr6Buf: binary.NewWriterF(func(w *binary.Writer) {
w.WriteUInt16(1)
w.WriteUInt16(0)
@ -67,7 +67,7 @@ func (e *AtElement) Pack() (r []*msg.Elem) {
}),
},
})
r = append(r, &msg.Elem{Text: &msg.Text{Str: " "}})
r = append(r, &msg.Elem{Text: &msg.Text{Str: proto.String(" ")}})
return
}
@ -75,9 +75,9 @@ func (e *ImageElement) Pack() (r []*msg.Elem) {
r = []*msg.Elem{}
r = append(r, &msg.Elem{
CustomFace: &msg.CustomFace{
FilePath: e.Filename,
FilePath: &e.Filename,
Md5: e.Md5,
Size: e.Size,
Size: &e.Size,
Flag: make([]byte, 4),
OldData: imgOld,
},
@ -89,16 +89,16 @@ func (e *GroupImageElement) Pack() (r []*msg.Elem) {
r = []*msg.Elem{}
r = append(r, &msg.Elem{
CustomFace: &msg.CustomFace{
FileType: 66,
Useful: 1,
FileType: proto.Int32(66),
Useful: proto.Int32(1),
//Origin: 1,
BizType: 5,
Width: e.Width,
Height: e.Height,
FileId: int32(e.FileId),
FilePath: e.ImageId,
ImageType: e.ImageType,
Size: e.Size,
BizType: proto.Int32(5),
Width: &e.Width,
Height: &e.Height,
FileId: proto.Int32(int32(e.FileId)),
FilePath: &e.ImageId,
ImageType: &e.ImageType,
Size: &e.Size,
Md5: e.Md5[:],
Flag: make([]byte, 4),
//OldData: imgOld,
@ -111,12 +111,12 @@ 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,
FilePath: &e.ImageId,
ResId: &e.ImageId,
OldPicMd5: proto.Bool(false),
PicMd5: e.Md5,
DownloadPath: e.ImageId,
Original: 1,
DownloadPath: &e.ImageId,
Original: proto.Int32(1),
PbReserve: []byte{0x78, 0x02},
},
})
@ -129,25 +129,25 @@ func (e *ServiceElement) Pack() (r []*msg.Elem) {
r = append(r, &msg.Elem{
RichMsg: &msg.RichMsg{
Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...),
ServiceId: e.Id,
ServiceId: &e.Id,
MsgResId: []byte{},
},
})
r = append(r, &msg.Elem{
Text: &msg.Text{
Str: "你的QQ暂不支持查看[转发多条消息],请期待后续版本。",
Str: proto.String("你的QQ暂不支持查看[转发多条消息],请期待后续版本。"),
},
})
return
}
if e.Id == 33 {
r = append(r, &msg.Elem{
Text: &msg.Text{Str: e.ResId},
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,
ServiceId: &e.Id,
MsgResId: []byte{},
},
})
@ -156,7 +156,7 @@ func (e *ServiceElement) Pack() (r []*msg.Elem) {
r = append(r, &msg.Elem{
RichMsg: &msg.RichMsg{
Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...),
ServiceId: e.Id,
ServiceId: &e.Id,
},
})
return
@ -177,25 +177,25 @@ func (e *FriendFlashPicElement) Pack() (r []*msg.Elem) {
r = []*msg.Elem{}
flash := &msg.MsgElemInfoServtype3{
FlashC2CPic: &msg.NotOnlineImage{
FilePath: e.ImageId,
ResId: e.ImageId,
OldPicMd5: false,
FilePath: &e.ImageId,
ResId: &e.ImageId,
OldPicMd5: proto.Bool(false),
PicMd5: e.Md5,
DownloadPath: e.ImageId,
Original: 1,
DownloadPath: &e.ImageId,
Original: proto.Int32(1),
PbReserve: []byte{0x78, 0x02},
},
}
data, _ := proto.Marshal(flash)
r = append(r, &msg.Elem{
CommonElem: &msg.CommonElem{
ServiceType: 3,
ServiceType: proto.Int32(3),
PbElem: data,
},
})
r = append(r, &msg.Elem{
Text: &msg.Text{
Str: "[闪照]请使用新版手机QQ查看闪照。",
Str: proto.String("[闪照]请使用新版手机QQ查看闪照。"),
},
})
return
@ -205,12 +205,12 @@ 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,
FileType: proto.Int32(66),
Useful: proto.Int32(1),
Origin: proto.Int32(1),
FileId: proto.Int32(int32(e.FileId)),
FilePath: &e.ImageId,
Size: &e.Size,
Md5: e.Md5[:],
Flag: make([]byte, 4),
},
@ -218,13 +218,13 @@ func (e *GroupFlashPicElement) Pack() (r []*msg.Elem) {
data, _ := proto.Marshal(flash)
r = append(r, &msg.Elem{
CommonElem: &msg.CommonElem{
ServiceType: 3,
ServiceType: proto.Int32(3),
PbElem: data,
},
})
r = append(r, &msg.Elem{
Text: &msg.Text{
Str: "[闪照]请使用新版手机QQ查看闪照。",
Str: proto.String("[闪照]请使用新版手机QQ查看闪照。"),
},
})
return
@ -233,18 +233,18 @@ func (e *GroupFlashPicElement) Pack() (r []*msg.Elem) {
func (e *GroupShowPicElement) Pack() (r []*msg.Elem) {
r = []*msg.Elem{}
res := &msg.ResvAttr{ImageShow: &msg.AnimationImageShow{
EffectId: e.EffectId,
EffectId: &e.EffectId,
AnimationParam: []byte("{}"),
}}
reserve, _ := proto.Marshal(res)
r = append(r, &msg.Elem{
CustomFace: &msg.CustomFace{
FileType: 0,
Useful: 1,
ImageType: 1001,
FileId: int32(e.FileId),
FilePath: e.ImageId,
Size: e.Size,
FileType: proto.Int32(0),
Useful: proto.Int32(1),
ImageType: proto.Int32(1001),
FileId: proto.Int32(int32(e.FileId)),
FilePath: &e.ImageId,
Size: &e.Size,
Md5: e.Md5[:],
Flag: []byte{0x11, 0x00, 0x00, 0x00},
//OldData: imgOld,