-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
59 lines (47 loc) · 1.31 KB
/
main.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
package main
import (
"os"
"github.com/alejzeis/vic2-multi-proxy/client"
"github.com/alejzeis/vic2-multi-proxy/common"
"github.com/alejzeis/vic2-multi-proxy/server"
log "github.com/sirupsen/logrus"
"gopkg.in/ini.v1"
)
func main() {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
log.SetLevel(log.DebugLevel)
if len(os.Args) > 1 && os.Args[1] == "-server" {
log.WithFields(log.Fields{
"software": common.SoftwareName,
"version": common.SoftwareVersion,
"mode": "server",
}).Info("Starting...")
config := loadConfig()
matchmaker := new(server.Matchmaker)
matchmaker.Init()
relay := new(server.RelayServerImpl)
server.StartControlServer(config, matchmaker, relay)
} else {
log.WithFields(log.Fields{
"software": common.SoftwareName,
"version": common.SoftwareVersion,
"mode": "client",
}).Info("Starting...")
c := client.NewClient(client.NewConsoleCommandSource(), client.CreateStartRelay())
c.RunClient()
}
}
func loadConfig() *ini.File {
var configLocation string = "server.ini"
if os.Getenv("SERVER_CONFIG") != "" {
configLocation = os.Getenv("SERVER_CONFIG")
}
file, err := ini.Load(configLocation)
if err != nil {
log.WithField("config", configLocation).WithError(err).Error("Failed to load configuration file.")
panic(err)
}
return file
}