-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
100 lines (97 loc) · 2.34 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
package main
import (
"fmt"
"os"
"sync"
"time"
"github.com/riltech/centurion/core"
"github.com/riltech/centurion/core/bus"
"github.com/riltech/centurion/core/combat"
"github.com/riltech/centurion/core/config"
"github.com/riltech/centurion/core/player"
"github.com/riltech/centurion/core/scoreboard"
"github.com/riltech/centurion/example"
"github.com/sirupsen/logrus"
)
func main() {
file, err := os.Create("logs")
if err != nil {
logrus.Fatal(err)
}
defer func() {
file.Close()
}()
logrus.SetOutput(file)
logrus.SetFormatter(&logrus.TextFormatter{
DisableQuote: true,
})
logrus.Info("Centurion is starting")
spec, err := config.Init()
if err != nil {
logrus.Fatal(err)
}
exitHandler := core.NewExitHandler()
bus := bus.NewBus()
playerRepo := player.NewRepository()
playerService := player.NewService(playerRepo)
scoreRepository := scoreboard.NewRepository()
scoreService := scoreboard.NewService(scoreRepository, playerService)
combatRepository := combat.NewRepository()
combatService := combat.NewService(combatRepository)
engine := core.NewEngine(
spec.Port,
bus,
scoreService,
combatService,
playerService,
)
dashboard := core.NewDashboard(
bus,
scoreService,
combatService,
playerService,
)
wg := &sync.WaitGroup{}
wg.Add(1)
var exampleAttacker example.IAttacker
var exampleDefender example.IDefender
exitHandler.On(func() {
logrus.Info("Running exit handler")
engine.Stop()
bus.Stop()
if exampleAttacker != nil {
exampleAttacker.Stop()
}
if exampleDefender != nil {
exampleDefender.Stop()
}
// Let's be really graceful
<-time.After(2 * time.Second)
wg.Done()
})
go engine.Start()
if spec.ExampleEnabled {
exampleAttacker = example.NewAttacker("localhost:8080")
go func() {
// Wait a bit before startup
<-time.After(2 * time.Second)
exampleAttacker.Start()
}()
exampleDefender = example.NewDefender("localhost:8080")
go func() {
// Wait a bit less before startup
// as the defender has to install the module
<-time.After(1 * time.Second)
exampleDefender.Start()
}()
}
dashboard.Start()
if !exitHandler.IsRunning() {
exitHandler.Trigger()
}
wg.Wait()
fmt.Println("Final score")
attackers, defenders := scoreService.GetBoards()
fmt.Printf("Attackers %d - %d Defenders\n", attackers.OverallScore, defenders.OverallScore)
fmt.Println("Congratulations!")
}