mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
network: replace Params with Request
This commit is contained in:
parent
c1cbb69110
commit
aa4e0e0bbe
@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
|
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
|
||||||
"github.com/Mrs4s/MiraiGo/client/pb/profilecard"
|
"github.com/Mrs4s/MiraiGo/client/pb/profilecard"
|
||||||
"github.com/Mrs4s/MiraiGo/client/pb/structmsg"
|
"github.com/Mrs4s/MiraiGo/client/pb/structmsg"
|
||||||
"github.com/Mrs4s/MiraiGo/internal/packets"
|
|
||||||
"github.com/Mrs4s/MiraiGo/internal/proto"
|
"github.com/Mrs4s/MiraiGo/internal/proto"
|
||||||
"github.com/Mrs4s/MiraiGo/internal/tlv"
|
"github.com/Mrs4s/MiraiGo/internal/tlv"
|
||||||
)
|
)
|
||||||
@ -27,6 +26,23 @@ var (
|
|||||||
syncConst2 = rand.Int63()
|
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 {
|
func (c *QQClient) buildLoginRequest() *network.Request {
|
||||||
seq := c.nextSeq()
|
seq := c.nextSeq()
|
||||||
req := c.buildOicqRequestPacket(c.Uin, 0x0810, binary.NewWriterF(func(w *binary.Writer) {
|
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) {
|
req := c.buildOicqRequestPacket(0, 0x0812, binary.NewWriterF(func(w *binary.Writer) {
|
||||||
w.WriteHex(`0001110000001000000072000000`) // trans header
|
w.WriteHex(`0001110000001000000072000000`) // trans header
|
||||||
w.WriteUInt32(uint32(time.Now().Unix()))
|
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.WriteUInt16(0) // const
|
||||||
w.WriteUInt32(16) // app id
|
w.WriteUInt32(16) // app id
|
||||||
w.WriteUInt64(0) // const
|
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) {
|
req := c.buildOicqRequestPacket(0, 0x0812, binary.NewWriterF(func(w *binary.Writer) {
|
||||||
w.WriteHex(`0000620000001000000072000000`) // trans header
|
w.WriteHex(`0000620000001000000072000000`) // trans header
|
||||||
w.WriteUInt32(uint32(time.Now().Unix()))
|
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.WriteUInt16(5) // const
|
||||||
w.WriteByte(1) // const
|
w.WriteByte(1) // const
|
||||||
w.WriteUInt32(8) // product type
|
w.WriteUInt32(8) // product type
|
||||||
|
@ -73,7 +73,7 @@ func (c *QQClient) c2cMessageSyncProcessor(rsp *msg.GetMessageResponse, resp *ne
|
|||||||
if rsp.GetSyncFlag() != msg.SyncFlag_STOP {
|
if rsp.GetSyncFlag() != msg.SyncFlag_STOP {
|
||||||
c.Debug("continue sync with flag: %v", rsp.SyncFlag)
|
c.Debug("continue sync with flag: %v", rsp.SyncFlag)
|
||||||
req := c.buildGetMessageRequest(rsp.GetSyncFlag(), time.Now().Unix())
|
req := c.buildGetMessageRequest(rsp.GetSyncFlag(), time.Now().Unix())
|
||||||
req.Params = resp.Params
|
req.Params = resp.Params()
|
||||||
_, _ = c.callAndDecode(req)
|
_, _ = c.callAndDecode(req)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ func (c *QQClient) commMsgProcessor(pMsg *msg.Message, resp *network.Response) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.lastC2CMsgTime = int64(pMsg.Head.GetMsgTime())
|
c.lastC2CMsgTime = int64(pMsg.Head.GetMsgTime())
|
||||||
if resp.Params.Bool("init") {
|
if resp.Params().Bool("init") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if decoder, _ := peekC2CDecoder(pMsg.Head.GetMsgType()); decoder != nil {
|
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) {
|
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()
|
c.exceptAndDispatchGroupSysMsg()
|
||||||
}
|
}
|
||||||
if len(pMsg.Body.GetMsgContent()) == 0 {
|
if len(pMsg.Body.GetMsgContent()) == 0 {
|
||||||
|
@ -267,20 +267,21 @@ func decodeTransEmpResponse(c *QQClient, resp *network.Response) (interface{}, e
|
|||||||
body.ReadInt32() // app id?
|
body.ReadInt32() // app id?
|
||||||
code := body.ReadByte()
|
code := body.ReadByte()
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
if code == 0x30 {
|
var qrResp QRCodeLoginResponse
|
||||||
return &QRCodeLoginResponse{State: QRCodeWaitingForScan}, nil
|
switch code {
|
||||||
}
|
case 0x30:
|
||||||
if code == 0x35 {
|
qrResp.State = QRCodeWaitingForScan
|
||||||
return &QRCodeLoginResponse{State: QRCodeWaitingForConfirm}, nil
|
case 0x35:
|
||||||
}
|
qrResp.State = QRCodeWaitingForConfirm
|
||||||
if code == 0x36 {
|
case 0x36:
|
||||||
return &QRCodeLoginResponse{State: QRCodeCanceled}, nil
|
qrResp.State = QRCodeCanceled
|
||||||
}
|
case 0x11:
|
||||||
if code == 0x11 {
|
qrResp.State = QRCodeTimeout
|
||||||
return &QRCodeLoginResponse{State: QRCodeTimeout}, nil
|
default:
|
||||||
}
|
|
||||||
return nil, errors.Errorf("wtlogin.trans_emp sub cmd 0x12 error: %v", code)
|
return nil, errors.Errorf("wtlogin.trans_emp sub cmd 0x12 error: %v", code)
|
||||||
}
|
}
|
||||||
|
return qrResp, nil
|
||||||
|
}
|
||||||
c.Uin = body.ReadInt64()
|
c.Uin = body.ReadInt64()
|
||||||
c.highwaySession.Uin = strconv.FormatInt(c.Uin, 10)
|
c.highwaySession.Uin = strconv.FormatInt(c.Uin, 10)
|
||||||
body.ReadInt32() // sig create time
|
body.ReadInt32() // sig create time
|
||||||
|
@ -348,7 +348,7 @@ func decodeGetGroupMsgResponse(c *QQClient, resp *network.Response) (interface{}
|
|||||||
if m.Head.FromUin == nil {
|
if m.Head.FromUin == nil {
|
||||||
continue
|
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 {
|
if m.Content.GetPkgIndex() == 0 {
|
||||||
c.Debug("build fragmented message from history")
|
c.Debug("build fragmented message from history")
|
||||||
i := m.Head.GetMsgSeq() - m.Content.GetPkgNum()
|
i := m.Head.GetMsgSeq() - m.Content.GetPkgNum()
|
||||||
|
@ -13,9 +13,15 @@ type Response struct {
|
|||||||
CommandName string
|
CommandName string
|
||||||
Body []byte
|
Body []byte
|
||||||
|
|
||||||
Params Params
|
|
||||||
// Request is the original request that obtained this response.
|
// 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 (
|
var (
|
||||||
|
@ -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)
|
c.stat.PacketReceived.Add(1)
|
||||||
|
|
||||||
// snapshot of read call
|
// snapshot of read call
|
||||||
@ -321,9 +321,9 @@ func (c *QQClient) pktProc(req *network.Request, netErr error) {
|
|||||||
SequenceID: req.SequenceID,
|
SequenceID: req.SequenceID,
|
||||||
CommandName: req.CommandName,
|
CommandName: req.CommandName,
|
||||||
Body: req.Body,
|
Body: req.Body,
|
||||||
Params: call.Request.Params,
|
Request: call.Request,
|
||||||
// Request: nil,
|
|
||||||
}
|
}
|
||||||
|
delete(c.pending, req.SequenceID)
|
||||||
}
|
}
|
||||||
c.pendingMu.Unlock()
|
c.pendingMu.Unlock()
|
||||||
if call != nil && call.Request.CommandName == req.CommandName {
|
if call != nil && call.Request.CommandName == req.CommandName {
|
||||||
|
@ -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()))
|
|
||||||
})
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user