53 lines
1.3 KiB
Go
53 lines
1.3 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
|
|
noTimeout bool
|
|
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.BoolVar(&noTimeout, "no-timeout", false, "Disable inactivity timer")
|
|
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), !noTimeout)
|
|
|
|
go c.Connect()
|
|
select {}
|
|
}
|