66 "flag"
77 "github.com/RoboCup-SSL/ssl-game-controller/internal/app/rcon"
88 "github.com/RoboCup-SSL/ssl-game-controller/internal/app/sslconn"
9+ "github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
910 "github.com/RoboCup-SSL/ssl-game-controller/pkg/client"
1011 "log"
1112 "net"
@@ -17,6 +18,7 @@ var autoDetectAddress = flag.Bool("autoDetectHost", true, "Automatically detect
1718var refBoxAddr = flag .String ("address" , "localhost:10008" , "Address to connect to" )
1819var privateKeyLocation = flag .String ("privateKey" , "" , "A private key to be used to sign messages" )
1920var teamName = flag .String ("teamName" , "Test Team" , "The name of the team as it is sent by the referee" )
21+ var teamColor = flag .String ("teamColor" , "" , "The color of the team as it is sent by the referee" )
2022
2123var privateKey * rsa.PrivateKey
2224
@@ -37,6 +39,8 @@ func main() {
3739 if host != "" {
3840 log .Print ("Detected game-controller host: " , host )
3941 * refBoxAddr = client .GetConnectionString (* refBoxAddr , host )
42+ } else {
43+ log .Println ("No host detected" )
4044 }
4145 }
4246
@@ -55,12 +59,15 @@ func main() {
5559 c .reader = bufio .NewReaderSize (conn , 1 )
5660
5761 c .register ()
58- for ! c .sendDesiredKeeper (3 ) {
59- time .Sleep (time .Second )
60- }
62+ c .sendDesiredKeeper (3 )
6163
6264 for {
63- c .ReplyToChoices ()
65+ for i := 0 ; i < 30 ; i ++ {
66+ c .ReplyToChoices ()
67+ time .Sleep (time .Millisecond * 100 )
68+ }
69+ log .Print ("Waiting" )
70+ time .Sleep (time .Millisecond * 2000 )
6471 }
6572}
6673
@@ -75,11 +82,16 @@ func (c *Client) register() {
7582
7683 registration := rcon.TeamRegistration {}
7784 registration .TeamName = teamName
85+
86+ if color , validColor := state .Team_value [* teamColor ]; validColor {
87+ registration .Team = new (state.Team )
88+ * registration .Team = state .Team (color )
89+ }
7890 if privateKey != nil {
7991 registration .Signature = & rcon.Signature {Token : reply .GetControllerReply ().NextToken , Pkcs1V15 : []byte {}}
8092 registration .Signature .Pkcs1V15 = client .Sign (privateKey , & registration )
8193 }
82- log .Print ("Sending registration" )
94+ log .Print ("Sending registration: " , registration . String () )
8395 if err := sslconn .SendMessage (c .conn , & registration ); err != nil {
8496 log .Fatal ("Failed sending registration: " , err )
8597 }
@@ -110,14 +122,7 @@ func (c *Client) sendDesiredKeeper(id int32) (accepted bool) {
110122}
111123
112124func (c * Client ) ReplyToChoices () {
113- request := rcon.ControllerToTeam {}
114- if err := sslconn .ReceiveMessage (c .reader , & request ); err != nil {
115- log .Fatal ("Failed receiving controller request: " , err )
116- }
117- if request .GetAdvantageChoice () != nil {
118- log .Printf ("Received choice for: %v" , * request .GetAdvantageChoice ().Foul )
119- }
120- reply := rcon.TeamToController_AdvantageResponse_ {AdvantageResponse : rcon .TeamToController_CONTINUE }
125+ reply := rcon.TeamToController_AdvantageResponse {AdvantageResponse : rcon .AdvantageResponse_CONTINUE }
121126 response := rcon.TeamToController {Msg : & reply }
122127 c .sendRequest (& response )
123128}
0 commit comments