登录代码提交
This commit is contained in:
101
trunk/game/common/config/baseConfig.go
Normal file
101
trunk/game/common/config/baseConfig.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"goutil/configUtil"
|
||||
"goutil/debugUtil"
|
||||
)
|
||||
|
||||
// 基础配置对象
|
||||
type BaseConfig struct {
|
||||
// ChatCenter监听地址
|
||||
ChatCenterAddress string
|
||||
|
||||
// ManageCenter的API的域名地址
|
||||
ManageCenterDomain string
|
||||
|
||||
// 通信协议tcp/websocket
|
||||
Protocol string
|
||||
|
||||
// 内网地址
|
||||
PrivateIP string
|
||||
|
||||
// 公网地址
|
||||
PublicIP string
|
||||
|
||||
// 为ChatServer提价服务的端口
|
||||
ChatServerPort string
|
||||
|
||||
// 为GameServer提供服务的端口
|
||||
GameServerPort string
|
||||
|
||||
// 为GameServer提供服务的Web端口
|
||||
GameServerWebPort string
|
||||
|
||||
// 是否压缩返回给客户端的数据
|
||||
IfCompressData bool
|
||||
|
||||
// GoPs监控程序监听地址
|
||||
GopsAddr string
|
||||
}
|
||||
|
||||
func (this *BaseConfig) GetPrivateChatServerAddress() string {
|
||||
return fmt.Sprintf("%s:%s", this.PrivateIP, this.ChatServerPort)
|
||||
}
|
||||
|
||||
func (this *BaseConfig) GetPrivateGameServerAddress() string {
|
||||
return fmt.Sprintf("%s:%s", this.PrivateIP, this.GameServerPort)
|
||||
}
|
||||
|
||||
func (this *BaseConfig) GetPrivateGameServerWebAddress() string {
|
||||
return fmt.Sprintf("%s:%s", this.PrivateIP, this.GameServerWebPort)
|
||||
}
|
||||
|
||||
func (this *BaseConfig) GetPrivateGopsAddress() string {
|
||||
return fmt.Sprintf("%s:%s", this.PrivateIP, this.GopsAddr)
|
||||
}
|
||||
|
||||
func (this *BaseConfig) GetPublicChatServerAddress() string {
|
||||
return fmt.Sprintf("%s:%s", this.PublicIP, this.ChatServerPort)
|
||||
}
|
||||
|
||||
func (this *BaseConfig) GetPublicGameServerAddress() string {
|
||||
return fmt.Sprintf("%s:%s", this.PublicIP, this.GameServerPort)
|
||||
}
|
||||
|
||||
func (this *BaseConfig) GetPublicGameServerWebAddress() string {
|
||||
return fmt.Sprintf("http://%s:%s/API/player/login", this.PublicIP, this.GameServerWebPort)
|
||||
}
|
||||
|
||||
func (this *BaseConfig) String() string {
|
||||
bytes, _ := json.Marshal(this)
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
var (
|
||||
baseConfig *BaseConfig
|
||||
)
|
||||
|
||||
func initBaseConfig(config *configUtil.XmlConfig) error {
|
||||
tempConfig := new(BaseConfig)
|
||||
err := config.Unmarshal("root/BaseConfig", tempConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
baseConfig = tempConfig
|
||||
debugUtil.Printf("baseConfig:%v\n", baseConfig)
|
||||
|
||||
if baseConfig.Protocol != "tcp" && baseConfig.Protocol != "websocket" {
|
||||
panic("Protocol Error, it should be either tcp or websocket")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBaseConfig 获取服务器基础配置
|
||||
func GetBaseConfig() *BaseConfig {
|
||||
return baseConfig
|
||||
}
|
||||
56
trunk/game/common/config/config.go
Normal file
56
trunk/game/common/config/config.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"goutil/configUtil"
|
||||
"goutil/debugUtil"
|
||||
"goutil/logUtil"
|
||||
)
|
||||
|
||||
var (
|
||||
configManager = configMgr.NewConfigManager()
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 优先加基础配置
|
||||
configManager.RegisterInitFunc(initBaseConfig)
|
||||
configManager.RegisterInitFunc(initDBConfig)
|
||||
configManager.RegisterInitFunc(initMonitorConfig)
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 设置日志文件的存储目录
|
||||
logUtil.SetLogPath("LOG")
|
||||
|
||||
if err := reload(); err != nil {
|
||||
panic(fmt.Errorf("初始化配置文件失败,错误信息为:%s", err))
|
||||
}
|
||||
|
||||
// 注册重新加载的方法
|
||||
reloadMgr.RegisterReloadFunc("config.reload", reload)
|
||||
}
|
||||
|
||||
func reload() error {
|
||||
// 读取配置文件内容
|
||||
configObj := configUtil.NewXmlConfig()
|
||||
err := configObj.LoadFromFile("config.xml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
debug, err := configObj.Bool("root/DEBUG", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 设置debugUtil的状态
|
||||
debugUtil.SetDebug(debug)
|
||||
|
||||
// 调用所有已经注册的配置初始化方法
|
||||
if err := configManager.Init(configObj); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
29
trunk/game/common/config/dbConfig.go
Normal file
29
trunk/game/common/config/dbConfig.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"goutil/configUtil"
|
||||
"goutil/debugUtil"
|
||||
"goutil/mysqlUtil"
|
||||
)
|
||||
|
||||
var (
|
||||
dbConfig *mysqlUtil.DBConfig
|
||||
)
|
||||
|
||||
func initDBConfig(config *configUtil.XmlConfig) error {
|
||||
tempConfig := new(mysqlUtil.DBConfig)
|
||||
err := config.Unmarshal("root/DBConnection", tempConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dbConfig = tempConfig
|
||||
debugUtil.Printf("dbConfig:%v\n", dbConfig)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDBConfig 获取mysql数据库配置
|
||||
func GetDBConfig() *mysqlUtil.DBConfig {
|
||||
return dbConfig
|
||||
}
|
||||
27
trunk/game/common/config/monitorConfig.go
Normal file
27
trunk/game/common/config/monitorConfig.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"goutil/configUtil"
|
||||
"goutil/debugUtil"
|
||||
)
|
||||
|
||||
var (
|
||||
monitorConfig *monitorMgr.MonitorConfig
|
||||
)
|
||||
|
||||
func initMonitorConfig(config *configUtil.XmlConfig) error {
|
||||
tempConfig := new(monitorMgr.MonitorConfig)
|
||||
err := config.Unmarshal("root/MonitorConfig", tempConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
monitorConfig = tempConfig
|
||||
debugUtil.Printf("monitorConfig:%v\n", monitorConfig)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetMonitorConfig 获监测配置
|
||||
func GetMonitorConfig() *monitorMgr.MonitorConfig {
|
||||
return monitorConfig
|
||||
}
|
||||
Reference in New Issue
Block a user