Skip to content

Commit

Permalink
[feature] Allow teams to send a ping to the GC to test network connec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
g3force committed May 3, 2019
1 parent 60a4690 commit 2083222
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 35 deletions.
9 changes: 7 additions & 2 deletions internal/app/controller/teamConnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ func (c *GameController) teamConnected(team Team) (connected bool, verified bool
func (c *GameController) ProcessTeamRequests(teamName string, request refproto.TeamToController) error {
c.ConnectionMutex.Lock()
defer c.ConnectionMutex.Unlock()

if _, ok := request.GetMsg().(*refproto.TeamToController_Ping); ok {
return nil
}

log.Print("Received request from team: ", proto.MarshalTextString(&request))

if x, ok := request.GetMsg().(*refproto.TeamToController_AdvantageResponse_); ok {
if msg, ok := request.GetMsg().(*refproto.TeamToController_AdvantageResponse_); ok {
if c.outstandingTeamChoice == nil {
return errors.New("No outstanding choice available. You are probably too late.")
}
responseTime := c.Engine.TimeProvider().Sub(c.outstandingTeamChoice.IssueTime)
if x.AdvantageResponse == refproto.TeamToController_CONTINUE {
if msg.AdvantageResponse == refproto.TeamToController_CONTINUE {
log.Printf("Team %v decided to continue the game within %v", c.outstandingTeamChoice.Team, responseTime)
switch c.outstandingTeamChoice.Event.GameEvent.Type {
case GameEventBotCrashUnique:
Expand Down
82 changes: 49 additions & 33 deletions pkg/refproto/ssl_game_controller_team.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/refproto/ssl_game_controller_team.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ message TeamToController {
AdvantageResponse advantage_response = 3;
// request to substitute a robot at the next possibility
bool substitute_bot = 4;
// send a ping to the GC to test if the connection is still open.
// the value is ignored and a reply is sent back
bool ping = 5;
}

enum AdvantageResponse {
Expand Down

0 comments on commit 2083222

Please sign in to comment.