-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathconfig.go
More file actions
74 lines (63 loc) · 1.53 KB
/
Copy pathconfig.go
File metadata and controls
74 lines (63 loc) · 1.53 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
package typhoon
import (
"encoding/base64"
"encoding/json"
"image"
_ "image/png"
"io/ioutil"
"log"
"os"
)
type BufferConfig struct {
HandshakeAddress int `json:"handshake_address"`
PlayerName int `json:"player_name"`
ChatMessage int `json:"chat_message"`
}
type Config struct {
ListenAddress string `json:"listen_address"`
MaxPlayers int `json:"max_players"`
Motd string `json:"motd"`
Restricted bool `json:"restricted"`
Logs bool `json:"logs"`
Compression bool `json:"enable_compression"`
Threshold int `json:"compression_threshold"`
BufferConfig BufferConfig `json:"buffer_config"`
}
var (
config Config
favicon string
)
func initConfig() (err error) {
imgFile, _ := os.Open("./favicon.png")
defer imgFile.Close()
img, _, err := image.Decode(imgFile)
if err == nil {
b := img.Bounds()
if err == nil {
if b.Max.X != 64 || b.Max.Y != 64 {
log.Printf("Invalid icon for server (resize to 64x64 pixels?)")
}
fav, err := ioutil.ReadFile("./favicon.png")
if err == nil {
favicon = "data:image/png;base64," + base64.StdEncoding.EncodeToString(fav)
}
}
}
file, err := ioutil.ReadFile("./config.json")
if err != nil {
panic(err)
}
if err := json.Unmarshal(file, &config); err != nil {
panic(err)
}
return
}
func (c *Core) GetConfig(config interface{}) {
file, err := ioutil.ReadFile("./config.json")
if err != nil {
panic(err)
}
if err := json.Unmarshal(file, config); err != nil {
panic(err)
}
}