client/cmd/botspectate/main.go
stephen mcquay c21e0c5582
Change how server address is specified
now you spell it as such:

gobot -addr wss://hackerbots.us
gobot -addr ws://localhost:8666
2016-07-13 19:46:08 -06:00

50 lines
905 B
Go

package main
import (
"flag"
"fmt"
"math/rand"
"os"
"time"
"hackerbots.us/client"
"hackerbots.us/server"
)
var addr = flag.String("addr", "ws://localhost:8666", "server hostname")
var forceJSON = flag.Bool("json", false, "force json encoding")
func main() {
rand.Seed(time.Now().UnixNano())
var gameId string
flag.Parse()
if flag.NArg() < 1 {
gameId = "debug"
} else {
gameId = flag.Arg(0)
}
c := &client.Client{
Server: *addr,
Name: "bspect",
GameId: gameId,
ForceJSON: *forceJSON,
StateStream: make(chan *server.Boardstate),
Die: make(chan struct{}),
Player: client.Spectator{},
}
var err error
err = c.Negotiate("spectator", c.Player)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: failed to negotiate: %s\n", c.Name, err)
os.Exit(1)
}
go func() {
if err := c.Play(); err != nil {
close(c.Die)
}
}()
c.Visualize()
}