@@ -53,20 +53,45 @@ func NewGameController() (c *GameController) {
53
53
c .AutoRefServer = rcon .NewAutoRefServer ()
54
54
c .AutoRefServer .LoadTrustedKeys (c .Config .Server .AutoRef .TrustedKeysDir )
55
55
c .AutoRefServer .ProcessRequest = c .ProcessAutoRefRequests
56
- go c .AutoRefServer .Listen (c .Config .Server .AutoRef .Address )
57
56
58
57
c .TeamServer = rcon .NewTeamServer ()
59
58
c .TeamServer .LoadTrustedKeys (c .Config .Server .Team .TrustedKeysDir )
60
59
c .TeamServer .ProcessTeamRequest = c .ProcessTeamRequests
61
- go c .TeamServer .Listen (c .Config .Server .Team .Address )
62
60
63
61
c .Engine = NewEngine (c .Config .Game )
64
62
c .timer = timer .NewTimer ()
65
- c .timer .Start ()
66
63
67
64
return
68
65
}
69
66
67
+ // Run the GameController by starting several go-routines. This method will not block.
68
+ func (c * GameController ) Run () {
69
+
70
+ if err := c .historyPreserver .Open (); err != nil {
71
+ log .Print ("Could not open history" , err )
72
+ } else {
73
+ history , err := c .historyPreserver .Load ()
74
+ if err != nil {
75
+ log .Print ("Could not load history" , err )
76
+ } else if len (* history ) > 0 {
77
+ c .Engine .History = * history
78
+ * c .Engine .State = c .Engine .History [len (c .Engine .History )- 1 ].State
79
+ c .Engine .RefereeEvents = c .Engine .History [len (c .Engine .History )- 1 ].RefereeEvents
80
+ }
81
+ }
82
+
83
+ c .ApiServer .PublishState (* c .Engine .State )
84
+ c .ApiServer .PublishRefereeEvents (c .Engine .RefereeEvents )
85
+ c .TeamServer .AllowedTeamNames = []string {c .Engine .State .TeamState [TeamYellow ].Name ,
86
+ c .Engine .State .TeamState [TeamBlue ].Name }
87
+
88
+ c .timer .Start ()
89
+ go c .publishApi ()
90
+ go c .publishNetwork ()
91
+ go c .AutoRefServer .Listen (c .Config .Server .AutoRef .Address )
92
+ go c .TeamServer .Listen (c .Config .Server .Team .Address )
93
+ }
94
+
70
95
func (c * GameController ) ProcessGeometry (data * sslproto.SSL_GeometryData ) {
71
96
if int32 (math .Round (c .Engine .Geometry .FieldWidth * 1000.0 )) != * data .Field .FieldWidth {
72
97
newFieldWidth := float64 (* data .Field .FieldWidth ) / 1000.0
@@ -194,29 +219,6 @@ func (c *GameController) ProcessTeamRequests(teamName string, request refproto.T
194
219
return nil
195
220
}
196
221
197
- // Run the GameController by starting an endless loop in the background
198
- func (c * GameController ) Run () {
199
-
200
- if err := c .historyPreserver .Open (); err != nil {
201
- log .Print ("Could not open history" , err )
202
- } else {
203
- history , err := c .historyPreserver .Load ()
204
- if err != nil {
205
- log .Print ("Could not load history" , err )
206
- } else if len (* history ) > 0 {
207
- c .Engine .History = * history
208
- * c .Engine .State = c .Engine .History [len (c .Engine .History )- 1 ].State
209
- c .Engine .RefereeEvents = c .Engine .History [len (c .Engine .History )- 1 ].RefereeEvents
210
- }
211
- }
212
-
213
- c .ApiServer .PublishState (* c .Engine .State )
214
- c .ApiServer .PublishRefereeEvents (c .Engine .RefereeEvents )
215
-
216
- go c .publishApi ()
217
- go c .publishNetwork ()
218
- }
219
-
220
222
func (c * GameController ) publishApi () {
221
223
defer c .historyPreserver .Close ()
222
224
for {
0 commit comments