2024-02-21 21:16:31 +00:00
|
|
|
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
|
2024-07-21 17:47:38 +00:00
|
|
|
noTimeout bool
|
2024-02-21 21:16:31 +00:00
|
|
|
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)")
|
2024-07-21 17:47:38 +00:00
|
|
|
flag.BoolVar(&noTimeout, "no-timeout", false, "Disable inactivity timer")
|
2024-02-21 21:16:31 +00:00
|
|
|
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))
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2024-07-21 17:47:38 +00:00
|
|
|
c := bot.NewClient(beiAddress, serverAddress, username, password, points, int8(variant), !noTimeout)
|
2024-02-21 21:16:31 +00:00
|
|
|
|
|
|
|
go c.Connect()
|
2024-04-22 20:29:45 +00:00
|
|
|
select {}
|
2024-02-21 21:16:31 +00:00
|
|
|
}
|