Skip to content

Commit 4352d2b

Browse files
committed
[bugfix] Remember team+autoRef connection on match reset
1 parent de6de2b commit 4352d2b

File tree

8 files changed

+64
-31
lines changed

8 files changed

+64
-31
lines changed

cmd/ssl-auto-ref-client/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ func (c *Client) sendGameEvent() {
105105
event.BallLeftFieldTouchLine.Location = &refproto.Location{X: new(float32), Y: new(float32)}
106106
*event.BallLeftFieldTouchLine.Location.X = 1
107107
*event.BallLeftFieldTouchLine.Location.Y = 4.5
108-
gameEvent := refproto.GameEvent{Event: &event}
108+
gameEvent := refproto.GameEvent{Event: &event, Type: new(refproto.GameEventType)}
109+
*gameEvent.Type = refproto.GameEventType_BALL_LEFT_FIELD_TOUCH_LINE
109110
request := refproto.AutoRefToController{GameEvent: &gameEvent}
110111
c.sendRequest(&request)
111112
}

internal/app/controller/controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (c *GameController) Run() {
7474
}
7575
}
7676

77-
c.ApiServer.PublishState(*c.Engine.State)
77+
c.ApiServer.PublishState(*c.Engine.State, c.Engine.EngineState)
7878
c.ApiServer.PublishUiProtocol(c.Engine.UiProtocol)
7979
c.TeamServer.AllowedTeamNames = []string{c.Engine.State.TeamState[TeamYellow].Name,
8080
c.Engine.State.TeamState[TeamBlue].Name}
@@ -130,7 +130,7 @@ func (c *GameController) publish() {
130130
c.Engine.State.TeamState[TeamBlue].Name}
131131

132132
c.publishUiProtocol()
133-
c.ApiServer.PublishState(*c.Engine.State)
133+
c.ApiServer.PublishState(*c.Engine.State, c.Engine.EngineState)
134134
}
135135

