Skip to content

Commit d2f0928

Browse files
committed
Bugfix: More reliably check for state changes in API server
1 parent efda41b commit d2f0928

File tree

1 file changed

+16
-32
lines changed

1 file changed

+16
-32
lines changed

internal/app/api/server.go

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -252,51 +252,35 @@ func stateChanged(s1, s2 *state.State) bool {
252252
if s1 == nil || s2 == nil {
253253
return true
254254
}
255-
if *s1.Stage != *s2.Stage {
256-
return true
257-
}
258-
if !reflect.DeepEqual(s1.Command, s2.Command) {
259-
return true
260-
}
261255
if s1.StageTimeElapsed.Seconds != s2.StageTimeElapsed.Seconds {
262256
return true
263257
}
264258
if s1.StageTimeLeft.Seconds != s2.StageTimeLeft.Seconds {
265259
return true
266260
}
267-
if !reflect.DeepEqual(s1.MatchTimeStart, s2.MatchTimeStart) {
261+
if s1.CurrentActionTimeRemaining.Seconds != s2.CurrentActionTimeRemaining.Seconds {
268262
return true
269263
}
270264
for _, team := range state.BothTeams() {
271265
if teamStateChanged(s1.TeamInfo(team), s2.TeamInfo(team)) {
272266
return true
273267
}
274268
}
275-
if !reflect.DeepEqual(s1.PlacementPos, s2.PlacementPos) {
276-
return true
277-
}
278-
if !reflect.DeepEqual(s1.NextCommand, s2.NextCommand) {
279-
return true
280-
}
281-
if s1.CurrentActionTimeRemaining.Seconds != s2.CurrentActionTimeRemaining.Seconds {
282-
return true
283-
}
284-
if !reflect.DeepEqual(s1.GameEvents, s2.GameEvents) {
285-
return true
286-
}
287-
if !reflect.DeepEqual(s1.GameEventProposals, s2.GameEventProposals) {
288-
return true
289-
}
290-
if *s1.Division != *s2.Division {
291-
return true
292-
}
293-
if *s1.AutoContinue != *s2.AutoContinue {
294-
return true
295-
}
296-
if *s1.FirstKickoffTeam != *s2.FirstKickoffTeam {
297-
return true
298-
}
299-
return false
269+
270+
s1c := new(state.State)
271+
s2c := new(state.State)
272+
proto.Merge(s1c, s1)
273+
proto.Merge(s2c, s2)
274+
s1c.StageTimeElapsed = nil
275+
s2c.StageTimeElapsed = nil
276+
s1c.StageTimeLeft = nil
277+
s2c.StageTimeLeft = nil
278+
s1c.CurrentActionTimeRemaining = nil
279+
s2c.CurrentActionTimeRemaining = nil
280+
s1c.TeamState = nil
281+
s2c.TeamState = nil
282+
283+
return !proto.Equal(s1c, s2c)
300284
}
301285

302286
func teamStateChanged(s1, s2 *state.TeamInfo) bool {

0 commit comments

Comments
 (0)