Skip to content

Commit 5d9b8af

Browse files
committed
[test] Allow setting ready flag in autoRef test client
1 parent f9b9fd9 commit 5d9b8af

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

cmd/ssl-auto-ref-client/main.go

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ var clientIdentifier = flag.String("identifier", "test", "The identifier of the
2424

2525
var privateKey *rsa.PrivateKey
2626

27+
var metadata *rcon.GameStateMetadata
28+
2729
type Client struct {
2830
conn net.Conn
2931
token string
@@ -33,6 +35,9 @@ func main() {
3335
flag.Parse()
3436

3537
privateKey = client.LoadPrivateKey(*privateKeyLocation)
38+
metadata = new(rcon.GameStateMetadata)
39+
metadata.TeamYellow = new(rcon.GameStateMetadataTeam)
40+
metadata.TeamBlue = new(rcon.GameStateMetadataTeam)
3641

3742
if *autoDetectAddress {
3843
log.Print("Trying to detect host based on incoming referee messages...")
@@ -47,7 +52,11 @@ func main() {
4752
if err != nil {
4853
log.Fatal("could not connect to game-controller at ", *refBoxAddr)
4954
}
50-
defer conn.Close()
55+
defer func() {
56+
if err := conn.Close(); err != nil {
57+
log.Printf("Could not close connection: %v", err)
58+
}
59+
}()
5160
log.Printf("Connected to game-controller at %v", *refBoxAddr)
5261
c := Client{}
5362
c.conn = conn
@@ -61,6 +70,20 @@ func main() {
6170
}
6271
}()
6372

73+
commands := map[string]func([]string){}
74+
commands["ballLeftField"] = func(_ []string) {
75+
c.sendBallLeftField()
76+
}
77+
commands["botCrashUnique"] = func(_ []string) {
78+
c.sendBotCrashUnique()
79+
}
80+
commands["doubleTouch"] = func(_ []string) {
81+
c.sendDoubleTouch()
82+
}
83+
commands["ready"] = func(args []string) {
84+
c.sendReady(args)
85+
}
86+
6487
reader := bufio.NewReader(os.Stdin)
6588
for {
6689
fmt.Print("-> ")
@@ -73,19 +96,14 @@ func main() {
7396
}
7497
// convert CRLF to LF
7598
text = strings.Replace(text, "\n", "", -1)
76-
77-
if strings.Compare("ballLeftField", text) == 0 {
78-
c.sendBallLeftField()
79-
} else if strings.Compare("botCrashUnique", text) == 0 {
80-
c.sendBotCrashUnique()
81-
} else if strings.Compare("doubleTouch", text) == 0 {
82-
c.sendDoubleTouch()
99+
cmd := strings.Split(text, " ")
100+
if fn, ok := commands[cmd[0]]; ok {
101+
fn(cmd[1:])
83102
} else {
84-
fmt.Println("Available commands: ")
85-
fmt.Printf(" %-20s: %s\n", "help", "Show this help text")
86-
fmt.Printf(" %-20s: %s\n", "ballLeftField", "Send game event")
87-
fmt.Printf(" %-20s: %s\n", "botCrashUnique", "Send game event")
88-
fmt.Printf(" %-20s: %s\n", "doubleTouch", "Send game event")
103+
fmt.Println("Available commands:")
104+
for cmd := range commands {
105+
fmt.Printf(" %-20s\n", cmd)
106+
}
89107
}
90108
}
91109
}
@@ -212,6 +230,24 @@ func (c *Client) sendRequest(request *rcon.AutoRefToController, doLog bool) {
212230
}
213231
}
214232

233+
func (c *Client) sendReady(args []string) {
234+
if len(args) > 0 {
235+
metadata.ReadyToContinue = new(bool)
236+
if args[0] == "true" {
237+
*metadata.ReadyToContinue = true
238+
} else {
239+
*metadata.ReadyToContinue = false
240+
}
241+
} else {
242+
metadata.ReadyToContinue = nil
243+
}
244+
245+
request := rcon.AutoRefToController{
246+
GameStateMetadata: metadata,
247+
}
248+
c.sendRequest(&request, true)
249+
}
250+
215251
func logIf(doLog bool, v ...interface{}) {
216252
if doLog {
217253
log.Print(v...)

0 commit comments

Comments
 (0)