forked from xiaonanln/goworld
/
read_config.go
702 lines (627 loc) · 20 KB
/
read_config.go
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
package config
import (
"strings"
"strconv"
"fmt"
"encoding/json"
"sync"
"sort"
"time"
"path"
"github.com/go-ini/ini"
"github.com/pkg/errors"
"github.com/xiaonanln/goworld/engine/common"
"github.com/xiaonanln/goworld/engine/gwlog"
)
const (
_DEFAULT_CONFIG_FILE = "goworld.ini"
_DEFAULT_LOCALHOST_IP = "127.0.0.1"
_DEFAULT_SAVE_ITNERVAL = time.Minute * 5
_DEFAULT_HTTP_IP = "127.0.0.1"
_DEFAULT_LOG_LEVEL = "debug"
_DEFAULT_STORAGE_DB = "goworld"
)
var (
configFilePath = _DEFAULT_CONFIG_FILE
goWorldConfig *GoWorldConfig
configLock sync.Mutex
)
// GameConfig defines fields of game config
type GameConfig struct {
BootEntity string
SaveInterval time.Duration
LogFile string
LogStderr bool
HTTPIp string
HTTPPort int
LogLevel string
GoMaxProcs int
PositionSyncIntervalMS int
BanBootEntity bool
}
// GateConfig defines fields of gate config
type GateConfig struct {
Ip string
Port int
LogFile string
LogStderr bool
HTTPIp string
HTTPPort int
LogLevel string
GoMaxProcs int
CompressConnection bool
CompressFormat string
EncryptConnection bool
RSAKey string
RSACertificate string
HeartbeatCheckInterval int
PositionSyncIntervalMS int
}
// DispatcherConfig defines fields of dispatcher config
type DispatcherConfig struct {
BindIp string
BindPort int
Ip string
Port int
LogFile string
LogStderr bool
HTTPIp string
HTTPPort int
LogLevel string
}
// GoWorldConfig defines the total GoWorld config file structure
type GoWorldConfig struct {
DispatcherCommon DispatcherConfig
GameCommon GameConfig
GateCommon GateConfig
Dispatchers map[int]*DispatcherConfig
Games map[int]*GameConfig
Gates map[int]*GateConfig
Storage StorageConfig
KVDB KVDBConfig
Debug DebugConfig
}
// StorageConfig defines fields of storage config
type StorageConfig struct {
Type string // Type of storage (filesystem, mongodb, redis, mysql)
Directory string // Directory of filesystem storage (filesystem)
Url string // Connection URL (mongodb, redis, mysql)
DB string // Database name (mongodb, redis)
Driver string // SQL Driver name (mysql)
StartNodes common.StringSet
}
// KVDBConfig defines fields of KVDB config
type KVDBConfig struct {
Type string
Url string // MongoDB
DB string // MongoDB
Collection string // MongoDB
Driver string // SQL Driver: e.x. mysql
StartNodes common.StringSet
}
type DebugConfig struct {
Debug bool
}
// SetConfigFile sets the config file path (goworld.ini by default)
func SetConfigFile(f string) {
configFilePath = f
}
// GetConfigDir returns the directory of goworld.ini
func GetConfigDir() string {
dir, _ := path.Split(configFilePath)
return dir
}
// GetConfigFilePath returns the config file path
func GetConfigFilePath() string {
return configFilePath
}
// Get returns the total GoWorld config
func Get() *GoWorldConfig {
configLock.Lock()
defer configLock.Unlock() // protect concurrent access from Games & Gate
if goWorldConfig == nil {
goWorldConfig = readGoWorldConfig()
gwlog.Infof(">>> config <<< debug = %v", goWorldConfig.Debug.Debug)
gwlog.Infof(">>> config <<< dispatcher count = %d", len(goWorldConfig.Dispatchers))
gwlog.Infof(">>> config <<< game count = %d", len(goWorldConfig.Games))
gwlog.Infof(">>> config <<< gate count = %d", len(goWorldConfig.Gates))
gwlog.Infof(">>> config <<< storage type = %s", goWorldConfig.Storage.Type)
gwlog.Infof(">>> config <<< KVDB type = %s", goWorldConfig.KVDB.Type)
}
return goWorldConfig
}
// Reload forces goworld server to reload the whole config
func Reload() *GoWorldConfig {
configLock.Lock()
goWorldConfig = nil
configLock.Unlock()
return Get()
}
// GetGame gets the game config of specified game ID
func GetGame(gameid uint16) *GameConfig {
return Get().Games[int(gameid)]
}
// GetGate gets the gate config of specified gate ID
func GetGate(gateid uint16) *GateConfig {
return Get().Gates[int(gateid)]
}
// GetDispatcherIDs returns all dispatcher IDs
func GetDispatcherIDs() []uint16 {
cfg := Get()
dispIDs := make([]int, 0, len(cfg.Dispatchers))
for id := range cfg.Dispatchers {
dispIDs = append(dispIDs, id)
}
sort.Ints(dispIDs)
res := make([]uint16, len(dispIDs))
for i, id := range dispIDs {
res[i] = uint16(id)
}
return res
}
// GetGameIDs returns all game IDs
func GetGameIDs() []uint16 {
cfg := Get()
gameIDs := make([]int, 0, len(cfg.Games))
for id := range cfg.Games {
gameIDs = append(gameIDs, id)
}
sort.Ints(gameIDs)
res := make([]uint16, len(gameIDs))
for i, id := range gameIDs {
res[i] = uint16(id)
}
return res
}
// GetGameNum returns the number of games
func GetGamesNum() int {
return len(Get().Games)
}
// GetGateIDs returns all gate IDs
func GetGateIDs() []uint16 {
cfg := Get()
gateIDs := make([]int, 0, len(cfg.Gates))
for id := range cfg.Gates {
gateIDs = append(gateIDs, id)
}
sort.Ints(gateIDs)
res := make([]uint16, len(gateIDs))
for i, id := range gateIDs {
res[i] = uint16(id)
}
return res
}
// GetGatesNum returns the number of gates
func GetGatesNum() int {
return len(Get().Gates)
}
// GetDispatcher returns the dispatcher config
func GetDispatcher(dispid uint16) *DispatcherConfig {
return Get().Dispatchers[int(dispid)]
}
// GetStorage returns the storage config
func GetStorage() *StorageConfig {
return &Get().Storage
}
// GetKVDB returns the KVDB config
func GetKVDB() *KVDBConfig {
return &Get().KVDB
}
// DumpPretty format config to string in pretty format
func DumpPretty(cfg interface{}) string {
s, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return err.Error()
}
return string(s)
}
func Debug() bool {
return Get().Debug.Debug
}
func readGoWorldConfig() *GoWorldConfig {
config := GoWorldConfig{
Dispatchers: map[int]*DispatcherConfig{},
Games: map[int]*GameConfig{},
Gates: map[int]*GateConfig{},
}
gwlog.Infof("Using config file: %s", configFilePath)
iniFile, err := ini.Load(configFilePath)
checkConfigError(err, "")
gameCommonSec := iniFile.Section("game_common")
readGameCommonConfig(gameCommonSec, &config.GameCommon)
gateCommonSec := iniFile.Section("gate_common")
readGateCommonConfig(gateCommonSec, &config.GateCommon)
dispatcherCommonSec := iniFile.Section("dispatcher_common")
readDispatcherCommonConfig(dispatcherCommonSec, &config.DispatcherCommon)
for _, sec := range iniFile.Sections() {
secName := sec.Name()
if secName == "DEFAULT" {
continue
}
//gwlog.Infof("Section %s", sec.Name())
secName = strings.ToLower(secName)
if secName == "game_common" || secName == "gate_common" || secName == "dispatcher_common" {
// ignore common section here
} else if len(secName) > 10 && secName[:10] == "dispatcher" {
// dispatcher config
id, err := strconv.Atoi(secName[10:])
checkConfigError(err, fmt.Sprintf("invalid dispatcher name: %s", secName))
config.Dispatchers[id] = readDispatcherConfig(sec, &config.DispatcherCommon)
} else if len(secName) > 4 && secName[:4] == "game" {
// game config
id, err := strconv.Atoi(secName[4:])
checkConfigError(err, fmt.Sprintf("invalid game name: %s", secName))
config.Games[id] = readGameConfig(sec, &config.GameCommon)
} else if len(secName) > 4 && secName[:4] == "gate" {
id, err := strconv.Atoi(secName[4:])
checkConfigError(err, fmt.Sprintf("invalid gate name: %s", secName))
config.Gates[id] = readGateConfig(sec, &config.GateCommon)
} else if secName == "storage" {
// storage config
readStorageConfig(sec, &config.Storage)
} else if secName == "kvdb" {
// kvdb config
readKVDBConfig(sec, &config.KVDB)
} else if secName == "debug" {
// debug config
readDebugConfig(sec, &config.Debug)
} else {
gwlog.Fatalf("unknown section: %s", secName)
}
}
validateConfig(&config)
return &config
}
func readGameCommonConfig(section *ini.Section, scc *GameConfig) {
scc.BootEntity = "Boot"
scc.LogFile = "game.log"
scc.LogStderr = true
scc.LogLevel = _DEFAULT_LOG_LEVEL
scc.SaveInterval = _DEFAULT_SAVE_ITNERVAL
scc.HTTPIp = _DEFAULT_HTTP_IP
scc.HTTPPort = 0 // pprof not enabled by default
scc.GoMaxProcs = 0
scc.PositionSyncIntervalMS = 100 // sync positions per 100ms by default
_readGameConfig(section, scc)
}
func readGameConfig(sec *ini.Section, gameCommonConfig *GameConfig) *GameConfig {
var sc GameConfig = *gameCommonConfig // copy from game_common
_readGameConfig(sec, &sc)
// validate game config
if sc.BootEntity == "" {
panic("boot_entity is not set in game config")
}
return &sc
}
func _readGameConfig(sec *ini.Section, sc *GameConfig) {
for _, key := range sec.Keys() {
name := strings.ToLower(key.Name())
if name == "boot_entity" {
sc.BootEntity = key.MustString(sc.BootEntity)
} else if name == "save_interval" {
sc.SaveInterval = time.Second * time.Duration(key.MustInt(int(_DEFAULT_SAVE_ITNERVAL/time.Second)))
} else if name == "log_file" {
sc.LogFile = key.MustString(sc.LogFile)
} else if name == "log_stderr" {
sc.LogStderr = key.MustBool(sc.LogStderr)
} else if name == "http_ip" {
sc.HTTPIp = key.MustString(sc.HTTPIp)
} else if name == "http_port" {
sc.HTTPPort = key.MustInt(sc.HTTPPort)
} else if name == "log_level" {
sc.LogLevel = key.MustString(sc.LogLevel)
} else if name == "gomaxprocs" {
sc.GoMaxProcs = key.MustInt(sc.GoMaxProcs)
} else if name == "position_sync_interval_ms" {
sc.PositionSyncIntervalMS = key.MustInt(sc.PositionSyncIntervalMS)
} else if name == "ban_boot_entity" {
sc.BanBootEntity = key.MustBool(sc.BanBootEntity)
} else {
gwlog.Fatalf("section %s has unknown key: %s", sec.Name(), key.Name())
}
}
}
func readGateCommonConfig(section *ini.Section, gcc *GateConfig) {
gcc.LogFile = "gate.log"
gcc.LogStderr = true
gcc.LogLevel = _DEFAULT_LOG_LEVEL
gcc.Ip = "0.0.0.0"
gcc.HTTPIp = _DEFAULT_HTTP_IP
gcc.HTTPPort = 0 // pprof not enabled by default
gcc.GoMaxProcs = 0
gcc.CompressFormat = ""
gcc.CompressFormat = "gwsnappy"
gcc.RSAKey = "rsa.key"
gcc.RSACertificate = "rsa.crt"
gcc.HeartbeatCheckInterval = 0
gcc.PositionSyncIntervalMS = 100
_readGateConfig(section, gcc)
}
func readGateConfig(sec *ini.Section, gateCommonConfig *GateConfig) *GateConfig {
var sc GateConfig = *gateCommonConfig // copy from game_common
_readGateConfig(sec, &sc)
// validate game config here
if sc.CompressConnection && sc.CompressFormat == "" {
gwlog.Fatalf("Gate %s: compress_connection is enabled, but compress format is not set", sec.Name())
}
if sc.EncryptConnection && sc.RSAKey == "" {
gwlog.Fatalf("Gate %s: encrypt_connection is enabled, but rsa_key is not set", sec.Name())
}
if sc.EncryptConnection && sc.RSACertificate == "" {
gwlog.Fatalf("Gate %s: encrypt_connection is enabled, but rsa_certificate is not set", sec.Name())
}
return &sc
}
func _readGateConfig(sec *ini.Section, sc *GateConfig) {
for _, key := range sec.Keys() {
name := strings.ToLower(key.Name())
if name == "ip" {
sc.Ip = key.MustString(sc.Ip)
} else if name == "port" {
sc.Port = key.MustInt(sc.Port)
} else if name == "log_file" {
sc.LogFile = key.MustString(sc.LogFile)
} else if name == "log_stderr" {
sc.LogStderr = key.MustBool(sc.LogStderr)
} else if name == "http_ip" {
sc.HTTPIp = key.MustString(sc.HTTPIp)
} else if name == "http_port" {
sc.HTTPPort = key.MustInt(sc.HTTPPort)
} else if name == "log_level" {
sc.LogLevel = key.MustString(sc.LogLevel)
} else if name == "gomaxprocs" {
sc.GoMaxProcs = key.MustInt(sc.GoMaxProcs)
} else if name == "compress_connection" {
sc.CompressConnection = key.MustBool(sc.CompressConnection)
} else if name == "compress_format" {
sc.CompressFormat = key.MustString(sc.CompressFormat)
} else if name == "encrypt_connection" {
sc.EncryptConnection = key.MustBool(sc.EncryptConnection)
} else if name == "rsa_key" {
sc.RSAKey = key.MustString(sc.RSAKey)
} else if name == "rsa_certificate" {
sc.RSACertificate = key.MustString(sc.RSACertificate)
} else if name == "heartbeat_check_interval" {
sc.HeartbeatCheckInterval = key.MustInt(sc.HeartbeatCheckInterval)
} else if name == "position_sync_interval_ms" {
sc.PositionSyncIntervalMS = key.MustInt(sc.PositionSyncIntervalMS)
} else {
gwlog.Fatalf("section %s has unknown key: %s", sec.Name(), key.Name())
}
}
}
func readDispatcherCommonConfig(section *ini.Section, dc *DispatcherConfig) {
dc.BindIp = _DEFAULT_LOCALHOST_IP
dc.Ip = _DEFAULT_LOCALHOST_IP
dc.LogFile = "dispatcher.log"
dc.LogStderr = true
dc.LogLevel = _DEFAULT_LOG_LEVEL
dc.HTTPIp = _DEFAULT_HTTP_IP
dc.HTTPPort = 0
_readDispatcherConfig(section, dc)
}
func readDispatcherConfig(sec *ini.Section, dispatcherCommonConfig *DispatcherConfig) *DispatcherConfig {
dc := *dispatcherCommonConfig // copy from game_common
_readDispatcherConfig(sec, &dc)
// validate dispatcher config
return &dc
}
func _readDispatcherConfig(sec *ini.Section, config *DispatcherConfig) {
for _, key := range sec.Keys() {
name := strings.ToLower(key.Name())
if name == "ip" {
config.Ip = key.MustString(config.Ip)
} else if name == "port" {
config.Port = key.MustInt(config.Port)
} else if name == "bind_ip" {
config.BindIp = key.MustString(config.BindIp)
} else if name == "bind_port" {
config.BindPort = key.MustInt(config.Port)
} else if name == "log_file" {
config.LogFile = key.MustString(config.LogFile)
} else if name == "log_stderr" {
config.LogStderr = key.MustBool(config.LogStderr)
} else if name == "http_ip" {
config.HTTPIp = key.MustString(config.HTTPIp)
} else if name == "http_port" {
config.HTTPPort = key.MustInt(config.HTTPPort)
} else if name == "log_level" {
config.LogLevel = key.MustString(config.LogLevel)
} else {
gwlog.Fatalf("section %s has unknown key: %s", sec.Name(), key.Name())
}
}
return
}
func readStorageConfig(sec *ini.Section, config *StorageConfig) {
// setup default values
config.Type = "filesystem"
config.Directory = "_entity_storage"
config.DB = _DEFAULT_STORAGE_DB
config.Url = ""
config.Driver = ""
config.StartNodes = common.StringSet{}
for _, key := range sec.Keys() {
name := strings.ToLower(key.Name())
if name == "type" {
config.Type = key.MustString(config.Type)
} else if name == "directory" {
config.Directory = key.MustString(config.Directory)
} else if name == "url" {
config.Url = key.MustString(config.Url)
} else if name == "db" {
config.DB = key.MustString(config.DB)
} else if name == "driver" {
config.Driver = key.MustString(config.Driver)
} else if strings.HasPrefix(name, "start_nodes_") {
config.StartNodes.Add(key.MustString(""))
} else {
gwlog.Fatalf("section %s has unknown key: %s", sec.Name(), key.Name())
}
}
if config.Type == "redis" {
if config.DB == "" {
config.DB = "0"
}
}
validateStorageConfig(config)
}
func readKVDBConfig(sec *ini.Section, config *KVDBConfig) {
config.StartNodes = common.StringSet{}
for _, key := range sec.Keys() {
name := strings.ToLower(key.Name())
if name == "type" {
config.Type = key.MustString(config.Type)
} else if name == "url" {
config.Url = key.MustString(config.Url)
} else if name == "db" {
config.DB = key.MustString(config.DB)
} else if name == "collection" {
config.Collection = key.MustString(config.Collection)
} else if name == "driver" {
config.Driver = key.MustString(config.Driver)
} else if strings.HasPrefix(name, "start_nodes_") {
config.StartNodes.Add(key.MustString(""))
} else {
gwlog.Fatalf("section %s has unknown key: %s", sec.Name(), key.Name())
}
}
if config.Type == "redis" {
if config.DB == "" {
config.DB = "0"
}
}
validateKVDBConfig(config)
}
func validateKVDBConfig(config *KVDBConfig) {
if config.Type == "" {
// KVDB not enabled, it's OK
} else if config.Type == "mongodb" {
// must set DB and Collection for mongodb
if config.Url == "" || config.DB == "" || config.Collection == "" {
gwlog.Fatalf("invalid %s KVDB config:\n%s", config.Type, DumpPretty(config))
}
} else if config.Type == "redis" {
if config.Url == "" {
gwlog.Fatalf("invalid %s KVDB config:\n%s", config.Type, DumpPretty(config))
}
_, err := strconv.Atoi(config.DB) // make sure db is integer for redis
if err != nil {
gwlog.Panic(errors.Wrap(err, "redis db must be integer"))
}
} else if config.Type == "redis_cluster" {
if len(config.StartNodes) == 0 {
gwlog.Fatalf("must have at least 1 start_nodes for [kvdb].redis_cluster")
}
for s := range config.StartNodes {
if s == "" {
gwlog.Fatalf("start_nodes must not be empty")
}
}
} else if config.Type == "sql" {
if config.Driver == "" {
gwlog.Fatalf("invalid %s KVDB config:\n %s", config.Type, DumpPretty(config))
}
if config.Url == "" {
gwlog.Fatalf("invalid %s KVDB config:\n%s", config.Type, DumpPretty(config))
}
} else {
gwlog.Fatalf("unknown storage type: %s", config.Type)
}
}
func readDebugConfig(sec *ini.Section, config *DebugConfig) {
config.Debug = false
for _, key := range sec.Keys() {
name := strings.ToLower(key.Name())
if name == "debug" {
config.Debug = key.MustBool(config.Debug)
} else {
gwlog.Fatalf("section %s has unknown key: %s", sec.Name(), key.Name())
}
}
}
func checkConfigError(err error, msg string) {
if err != nil {
if msg == "" {
msg = err.Error()
}
gwlog.Fatalf("read config error: %s", msg)
}
}
func validateStorageConfig(config *StorageConfig) {
if config.Type == "filesystem" {
// directory must be set
if config.Directory == "" {
gwlog.Fatalf("directory is not set in %s storage config", config.Type)
}
} else if config.Type == "mongodb" {
if config.Url == "" {
gwlog.Fatalf("url is not set in %s storage config", config.Type)
}
if config.DB == "" {
gwlog.Fatalf("db is not set in %s storage config", config.Type)
}
} else if config.Type == "redis" {
if config.Url == "" {
gwlog.Fatalf("redis host is not set")
}
if _, err := strconv.Atoi(config.DB); err != nil {
gwlog.Panic(errors.Wrap(err, "redis db must be integer"))
}
} else if config.Type == "redis_cluster" {
if len(config.StartNodes) == 0 {
gwlog.Fatalf("must have at least 1 start_nodes for [storage].redis_cluster")
}
for s := range config.StartNodes {
if s == "" {
gwlog.Fatalf("start_nodes must not be empty")
}
}
} else if config.Type == "sql" {
if config.Driver == "" {
gwlog.Fatalf("sql driver is not set")
}
if config.Url == "" {
gwlog.Fatalf("db url is not set")
}
} else {
gwlog.Fatalf("unknown storage type: %s", config.Type)
}
}
func validateConfig(config *GoWorldConfig) {
dispatchersNum := len(config.Dispatchers)
if dispatchersNum <= 0 {
gwlog.Fatalf("dispatcher not found in config file, must has at least 1 dispatcher")
}
for dispatcherid := 1; dispatcherid <= dispatchersNum; dispatcherid++ {
if _, ok := config.Dispatchers[dispatcherid]; !ok {
gwlog.Fatalf("found %d dispatchers in config file, but dispatcher%d is not found. dispatcherid must be 1~%d", dispatchersNum, dispatcherid, dispatchersNum)
}
}
gamesNum := len(config.Games)
if gamesNum <= 0 {
gwlog.Fatalf("game not found in config file, must has at least 1 game")
}
hasNotBanBootEntityGame := false
for gameid := 1; gameid <= gamesNum; gameid++ {
if gameCfg, ok := config.Games[gameid]; ok {
if !gameCfg.BanBootEntity {
hasNotBanBootEntityGame = true //
}
} else {
gwlog.Fatalf("found %d games in config file, but game%d is not found. gameid must be 1~%d", gamesNum, gameid, gamesNum)
}
}
if !hasNotBanBootEntityGame {
gwlog.Fatalf("must has at least 1 game with ban_boot_entity = false!")
}
gatesNum := len(config.Gates)
if gatesNum <= 0 {
gwlog.Fatalf("gate not found in config file, must has at least 1 gate")
}
for gateid := 1; gateid <= gatesNum; gateid++ {
if _, ok := config.Gates[gateid]; !ok {
gwlog.Fatalf("found %d gates in config file, but gate%d is not found. gateid must be 1~%d", gatesNum, gateid, gatesNum)
}
}
}