forked from pzduniak/aiw3-np-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
110 lines (95 loc) · 2.84 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
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
package main
import (
"github.com/knackebrot/aiw3-np-server/config"
"github.com/knackebrot/aiw3-np-server/environment"
"github.com/knackebrot/aiw3-np-server/http"
//"github.com/knackebrot/aiw3-np-server/misc"
"github.com/knackebrot/aiw3-np-server/np"
//"github.com/knackebrot/aiw3-np-server/np/aci"
"github.com/yvasiyarov/gorelic"
//"github.com/knackebrot/aiw3-np-server/playerlog"
"github.com/eaigner/jet"
_ "github.com/go-sql-driver/mysql"
"github.com/pzduniak/logger"
"gopkg.in/redis.v2"
)
func main() {
// Add the Stdout logger
logger.AddOutput(logger.Stdout{
MinLevel: logger.ERROR, //logger.DEBUG,
Colored: true,
})
// Load settings from config.toml in working directory
settings := config.Load("./config.toml")
/*logger.AddOutput(&logger.File{
MinLevel: logger.WARNING,
Path: "./server.log",
})*/
// Load the aCI3 key
//err := aci.LoadKey(settings.NP.AnticheatKeyPath)
//if err != nil {
//logger.Fatalf("Cannot load aCI3 key; %s", err)
//} else {
//logger.Infof("Loaded aCI3 key")
//}
// Start the NewRelic client if it's enabled in the config file
if settings.NewRelic.Enabled {
agent := gorelic.NewAgent()
agent.Verbose = settings.NewRelic.Verbose
agent.NewrelicName = settings.NewRelic.Name
agent.NewrelicLicense = settings.NewRelic.License
agent.Run()
}
// Generate a Jet database connector.
// Here, err shows if the connection string syntax is valid.
// The actual creds are checked during the first query.
database, err := jet.Open(
settings.Database.Driver,
settings.Database.ConnectionString,
)
defer database.Close()
if err != nil {
logger.Fatalf("Cannot connect to database; %s", err)
}
// But Redis connects here! As far as I know, autoreconnect is implemented
cache := redis.NewTCPClient(&redis.Options{
Addr: settings.Redis.Address,
Password: settings.Redis.Password,
DB: int64(settings.Redis.Database),
})
defer cache.Close()
// Set up a new environment object
environment.SetEnvironment(&environment.Environment{
Config: settings,
Database: database,
Redis: cache,
})
// This thing is massive
// The main network platform server that game connects to
if settings.NP.Enabled {
np_server := np.New()
go np_server.Start()
}
// HTTP-based remote authentication form and a simple API
// Is supposed to replace half of 3k
if settings.HTTP.Enabled {
http_server := http.New()
go http_server.Start()
}
/*if settings.PlayerLog.Enabled {
playerlog_server := playerlog.Init(settings.PlayerLog)
go playerlog_server.Start()
}
if settings.Misc.Enabled {
misc_server := misc.Init(settings.Misc)
go misc_server.Start()
}*/
// select{} stops execution of the program until all goroutines close
// TODO: add panic recovery!
if settings.NP.Enabled ||
settings.PlayerLog.Enabled ||
settings.Misc.Enabled ||
settings.HTTP.Enabled {
select {}
}
}