136136
// publishUiProtocol publishes the UI protocol, if it has changed
@@ -144,13 +144,13 @@ func (c *GameController) publishUiProtocol() {
144144
// updateOnlineStates checks if teams and autoRefs are online and writes this into the state
145145
func (c *GameController) updateOnlineStates() {
146146
for _, team := range []Team{TeamYellow, TeamBlue} {
147-
c.Engine.State.TeamState[team].Connected, c.Engine.State.TeamState[team].ConnectionVerified = c.teamConnected(team)
147+
c.Engine.EngineState.TeamConnected[team], c.Engine.EngineState.TeamConnectionVerified[team] = c.teamConnected(team)
148148
}
149149
var autoRefs []string
150150
for _, autoRef := range c.AutoRefServer.Clients {
151151
autoRefs = append(autoRefs, autoRef.Id)
152152
}
153-
c.Engine.State.AutoRefsConnected = autoRefs
153+
c.Engine.EngineState.AutoRefsConnected = autoRefs
154154
}
155155

156156
// publishToNetwork publishes the current state to the network (multicast) every 100ms

internal/app/controller/engine.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,27 @@ import (
1111
"time"
1212
)
1313

14+
type EngineState struct {
15+
AutoRefsConnected []string `json:"autoRefsConnected" yaml:"autoRefsConnected"`
16+
TeamConnected map[Team]bool `json:"teamConnected" yaml:"teamConnected"`
17+
TeamConnectionVerified map[Team]bool `json:"teamConnectionVerified" yaml:"teamConnectionVerified"`
18+
}
19+
20+
func NewEngineState() (e EngineState) {
21+
e.AutoRefsConnected = []string{}
22+
e.TeamConnected = map[Team]bool{}
23+
e.TeamConnected[TeamYellow] = false
24+
e.TeamConnected[TeamBlue] = false
25+
e.TeamConnectionVerified = map[Team]bool{}
26+
e.TeamConnectionVerified[TeamYellow] = false
27+
e.TeamConnectionVerified[TeamBlue] = false
28+
return
29+
}
30+
1431
type Engine struct {
1532
State *State
1633
UiProtocol []UiProtocolEntry
34+
EngineState EngineState
1735
StageTimes map[Stage]time.Duration
1836
config config.Game
1937
TimeProvider func() time.Time
@@ -24,6 +42,7 @@ type Engine struct {
2442

2543
func NewEngine(config config.Game, seed int64) (e Engine) {
2644
e.config = config
45+
e.EngineState = NewEngineState()
2746
e.loadStages()
2847
e.ResetGame()
2948
e.TimeProvider = func() time.Time { return time.Now() }

internal/app/controller/state.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,6 @@ type TeamInfo struct {
323323
BallPlacementFailures int `json:"ballPlacementFailures" yaml:"ballPlacementFailures"`
324324
CanPlaceBall bool `json:"canPlaceBall" yaml:"canPlaceBall"`
325325
MaxAllowedBots int `json:"maxAllowedBots" yaml:"maxAllowedBots"`
326-
Connected bool `json:"connected" yaml:"connected"`
327-
ConnectionVerified bool `json:"connectionVerified" yaml:"connectionVerified"`
328326
BotSubstitutionIntend bool `json:"botSubstitutionIntend" yaml:"botSubstitutionIntend"`
329327
}
330328

@@ -378,7 +376,6 @@ type State struct {
378376
AutoContinue bool `json:"autoContinue" yaml:"autoContinue"`
379377
NextCommand RefCommand `json:"nextCommand" yaml:"nextCommand"`
380378
NextCommandFor Team `json:"nextCommandFor" yaml:"nextCommandFor"`
381-
AutoRefsConnected []string `json:"autoRefsConnected" yaml:"autoRefsConnected"`
382379
GameEventBehavior map[GameEventType]GameEventBehavior `json:"gameEventBehavior" yaml:"gameEventBehavior"`
383380
GameEventProposals []*GameEventProposal `json:"gameEventProposals" yaml:"gameEventProposals"`
384381
CurrentActionDeadline time.Time `json:"currentActionDeadline" yaml:"currentActionDeadline"`
@@ -413,7 +410,6 @@ func NewState() (s *State) {
413410
s.GameEventBehavior[event] = GameEventBehaviorOn
414411
}
415412

416-
s.AutoRefsConnected = []string{}
417413
s.GameEventProposals = []*GameEventProposal{}
418414

419415
return
@@ -423,8 +419,6 @@ func (s State) DeepCopy() (c State) {
423419
c = s
424420
c.GameEvents = []*GameEvent{}
425421
copy(c.GameEvents, s.GameEvents)
426-
c.AutoRefsConnected = []string{}
427-
copy(c.AutoRefsConnected, s.AutoRefsConnected)
428422
c.GameEventProposals = []*GameEventProposal{}
429423
copy(c.GameEventProposals, s.GameEventProposals)
430424
if s.PlacementPos != nil {

internal/app/controller/uiServer.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ import (
88
)
99

1010
type ApiServer struct {
11-
Consumer EventConsumer
12-
connections []*websocket.Conn
13-
latestState State
14-
latestUiProtocol []UiProtocolEntry
11+
Consumer EventConsumer
12+
connections []*websocket.Conn
13+
latestState State
14+
latestUiProtocol []UiProtocolEntry
15+
latestEngineState EngineState
1516
}
1617

1718
type EventConsumer interface {
1819
OnNewEvent(event Event)
1920
}
2021

2122
type MessageWrapper struct {
22-
State *State `json:"state"`
23-
UiProtocol *[]UiProtocolEntry `json:"gameEvents"`
23+
State *State `json:"state"`
24+
UiProtocol *[]UiProtocolEntry `json:"gameEvents"`
25+
EngineState *EngineState `json:"engineState"`
2426
}
2527

2628
// WsHandler handles incoming web socket connections
@@ -62,7 +64,7 @@ func (a *ApiServer) PublishWrapper(wrapper MessageWrapper) {
6264
}
6365

6466
func (a *ApiServer) publishFullWrapper(conn *websocket.Conn) {
65-
wrapper := MessageWrapper{&a.latestState, &a.latestUiProtocol}
67+
wrapper := MessageWrapper{&a.latestState, &a.latestUiProtocol, &a.latestEngineState}
6668
b, err := json.Marshal(wrapper)
6769
if err != nil {
6870
log.Println("Marshal error:", err)
@@ -73,9 +75,10 @@ func (a *ApiServer) publishFullWrapper(conn *websocket.Conn) {
7375
}
7476
}
7577

76-
func (a *ApiServer) PublishState(state State) {
78+
func (a *ApiServer) PublishState(state State, engineState EngineState) {
7779
a.latestState = state
78-
wrapper := MessageWrapper{State: &state}
80+
a.latestEngineState = engineState
81+
wrapper := MessageWrapper{State: &state, EngineState: &engineState}
7982
a.PublishWrapper(wrapper)
8083
}
8184

src/components/events/Events.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,21 @@
6565
state() {
6666
return this.$store.state.refBoxState
6767
},
68+
engineState() {
69+
return this.$store.state.engineState
70+
},
6871
autoRefsConnected() {
69-
if (this.state.autoRefsConnected != null) {
70-
return this.state.autoRefsConnected.length;
72+
if (this.engineState.autoRefsConnected != null) {
73+
return this.engineState.autoRefsConnected.length;
7174
}
7275
return 0;
7376
},
7477
autoRefs() {
7578
if (this.autoRefsConnected) {
7679
let autoRefs = 'Connected AutoRefs: ';
77-
for (let i = 0; i < this.state.autoRefsConnected.length; i++) {
78-
autoRefs += this.state.autoRefsConnected[i];
79-
if (i !== (this.state.autoRefsConnected.length - 1)) {
80+
for (let i = 0; i < this.engineState.autoRefsConnected.length; i++) {
81+
autoRefs += this.engineState.autoRefsConnected[i];
82+
if (i !== (this.engineState.autoRefsConnected.length - 1)) {
8083
autoRefs += ', '
8184
}
8285
}

src/components/team/TeamOverview.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<h2>{{teamColor}} Team
44
<span v-b-tooltip.hover
55
title="Team connected"
6-
v-if="team.connected">
6+
v-if="teamConnected">
77
<font-awesome-icon
88
class="fa-xs"
99
icon="signal"/>
1010
</span>
1111
<span v-b-tooltip.hover
1212
title="connection verified"
13-
v-if="team.connectionVerified">
13+
v-if="teamConnectionVerified">
1414
<font-awesome-icon
1515
class="fa-xs"
1616
icon="shield-alt"/>
@@ -108,6 +108,12 @@
108108
},
109109
maxAllowedBots() {
110110
return this.team.maxAllowedBots;
111+
},
112+
teamConnected() {
113+
return this.$store.state.engineState.teamConnected[this.teamColor]
114+
},
115+
teamConnectionVerified() {
116+
return this.$store.state.engineState.teamConnectionVerified[this.teamColor]
111117
}
112118
}
113119
}

src/store.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export class TeamState {
1717
ballPlacementFailures = 0;
1818
canPlaceBall = true;
1919
maxAllowedBots = 0;
20-
connected = false;
21-
connectionVerified = false;
2220
}
2321

2422
export class RefBoxState {
@@ -34,16 +32,22 @@ export class RefBoxState {
3432
autoContinue = true;
3533
nextCommand = '';
3634
nextCommandFor = '';
37-
autoRefsConnected = [];
3835
gameEventBehavior = {};
3936
gameEventProposals = [{proposerId: '', gameEvent: {type: '', details: {foo: 'bar'}}, validUntil: 0}];
4037
currentActionTimeRemaining = 0;
4138
}
4239

40+
export class EngineState {
41+
autoRefsConnected = [];
42+
teamConnected = {'Yellow': false, 'Blue': false};
43+
teamConnectionVerified = {'Yellow': false, 'Blue': false};
44+
}
45+
4346
export default new Vuex.Store({
4447
state: {
4548
refBoxState: new RefBoxState(),
46-
gameEvents: []
49+
gameEvents: [],
50+
engineState: new EngineState()
4751
},
4852
mutations: {
4953
SOCKET_ONOPEN() {
@@ -59,6 +63,9 @@ export default new Vuex.Store({
5963
if (message.gameEvents) {
6064
state.gameEvents = message.gameEvents;
6165
}
66+
if (message.engineState) {
67+
state.engineState = message.engineState;
68+
}
6269
},
6370
SOCKET_RECONNECT() {
6471
},

0 commit comments

Comments
 (0)