mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 15:42:25 +08:00
完善机器人
This commit is contained in:
@@ -3,3 +3,20 @@ level = "DEBUG"
|
||||
mode = "CONSOLE"
|
||||
track = true
|
||||
max_size = 10485760
|
||||
|
||||
[hk4e]
|
||||
client_proto_proxy_enable = false
|
||||
|
||||
[hk4e_robot]
|
||||
region_list_url = "https://hk4e.flswld.com" # 一级dispatch地址
|
||||
region_list_param = "" # 一级dispatch的url参数
|
||||
cur_region_url = "https://hk4e.flswld.com/query_cur_region" # 二级dispatch地址
|
||||
cur_region_param = "?version=OSRELWin3.2.0&key_id=5" # 二级dispatch的url参数
|
||||
key_id = "5" # 客户端密钥编号
|
||||
login_sdk_url = "https://hk4e.flswld.com" # sdk登录服务器地址
|
||||
account = "flswld" # 帐号
|
||||
password = "" # base64编码的rsa公钥加密后的密码
|
||||
client_version = "CNRELWin3.2.0_R11611027_S11212885_D11793813" # 客户端版本号
|
||||
dos_enable = false # 是否开启压力测试
|
||||
dos_num = 1 # 压力测试并发数量 帐号自动添加后缀编号
|
||||
dos_loop_login = false # 压力测试是否循环登录退出
|
||||
|
||||
@@ -2,12 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hk4e/pkg/endec"
|
||||
"hk4e/robot/net"
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/protocol/cmd"
|
||||
@@ -22,8 +26,6 @@ func main() {
|
||||
logger.CloseLogger()
|
||||
}()
|
||||
|
||||
config.GetConfig().Hk4e.ClientProtoProxyEnable = false
|
||||
|
||||
// // 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 {
|
||||
@@ -32,8 +34,12 @@ func main() {
|
||||
// engine.RunEngine([]int{0, 1, 2, 3}, 4, 1, "0.0.0.0")
|
||||
// time.Sleep(time.Second * 30)
|
||||
|
||||
for i := 0; i < 1; i++ {
|
||||
go runRobot("test_" + strconv.Itoa(i))
|
||||
if config.GetConfig().Hk4eRobot.DosEnable {
|
||||
for i := 0; i < int(config.GetConfig().Hk4eRobot.DosNum); i++ {
|
||||
go httpLogin(config.GetConfig().Hk4eRobot.Account + "_" + strconv.Itoa(i))
|
||||
}
|
||||
} else {
|
||||
httpLogin(config.GetConfig().Hk4eRobot.Account)
|
||||
}
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
@@ -52,31 +58,63 @@ 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")
|
||||
func httpLogin(account string) {
|
||||
logger.Info("robot start, account: %v", account)
|
||||
dispatchInfo, err := login.GetDispatchInfo(config.GetConfig().Hk4eRobot.RegionListUrl,
|
||||
config.GetConfig().Hk4eRobot.RegionListParam,
|
||||
config.GetConfig().Hk4eRobot.CurRegionUrl,
|
||||
config.GetConfig().Hk4eRobot.CurRegionParam,
|
||||
config.GetConfig().Hk4eRobot.KeyId)
|
||||
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}))
|
||||
accountInfo, err := login.AccountLogin(config.GetConfig().Hk4eRobot.LoginSdkUrl, account, config.GetConfig().Hk4eRobot.Password)
|
||||
if err != nil {
|
||||
logger.Error("account login error: %v", err)
|
||||
return
|
||||
}
|
||||
session, err := login.GateLogin(dispatchInfo, accountInfo, "5")
|
||||
for {
|
||||
gateLogin(account, dispatchInfo, accountInfo)
|
||||
if !config.GetConfig().Hk4eRobot.DosLoopLogin {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
func gateLogin(account string, dispatchInfo *login.DispatchInfo, accountInfo *login.AccountInfo) {
|
||||
session, err := login.GateLogin(dispatchInfo, accountInfo, config.GetConfig().Hk4eRobot.KeyId)
|
||||
if err != nil {
|
||||
logger.Error("gate login error: %v", err)
|
||||
return
|
||||
}
|
||||
clientVersionHashData, err := hex.DecodeString(
|
||||
endec.Sha1Str(config.GetConfig().Hk4eRobot.ClientVersion + session.ClientVersionRandomKey + "mhy2020"),
|
||||
)
|
||||
if err != nil {
|
||||
logger.Error("gen clientVersionHashData error: %v", err)
|
||||
return
|
||||
}
|
||||
session.SendMsg(cmd.PlayerLoginReq, &proto.PlayerLoginReq{
|
||||
AccountUid: strconv.Itoa(int(accountInfo.AccountId)),
|
||||
Token: accountInfo.ComboToken,
|
||||
AccountType: 1,
|
||||
SubChannelId: 1,
|
||||
LanguageType: 2,
|
||||
PlatformType: 3,
|
||||
Checksum: "$008094416f86a051270e64eb0b405a38825",
|
||||
ChecksumClientVersion: "CNRELWin3.2.0",
|
||||
ClientDataVersion: 11793813,
|
||||
ClientVerisonHash: base64.StdEncoding.EncodeToString(clientVersionHashData),
|
||||
ClientVersion: config.GetConfig().Hk4eRobot.ClientVersion,
|
||||
SecurityCmdReply: session.SecurityCmdBuffer,
|
||||
SecurityLibraryMd5: "574a507ffee2eb6f997d11f71c8ae1fa",
|
||||
Token: accountInfo.ComboToken,
|
||||
})
|
||||
clientLogic(account, session)
|
||||
}
|
||||
|
||||
func clientLogic(account string, session *net.Session) {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
pingSeq := uint32(0)
|
||||
for {
|
||||
@@ -92,20 +130,32 @@ func runRobot(name string) {
|
||||
// 从这个管道接收服务器发来的消息
|
||||
logger.Debug("recv protoMsg: %v", protoMsg)
|
||||
switch protoMsg.CmdId {
|
||||
case cmd.PlayerLoginRsp:
|
||||
rsp := protoMsg.PayloadMessage.(*proto.PlayerLoginRsp)
|
||||
logger.Info("login ok, rsp: %v", rsp)
|
||||
case cmd.DoSetPlayerBornDataNotify:
|
||||
session.SendMsg(cmd.SetPlayerBornDataReq, &proto.SetPlayerBornDataReq{
|
||||
AvatarId: 10000007,
|
||||
NickName: name,
|
||||
NickName: account,
|
||||
})
|
||||
case cmd.PlayerEnterSceneNotify:
|
||||
ntf := protoMsg.PayloadMessage.(*proto.PlayerEnterSceneNotify)
|
||||
session.SendMsg(cmd.EnterSceneReadyReq, &proto.EnterSceneReadyReq{EnterSceneToken: ntf.EnterSceneToken})
|
||||
case cmd.EnterSceneReadyRsp:
|
||||
ntf := protoMsg.PayloadMessage.(*proto.EnterSceneReadyRsp)
|
||||
session.SendMsg(cmd.SceneInitFinishReq, &proto.SceneInitFinishReq{EnterSceneToken: ntf.EnterSceneToken})
|
||||
case cmd.SceneInitFinishRsp:
|
||||
ntf := protoMsg.PayloadMessage.(*proto.SceneInitFinishRsp)
|
||||
session.SendMsg(cmd.EnterSceneDoneReq, &proto.EnterSceneDoneReq{EnterSceneToken: ntf.EnterSceneToken})
|
||||
case cmd.EnterSceneDoneRsp:
|
||||
ntf := protoMsg.PayloadMessage.(*proto.EnterSceneDoneRsp)
|
||||
session.SendMsg(cmd.PostEnterSceneReq, &proto.PostEnterSceneReq{EnterSceneToken: ntf.EnterSceneToken})
|
||||
if config.GetConfig().Hk4eRobot.DosLoopLogin {
|
||||
return
|
||||
}
|
||||
}
|
||||
case <-session.DeadEvent:
|
||||
logger.Info("robot exit, name: %v", name)
|
||||
logger.Info("robot exit, account: %v", account)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user