Skip to content

Commit 1486ea4

Browse files
committed
feature: Consume request flags from remote-control
1 parent 05a5a54 commit 1486ea4

16 files changed

+563
-323
lines changed

internal/app/api/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func teamStateChanged(s1, s2 *state.TeamInfo) bool {
334334
if *s1.MaxAllowedBots != *s2.MaxAllowedBots {
335335
return true
336336
}
337-
if *s1.BotSubstitutionIntent != *s2.BotSubstitutionIntent {
337+
if *s1.RequestsBotSubstitution != *s2.RequestsBotSubstitution {
338338
return true
339339
}
340340
return false

internal/app/publish/messagegenerator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func updateTeam(teamInfo *state.Referee_TeamInfo, teamState *state.TeamInfo) {
123123
*teamInfo.BallPlacementFailuresReached = *teamState.BallPlacementFailuresReached
124124
*teamInfo.CanPlaceBall = *teamState.CanPlaceBall
125125
*teamInfo.MaxAllowedBots = unsigned32(*teamState.MaxAllowedBots)
126-
*teamInfo.BotSubstitutionIntent = *teamState.BotSubstitutionIntent
126+
*teamInfo.BotSubstitutionIntent = *teamState.RequestsBotSubstitution
127127
timeoutTime, _ := ptypes.Duration(teamState.TimeoutTimeLeft)
128128
*teamInfo.TimeoutTime = mapTime(timeoutTime)
129129
}

internal/app/rcon/server_remotecontrol.go

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ type RemoteControlServer struct {
1919
}
2020

2121
type RemoteControlClient struct {
22-
team *state.Team
22+
gcEngine *engine.Engine
23+
team *state.Team
2324
*Client
2425
}
2526

@@ -67,11 +68,14 @@ func (c *RemoteControlClient) receiveRegistration(server *RemoteControlServer) e
6768
func (s *RemoteControlServer) handleClientConnection(conn net.Conn) {
6869
defer func() {
6970
if err := conn.Close(); err != nil {
70-
log.Printf("Could not close team client connection: %v", err)
71+
log.Printf("Could not close remote control client connection: %v", err)
7172
}
7273
}()
7374

74-
client := RemoteControlClient{Client: &Client{conn: conn, token: uuid.New()}}
75+
client := RemoteControlClient{
76+
Client: &Client{conn: conn, token: uuid.New()},
77+
gcEngine: s.gcEngine,
78+
}
7579
client.reply(client.Ok())
7680

7781
err := client.receiveRegistration(s)
@@ -125,11 +129,19 @@ func (s *RemoteControlServer) SendRequest(teamName string, request ControllerToR
125129
if client, ok := s.clients[teamName]; ok {
126130
return sslconn.SendMessage(client.conn, &request)
127131
}
128-
return errors.Errorf("Team Client '%v' not connected", teamName)
132+
return errors.Errorf("Remote control client '%v' not connected", teamName)
129133
}
130134

131135
func (c *RemoteControlClient) reply(reply ControllerReply) {
132136
response := ControllerToRemoteControl{ControllerReply: &reply}
137+
138+
teamState := c.gcEngine.CurrentState().TeamState[c.team.String()]
139+
response.Keeper = teamState.Goalkeeper
140+
response.SubstituteBot = teamState.RequestsBotSubstitution
141+
response.EmergencyStop = teamState.RequestsEmergencyStop
142+
response.Timeout = teamState.RequestsTimeout
143+
response.ChallengeFlag = teamState.RequestsChallenge
144+
133145
if err := sslconn.SendMessage(c.conn, &response); err != nil {
134146
log.Print("Failed to send reply: ", err)
135147
}
@@ -141,45 +153,67 @@ func (s *RemoteControlServer) processRequest(team state.Team, request RemoteCont
141153
return nil
142154
}
143155

144-
log.Print("Received request from team: ", proto.MarshalTextString(&request))
156+
log.Print("Received request from remote-control: ", proto.MarshalTextString(&request))
145157

146158
currentState := s.gcEngine.CurrentState()
147159
teamState := *currentState.TeamInfo(team)
148-
origin := team.String()
160+
161+
if x, ok := request.GetMsg().(*RemoteControlToController_DesiredKeeper); ok && *teamState.Goalkeeper != x.DesiredKeeper {
162+
if err := mayChangeKeeper(s.gcEngine.CurrentGcState(), &teamState); err != nil {
163+
return errors.Wrap(err, "Remote control requests to change keeper, but: ")
164+
}
165+
s.updateTeamConfig(team, &statemachine.UpdateTeamState{
166+
Goalkeeper: &x.DesiredKeeper,
167+
})
168+
}
149169

150170
if x, ok := request.GetMsg().(*RemoteControlToController_SubstituteBot); ok {
151-
if *teamState.BotSubstitutionIntent != x.SubstituteBot {
152-
log.Printf("Remote control %v requests to change bot substituation intent to %v", team.String(), x.SubstituteBot)
153-
s.gcEngine.Enqueue(&statemachine.Change{
154-
Origin: &origin,
155-
Change: &statemachine.Change_UpdateTeamState{
156-
UpdateTeamState: &statemachine.UpdateTeamState{
157-
ForTeam: &team,
158-
BotSubstitutionIntent: &x.SubstituteBot,
159-
}},
171+
if *teamState.RequestsBotSubstitution != x.SubstituteBot {
172+
s.updateTeamConfig(team, &statemachine.UpdateTeamState{
173+
RequestsBotSubstitution: &x.SubstituteBot,
160174
})
161175
}
162176
return nil
163177
}
164178

165-
if x, ok := request.GetMsg().(*RemoteControlToController_DesiredKeeper); ok && *teamState.Goalkeeper != x.DesiredKeeper {
166-
if currentState.Command.IsRunning() || currentState.Command.IsPrepare() {
167-
return errors.New("Can not change keeper while game is running.")
179+
if x, ok := request.GetMsg().(*RemoteControlToController_Timeout); ok {
180+
if *teamState.RequestsTimeout != x.Timeout {
181+
s.updateTeamConfig(team, &statemachine.UpdateTeamState{
182+
RequestsTimeout: &x.Timeout,
183+
})
184+
}
185+
return nil
186+
}
187+
188+
if x, ok := request.GetMsg().(*RemoteControlToController_ChallengeFlag); ok {
189+
if *teamState.RequestsChallenge != x.ChallengeFlag {
190+
s.updateTeamConfig(team, &statemachine.UpdateTeamState{
191+
RequestsChallenge: &x.ChallengeFlag,
192+
})
168193
}
194+
return nil
195+
}
169196

170-
if err := mayChangeKeeper(s.gcEngine.CurrentGcState(), &teamState); err != nil {
171-
return errors.Wrap(err, "Remote control requests to change keeper, but: ")
197+
if x, ok := request.GetMsg().(*RemoteControlToController_EmergencyStop); ok {
198+
// note: emergency stop can not be disabled again
199+
if x.EmergencyStop {
200+
s.updateTeamConfig(team, &statemachine.UpdateTeamState{
201+
RequestsEmergencyStop: &x.EmergencyStop,
202+
})
172203
}
173-
log.Printf("Remote control %v requests to change keeper to %v", team, x.DesiredKeeper)
174-
s.gcEngine.Enqueue(&statemachine.Change{
175-
Origin: &origin,
176-
Change: &statemachine.Change_UpdateTeamState{
177-
UpdateTeamState: &statemachine.UpdateTeamState{
178-
ForTeam: &team,
179-
Goalkeeper: &x.DesiredKeeper,
180-
}},
181-
})
204+
return nil
182205
}
183206

184207
return nil
185208
}
209+
210+
func (s *RemoteControlServer) updateTeamConfig(team state.Team, update *statemachine.UpdateTeamState) {
211+
origin := "Remote Control " + team.String()
212+
update.ForTeam = &team
213+
s.gcEngine.Enqueue(&statemachine.Change{
214+
Origin: &origin,
215+
Change: &statemachine.Change_UpdateTeamState{
216+
UpdateTeamState: update,
217+
},
218+
})
219+
}

internal/app/rcon/server_team.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ func (s *TeamServer) processRequest(teamName string, request TeamToController) e
170170
teamState := *currentState.TeamInfo(team)
171171

172172
if x, ok := request.GetMsg().(*TeamToController_SubstituteBot); ok {
173-
if *teamState.BotSubstitutionIntent != x.SubstituteBot {
173+
if *teamState.RequestsBotSubstitution != x.SubstituteBot {
174174
log.Printf("Team %v requests to change bot substituation intent to %v", team, x.SubstituteBot)
175175
s.gcEngine.Enqueue(&statemachine.Change{
176176
Origin: &teamName,
177177
Change: &statemachine.Change_UpdateTeamState{
178178
UpdateTeamState: &statemachine.UpdateTeamState{
179-
ForTeam: &team,
180-
BotSubstitutionIntent: &x.SubstituteBot,
179+
ForTeam: &team,
180+
RequestsBotSubstitution: &x.SubstituteBot,
181181
}},
182182
})
183183
}

internal/app/rcon/ssl_gc_rcon_remotecontrol.pb.go

Lines changed: 43 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)