机器人gate登录

This commit is contained in:
flswld
2023-02-14 17:20:17 +08:00
parent c25473b070
commit 4de697cf9a
7 changed files with 236 additions and 80 deletions

14
robot/cmd/dpdk_test.go Normal file
View File

@@ -0,0 +1,14 @@
//go:build linux
// +build linux
package main
import (
"testing"
"github.com/FlourishingWorld/dpdk-go/engine"
)
func TestDpdk(t *testing.T) {
_ = engine.InitEngine("00:0C:29:3E:3E:DF", "192.168.199.199", "255.255.255.0", "192.168.199.1")
}

View File

@@ -1,9 +1,9 @@
package main
import (
"encoding/base64"
"os"
"os/signal"
"strconv"
"syscall"
"time"
@@ -13,51 +13,59 @@ import (
"hk4e/protocol/cmd"
"hk4e/protocol/proto"
"hk4e/robot/login"
"hk4e/robot/net"
"github.com/FlourishingWorld/dpdk-go/engine"
)
func main() {
config.InitConfig("application.toml")
logger.InitLogger("robot")
err := engine.InitEngine("00:0C:29:3E:3E:DF", "192.168.199.199", "255.255.255.0", "192.168.199.1")
if err != nil {
panic(err)
}
engine.RunEngine([]int{0, 1, 2, 3}, 4, 1, "0.0.0.0")
// // DPDK模式需开启
// err := engine.InitEngine("00:0C:29:3E:3E:DF", "192.168.199.199", "255.255.255.0", "192.168.199.1")
// if err != nil {
// panic(err)
// }
// engine.RunEngine([]int{0, 1, 2, 3}, 4, 1, "0.0.0.0")
// time.Sleep(time.Second * 30)
time.Sleep(time.Second * 30)
dispatchInfo, err := login.GetDispatchInfo("https://hk4e.flswld.com", "?version=OSRELWin3.2.0")
dispatchInfo, err := login.GetDispatchInfo("https://hk4e.flswld.com",
"https://hk4e.flswld.com/query_cur_region",
"",
"?version=OSRELWin3.2.0&key_id=5",
"5")
if err != nil {
panic(err)
}
accountInfo, err := login.AccountLogin("https://hk4e.flswld.com", "flswld", "123456")
accountInfo, err := login.AccountLogin("https://hk4e.flswld.com", "test123@@12345678", base64.StdEncoding.EncodeToString([]byte{0x00}))
if err != nil {
panic(err)
}
session, err := login.GateLogin(dispatchInfo, accountInfo, "5")
if err != nil {
panic(err)
}
gateAddr := dispatchInfo.GateIp + strconv.Itoa(int(dispatchInfo.GatePort))
session := net.NewSession(gateAddr, dispatchInfo.DispatchKey, 30000)
go func() {
protoMsg := <-session.RecvChan
logger.Debug("protoMsg: %v", protoMsg)
for {
// 从这个管道接收服务器发来的消息
protoMsg := <-session.RecvChan
logger.Debug("recv protoMsg: %v", protoMsg)
}
}()
go func() {
session.SendChan <- &hk4egatenet.ProtoMsg{
ConvId: 0,
CmdId: cmd.GetPlayerTokenReq,
HeadMessage: &proto.PacketHead{
ClientSequenceId: 1,
SentMs: uint64(time.Now().UnixMilli()),
},
PayloadMessage: &proto.GetPlayerTokenReq{
AccountToken: accountInfo.ComboToken,
AccountUid: strconv.Itoa(int(accountInfo.AccountId)),
KeyId: 5,
ClientRandKey: "",
},
for {
time.Sleep(time.Second)
// 通过这个管道发消息给服务器
session.SendChan <- &hk4egatenet.ProtoMsg{
ConvId: 0,
CmdId: cmd.PingReq,
HeadMessage: &proto.PacketHead{
ClientSequenceId: 0,
SentMs: uint64(time.Now().UnixMilli()),
},
PayloadMessage: &proto.PingReq{
ClientTime: uint32(time.Now().UnixMilli()),
Seq: 0,
},
}
}
}()
@@ -67,7 +75,10 @@ func main() {
s := <-c
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
engine.StopEngine()
// // DPDK模式需开启
// engine.StopEngine()
time.Sleep(time.Second)
return
case syscall.SIGHUP: