gate到robot转发模式

This commit is contained in:
flswld committed 2023-06-15 11:13:03 +08:00
1 parent 8d039dee06
commit 12a8381c43
34 files changed
+3132 -440

No files matched your search

+3
View File
@@ -44,12 +44,15 @@ type Hk4e struct {
GameDataConfigPath string `toml:"game_data_config_path"`
GachaHistoryServer string `toml:"gacha_history_server"`
ClientProtoProxyEnable bool `toml:"client_proto_proxy_enable"`
ForwardModeEnable bool `toml:"forward_mode_enable"`
Version string `toml:"version"` // 支持的客户端协议版本号 三位数字 多个以逗号分隔 如300,310,320
GateTcpMqAddr string `toml:"gate_tcp_mq_addr"` // 访问网关tcp直连消息队列的地址 填网关的内网地址
GateTcpMqPort int32 `toml:"gate_tcp_mq_port"`
LoginSdkUrl string `toml:"login_sdk_url"` // 网关登录验证token的sdk服务器地址 目前填dispatch的内网地址
LoadSceneLuaConfig bool `toml:"load_scene_lua_config"` // 是否加载场景详情LUA配置数据
DispatchUrl string `toml:"dispatch_url"` // 二级dispatch地址 将域名改为dispatch的外网地址
ForwardRegionUrl string `toml:"forward_region_url"` // 转发的一级dispatch地址
ForwardDispatchUrl string `toml:"forward_dispatch_url"` // 转发的二级dispatch地址
}
// Hk4eRobot 原神机器人
+5 -1
View File
@@ -67,7 +67,7 @@ func NewMessageQueue(serverType string, appId string, discoveryClient *rpc.Disco
r.discoveryClient = discoveryClient
if serverType == api.GATE {
go r.runGateTcpMqServer()
} else if serverType == api.GS || serverType == api.ANTICHEAT || serverType == api.PATHFINDING {
} else if serverType == api.GS || serverType == api.ANTICHEAT || serverType == api.PATHFINDING || serverType == api.ROBOT {
go r.runGateTcpMqClient()
}
go r.natsMsgRecvHandler()
@@ -79,6 +79,7 @@ func (m *MessageQueue) Close() {
// 等待所有待发送的消息发送完毕
for {
if len(m.netMsgInput) == 0 {
time.Sleep(time.Millisecond * 100)
break
}
time.Sleep(time.Millisecond * 100)
@@ -173,6 +174,7 @@ func (m *MessageQueue) sendHandler() {
api.GS: make(map[string]*GateTcpMqInst),
api.ANTICHEAT: make(map[string]*GateTcpMqInst),
api.PATHFINDING: make(map[string]*GateTcpMqInst),
api.ROBOT: make(map[string]*GateTcpMqInst),
}
for {
select {
@@ -321,6 +323,8 @@ func (m *MessageQueue) gateTcpMqHandshake(conn net.Conn) {
inst.serverType = api.ANTICHEAT
case api.PATHFINDING:
inst.serverType = api.PATHFINDING
case api.ROBOT:
inst.serverType = api.ROBOT
default:
logger.Error("invalid server type")
return
+18 -7
View File
@@ -49,13 +49,17 @@ type ConnCtrlMsg struct {
}
const (
ServerAppidBindNotify = iota // 玩家连接绑定的各个服务器appid通知
ServerUserOnlineStateChangeNotify // 广播玩家上线和离线状态以及所在GS的appid
ServerUserGsChangeNotify // 跨服玩家迁移通知
ServerUserMpReq // 跨服多人世界相关请求
ServerUserMpRsp // 跨服多人世界相关响应
ServerChatMsgNotify // 跨服玩家聊天消息通知
ServerAddFriendNotify // 跨服添加好友通知
ServerAppidBindNotify = iota // 玩家连接绑定的各个服务器appid通知
ServerUserOnlineStateChangeNotify // 广播玩家上线和离线状态以及所在GS的appid
ServerUserGsChangeNotify // 跨服玩家迁移通知
ServerUserMpReq // 跨服多人世界相关请求
ServerUserMpRsp // 跨服多人世界相关响应
ServerChatMsgNotify // 跨服玩家聊天消息通知
ServerAddFriendNotify // 跨服添加好友通知
ServerForwardModeClientConnNotify // 转发模式客户端连接通知
ServerForwardModeClientCloseNotify // 转发模式客户端断开连接通知
ServerForwardModeServerCloseNotify // 转发模式服务器断开连接通知
ServerForwardDispatchInfoNotify // 转发模式区服信息通知
)
type ServerMsg struct {
@@ -67,6 +71,7 @@ type ServerMsg struct {
UserMpInfo *UserMpInfo
ChatMsgInfo *ChatMsgInfo
AddFriendInfo *AddFriendInfo
ForwardDispatchInfo *ForwardDispatchInfo
}
type OriginInfo struct {
@@ -112,3 +117,9 @@ type AddFriendInfo struct {
TargetUserId uint32
ApplyPlayerOnlineInfo *UserBaseInfo
}
type ForwardDispatchInfo struct {
GateIp string
GatePort uint32
DispatchKey []byte
}
+20
View File
@@ -55,6 +55,26 @@ func (m *MessageQueue) SendToPathfinding(appId string, netMsg *NetMsg) {
m.netMsgInput <- netMsg
}
func (m *MessageQueue) SendToRobot(appId string, netMsg *NetMsg) {
netMsg.Topic = m.getTopic(api.ROBOT, appId)
netMsg.ServerType = api.ROBOT
netMsg.AppId = appId
originServerType, originServerAppId := m.getOriginServer()
netMsg.OriginServerType = originServerType
netMsg.OriginServerAppId = originServerAppId
m.netMsgInput <- netMsg
}
func (m *MessageQueue) SendToDispatch(appId string, netMsg *NetMsg) {
netMsg.Topic = m.getTopic(api.DISPATCH, appId)
netMsg.ServerType = api.DISPATCH
netMsg.AppId = appId
originServerType, originServerAppId := m.getOriginServer()
netMsg.OriginServerType = originServerType
netMsg.OriginServerAppId = originServerAppId
m.netMsgInput <- netMsg
}
func (m *MessageQueue) SendToAll(netMsg *NetMsg) {
netMsg.Topic = "ALL_SERVER_HK4E"
netMsg.ServerType = "ALL_SERVER_HK4E"
+2 -24
View File
@@ -1,7 +1,6 @@
package region
import (
"encoding/base64"
"os"
"hk4e/common/config"
@@ -9,8 +8,6 @@ import (
"hk4e/pkg/logger"
"hk4e/pkg/random"
"hk4e/protocol/proto"
pb "google.golang.org/protobuf/proto"
)
func LoadRsaKey() (signRsaKey []byte, encRsaKeyMap map[string][]byte, pwdRsaKey []byte) {
@@ -21,7 +18,7 @@ func LoadRsaKey() (signRsaKey []byte, encRsaKeyMap map[string][]byte, pwdRsaKey
logger.Error("open region_sign_key.pem error: %v", err)
return nil, nil, nil
}
encKeyIdList := []string{"2", "3", "4", "5"}
encKeyIdList := []string{"1", "2", "3", "4", "5"}
for _, v := range encKeyIdList {
encRsaKeyMap[v], err = os.ReadFile("key/region_enc_key_" + v + ".pem")
if err != nil {
@@ -82,25 +79,6 @@ func GetRegionCurr(kcpAddr string, kcpPort int32, ec2b *random.Ec2b) *proto.Quer
GateserverPort: uint32(kcpPort),
SecretKey: dispatchEc2bData,
}
regionCurr.ClientSecretKey = dispatchEc2bData
return regionCurr
}
func GetRegionListBase64(ec2b *random.Ec2b) string {
regionList := GetRegionList(ec2b)
regionListData, err := pb.Marshal(regionList)
if err != nil {
logger.Error("pb marshal QueryRegionListHttpRsp error: %v", err)
return ""
}
return base64.StdEncoding.EncodeToString(regionListData)
}
func GetRegionCurrBase64(kcpAddr string, kcpPort int32, ec2b *random.Ec2b) string {
regionCurr := GetRegionCurr(kcpAddr, kcpPort, ec2b)
regionCurrData, err := pb.Marshal(regionCurr)
if err != nil {
logger.Error("pb marshal QueryCurrRegionHttpRsp error: %v", err)
return ""
}
return base64.StdEncoding.EncodeToString(regionCurrData)
}