Skip to content

Commit

Permalink
client: remove payload parameter in decoder function
Browse files Browse the repository at this point in the history
replace with (*network.Packet).Payload
  • Loading branch information
wdvxdr1123 committed Feb 11, 2023
1 parent 481c830 commit 96d46f6
Show file tree
Hide file tree
Showing 25 changed files with 145 additions and 145 deletions.
24 changes: 12 additions & 12 deletions client/c2c_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
AddressBookSource // 来自通讯录
)

func (c *QQClient) c2cMessageSyncProcessor(rsp *msg.GetMessageResponse, info *network.Packet) {
func (c *QQClient) c2cMessageSyncProcessor(rsp *msg.GetMessageResponse, info network.RequestParams) {
c.sig.SyncCookie = rsp.SyncCookie
c.sig.PubAccountCookie = rsp.PubAccountCookie
// c.msgCtrlBuf = rsp.MsgCtrlBuf
Expand Down Expand Up @@ -73,11 +73,11 @@ func (c *QQClient) c2cMessageSyncProcessor(rsp *msg.GetMessageResponse, info *ne
if rsp.SyncFlag.Unwrap() != msg.SyncFlag_STOP {
c.debug("continue sync with flag: %v", rsp.SyncFlag)
seq, pkt := c.buildGetMessageRequestPacket(rsp.SyncFlag.Unwrap(), time.Now().Unix())
_, _ = c.sendAndWait(seq, pkt, info.Params)
_, _ = c.sendAndWait(seq, pkt, info)
}
}

func (c *QQClient) commMsgProcessor(pMsg *msg.Message, info *network.Packet) {
func (c *QQClient) commMsgProcessor(pMsg *msg.Message, info network.RequestParams) {
strKey := fmt.Sprintf("%d%d%d%d", pMsg.Head.FromUin.Unwrap(), pMsg.Head.ToUin.Unwrap(), pMsg.Head.MsgSeq.Unwrap(), pMsg.Head.MsgUid.Unwrap())
if _, ok := c.msgSvcCache.GetAndUpdate(strKey, time.Hour); ok {
c.debug("c2c msg %v already exists in cache. skip.", pMsg.Head.MsgUid.Unwrap())
Expand All @@ -89,7 +89,7 @@ func (c *QQClient) commMsgProcessor(pMsg *msg.Message, info *network.Packet) {
return
}
c.lastC2CMsgTime = int64(pMsg.Head.MsgTime.Unwrap())
if info.Params.Bool("init") {
if info.Bool("init") {
return
}
if decoder, _ := peekC2CDecoder(pMsg.Head.MsgType.Unwrap()); decoder != nil {
Expand All @@ -99,7 +99,7 @@ func (c *QQClient) commMsgProcessor(pMsg *msg.Message, info *network.Packet) {
}
}

func privateMessageDecoder(c *QQClient, pMsg *msg.Message, _ *network.Packet) {
func privateMessageDecoder(c *QQClient, pMsg *msg.Message, _ network.RequestParams) {
switch pMsg.Head.C2CCmd.Unwrap() {
case 11, 175: // friend msg
if pMsg.Head.FromUin.Unwrap() == c.Uin {
Expand Down Expand Up @@ -141,7 +141,7 @@ func privateMessageDecoder(c *QQClient, pMsg *msg.Message, _ *network.Packet) {
}
}

func privatePttDecoder(c *QQClient, pMsg *msg.Message, _ *network.Packet) {
func privatePttDecoder(c *QQClient, pMsg *msg.Message, _ network.RequestParams) {
if pMsg.Body == nil || pMsg.Body.RichText == nil || pMsg.Body.RichText.Ptt == nil {
return
}
Expand All @@ -152,7 +152,7 @@ func privatePttDecoder(c *QQClient, pMsg *msg.Message, _ *network.Packet) {
c.PrivateMessageEvent.dispatch(c, c.parsePrivateMessage(pMsg))
}

func tempSessionDecoder(c *QQClient, pMsg *msg.Message, _ *network.Packet) {
func tempSessionDecoder(c *QQClient, pMsg *msg.Message, _ network.RequestParams) {
if pMsg.Head.C2CTmpMsgHead == nil || pMsg.Body == nil {
return
}
Expand Down Expand Up @@ -213,7 +213,7 @@ func tempSessionDecoder(c *QQClient, pMsg *msg.Message, _ *network.Packet) {
}
}

func troopAddMemberBroadcastDecoder(c *QQClient, pMsg *msg.Message, _ *network.Packet) {
func troopAddMemberBroadcastDecoder(c *QQClient, pMsg *msg.Message, _ network.RequestParams) {
groupJoinLock.Lock()
defer groupJoinLock.Unlock()
group := c.FindGroupByUin(pMsg.Head.FromUin.Unwrap())
Expand All @@ -240,13 +240,13 @@ func troopAddMemberBroadcastDecoder(c *QQClient, pMsg *msg.Message, _ *network.P
}
}

func systemMessageDecoder(c *QQClient, _ *msg.Message, _ *network.Packet) {
func systemMessageDecoder(c *QQClient, _ *msg.Message, _ network.RequestParams) {
_, pkt := c.buildSystemMsgNewFriendPacket()
_ = c.sendPacket(pkt)
}

func troopSystemMessageDecoder(c *QQClient, pMsg *msg.Message, info *network.Packet) {
if !info.Params.Bool("used_reg_proxy") && pMsg.Head.MsgType.Unwrap() != 85 && pMsg.Head.MsgType.Unwrap() != 36 {
func troopSystemMessageDecoder(c *QQClient, pMsg *msg.Message, info network.RequestParams) {
if !info.Bool("used_reg_proxy") && pMsg.Head.MsgType.Unwrap() != 85 && pMsg.Head.MsgType.Unwrap() != 36 {
c.exceptAndDispatchGroupSysMsg()
}
if len(pMsg.Body.MsgContent) == 0 {
Expand All @@ -260,7 +260,7 @@ func troopSystemMessageDecoder(c *QQClient, pMsg *msg.Message, info *network.Pac
}
}

func msgType0x211Decoder(c *QQClient, pMsg *msg.Message, info *network.Packet) {
func msgType0x211Decoder(c *QQClient, pMsg *msg.Message, info network.RequestParams) {
if pMsg.Head.C2CCmd.Unwrap() == 6 || pMsg.Head.C2CTmpMsgHead != nil {
tempSessionDecoder(c, pMsg, info)
}
Expand Down
2 changes: 1 addition & 1 deletion client/c2c_switch.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (h *handlerInfo) getParams() network.RequestParams {
return h.params
}

var decoders = map[string]func(*QQClient, *network.Packet, []byte) (any, error){
var decoders = map[string]func(*QQClient, *network.Packet) (any, error){
"wtlogin.login": decodeLoginResponse,
"wtlogin.exchange_emp": decodeExchangeEmpResponse,
"wtlogin.trans_emp": decodeTransEmpResponse,
Expand Down
86 changes: 43 additions & 43 deletions client/decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var (
)

// wtlogin.login
func decodeLoginResponse(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
reader := binary.NewReader(payload)
func decodeLoginResponse(c *QQClient, pkt *network.Packet) (any, error) {
reader := binary.NewReader(pkt.Payload)
reader.ReadUInt16() // sub command
t := reader.ReadByte()
reader.ReadUInt16()
Expand Down Expand Up @@ -188,9 +188,9 @@ func decodeLoginResponse(c *QQClient, _ *network.Packet, payload []byte) (any, e
}

// StatSvc.register
func decodeClientRegisterResponse(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeClientRegisterResponse(c *QQClient, pkt *network.Packet) (any, error) {
request := &jce.RequestPacket{}
request.ReadFrom(jce.NewJceReader(payload))
request.ReadFrom(jce.NewJceReader(pkt.Payload))
data := &jce.RequestDataVersion2{}
data.ReadFrom(jce.NewJceReader(request.SBuffer))
svcRsp := &jce.SvcRespRegister{}
Expand All @@ -205,8 +205,8 @@ func decodeClientRegisterResponse(c *QQClient, _ *network.Packet, payload []byte
}

// wtlogin.exchange_emp
func decodeExchangeEmpResponse(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
reader := binary.NewReader(payload)
func decodeExchangeEmpResponse(c *QQClient, pkt *network.Packet) (any, error) {
reader := binary.NewReader(pkt.Payload)
cmd := reader.ReadUInt16()
t := reader.ReadByte()
reader.ReadUInt16()
Expand All @@ -228,11 +228,11 @@ func decodeExchangeEmpResponse(c *QQClient, _ *network.Packet, payload []byte) (
}

// wtlogin.trans_emp
func decodeTransEmpResponse(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
if len(payload) < 48 {
func decodeTransEmpResponse(c *QQClient, pkt *network.Packet) (any, error) {
if len(pkt.Payload) < 48 {
return nil, errors.New("missing payload length")
}
reader := binary.NewReader(payload)
reader := binary.NewReader(pkt.Payload)
reader.ReadBytes(5) // trans req head
reader.ReadByte()
reader.ReadUInt16()
Expand Down Expand Up @@ -317,9 +317,9 @@ func decodeTransEmpResponse(c *QQClient, _ *network.Packet, payload []byte) (any
}

// ConfigPushSvc.PushReq
func decodePushReqPacket(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodePushReqPacket(c *QQClient, pkt *network.Packet) (any, error) {
request := &jce.RequestPacket{}
request.ReadFrom(jce.NewJceReader(payload))
request.ReadFrom(jce.NewJceReader(pkt.Payload))
data := &jce.RequestDataVersion2{}
data.ReadFrom(jce.NewJceReader(request.SBuffer))
r := jce.NewJceReader(data.Map["PushReq"]["ConfigPush.PushReq"][1:])
Expand Down Expand Up @@ -385,25 +385,25 @@ func decodePushReqPacket(c *QQClient, _ *network.Packet, payload []byte) (any, e
}

seq := r.ReadInt64(3)
_, pkt := c.buildConfPushRespPacket(t, seq, jceBuf)
return nil, c.sendPacket(pkt)
_, resp := c.buildConfPushRespPacket(t, seq, jceBuf)
return nil, c.sendPacket(resp)
}

// MessageSvc.PbGetMsg
func decodeMessageSvcPacket(c *QQClient, info *network.Packet, payload []byte) (any, error) {
func decodeMessageSvcPacket(c *QQClient, pkt *network.Packet) (any, error) {
rsp := msg.GetMessageResponse{}
err := proto.Unmarshal(payload, &rsp)
err := proto.Unmarshal(pkt.Payload, &rsp)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
}
c.c2cMessageSyncProcessor(&rsp, info)
c.c2cMessageSyncProcessor(&rsp, pkt.Params)
return nil, nil
}

// MessageSvc.PushNotify
func decodeSvcNotify(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeSvcNotify(c *QQClient, pkt *network.Packet) (any, error) {
request := &jce.RequestPacket{}
request.ReadFrom(jce.NewJceReader(payload[4:]))
request.ReadFrom(jce.NewJceReader(pkt.Payload[4:]))
data := &jce.RequestDataVersion2{}
data.ReadFrom(jce.NewJceReader(request.SBuffer))
if len(data.Map) == 0 {
Expand All @@ -428,9 +428,9 @@ func decodeSvcNotify(c *QQClient, _ *network.Packet, payload []byte) (any, error
}

// SummaryCard.ReqSummaryCard
func decodeSummaryCardResponse(_ *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeSummaryCardResponse(_ *QQClient, pkt *network.Packet) (any, error) {
request := &jce.RequestPacket{}
request.ReadFrom(jce.NewJceReader(payload))
request.ReadFrom(jce.NewJceReader(pkt.Payload))
data := &jce.RequestDataVersion2{}
data.ReadFrom(jce.NewJceReader(request.SBuffer))
rsp := func() *jce.JceReader {
Expand Down Expand Up @@ -494,9 +494,9 @@ func decodeSummaryCardResponse(_ *QQClient, _ *network.Packet, payload []byte) (
}

// friendlist.getFriendGroupList
func decodeFriendGroupListResponse(_ *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeFriendGroupListResponse(_ *QQClient, pkt *network.Packet) (any, error) {
request := &jce.RequestPacket{}
request.ReadFrom(jce.NewJceReader(payload))
request.ReadFrom(jce.NewJceReader(pkt.Payload))
data := &jce.RequestDataVersion3{}
data.ReadFrom(jce.NewJceReader(request.SBuffer))
r := jce.NewJceReader(data.Map["FLRESP"][1:])
Expand All @@ -519,9 +519,9 @@ func decodeFriendGroupListResponse(_ *QQClient, _ *network.Packet, payload []byt
}

// friendlist.delFriend
func decodeFriendDeleteResponse(_ *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeFriendDeleteResponse(_ *QQClient, pkt *network.Packet) (any, error) {
request := &jce.RequestPacket{}
request.ReadFrom(jce.NewJceReader(payload))
request.ReadFrom(jce.NewJceReader(pkt.Payload))
data := &jce.RequestDataVersion3{}
data.ReadFrom(jce.NewJceReader(request.SBuffer))
r := jce.NewJceReader(data.Map["DFRESP"][1:])
Expand All @@ -532,9 +532,9 @@ func decodeFriendDeleteResponse(_ *QQClient, _ *network.Packet, payload []byte)
}

// friendlist.GetTroopListReqV2
func decodeGroupListResponse(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeGroupListResponse(c *QQClient, pkt *network.Packet) (any, error) {
request := &jce.RequestPacket{}
request.ReadFrom(jce.NewJceReader(payload))
request.ReadFrom(jce.NewJceReader(pkt.Payload))
data := &jce.RequestDataVersion3{}
data.ReadFrom(jce.NewJceReader(request.SBuffer))
r := jce.NewJceReader(data.Map["GetTroopListRespV2"][1:])
Expand Down Expand Up @@ -563,9 +563,9 @@ func decodeGroupListResponse(c *QQClient, _ *network.Packet, payload []byte) (an
}

// friendlist.GetTroopMemberListReq
func decodeGroupMemberListResponse(_ *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeGroupMemberListResponse(_ *QQClient, pkt *network.Packet) (any, error) {
request := &jce.RequestPacket{}
request.ReadFrom(jce.NewJceReader(payload))
request.ReadFrom(jce.NewJceReader(pkt.Payload))
data := &jce.RequestDataVersion3{}
data.ReadFrom(jce.NewJceReader(request.SBuffer))
r := jce.NewJceReader(data.Map["GTMLRESP"][1:])
Expand Down Expand Up @@ -597,9 +597,9 @@ func decodeGroupMemberListResponse(_ *QQClient, _ *network.Packet, payload []byt
}

// group_member_card.get_group_member_card_info
func decodeGroupMemberInfoResponse(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeGroupMemberInfoResponse(c *QQClient, pkt *network.Packet) (any, error) {
rsp := pb.GroupMemberRspBody{}
if err := proto.Unmarshal(payload, &rsp); err != nil {
if err := proto.Unmarshal(pkt.Payload, &rsp); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
}
if rsp.MemInfo == nil || (rsp.MemInfo.Nick == nil && rsp.MemInfo.Age == 0) {
Expand Down Expand Up @@ -628,9 +628,9 @@ func decodeGroupMemberInfoResponse(c *QQClient, _ *network.Packet, payload []byt
}

// LongConn.OffPicUp
func decodeOffPicUpResponse(_ *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeOffPicUpResponse(_ *QQClient, pkt *network.Packet) (any, error) {
rsp := cmd0x352.RspBody{}
if err := proto.Unmarshal(payload, &rsp); err != nil {
if err := proto.Unmarshal(pkt.Payload, &rsp); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
}
if rsp.FailMsg != nil {
Expand Down Expand Up @@ -666,9 +666,9 @@ func decodeOffPicUpResponse(_ *QQClient, _ *network.Packet, payload []byte) (any
}

// OnlinePush.PbPushTransMsg
func decodeOnlinePushTransPacket(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeOnlinePushTransPacket(c *QQClient, pkt *network.Packet) (any, error) {
info := msg.TransMsgInfo{}
err := proto.Unmarshal(payload, &info)
err := proto.Unmarshal(pkt.Payload, &info)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
}
Expand Down Expand Up @@ -767,9 +767,9 @@ func decodeOnlinePushTransPacket(c *QQClient, _ *network.Packet, payload []byte)
}

// ProfileService.Pb.ReqSystemMsgNew.Friend
func decodeSystemMsgFriendPacket(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeSystemMsgFriendPacket(c *QQClient, pkt *network.Packet) (any, error) {
rsp := structmsg.RspSystemMsgNew{}
if err := proto.Unmarshal(payload, &rsp); err != nil {
if err := proto.Unmarshal(pkt.Payload, &rsp); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
}
if len(rsp.Friendmsgs) == 0 {
Expand All @@ -789,9 +789,9 @@ func decodeSystemMsgFriendPacket(c *QQClient, _ *network.Packet, payload []byte)
}

// MessageSvc.PushForceOffline
func decodeForceOfflinePacket(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeForceOfflinePacket(c *QQClient, pkt *network.Packet) (any, error) {
request := &jce.RequestPacket{}
request.ReadFrom(jce.NewJceReader(payload))
request.ReadFrom(jce.NewJceReader(pkt.Payload))
data := &jce.RequestDataVersion2{}
data.ReadFrom(jce.NewJceReader(request.SBuffer))
r := jce.NewJceReader(data.Map["req_PushForceOffline"]["PushNotifyPack.RequestPushForceOffline"][1:])
Expand All @@ -802,7 +802,7 @@ func decodeForceOfflinePacket(c *QQClient, _ *network.Packet, payload []byte) (a
}

// StatSvc.ReqMSFOffline
func decodeMSFOfflinePacket(c *QQClient, _ *network.Packet, _ []byte) (any, error) {
func decodeMSFOfflinePacket(c *QQClient, _ *network.Packet) (any, error) {
// c.lastLostMsg = "服务器端强制下线."
c.Disconnect()
// 这个decoder不能消耗太多时间, event另起线程处理
Expand All @@ -811,9 +811,9 @@ func decodeMSFOfflinePacket(c *QQClient, _ *network.Packet, _ []byte) (any, erro
}

// OidbSvc.0xd79
func decodeWordSegmentation(_ *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeWordSegmentation(_ *QQClient, pkt *network.Packet) (any, error) {
rsp := oidb.D79RspBody{}
err := unpackOIDBPackage(payload, &rsp)
err := unpackOIDBPackage(pkt.Payload, &rsp)
if err != nil {
return nil, err
}
Expand All @@ -823,7 +823,7 @@ func decodeWordSegmentation(_ *QQClient, _ *network.Packet, payload []byte) (any
return nil, errors.New("no word received")
}

func decodeSidExpiredPacket(c *QQClient, i *network.Packet, _ []byte) (any, error) {
func decodeSidExpiredPacket(c *QQClient, pkt *network.Packet) (any, error) {
/*
_, err := c.sendAndWait(c.buildRequestChangeSigPacket(true))
if err != nil {
Expand Down Expand Up @@ -855,6 +855,6 @@ func decodeAppInfoResponse(_ *QQClient, _ *incomingPacketInfo, payload []byte) (
}
*/

func ignoreDecoder(_ *QQClient, _ *network.Packet, _ []byte) (any, error) {
func ignoreDecoder(_ *QQClient, _ *network.Packet) (any, error) {
return nil, nil
}
4 changes: 2 additions & 2 deletions client/face.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func (c *QQClient) buildFaceroamRequestPacket() (uint16, []byte) {
return c.uniPacket("Faceroam.OpReq", payload)
}

func decodeFaceroamResponse(c *QQClient, _ *network.Packet, payload []byte) (any, error) {
func decodeFaceroamResponse(c *QQClient, pkt *network.Packet) (any, error) {
rsp := faceroam.FaceroamRspBody{}
if err := proto.Unmarshal(payload, &rsp); err != nil {
if err := proto.Unmarshal(pkt.Payload, &rsp); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
}
if rsp.RspUserInfo == nil {
Expand Down
Loading

0 comments on commit 96d46f6

Please sign in to comment.