mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
internal/packets: remove
move to other packages.
This commit is contained in:
parent
7f557c197c
commit
94b761717e
@ -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) buildLoginPacket() (uint16, []byte) {
|
func (c *QQClient) buildLoginPacket() (uint16, []byte) {
|
||||||
seq := c.nextSeq()
|
seq := c.nextSeq()
|
||||||
t := &oicq.TLV{
|
t := &oicq.TLV{
|
||||||
@ -131,7 +147,7 @@ func (c *QQClient) buildQRCodeFetchRequestPacket(size, margin, ecLevel uint32) (
|
|||||||
Body: binary.NewWriterF(func(w *binary.Writer) {
|
Body: 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
|
||||||
@ -171,7 +187,7 @@ func (c *QQClient) buildQRCodeResultQueryRequestPacket(sig []byte) (uint16, []by
|
|||||||
Body: binary.NewWriterF(func(w *binary.Writer) {
|
Body: 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
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
package network
|
package network
|
||||||
|
|
||||||
|
type IncomingPacket struct {
|
||||||
|
SequenceId uint16
|
||||||
|
Flag2 byte
|
||||||
|
CommandName string
|
||||||
|
SessionId []byte
|
||||||
|
Payload []byte
|
||||||
|
}
|
||||||
|
|
||||||
type IncomingPacketInfo struct {
|
type IncomingPacketInfo struct {
|
||||||
CommandName string
|
CommandName string
|
||||||
SequenceId uint16
|
SequenceId uint16
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/client/internal/network"
|
"github.com/Mrs4s/MiraiGo/client/internal/network"
|
||||||
"github.com/Mrs4s/MiraiGo/client/internal/oicq"
|
"github.com/Mrs4s/MiraiGo/client/internal/oicq"
|
||||||
"github.com/Mrs4s/MiraiGo/internal/packets"
|
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
"github.com/Mrs4s/MiraiGo/utils"
|
"github.com/Mrs4s/MiraiGo/utils"
|
||||||
)
|
)
|
||||||
@ -324,12 +323,12 @@ func (c *QQClient) netLoop() {
|
|||||||
errCount = 0
|
errCount = 0
|
||||||
c.debug("rev pkt: %v seq: %v", resp.CommandName, resp.SequenceID)
|
c.debug("rev pkt: %v seq: %v", resp.CommandName, resp.SequenceID)
|
||||||
c.stat.PacketReceived.Add(1)
|
c.stat.PacketReceived.Add(1)
|
||||||
pkt := &packets.IncomingPacket{
|
pkt := &network.IncomingPacket{
|
||||||
SequenceId: uint16(resp.SequenceID),
|
SequenceId: uint16(resp.SequenceID),
|
||||||
CommandName: resp.CommandName,
|
CommandName: resp.CommandName,
|
||||||
Payload: resp.Body,
|
Payload: resp.Body,
|
||||||
}
|
}
|
||||||
go func(pkt *packets.IncomingPacket) {
|
go func(pkt *network.IncomingPacket) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if pan := recover(); pan != nil {
|
if pan := recover(); pan != nil {
|
||||||
c.error("panic on decoder %v : %v\n%s", pkt.CommandName, pan, debug.Stack())
|
c.error("panic on decoder %v : %v\n%s", pkt.CommandName, pan, debug.Stack())
|
||||||
|
@ -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()))
|
|
||||||
})
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user