1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

network: replace Params with Request

This commit is contained in:
wdvxdr 2022-01-28 22:54:32 +08:00
parent c1cbb69110
commit aa4e0e0bbe
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
7 changed files with 47 additions and 46 deletions

View File

@ -17,7 +17,6 @@ import (
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
"github.com/Mrs4s/MiraiGo/client/pb/profilecard"
"github.com/Mrs4s/MiraiGo/client/pb/structmsg"
"github.com/Mrs4s/MiraiGo/internal/packets"
"github.com/Mrs4s/MiraiGo/internal/proto"
"github.com/Mrs4s/MiraiGo/internal/tlv"
)
@ -27,6 +26,23 @@ var (
syncConst2 = rand.Int63()
)
func buildCode2DRequestPacket(seq uint32, j uint64, cmd uint16, bodyFunc func(writer *binary.Writer)) []byte {
return binary.NewWriterF(func(w *binary.Writer) {
w.WriteByte(2)
pos := w.FillUInt16()
w.WriteUInt16(cmd)
w.Write(make([]byte, 21))
w.WriteByte(3)
w.WriteUInt16(0)
w.WriteUInt16(50) // version
w.WriteUInt32(seq)
w.WriteUInt64(j)
bodyFunc(w)
w.WriteByte(3)
w.WriteUInt16At(pos, uint16(w.Len()))
})
}
func (c *QQClient) buildLoginRequest() *network.Request {
seq := c.nextSeq()
req := c.buildOicqRequestPacket(c.Uin, 0x0810, binary.NewWriterF(func(w *binary.Writer) {
@ -130,7 +146,7 @@ func (c *QQClient) buildQRCodeFetchRequest(size, margin, ecLevel uint32) *networ
req := c.buildOicqRequestPacket(0, 0x0812, binary.NewWriterF(func(w *binary.Writer) {
w.WriteHex(`0001110000001000000072000000`) // trans header
w.WriteUInt32(uint32(time.Now().Unix()))
w.Write(packets.BuildCode2DRequestPacket(0, 0, 0x31, func(w *binary.Writer) {
w.Write(buildCode2DRequestPacket(0, 0, 0x31, func(w *binary.Writer) {
w.WriteUInt16(0) // const
w.WriteUInt32(16) // app id
w.WriteUInt64(0) // const
@ -163,7 +179,7 @@ func (c *QQClient) buildQRCodeResultQueryRequest(sig []byte) *network.Request {
req := c.buildOicqRequestPacket(0, 0x0812, binary.NewWriterF(func(w *binary.Writer) {
w.WriteHex(`0000620000001000000072000000`) // trans header
w.WriteUInt32(uint32(time.Now().Unix()))
w.Write(packets.BuildCode2DRequestPacket(1, 0, 0x12, func(w *binary.Writer) {
w.Write(buildCode2DRequestPacket(1, 0, 0x12, func(w *binary.Writer) {
w.WriteUInt16(5) // const
w.WriteByte(1) // const
w.WriteUInt32(8) // product type

View File

@ -73,7 +73,7 @@ func (c *QQClient) c2cMessageSyncProcessor(rsp *msg.GetMessageResponse, resp *ne
if rsp.GetSyncFlag() != msg.SyncFlag_STOP {
c.Debug("continue sync with flag: %v", rsp.SyncFlag)
req := c.buildGetMessageRequest(rsp.GetSyncFlag(), time.Now().Unix())
req.Params = resp.Params
req.Params = resp.Params()
_, _ = c.callAndDecode(req)
}
}
@ -90,7 +90,7 @@ func (c *QQClient) commMsgProcessor(pMsg *msg.Message, resp *network.Response) {
return
}
c.lastC2CMsgTime = int64(pMsg.Head.GetMsgTime())
if resp.Params.Bool("init") {
if resp.Params().Bool("init") {
return
}
if decoder, _ := peekC2CDecoder(pMsg.Head.GetMsgType()); decoder != nil {
@ -232,7 +232,7 @@ func systemMessageDecoder(c *QQClient, _ *msg.Message, _ *network.Response) {
}
func troopSystemMessageDecoder(c *QQClient, pMsg *msg.Message, info *network.Response) {
if !info.Params.Bool("used_reg_proxy") && pMsg.Head.GetMsgType() != 85 && pMsg.Head.GetMsgType() != 36 {
if !info.Params().Bool("used_reg_proxy") && pMsg.Head.GetMsgType() != 85 && pMsg.Head.GetMsgType() != 36 {
c.exceptAndDispatchGroupSysMsg()
}
if len(pMsg.Body.GetMsgContent()) == 0 {

View File

@ -267,19 +267,20 @@ func decodeTransEmpResponse(c *QQClient, resp *network.Response) (interface{}, e
body.ReadInt32() // app id?
code := body.ReadByte()
if code != 0 {
if code == 0x30 {
return &QRCodeLoginResponse{State: QRCodeWaitingForScan}, nil
var qrResp QRCodeLoginResponse
switch code {
case 0x30:
qrResp.State = QRCodeWaitingForScan
case 0x35:
qrResp.State = QRCodeWaitingForConfirm
case 0x36:
qrResp.State = QRCodeCanceled
case 0x11:
qrResp.State = QRCodeTimeout
default:
return nil, errors.Errorf("wtlogin.trans_emp sub cmd 0x12 error: %v", code)
}
if code == 0x35 {
return &QRCodeLoginResponse{State: QRCodeWaitingForConfirm}, nil
}
if code == 0x36 {
return &QRCodeLoginResponse{State: QRCodeCanceled}, nil
}
if code == 0x11 {
return &QRCodeLoginResponse{State: QRCodeTimeout}, nil
}
return nil, errors.Errorf("wtlogin.trans_emp sub cmd 0x12 error: %v", code)
return qrResp, nil
}
c.Uin = body.ReadInt64()
c.highwaySession.Uin = strconv.FormatInt(c.Uin, 10)

View File

@ -348,7 +348,7 @@ func decodeGetGroupMsgResponse(c *QQClient, resp *network.Response) (interface{}
if m.Head.FromUin == nil {
continue
}
if m.Content != nil && m.Content.GetPkgNum() > 1 && !resp.Params.Bool("raw") {
if m.Content != nil && m.Content.GetPkgNum() > 1 && !resp.Params().Bool("raw") {
if m.Content.GetPkgIndex() == 0 {
c.Debug("build fragmented message from history")
i := m.Head.GetMsgSeq() - m.Content.GetPkgNum()

View File

@ -13,9 +13,15 @@ type Response struct {
CommandName string
Body []byte
Params Params
// Request is the original request that obtained this response.
// Request *Request
Request *Request
}
func (r *Response) Params() Params {
if r.Request == nil {
return nil
}
return r.Request.Params
}
var (

View File

@ -310,7 +310,7 @@ func (c *QQClient) pktProc(req *network.Request, netErr error) {
}
}()
c.Debug("rev resp: %v seq: %v", req.CommandName, req.SequenceID)
c.Debug("recv pkt: %v seq: %v", req.CommandName, req.SequenceID)
c.stat.PacketReceived.Add(1)
// snapshot of read call
@ -321,9 +321,9 @@ func (c *QQClient) pktProc(req *network.Request, netErr error) {
SequenceID: req.SequenceID,
CommandName: req.CommandName,
Body: req.Body,
Params: call.Request.Params,
// Request: nil,
Request: call.Request,
}
delete(c.pending, req.SequenceID)
}
c.pendingMu.Unlock()
if call != nil && call.Request.CommandName == req.CommandName {

View File

@ -1,22 +0,0 @@
package packets
import (
"github.com/Mrs4s/MiraiGo/binary"
)
func BuildCode2DRequestPacket(seq uint32, j uint64, cmd uint16, bodyFunc func(writer *binary.Writer)) []byte {
return binary.NewWriterF(func(w *binary.Writer) {
w.WriteByte(2)
pos := w.FillUInt16()
w.WriteUInt16(cmd)
w.Write(make([]byte, 21))
w.WriteByte(3)
w.WriteUInt16(0)
w.WriteUInt16(50) // version
w.WriteUInt32(seq)
w.WriteUInt64(j)
bodyFunc(w)
w.WriteByte(3)
w.WriteUInt16At(pos, uint16(w.Len()))
})
}