mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 16:02:26 +08:00
机器人进入场景请求
This commit is contained in:
@@ -4,11 +4,11 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"hk4e/common/config"
|
"hk4e/common/config"
|
||||||
hk4egatenet "hk4e/gate/net"
|
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
"hk4e/protocol/cmd"
|
"hk4e/protocol/cmd"
|
||||||
"hk4e/protocol/proto"
|
"hk4e/protocol/proto"
|
||||||
@@ -19,6 +19,8 @@ func main() {
|
|||||||
config.InitConfig("application.toml")
|
config.InitConfig("application.toml")
|
||||||
logger.InitLogger("robot")
|
logger.InitLogger("robot")
|
||||||
|
|
||||||
|
config.CONF.Hk4e.ClientProtoProxyEnable = false
|
||||||
|
|
||||||
// // DPDK模式需开启
|
// // DPDK模式需开启
|
||||||
// err := engine.InitEngine("00:0C:29:3E:3E:DF", "192.168.199.199", "255.255.255.0", "192.168.199.1")
|
// err := engine.InitEngine("00:0C:29:3E:3E:DF", "192.168.199.199", "255.255.255.0", "192.168.199.1")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
@@ -27,47 +29,9 @@ func main() {
|
|||||||
// engine.RunEngine([]int{0, 1, 2, 3}, 4, 1, "0.0.0.0")
|
// 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",
|
for i := 0; i < 1; i++ {
|
||||||
"https://hk4e.flswld.com/query_cur_region",
|
go runRobot("test_" + strconv.Itoa(i))
|
||||||
"",
|
|
||||||
"?version=OSRELWin3.2.0&key_id=5",
|
|
||||||
"5")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
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)
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
// 从这个管道接收服务器发来的消息
|
|
||||||
protoMsg := <-session.RecvChan
|
|
||||||
logger.Debug("recv protoMsg: %v", protoMsg)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
go func() {
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||||
@@ -87,3 +51,62 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runRobot(name string) {
|
||||||
|
logger.Info("robot start, name: %v", name)
|
||||||
|
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 {
|
||||||
|
logger.Error("get dispatch info error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
accountInfo, err := login.AccountLogin("https://hk4e.flswld.com", name+"@@12345678", base64.StdEncoding.EncodeToString([]byte{0x00}))
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("account login error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
session, err := login.GateLogin(dispatchInfo, accountInfo, "5")
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("gate login error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
session.SendMsg(cmd.PlayerLoginReq, &proto.PlayerLoginReq{
|
||||||
|
AccountUid: strconv.Itoa(int(accountInfo.AccountId)),
|
||||||
|
Token: accountInfo.ComboToken,
|
||||||
|
})
|
||||||
|
ticker := time.NewTicker(time.Second)
|
||||||
|
pingSeq := uint32(0)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
pingSeq++
|
||||||
|
// 通过这个接口发消息给服务器
|
||||||
|
session.SendMsg(cmd.PingReq, &proto.PingReq{
|
||||||
|
ClientTime: uint32(time.Now().UnixMilli()),
|
||||||
|
Seq: pingSeq,
|
||||||
|
})
|
||||||
|
case protoMsg := <-session.RecvChan:
|
||||||
|
// 从这个管道接收服务器发来的消息
|
||||||
|
logger.Debug("recv protoMsg: %v", protoMsg)
|
||||||
|
switch protoMsg.CmdId {
|
||||||
|
case cmd.DoSetPlayerBornDataNotify:
|
||||||
|
session.SendMsg(cmd.SetPlayerBornDataReq, &proto.SetPlayerBornDataReq{
|
||||||
|
AvatarId: 10000007,
|
||||||
|
NickName: name,
|
||||||
|
})
|
||||||
|
case cmd.PlayerEnterSceneNotify:
|
||||||
|
ntf := protoMsg.PayloadMessage.(*proto.PlayerEnterSceneNotify)
|
||||||
|
session.SendMsg(cmd.EnterSceneReadyReq, &proto.EnterSceneReadyReq{EnterSceneToken: ntf.EnterSceneToken})
|
||||||
|
session.SendMsg(cmd.SceneInitFinishReq, &proto.SceneInitFinishReq{EnterSceneToken: ntf.EnterSceneToken})
|
||||||
|
session.SendMsg(cmd.EnterSceneDoneReq, &proto.EnterSceneDoneReq{EnterSceneToken: ntf.EnterSceneToken})
|
||||||
|
session.SendMsg(cmd.PostEnterSceneReq, &proto.PostEnterSceneReq{EnterSceneToken: ntf.EnterSceneToken})
|
||||||
|
}
|
||||||
|
case <-session.DeadEvent:
|
||||||
|
logger.Info("robot exit, name: %v", name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,10 +6,8 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"hk4e/common/region"
|
"hk4e/common/region"
|
||||||
hk4egatenet "hk4e/gate/net"
|
|
||||||
"hk4e/pkg/endec"
|
"hk4e/pkg/endec"
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
"hk4e/pkg/random"
|
"hk4e/pkg/random"
|
||||||
@@ -49,20 +47,12 @@ func GateLogin(dispatchInfo *DispatchInfo, accountInfo *AccountInfo, keyId strin
|
|||||||
logger.Error("parse key id error: %v", err)
|
logger.Error("parse key id error: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
session.SendChan <- &hk4egatenet.ProtoMsg{
|
session.SendMsg(cmd.GetPlayerTokenReq, &proto.GetPlayerTokenReq{
|
||||||
ConvId: 0,
|
AccountToken: accountInfo.ComboToken,
|
||||||
CmdId: cmd.GetPlayerTokenReq,
|
AccountUid: strconv.Itoa(int(accountInfo.AccountId)),
|
||||||
HeadMessage: &proto.PacketHead{
|
KeyId: uint32(keyIdInt),
|
||||||
ClientSequenceId: 0,
|
ClientRandKey: clientSeedBase64,
|
||||||
SentMs: uint64(time.Now().UnixMilli()),
|
})
|
||||||
},
|
|
||||||
PayloadMessage: &proto.GetPlayerTokenReq{
|
|
||||||
AccountToken: accountInfo.ComboToken,
|
|
||||||
AccountUid: strconv.Itoa(int(accountInfo.AccountId)),
|
|
||||||
KeyId: uint32(keyIdInt),
|
|
||||||
ClientRandKey: clientSeedBase64,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
protoMsg := <-session.RecvChan
|
protoMsg := <-session.RecvChan
|
||||||
if protoMsg.CmdId != cmd.GetPlayerTokenRsp {
|
if protoMsg.CmdId != cmd.GetPlayerTokenRsp {
|
||||||
return nil, errors.New("recv pkt is not GetPlayerTokenRsp")
|
return nil, errors.New("recv pkt is not GetPlayerTokenRsp")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net
|
package net
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"hk4e/gate/client_proto"
|
"hk4e/gate/client_proto"
|
||||||
@@ -8,6 +9,9 @@ import (
|
|||||||
hk4egatenet "hk4e/gate/net"
|
hk4egatenet "hk4e/gate/net"
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
"hk4e/protocol/cmd"
|
"hk4e/protocol/cmd"
|
||||||
|
"hk4e/protocol/proto"
|
||||||
|
|
||||||
|
pb "google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
@@ -17,6 +21,8 @@ type Session struct {
|
|||||||
RecvChan chan *hk4egatenet.ProtoMsg
|
RecvChan chan *hk4egatenet.ProtoMsg
|
||||||
ServerCmdProtoMap *cmd.CmdProtoMap
|
ServerCmdProtoMap *cmd.CmdProtoMap
|
||||||
ClientCmdProtoMap *client_proto.ClientCmdProtoMap
|
ClientCmdProtoMap *client_proto.ClientCmdProtoMap
|
||||||
|
ClientSeq uint32
|
||||||
|
DeadEvent chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSession(gateAddr string, dispatchKey []byte, localPort int) (*Session, error) {
|
func NewSession(gateAddr string, dispatchKey []byte, localPort int) (*Session, error) {
|
||||||
@@ -37,12 +43,27 @@ func NewSession(gateAddr string, dispatchKey []byte, localPort int) (*Session, e
|
|||||||
RecvChan: make(chan *hk4egatenet.ProtoMsg, 1000),
|
RecvChan: make(chan *hk4egatenet.ProtoMsg, 1000),
|
||||||
ServerCmdProtoMap: cmd.NewCmdProtoMap(),
|
ServerCmdProtoMap: cmd.NewCmdProtoMap(),
|
||||||
ClientCmdProtoMap: client_proto.NewClientCmdProtoMap(),
|
ClientCmdProtoMap: client_proto.NewClientCmdProtoMap(),
|
||||||
|
ClientSeq: 0,
|
||||||
|
DeadEvent: make(chan bool, 10),
|
||||||
}
|
}
|
||||||
go r.recvHandle()
|
go r.recvHandle()
|
||||||
go r.sendHandle()
|
go r.sendHandle()
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Session) SendMsg(cmdId uint16, msg pb.Message) {
|
||||||
|
atomic.AddUint32(&s.ClientSeq, 1)
|
||||||
|
s.SendChan <- &hk4egatenet.ProtoMsg{
|
||||||
|
ConvId: 0,
|
||||||
|
CmdId: cmdId,
|
||||||
|
HeadMessage: &proto.PacketHead{
|
||||||
|
ClientSequenceId: s.ClientSeq,
|
||||||
|
SentMs: uint64(time.Now().UnixMilli()),
|
||||||
|
},
|
||||||
|
PayloadMessage: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Session) recvHandle() {
|
func (s *Session) recvHandle() {
|
||||||
logger.Info("recv handle start")
|
logger.Info("recv handle start")
|
||||||
conn := s.Conn
|
conn := s.Conn
|
||||||
@@ -67,6 +88,7 @@ func (s *Session) recvHandle() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.DeadEvent <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) sendHandle() {
|
func (s *Session) sendHandle() {
|
||||||
@@ -94,4 +116,5 @@ func (s *Session) sendHandle() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.DeadEvent <- true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user