mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 17:02:26 +08:00
完善机器人
This commit is contained in:
@@ -10,12 +10,13 @@ var CONF *Config = nil
|
|||||||
|
|
||||||
// Config 配置
|
// Config 配置
|
||||||
type Config struct {
|
type Config struct {
|
||||||
HttpPort int32 `toml:"http_port"`
|
HttpPort int32 `toml:"http_port"`
|
||||||
Logger Logger `toml:"logger"`
|
Logger Logger `toml:"logger"`
|
||||||
Database Database `toml:"database"`
|
Database Database `toml:"database"`
|
||||||
Redis Redis `toml:"redis"`
|
Redis Redis `toml:"redis"`
|
||||||
Hk4e Hk4e `toml:"hk4e"`
|
Hk4e Hk4e `toml:"hk4e"`
|
||||||
MQ MQ `toml:"mq"`
|
Hk4eRobot Hk4eRobot `toml:"hk4e_robot"`
|
||||||
|
MQ MQ `toml:"mq"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logger 日志
|
// Logger 日志
|
||||||
@@ -36,7 +37,7 @@ type Redis struct {
|
|||||||
Password string `toml:"password"`
|
Password string `toml:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hk4e 原神相关
|
// Hk4e 原神服务器
|
||||||
type Hk4e struct {
|
type Hk4e struct {
|
||||||
KcpAddr string `toml:"kcp_addr"` // 该地址只用来注册到节点服务器 填网关的外网地址 网关本地监听为0.0.0.0
|
KcpAddr string `toml:"kcp_addr"` // 该地址只用来注册到节点服务器 填网关的外网地址 网关本地监听为0.0.0.0
|
||||||
KcpPort int32 `toml:"kcp_port"`
|
KcpPort int32 `toml:"kcp_port"`
|
||||||
@@ -51,6 +52,22 @@ type Hk4e struct {
|
|||||||
DispatchUrl string `toml:"dispatch_url"` // 二级dispatch地址 将域名改为dispatch的外网地址
|
DispatchUrl string `toml:"dispatch_url"` // 二级dispatch地址 将域名改为dispatch的外网地址
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hk4eRobot 原神机器人
|
||||||
|
type Hk4eRobot struct {
|
||||||
|
RegionListUrl string `toml:"region_list_url"` // 一级dispatch地址
|
||||||
|
RegionListParam string `toml:"region_list_param"` // 一级dispatch的url参数
|
||||||
|
CurRegionUrl string `toml:"cur_region_url"` // 二级dispatch地址
|
||||||
|
CurRegionParam string `toml:"cur_region_param"` // 二级dispatch的url参数
|
||||||
|
KeyId string `toml:"key_id"` // 客户端密钥编号
|
||||||
|
LoginSdkUrl string `toml:"login_sdk_url"` // sdk登录服务器地址
|
||||||
|
Account string `toml:"account"` // 帐号
|
||||||
|
Password string `toml:"password"` // base64编码的rsa公钥加密后的密码
|
||||||
|
ClientVersion string `toml:"client_version"` // 客户端版本号
|
||||||
|
DosEnable bool `toml:"dos_enable"` // 是否开启压力测试
|
||||||
|
DosNum int32 `toml:"dos_num"` // 压力测试并发数量 帐号自动添加后缀编号
|
||||||
|
DosLoopLogin bool `toml:"dos_loop_login"` // 压力测试是否循环登录退出
|
||||||
|
}
|
||||||
|
|
||||||
// MQ 消息队列
|
// MQ 消息队列
|
||||||
type MQ struct {
|
type MQ struct {
|
||||||
NatsUrl string `toml:"nats_url"`
|
NatsUrl string `toml:"nats_url"`
|
||||||
|
|||||||
@@ -903,39 +903,33 @@ func DialWithOptions(raddr string) (*UDPSession, error) {
|
|||||||
network = "udp"
|
network = "udp"
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := net.ListenUDP(network, nil)
|
conn, err := net.DialUDP(network, nil, udpaddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
hsconn, err := net.DialUDP(network, nil, udpaddr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
enet := &Enet{
|
enet := &Enet{
|
||||||
Addr: raddr,
|
Addr: udpaddr.String(),
|
||||||
ConvId: 0,
|
ConvId: 0,
|
||||||
ConnType: ConnEnetSyn,
|
ConnType: ConnEnetSyn,
|
||||||
EnetType: EnetClientConnectKey,
|
EnetType: EnetClientConnectKey,
|
||||||
}
|
}
|
||||||
data := BuildEnet(enet.ConnType, enet.EnetType, enet.ConvId)
|
data := BuildEnet(enet.ConnType, enet.EnetType, enet.ConvId)
|
||||||
_, err = hsconn.Write(data)
|
_, err = conn.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
buf := make([]byte, mtuLimit)
|
buf := make([]byte, mtuLimit)
|
||||||
n, addr, err := hsconn.ReadFrom(buf)
|
n, addr, err := conn.ReadFrom(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
if addr.String() != raddr {
|
if addr.String() != udpaddr.String() {
|
||||||
// TODO 本质是为了安全考虑 但是用域名连接会出现这种情况看之后找个方法解决一下
|
return nil, errors.WithStack(errors.New("recv packet remote addr not match"))
|
||||||
// return nil, errors.New("recv packet remote addr not match")
|
|
||||||
}
|
}
|
||||||
udpPayload := buf[:n]
|
udpPayload := buf[:n]
|
||||||
connType, enetType, conv, err := ParseEnet(udpPayload)
|
connType, enetType, conv, err := ParseEnet(udpPayload)
|
||||||
if err != nil || connType != ConnEnetEst || enetType != EnetClientConnectKey {
|
if err != nil || connType != ConnEnetEst || enetType != EnetClientConnectKey {
|
||||||
return nil, errors.New("recv packet format error")
|
return nil, errors.WithStack(errors.New("recv packet format error"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return newUDPSession(conv, nil, conn, true, udpaddr), nil
|
return newUDPSession(conv, nil, conn, true, udpaddr), nil
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ func (k *KcpConnectManager) acceptHandle(listener *kcp.Listener) {
|
|||||||
}
|
}
|
||||||
conn.SetACKNoDelay(true)
|
conn.SetACKNoDelay(true)
|
||||||
conn.SetWriteDelay(false)
|
conn.SetWriteDelay(false)
|
||||||
|
conn.SetWindowSize(255, 255)
|
||||||
atomic.AddInt32(&CLIENT_CONN_NUM, 1)
|
atomic.AddInt32(&CLIENT_CONN_NUM, 1)
|
||||||
logger.Info("client connect, convId: %v", convId)
|
logger.Info("client connect, convId: %v", convId)
|
||||||
kcpRawSendChan := make(chan *ProtoMsg, 1000)
|
kcpRawSendChan := make(chan *ProtoMsg, 1000)
|
||||||
|
|||||||
@@ -94,7 +94,13 @@ func EncodePayloadToBin(kcpMsg *KcpMsg, xorKey []byte) (bin []byte) {
|
|||||||
if kcpMsg.ProtoData == nil {
|
if kcpMsg.ProtoData == nil {
|
||||||
kcpMsg.ProtoData = make([]byte, 0)
|
kcpMsg.ProtoData = make([]byte, 0)
|
||||||
}
|
}
|
||||||
bin = make([]byte, len(kcpMsg.HeadData)+len(kcpMsg.ProtoData)+12)
|
// 检查长度
|
||||||
|
packetLen := len(kcpMsg.HeadData) + len(kcpMsg.ProtoData) + 12
|
||||||
|
if packetLen > PacketMaxLen {
|
||||||
|
logger.Error("packet len too long")
|
||||||
|
return make([]byte, 0)
|
||||||
|
}
|
||||||
|
bin = make([]byte, packetLen)
|
||||||
// 头部幻数
|
// 头部幻数
|
||||||
bin[0] = 0x45
|
bin[0] = 0x45
|
||||||
bin[1] = 0x67
|
bin[1] = 0x67
|
||||||
|
|||||||
@@ -3,3 +3,20 @@ level = "DEBUG"
|
|||||||
mode = "CONSOLE"
|
mode = "CONSOLE"
|
||||||
track = true
|
track = true
|
||||||
max_size = 10485760
|
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 (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"hk4e/pkg/endec"
|
||||||
|
"hk4e/robot/net"
|
||||||
|
|
||||||
"hk4e/common/config"
|
"hk4e/common/config"
|
||||||
"hk4e/pkg/logger"
|
"hk4e/pkg/logger"
|
||||||
"hk4e/protocol/cmd"
|
"hk4e/protocol/cmd"
|
||||||
@@ -22,8 +26,6 @@ func main() {
|
|||||||
logger.CloseLogger()
|
logger.CloseLogger()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
config.GetConfig().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 {
|
||||||
@@ -32,8 +34,12 @@ 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)
|
||||||
|
|
||||||
for i := 0; i < 1; i++ {
|
if config.GetConfig().Hk4eRobot.DosEnable {
|
||||||
go runRobot("test_" + strconv.Itoa(i))
|
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)
|
c := make(chan os.Signal, 1)
|
||||||
@@ -52,31 +58,63 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runRobot(name string) {
|
func httpLogin(account string) {
|
||||||
logger.Info("robot start, name: %v", name)
|
logger.Info("robot start, account: %v", account)
|
||||||
dispatchInfo, err := login.GetDispatchInfo("https://hk4e.flswld.com",
|
dispatchInfo, err := login.GetDispatchInfo(config.GetConfig().Hk4eRobot.RegionListUrl,
|
||||||
"https://hk4e.flswld.com/query_cur_region",
|
config.GetConfig().Hk4eRobot.RegionListParam,
|
||||||
"",
|
config.GetConfig().Hk4eRobot.CurRegionUrl,
|
||||||
"?version=OSRELWin3.2.0&key_id=5",
|
config.GetConfig().Hk4eRobot.CurRegionParam,
|
||||||
"5")
|
config.GetConfig().Hk4eRobot.KeyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("get dispatch info error: %v", err)
|
logger.Error("get dispatch info error: %v", err)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
logger.Error("account login error: %v", err)
|
logger.Error("account login error: %v", err)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
logger.Error("gate login error: %v", err)
|
logger.Error("gate login error: %v", err)
|
||||||
return
|
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{
|
session.SendMsg(cmd.PlayerLoginReq, &proto.PlayerLoginReq{
|
||||||
AccountUid: strconv.Itoa(int(accountInfo.AccountId)),
|
AccountType: 1,
|
||||||
Token: accountInfo.ComboToken,
|
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)
|
ticker := time.NewTicker(time.Second)
|
||||||
pingSeq := uint32(0)
|
pingSeq := uint32(0)
|
||||||
for {
|
for {
|
||||||
@@ -92,20 +130,32 @@ func runRobot(name string) {
|
|||||||
// 从这个管道接收服务器发来的消息
|
// 从这个管道接收服务器发来的消息
|
||||||
logger.Debug("recv protoMsg: %v", protoMsg)
|
logger.Debug("recv protoMsg: %v", protoMsg)
|
||||||
switch protoMsg.CmdId {
|
switch protoMsg.CmdId {
|
||||||
|
case cmd.PlayerLoginRsp:
|
||||||
|
rsp := protoMsg.PayloadMessage.(*proto.PlayerLoginRsp)
|
||||||
|
logger.Info("login ok, rsp: %v", rsp)
|
||||||
case cmd.DoSetPlayerBornDataNotify:
|
case cmd.DoSetPlayerBornDataNotify:
|
||||||
session.SendMsg(cmd.SetPlayerBornDataReq, &proto.SetPlayerBornDataReq{
|
session.SendMsg(cmd.SetPlayerBornDataReq, &proto.SetPlayerBornDataReq{
|
||||||
AvatarId: 10000007,
|
AvatarId: 10000007,
|
||||||
NickName: name,
|
NickName: account,
|
||||||
})
|
})
|
||||||
case cmd.PlayerEnterSceneNotify:
|
case cmd.PlayerEnterSceneNotify:
|
||||||
ntf := protoMsg.PayloadMessage.(*proto.PlayerEnterSceneNotify)
|
ntf := protoMsg.PayloadMessage.(*proto.PlayerEnterSceneNotify)
|
||||||
session.SendMsg(cmd.EnterSceneReadyReq, &proto.EnterSceneReadyReq{EnterSceneToken: ntf.EnterSceneToken})
|
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})
|
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})
|
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})
|
session.SendMsg(cmd.PostEnterSceneReq, &proto.PostEnterSceneReq{EnterSceneToken: ntf.EnterSceneToken})
|
||||||
|
if config.GetConfig().Hk4eRobot.DosLoopLogin {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case <-session.DeadEvent:
|
case <-session.DeadEvent:
|
||||||
logger.Info("robot exit, name: %v", name)
|
logger.Info("robot exit, account: %v", account)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ func GateLogin(dispatchInfo *DispatchInfo, accountInfo *AccountInfo, keyId strin
|
|||||||
AccountUid: strconv.Itoa(int(accountInfo.AccountId)),
|
AccountUid: strconv.Itoa(int(accountInfo.AccountId)),
|
||||||
KeyId: uint32(keyIdInt),
|
KeyId: uint32(keyIdInt),
|
||||||
ClientRandKey: clientSeedBase64,
|
ClientRandKey: clientSeedBase64,
|
||||||
|
AccountType: 1,
|
||||||
|
ChannelId: 1,
|
||||||
|
SubChannelId: 1,
|
||||||
|
PlatformType: 3,
|
||||||
})
|
})
|
||||||
protoMsg := <-session.RecvChan
|
protoMsg := <-session.RecvChan
|
||||||
if protoMsg.CmdId != cmd.GetPlayerTokenRsp {
|
if protoMsg.CmdId != cmd.GetPlayerTokenRsp {
|
||||||
@@ -92,5 +96,7 @@ func GateLogin(dispatchInfo *DispatchInfo, accountInfo *AccountInfo, keyId strin
|
|||||||
key := make([]byte, 4096)
|
key := make([]byte, 4096)
|
||||||
copy(key, xorKey[:])
|
copy(key, xorKey[:])
|
||||||
session.XorKey = key
|
session.XorKey = key
|
||||||
|
session.ClientVersionRandomKey = getPlayerTokenRsp.ClientVersionRandomKey
|
||||||
|
session.SecurityCmdBuffer = getPlayerTokenRsp.SecurityCmdBuffer
|
||||||
return session, nil
|
return session, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type DispatchInfo struct {
|
|||||||
DispatchKey []byte
|
DispatchKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDispatchInfo(regionListUrl string, curRegionUrl string, regionListParam string, curRegionParam string, keyId string) (*DispatchInfo, error) {
|
func GetDispatchInfo(regionListUrl string, regionListParam string, curRegionUrl string, curRegionParam string, keyId string) (*DispatchInfo, error) {
|
||||||
logger.Info("http get url: %v", regionListUrl+"/query_region_list"+regionListParam)
|
logger.Info("http get url: %v", regionListUrl+"/query_region_list"+regionListParam)
|
||||||
regionListBase64, err := httpclient.GetRaw(regionListUrl + "/query_region_list" + regionListParam)
|
regionListBase64, err := httpclient.GetRaw(regionListUrl + "/query_region_list" + regionListParam)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -115,14 +115,14 @@ type AccountInfo struct {
|
|||||||
ComboToken string
|
ComboToken string
|
||||||
}
|
}
|
||||||
|
|
||||||
func AccountLogin(url string, account string, password string) (*AccountInfo, error) {
|
func AccountLogin(loginSdkUrl string, account string, password string) (*AccountInfo, error) {
|
||||||
loginAccountRequestJson := &api.LoginAccountRequestJson{
|
loginAccountRequestJson := &api.LoginAccountRequestJson{
|
||||||
Account: account,
|
Account: account,
|
||||||
Password: password,
|
Password: password,
|
||||||
IsCrypto: true,
|
IsCrypto: true,
|
||||||
}
|
}
|
||||||
logger.Info("http post url: %v", url+"/hk4e_global/mdk/shield/api/login")
|
logger.Info("http post url: %v", loginSdkUrl+"/hk4e_global/mdk/shield/api/login")
|
||||||
loginResult, err := httpclient.PostJson[api.LoginResult](url+"/hk4e_global/mdk/shield/api/login", loginAccountRequestJson)
|
loginResult, err := httpclient.PostJson[api.LoginResult](loginSdkUrl+"/hk4e_global/mdk/shield/api/login", loginAccountRequestJson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -147,8 +147,8 @@ func AccountLogin(url string, account string, password string) (*AccountInfo, er
|
|||||||
ChannelID: 1,
|
ChannelID: 1,
|
||||||
Data: string(loginTokenDataJson),
|
Data: string(loginTokenDataJson),
|
||||||
}
|
}
|
||||||
logger.Info("http post url: %v", url+"/hk4e_global/combo/granter/login/v2/login")
|
logger.Info("http post url: %v", loginSdkUrl+"/hk4e_global/combo/granter/login/v2/login")
|
||||||
comboTokenRsp, err := httpclient.PostJson[api.ComboTokenRsp](url+"/hk4e_global/combo/granter/login/v2/login", comboTokenReq)
|
comboTokenRsp, err := httpclient.PostJson[api.ComboTokenRsp](loginSdkUrl+"/hk4e_global/combo/granter/login/v2/login", comboTokenReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"hk4e/common/config"
|
||||||
|
|
||||||
"hk4e/gate/client_proto"
|
"hk4e/gate/client_proto"
|
||||||
"hk4e/gate/kcp"
|
"hk4e/gate/kcp"
|
||||||
hk4egatenet "hk4e/gate/net"
|
hk4egatenet "hk4e/gate/net"
|
||||||
@@ -15,14 +17,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
Conn *kcp.UDPSession
|
Conn *kcp.UDPSession
|
||||||
XorKey []byte
|
XorKey []byte
|
||||||
SendChan chan *hk4egatenet.ProtoMsg
|
SendChan chan *hk4egatenet.ProtoMsg
|
||||||
RecvChan chan *hk4egatenet.ProtoMsg
|
RecvChan chan *hk4egatenet.ProtoMsg
|
||||||
ServerCmdProtoMap *cmd.CmdProtoMap
|
ServerCmdProtoMap *cmd.CmdProtoMap
|
||||||
ClientCmdProtoMap *client_proto.ClientCmdProtoMap
|
ClientCmdProtoMap *client_proto.ClientCmdProtoMap
|
||||||
ClientSeq uint32
|
ClientSeq uint32
|
||||||
DeadEvent chan bool
|
DeadEvent chan bool
|
||||||
|
ClientVersionRandomKey string
|
||||||
|
SecurityCmdBuffer []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSession(gateAddr string, dispatchKey []byte, localPort int) (*Session, error) {
|
func NewSession(gateAddr string, dispatchKey []byte, localPort int) (*Session, error) {
|
||||||
@@ -36,15 +40,21 @@ func NewSession(gateAddr string, dispatchKey []byte, localPort int) (*Session, e
|
|||||||
}
|
}
|
||||||
conn.SetACKNoDelay(true)
|
conn.SetACKNoDelay(true)
|
||||||
conn.SetWriteDelay(false)
|
conn.SetWriteDelay(false)
|
||||||
|
conn.SetWindowSize(255, 255)
|
||||||
r := &Session{
|
r := &Session{
|
||||||
Conn: conn,
|
Conn: conn,
|
||||||
XorKey: dispatchKey,
|
XorKey: dispatchKey,
|
||||||
SendChan: make(chan *hk4egatenet.ProtoMsg, 1000),
|
SendChan: make(chan *hk4egatenet.ProtoMsg, 1000),
|
||||||
RecvChan: make(chan *hk4egatenet.ProtoMsg, 1000),
|
RecvChan: make(chan *hk4egatenet.ProtoMsg, 1000),
|
||||||
ServerCmdProtoMap: cmd.NewCmdProtoMap(),
|
ServerCmdProtoMap: cmd.NewCmdProtoMap(),
|
||||||
ClientCmdProtoMap: client_proto.NewClientCmdProtoMap(),
|
ClientCmdProtoMap: nil,
|
||||||
ClientSeq: 0,
|
ClientSeq: 0,
|
||||||
DeadEvent: make(chan bool, 10),
|
DeadEvent: make(chan bool, 10),
|
||||||
|
ClientVersionRandomKey: "",
|
||||||
|
SecurityCmdBuffer: nil,
|
||||||
|
}
|
||||||
|
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
|
||||||
|
r.ClientCmdProtoMap = client_proto.NewClientCmdProtoMap()
|
||||||
}
|
}
|
||||||
go r.recvHandle()
|
go r.recvHandle()
|
||||||
go r.sendHandle()
|
go r.sendHandle()
|
||||||
|
|||||||
Reference in New Issue
Block a user