优化代码

This commit is contained in:
flswld
2023-02-18 22:09:59 +08:00
parent 21fb9d400f
commit e580baeb46
37 changed files with 198 additions and 118 deletions

View File

@@ -46,7 +46,8 @@ type Hk4e struct {
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的内网地址
LoginSdkUrl string `toml:"login_sdk_url"` // 网关登录验证token的sdk服务器地址 目前填dispatch的内网地址
LoadSceneLuaConfig bool `toml:"load_scene_lua_config"` // 是否加载场景详情LUA配置数据
}
// MQ 消息队列
@@ -59,6 +60,10 @@ func InitConfig(filePath string) {
CONF.loadConfigFile(filePath)
}
func GetConfig() *Config {
return CONF
}
// 加载配置文件
func (c *Config) loadConfigFile(filePath string) {
_, err := toml.DecodeFile(filePath, &c)

View File

@@ -41,7 +41,7 @@ type MessageQueue struct {
func NewMessageQueue(serverType string, appId string, rpcClient *rpc.Client) (r *MessageQueue) {
r = new(MessageQueue)
conn, err := nats.Connect(config.CONF.MQ.NatsUrl)
conn, err := nats.Connect(config.GetConfig().MQ.NatsUrl)
if err != nil {
logger.Error("connect nats error: %v", err)
return nil
@@ -247,7 +247,7 @@ type GateTcpMqEvent struct {
}
func (m *MessageQueue) runGateTcpMqServer() {
addr, err := net.ResolveTCPAddr("tcp4", "0.0.0.0:"+strconv.Itoa(int(config.CONF.Hk4e.GateTcpMqPort)))
addr, err := net.ResolveTCPAddr("tcp4", "0.0.0.0:"+strconv.Itoa(int(config.GetConfig().Hk4e.GateTcpMqPort)))
if err != nil {
logger.Error("gate tcp mq parse port error: %v", err)
return

View File

@@ -19,7 +19,7 @@ type Client struct {
// NewClient 构造
func NewClient() (*Client, error) {
r := new(Client)
conn, err := nats.Connect(config.CONF.MQ.NatsUrl)
conn, err := nats.Connect(config.GetConfig().MQ.NatsUrl)
if err != nil {
return nil, err
}

View File

@@ -9,7 +9,7 @@ import (
)
func UnmarshalProtoObj(serverProtoObj pb.Message, clientProtoObj pb.Message, data []byte) bool {
if config.CONF.Hk4e.ClientProtoProxyEnable {
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
err := pb.Unmarshal(data, clientProtoObj)
if err != nil {
logger.Error("parse client proto obj error: %v", err)