-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
103 lines (84 loc) · 3.12 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
package main
import (
"fmt"
"github.com/altriusrs/netbeams/src/config"
"github.com/altriusrs/netbeams/src/environment"
"github.com/altriusrs/netbeams/src/heartbeat"
"github.com/altriusrs/netbeams/src/http"
"github.com/altriusrs/netbeams/src/logs"
"github.com/altriusrs/netbeams/src/netcheck"
"github.com/altriusrs/netbeams/src/player_manager"
"github.com/altriusrs/netbeams/src/tcp"
"github.com/altriusrs/netbeams/src/types"
"github.com/altriusrs/netbeams/src/udp"
"github.com/altriusrs/netbeams/src/upnp"
)
func main() {
environment.GetBuildContext()
// Spawn a new logger instance
logger := logs.NetLogger("Main")
defer logger.Terminate()
logger.Info("Welcome to NetBeams v" + environment.Version)
if environment.Context.IsDev {
fmt.Println("\x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m")
fmt.Println(" DEVELOPER ENVIRONMENT")
fmt.Println("\x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m \x1b[40;33m⬕⬔\x1b[0m")
}
logger.Info("Loading congiguration file")
logger.Info("Loading data")
configuration := config.Service()
configuration.StartService()
if config.Configuration.NetBeams.UseUPnP {
logger.Info("UPnP enabled - Startup may take a few seconds")
uservice := upnp.Spawn()
uservice.Start()
} else {
logger.Info("UPnP disabled")
}
// Spawn a new application instance
types.NewApplication()
// Spawn the netcheck service if required
if config.Configuration.Auth.Proxy.Enable || config.Configuration.Auth.VPN.Enable {
netchecker := netcheck.Service()
failed := netchecker.StartService()
if failed != nil {
logger.Error("Failed to start IP2Proxy databases")
logger.Error(failed.Error())
return
}
logger.Info("IP2Proxy databases loaded")
types.App.AddService(netchecker)
}
logger.Info("Starting server")
logger.Info("Name: " + config.Configuration.General.Name)
logger.Infof("Port: %d", config.Configuration.General.Port)
mode := "main"
if config.Configuration.NetBeams.MasterNode != "localhost" {
logger.Info("Main node: " + config.Configuration.NetBeams.MasterNode)
logger.Info("Switching to node mode")
mode = "node"
}
logger.Info("Mode: " + mode)
// Pass application to signal handler to allow graceful shutdown
types.App.RegisterSignalHandler()
// Spawn the required services
types.App.AddService(configuration)
types.App.AddService(http.Service())
types.App.AddService(player_manager.Service())
types.App.AddService(tcp.Service())
types.App.AddService(udp.Service())
types.App.AddService(heartbeat.Service())
switch mode {
case "main":
logger.Info("Starting main node")
case "node":
logger.Error("Node mode not implemented yet")
logger.Info("Please set the master node to 'localhost' in the configuration file")
return
// logger.Info("Starting node")
// app.StartNode()
}
types.App.Start()
types.App.Wait() // Wait for the application to terminate
logger.Info("Exiting")
}