bgammon-bei-bot/main.go

52 lines
1.2 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"os"
"code.rocket9labs.com/tslocum/bgammon-bei-bot/bot"
)
func main() {
var (
serverAddress string
beiAddress string
username string
password string
points int
variant int
debug int
)
flag.StringVar(&serverAddress, "server", "bgammon.org:1337", "Server address (bgammon protocol)")
flag.StringVar(&beiAddress, "bei", "", "Client address (BEI protocol)")
flag.StringVar(&username, "username", "", "Username")
flag.StringVar(&password, "password", "", "Password")
flag.IntVar(&points, "points", 1, "Match points")
flag.IntVar(&variant, "variant", 0, "Variant (0: Backgammon, 1: Acey-deucey, 2: Tabula)")
flag.IntVar(&debug, "debug", 0, "Port to serve debug information on (pprof)")
flag.Parse()
if beiAddress == "" {
log.Fatal("Client address must be specified via --bei flag.")
}
if password == "" {
password = os.Getenv("BOT_PASSWORD")
}
if debug > 0 {
go func() {
log.Fatal(http.ListenAndServe(fmt.Sprintf("localhost:%d", debug), nil))
}()
}
c := bot.NewClient(beiAddress, serverAddress, username, password, points, int8(variant))
go c.Connect()
c.HandleEvents()
}