mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
tidy: 将c2cDecoders switch化
This commit is contained in:
parent
80e2d83dab
commit
7a6c0df081
33
client/c2c_decoders.go
Normal file
33
client/c2c_decoders.go
Normal file
@ -0,0 +1,33 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package client
|
||||
|
||||
import "github.com/Mrs4s/MiraiGo/client/pb/msg"
|
||||
|
||||
var privateMsgDecoders = map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo){
|
||||
9: privateMessageDecoder, 10: privateMessageDecoder, 31: privateMessageDecoder,
|
||||
79: privateMessageDecoder, 97: privateMessageDecoder, 120: privateMessageDecoder,
|
||||
132: privateMessageDecoder, 133: privateMessageDecoder, 166: privateMessageDecoder,
|
||||
167: privateMessageDecoder, 140: tempSessionDecoder, 141: tempSessionDecoder,
|
||||
208: privatePttDecoder,
|
||||
}
|
||||
|
||||
var nonSvcNotifyTroopSystemMsgDecoders = map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo){
|
||||
36: troopSystemMessageDecoder, 85: troopSystemMessageDecoder,
|
||||
}
|
||||
|
||||
var troopSystemMsgDecoders = map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo){
|
||||
35: troopSystemMessageDecoder, 37: troopSystemMessageDecoder,
|
||||
45: troopSystemMessageDecoder, 46: troopSystemMessageDecoder, 84: troopSystemMessageDecoder,
|
||||
86: troopSystemMessageDecoder, 87: troopSystemMessageDecoder,
|
||||
} // IsSvcNotify
|
||||
|
||||
var sysMsgDecoders = map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo){
|
||||
187: systemMessageDecoder, 188: systemMessageDecoder, 189: systemMessageDecoder,
|
||||
190: systemMessageDecoder, 191: systemMessageDecoder,
|
||||
} // IsSvcNotify
|
||||
|
||||
var otherDecoders = map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo){
|
||||
33: troopAddMemberBroadcastDecoder, 529: msgType0x211Decoder,
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package client
|
||||
|
||||
//go:generate go run c2c_switcher.go
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
@ -13,31 +15,6 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
var privateMsgDecoders = map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo){
|
||||
9: privateMessageDecoder, 10: privateMessageDecoder, 31: privateMessageDecoder,
|
||||
79: privateMessageDecoder, 97: privateMessageDecoder, 120: privateMessageDecoder,
|
||||
132: privateMessageDecoder, 133: privateMessageDecoder, 166: privateMessageDecoder,
|
||||
167: privateMessageDecoder, 140: tempSessionDecoder, 141: tempSessionDecoder,
|
||||
208: privatePttDecoder,
|
||||
}
|
||||
|
||||
var troopSystemMsgDecoders = map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo){
|
||||
35: troopSystemMessageDecoder, 36: troopSystemMessageDecoder, 37: troopSystemMessageDecoder,
|
||||
45: troopSystemMessageDecoder, 46: troopSystemMessageDecoder, 84: troopSystemMessageDecoder,
|
||||
85: troopSystemMessageDecoder, 86: troopSystemMessageDecoder, 87: troopSystemMessageDecoder,
|
||||
}
|
||||
|
||||
var sysMsgDecoders = map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo){
|
||||
187: systemMessageDecoder, 188: systemMessageDecoder, 189: systemMessageDecoder,
|
||||
190: systemMessageDecoder, 191: systemMessageDecoder,
|
||||
}
|
||||
|
||||
var otherDecoders = map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo){
|
||||
33: troopAddMemberBroadcastDecoder, 529: msgType0x211Decoder,
|
||||
}
|
||||
|
||||
var c2cDecoders = map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo){}
|
||||
|
||||
type (
|
||||
TempSessionInfo struct {
|
||||
Source TempSessionSource
|
||||
@ -62,18 +39,6 @@ const (
|
||||
AddressBookSource TempSessionSource = 9 // 来自通讯录
|
||||
)
|
||||
|
||||
func init() {
|
||||
merge := func(m map[int32]func(*QQClient, *msg.Message, *incomingPacketInfo)) {
|
||||
for k, v := range m {
|
||||
c2cDecoders[k] = v
|
||||
}
|
||||
}
|
||||
merge(privateMsgDecoders)
|
||||
merge(troopSystemMsgDecoders)
|
||||
merge(sysMsgDecoders)
|
||||
merge(otherDecoders)
|
||||
}
|
||||
|
||||
func (c *QQClient) c2cMessageSyncProcessor(rsp *msg.GetMessageResponse, info *incomingPacketInfo) {
|
||||
c.syncCookie = rsp.SyncCookie
|
||||
c.pubAccountCookie = rsp.PubAccountCookie
|
||||
@ -127,7 +92,7 @@ func (c *QQClient) commMsgProcessor(pMsg *msg.Message, info *incomingPacketInfo)
|
||||
if info.Params.bool("init") {
|
||||
return
|
||||
}
|
||||
if decoder, ok := c2cDecoders[pMsg.Head.GetMsgType()]; ok {
|
||||
if decoder, _ := peekC2CDecoder(pMsg.Head.GetMsgType()); decoder != nil {
|
||||
decoder(c, pMsg, info)
|
||||
} else {
|
||||
c.Debug("unknown msg type on c2c processor: %v - %v", pMsg.Head.GetMsgType(), pMsg.Head.GetC2CCmd())
|
||||
|
@ -395,14 +395,17 @@ func decodeSvcNotify(c *QQClient, _ *incomingPacketInfo, payload []byte) (interf
|
||||
}
|
||||
notify := &jce.RequestPushNotify{}
|
||||
notify.ReadFrom(jce.NewJceReader(data.Map["req_PushNotify"]["PushNotifyPack.RequestPushNotify"][1:]))
|
||||
if _, ok := troopSystemMsgDecoders[notify.MsgType]; ok && notify.MsgType != 85 && notify.MsgType != 36 {
|
||||
if decoder, typ := peekC2CDecoder(notify.MsgType); decoder != nil {
|
||||
// notify.MsgType != 85 && notify.MsgType != 36 moves to c2c_decoders.go [nonSvcNotifyTroopSystemMsgDecoders]
|
||||
if typ == troopSystemMsgDecoders {
|
||||
c.exceptAndDispatchGroupSysMsg()
|
||||
return nil, nil
|
||||
}
|
||||
if _, ok := sysMsgDecoders[notify.MsgType]; ok {
|
||||
if typ == sysMsgDecoders {
|
||||
_, pkt := c.buildSystemMsgNewFriendPacket()
|
||||
return nil, c.sendPacket(pkt)
|
||||
}
|
||||
}
|
||||
_, err := c.sendAndWait(c.buildGetMessageRequestPacket(msg.SyncFlag_START, time.Now().Unix()))
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user