mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
fix group fragmented message parse error.
This commit is contained in:
parent
90633fd3e7
commit
6b4afcf5d7
@ -54,6 +54,7 @@ type QQClient struct {
|
|||||||
|
|
||||||
lastMessageSeq int32
|
lastMessageSeq int32
|
||||||
lastMessageSeqTmp sync.Map
|
lastMessageSeqTmp sync.Map
|
||||||
|
groupMsgBuilders sync.Map
|
||||||
onlinePushCache []int16 // reset on reconnect
|
onlinePushCache []int16 // reset on reconnect
|
||||||
requestPacketRequestId int32
|
requestPacketRequestId int32
|
||||||
messageSeq int32
|
messageSeq int32
|
||||||
|
@ -229,7 +229,7 @@ func decodeMessageSvcPacket(c *QQClient, _ uint16, payload []byte) (interface{},
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeGroupMessagePacket(c *QQClient, _ uint16, payload []byte) (interface{}, error) {
|
func decodeGroupMessagePacket(c *QQClient, seq uint16, payload []byte) (interface{}, error) {
|
||||||
pkt := msg.PushMessagePacket{}
|
pkt := msg.PushMessagePacket{}
|
||||||
err := proto.Unmarshal(payload, &pkt)
|
err := proto.Unmarshal(payload, &pkt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -242,6 +242,25 @@ func decodeGroupMessagePacket(c *QQClient, _ uint16, payload []byte) (interface{
|
|||||||
})
|
})
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
if pkt.Message.Content.PkgNum > 1 {
|
||||||
|
var builder *groupMessageBuilder
|
||||||
|
i, ok := c.groupMsgBuilders.Load(pkt.Message.Content.DivSeq)
|
||||||
|
if !ok {
|
||||||
|
builder = &groupMessageBuilder{
|
||||||
|
MessageSeq: pkt.Message.Content.DivSeq,
|
||||||
|
MessageCount: pkt.Message.Content.PkgNum,
|
||||||
|
}
|
||||||
|
c.groupMsgBuilders.Store(pkt.Message.Content.DivSeq, builder)
|
||||||
|
} else {
|
||||||
|
builder = i.(*groupMessageBuilder)
|
||||||
|
}
|
||||||
|
builder.MessageSlices = append(builder.MessageSlices, pkt.Message)
|
||||||
|
if int32(len(builder.MessageSlices)) >= builder.MessageCount {
|
||||||
|
c.groupMsgBuilders.Delete(pkt.Message.Content.DivSeq)
|
||||||
|
c.dispatchGroupMessage(c.parseGroupMessage(builder.build()))
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
c.dispatchGroupMessage(c.parseGroupMessage(pkt.Message))
|
c.dispatchGroupMessage(c.parseGroupMessage(pkt.Message))
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeviceInfo struct {
|
type DeviceInfo struct {
|
||||||
@ -44,6 +45,12 @@ type Version struct {
|
|||||||
Sdk uint32
|
Sdk uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type groupMessageBuilder struct {
|
||||||
|
MessageSeq int32
|
||||||
|
MessageCount int32
|
||||||
|
MessageSlices []*msg.Message
|
||||||
|
}
|
||||||
|
|
||||||
var SystemDeviceInfo = &DeviceInfo{
|
var SystemDeviceInfo = &DeviceInfo{
|
||||||
Display: []byte("MIRAI.123456.001"),
|
Display: []byte("MIRAI.123456.001"),
|
||||||
Product: []byte("mirai"),
|
Product: []byte("mirai"),
|
||||||
@ -227,3 +234,14 @@ func parseMessageElems(elems []*msg.Elem) []message.IMessageElement {
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *groupMessageBuilder) build() *msg.Message {
|
||||||
|
sort.Slice(b.MessageSlices, func(i, j int) bool {
|
||||||
|
return b.MessageSlices[i].Content.PkgIndex < b.MessageSlices[i].Content.PkgIndex
|
||||||
|
})
|
||||||
|
base := b.MessageSlices[0]
|
||||||
|
for _, m := range b.MessageSlices[1:] {
|
||||||
|
base.Body.RichText.Elems = append(base.Body.RichText.Elems, m.Body.RichText.Elems...)
|
||||||
|
}
|
||||||
|
return base
|
||||||
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -109,6 +109,7 @@ message UinPairMessage {
|
|||||||
|
|
||||||
message Message {
|
message Message {
|
||||||
MessageHead head = 1;
|
MessageHead head = 1;
|
||||||
|
ContentHead content = 2;
|
||||||
MessageBody body = 3;
|
MessageBody body = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user