From 0e109a5f9cd3373811f5dc89cee772b4a1bb1414 Mon Sep 17 00:00:00 2001 From: Nicolai Ommer Date: Sun, 24 Jul 2022 17:21:16 +0200 Subject: [PATCH] Keep auto-recorder log file open during breaks --- pkg/auto/auto-recorder.go | 23 +++++++++++++++++------ pkg/persistence/recorder.go | 5 +++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/pkg/auto/auto-recorder.go b/pkg/auto/auto-recorder.go index 219c4c2..95fdf98 100644 --- a/pkg/auto/auto-recorder.go +++ b/pkg/auto/auto-recorder.go @@ -50,10 +50,18 @@ func (r *Recorder) receiveRefereeMessage(data []byte, _ *net.UDPAddr) { if err := r.Recorder.StartWithName(name); err != nil { log.Println("Failed to start recorder: ", err) } - } else if r.Recorder.IsRunning() && (isNoGameStage(&message) || !isTeamSet(&message)) { - log.Println("Stop recording") - if err := r.Recorder.Stop(); err != nil { - log.Println("Failed to stop recorder: ", err) + } else if r.Recorder.IsRunning() { + if isPostGame(&message) || !isTeamSet(&message) { + log.Println("Stop recording") + if err := r.Recorder.Stop(); err != nil { + log.Println("Failed to stop recorder: ", err) + } + } else if !r.Recorder.Paused && isBreakStage(&message) { + log.Println("Pause recording") + r.Recorder.Paused = true + } else if r.Recorder.Paused && !isBreakStage(&message) { + log.Println("Resume recording") + r.Recorder.Paused = false } } } @@ -83,12 +91,11 @@ func isTeamSet(message *referee.Referee) bool { *message.Blue.Name != "" && *message.Yellow.Name != "" } -func isNoGameStage(message *referee.Referee) bool { +func isBreakStage(message *referee.Referee) bool { switch *message.Stage { case referee.Referee_EXTRA_HALF_TIME, referee.Referee_NORMAL_HALF_TIME, referee.Referee_PENALTY_SHOOTOUT_BREAK, - referee.Referee_POST_GAME, referee.Referee_EXTRA_TIME_BREAK: return true default: @@ -96,6 +103,10 @@ func isNoGameStage(message *referee.Referee) bool { } } +func isPostGame(message *referee.Referee) bool { + return *message.Stage == referee.Referee_POST_GAME +} + func isPreStage(message *referee.Referee) bool { switch *message.Stage { case referee.Referee_NORMAL_FIRST_HALF_PRE, diff --git a/pkg/persistence/recorder.go b/pkg/persistence/recorder.go index fea1446..9af4ae6 100644 --- a/pkg/persistence/recorder.go +++ b/pkg/persistence/recorder.go @@ -13,6 +13,7 @@ type Recorder struct { Slots []*RecorderSlot writer Writer running bool + Paused bool mutex sync.Mutex } @@ -50,6 +51,7 @@ func (r *Recorder) StartWithName(name string) error { slot.server.Consumer = r.slotConsumer(slot) slot.server.Start() } + r.Paused = false r.running = true return nil } @@ -85,6 +87,9 @@ func (r *Recorder) openLogWriter(logFileName string) error { } func (r *Recorder) processSlotMessage(slot *RecorderSlot, data []byte) { + if r.Paused { + return + } timestamp := time.Now().UnixNano() logMessage := Message{Timestamp: timestamp, MessageType: slot.MessageType, Message: data} r.mutex.Lock()