conf.go
4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package conf
import (
"encoding/xml"
"io/ioutil"
_ "strings"
"common/logger"
)
type MysqlConf struct {
Ip string `xml:",attr"`
Port int `xml:",attr"`
User string `xml:",attr"`
Pwd string `xml:",attr"`
Database string `xml:",attr"`
LoadInterval int `xml:",attr"`
}
type ListenAddr struct {
Host string `xml:",attr"`
Test int `xml:",attr"`
SourceType uint32 `xml:",attr"`
}
type ListenRpcAddr struct {
Host string `xml:",attr"`
}
type ZooKeeper struct {
Host string `xml:",attr"`
}
type ClientVersion struct {
Lastest string `xml:",attr"`
}
type Alliance struct {
ClubNumMax int `xml:",attr"`
}
type Jackpot struct {
Award2ClubPercent int `xml:",attr"`
}
type RedisConf struct {
Host string `xml:",attr"`
Db uint32 `xml:",attr"`
Password string `xml:",attr"`
}
type TexasConf struct {
GameDB MysqlConf `xml:"GameDB"`
ListenAddrConf ListenAddr `xml:"ListenAddr"`
ListenRpcAddrConf ListenRpcAddr `xml:"ListenRpcAddr"`
ZooKeeperConf ZooKeeper `xml:"ZooKeeper"`
VersionConf ClientVersion `xml:"ClientVersion"`
BlindConf Blinds `xml:"Blinds"`
HandlevelConf Handlevels `xml:"Handlevels"`
AllianceConf Alliance `xml:"Alliance"`
JackpotConf Jackpot `xml:"Jackpot"`
EventReportHttpAddrConf EventReportHttpAddr `xml:"EventReportHttpAddr"`
ServerHttpAddr ServerHttpAddrConf `xml:"ServerHttpAddr"`
Redis RedisConf `xml:"Redis"`
}
type Blinds struct {
XMLName xml.Name `xml:"Blinds"`
BlindList []Blind `xml:"Blind"`
}
type Blind struct {
XMLName xml.Name `xml:"Blind"`
ID int `xml:",attr"`
Scale int64 `xml:",attr"`
DrawinAmout int64 `xml:",attr"`
}
type Handlevels struct {
XMLName xml.Name `xml:"Handlevels"`
HandlevelList []Handlevel `xml:"Handlevel"`
}
type Handlevel struct {
XMLName xml.Name `xml:"Handlevel"`
ID int `xml:",attr"`
AwardPercent int `xml:",attr"`
}
type EventReportHttpAddr struct {
Host string `xml:",attr"`
CurrencyUri string `xml:",attr"`
EventUri string `xml:",attr"`
FairPlayUri string `xml:",attr"`
DeviceInfoUri string `xml:",attr"`
}
var (
config = new(TexasConf)
)
func GetRedisConf() RedisConf {
return config.Redis
}
func GetGameDBConf() MysqlConf {
return config.GameDB
}
func GetSourceType() uint32 {
return config.ListenAddrConf.SourceType
}
func GetSocketListenAddr() string {
return config.ListenAddrConf.Host
}
func GetRpcListenAddr() string {
return config.ListenRpcAddrConf.Host
}
func GetEventReportHttpAddrConf() EventReportHttpAddr {
return config.EventReportHttpAddrConf
}
func GetLastestVersion() string {
return config.VersionConf.Lastest
}
func GetAllianceClubNumMax() int {
return config.AllianceConf.ClubNumMax
}
func GetAward2ClubPercent() int {
return config.JackpotConf.Award2ClubPercent
}
func LoadConf(filename string) error {
content, err := ioutil.ReadFile(filename)
if err != nil {
logger.Notic("read file:%v error:", filename, err)
return err
}
logger.Info("conf xml:%v", string(content))
err = xml.Unmarshal(content, config)
if err != nil {
logger.Notic("decode xml error:%v", err)
return err
}
DumpConf()
return nil
}
func DumpConf() {
logger.Info("--------------config dump----start--------")
logger.Info("Player Mysql ip:%v port: %V user:%v pwd:%v database:%v", config.GameDB.Ip, config.GameDB.Port, config.GameDB.User, config.GameDB.Pwd, config.GameDB.Database)
logger.Info("ListenAddr:%v", config.ListenAddrConf.Host)
logger.Info("VersionConfg:%v", config.VersionConf.Lastest)
logger.Info("Blinds:%+v", config.BlindConf)
logger.Info("config.BlindConf:%+v", config.BlindConf)
logger.Info("config.HandlevelConf:%+v", config.HandlevelConf)
logger.Info("AllianceConf:%+v", config.AllianceConf.ClubNumMax)
logger.Info("RedisConf:+%v", config.Redis)
logger.Info("--------------config dump----end--------")
}
func GetBlindConf() Blinds {
return config.BlindConf
}
func GetBlindByIndex(idx uint32) Blind {
for _, value := range config.BlindConf.BlindList {
if value.ID == int(idx) {
return value
}
}
return config.BlindConf.BlindList[0]
}
func GetHandlevelByIndex(idx uint32) Handlevel {
for _, value := range config.HandlevelConf.HandlevelList {
if value.ID == int(idx) {
return value
}
}
return config.HandlevelConf.HandlevelList[0]
}
func GetHandlevels() []Handlevel {
return config.HandlevelConf.HandlevelList
}
func IsTest() bool {
if config.ListenAddrConf.Test == 1 {
return true
}
return false
}
func GetServerHttpAddrConf() string {
return config.ServerHttpAddr.Host
}
type ServerHttpAddrConf struct {
Host string `xml:",attr"`
}