-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
56 lines (49 loc) · 1.77 KB
/
conf.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
package net4g
import (
"time"
"fmt"
"github.com/carsonsx/gutil"
)
type ReadMode string
const (
READ_MODE_BY_LENGTH ReadMode = "by_length"
READ_MODE_BEGIN_END ReadMode = "begin_end"
)
var NetConfig netConfig
type netConfig struct {
ServerName string `json:"server_name"`
Address string `json:"-"`
Host string `json:"host"`
Port int `json:"port"`
ReadMode ReadMode `json:"read_mode"`
MaxLength uint64 `json:"max_length"`
BeginBytes []byte `json:"-"`
EndBytes []byte `json:"-"`
HeaderSize int `json:"header_size"`
LengthIndex int `json:"length_index"`
LengthSize int `json:"length_size"`
LittleEndian bool `json:"little_endian"`
HeartbeatFrequency time.Duration `json:"heartbeat_frequency"`
HeartbeatData []byte `json:"heartbeat_data"`
NetTolerableTime time.Duration `json:"net_tolerable_time"`
IdSize int `json:"id_size"`
KeepWriteData bool `json:"keep_write_data"`
MonitorBeat int `json:"monitor_beat"`
}
func init() {
NetConfig.ServerName = "GameServer"
NetConfig.Port = 6666
NetConfig.ReadMode = READ_MODE_BY_LENGTH
NetConfig.MaxLength = 1 << 16
NetConfig.HeaderSize = 2
NetConfig.LengthIndex = 0
NetConfig.LengthSize = 2
NetConfig.LittleEndian = false
NetConfig.HeartbeatFrequency = 10 //second
NetConfig.HeartbeatData = []byte{}
NetConfig.NetTolerableTime = 3 // second
NetConfig.IdSize = 2
NetConfig.MonitorBeat = 3 // second
gutil.LoadJsonFile(&NetConfig, nil, "net4g.json", "conf/net4g.json", "config/net4g.json")
NetConfig.Address = fmt.Sprintf("%s:%d", NetConfig.Host, NetConfig.Port)
}