From 94b761717e4d875ce22d3d36c1358e1343ba1aae Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Sat, 11 Feb 2023 15:35:58 +0800 Subject: [PATCH] internal/packets: remove move to other packages. --- client/builders.go | 22 +++++++++++++++++++--- client/internal/network/packet.go | 8 ++++++++ client/network.go | 5 ++--- internal/packets/global.go | 30 ------------------------------ 4 files changed, 29 insertions(+), 36 deletions(-) delete mode 100644 internal/packets/global.go diff --git a/client/builders.go b/client/builders.go index 0bcc1750..1a33a670 100644 --- a/client/builders.go +++ b/client/builders.go @@ -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) buildLoginPacket() (uint16, []byte) { seq := c.nextSeq() t := &oicq.TLV{ @@ -131,7 +147,7 @@ func (c *QQClient) buildQRCodeFetchRequestPacket(size, margin, ecLevel uint32) ( Body: 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 @@ -171,7 +187,7 @@ func (c *QQClient) buildQRCodeResultQueryRequestPacket(sig []byte) (uint16, []by Body: 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 diff --git a/client/internal/network/packet.go b/client/internal/network/packet.go index 492791ef..3af2626f 100644 --- a/client/internal/network/packet.go +++ b/client/internal/network/packet.go @@ -1,5 +1,13 @@ package network +type IncomingPacket struct { + SequenceId uint16 + Flag2 byte + CommandName string + SessionId []byte + Payload []byte +} + type IncomingPacketInfo struct { CommandName string SequenceId uint16 diff --git a/client/network.go b/client/network.go index 26e395c4..80566c0e 100644 --- a/client/network.go +++ b/client/network.go @@ -10,7 +10,6 @@ import ( "github.com/Mrs4s/MiraiGo/client/internal/network" "github.com/Mrs4s/MiraiGo/client/internal/oicq" - "github.com/Mrs4s/MiraiGo/internal/packets" "github.com/Mrs4s/MiraiGo/message" "github.com/Mrs4s/MiraiGo/utils" ) @@ -324,12 +323,12 @@ func (c *QQClient) netLoop() { errCount = 0 c.debug("rev pkt: %v seq: %v", resp.CommandName, resp.SequenceID) c.stat.PacketReceived.Add(1) - pkt := &packets.IncomingPacket{ + pkt := &network.IncomingPacket{ SequenceId: uint16(resp.SequenceID), CommandName: resp.CommandName, Payload: resp.Body, } - go func(pkt *packets.IncomingPacket) { + go func(pkt *network.IncomingPacket) { defer func() { if pan := recover(); pan != nil { c.error("panic on decoder %v : %v\n%s", pkt.CommandName, pan, debug.Stack()) diff --git a/internal/packets/global.go b/internal/packets/global.go deleted file mode 100644 index 32f3ce46..00000000 --- a/internal/packets/global.go +++ /dev/null @@ -1,30 +0,0 @@ -package packets - -import ( - "github.com/Mrs4s/MiraiGo/binary" -) - -type IncomingPacket struct { - SequenceId uint16 - Flag2 byte - CommandName string - SessionId []byte - Payload []byte -} - -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())) - }) -}