@@ -24,6 +24,8 @@ var clientIdentifier = flag.String("identifier", "test", "The identifier of the
24
24
25
25
var privateKey * rsa.PrivateKey
26
26
27
+ var metadata * rcon.GameStateMetadata
28
+
27
29
type Client struct {
28
30
conn net.Conn
29
31
token string
@@ -33,6 +35,9 @@ func main() {
33
35
flag .Parse ()
34
36
35
37
privateKey = client .LoadPrivateKey (* privateKeyLocation )
38
+ metadata = new (rcon.GameStateMetadata )
39
+ metadata .TeamYellow = new (rcon.GameStateMetadataTeam )
40
+ metadata .TeamBlue = new (rcon.GameStateMetadataTeam )
36
41
37
42
if * autoDetectAddress {
38
43
log .Print ("Trying to detect host based on incoming referee messages..." )
@@ -47,7 +52,11 @@ func main() {
47
52
if err != nil {
48
53
log .Fatal ("could not connect to game-controller at " , * refBoxAddr )
49
54
}
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
+ }()
51
60
log .Printf ("Connected to game-controller at %v" , * refBoxAddr )
52
61
c := Client {}
53
62
c .conn = conn
@@ -61,6 +70,20 @@ func main() {
61
70
}
62
71
}()
63
72
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
+
64
87
reader := bufio .NewReader (os .Stdin )
65
88
for {
66
89
fmt .Print ("-> " )
@@ -73,19 +96,14 @@ func main() {
73
96
}
74
97
// convert CRLF to LF
75
98
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 :])
83
102
} 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
+ }
89
107
}
90
108
}
91
109
}
@@ -212,6 +230,24 @@ func (c *Client) sendRequest(request *rcon.AutoRefToController, doLog bool) {
212
230
}
213
231
}
214
232
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
+
215
251
func logIf (doLog bool , v ... interface {}) {
216
252
if doLog {
217
253
log .Print (v ... )
0 commit comments