Add option --no-timeout
This commit is contained in:
parent
93fba875ad
commit
e769215e74
4 changed files with 16 additions and 13 deletions
|
@ -42,7 +42,7 @@ type Client struct {
|
|||
game *bgammon.GameState
|
||||
}
|
||||
|
||||
func NewClient(beiAddress string, serverAddress string, username string, password string, points int, variant int8) *Client {
|
||||
func NewClient(beiAddress string, serverAddress string, username string, password string, points int, variant int8, timeout bool) *Client {
|
||||
const bufferSize = 10
|
||||
c := &Client{
|
||||
Address: serverAddress,
|
||||
|
@ -60,15 +60,14 @@ func NewClient(beiAddress string, serverAddress string, username string, passwor
|
|||
c.beiClient = NewBEIClient(beiAddress, false)
|
||||
}
|
||||
go c.handleEvents()
|
||||
go c.handleTimeout()
|
||||
go c.handleTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func NewLocalClient(conn net.Conn, serverAddress string, username string, password string, points int, variant int8, beiClient *BEIClient) *Client {
|
||||
c := NewClient("", serverAddress, username, password, points, variant)
|
||||
func NewLocalClient(conn net.Conn, serverAddress string, username string, password string, points int, variant int8, timeout bool, beiClient *BEIClient) *Client {
|
||||
c := NewClient("", serverAddress, username, password, points, variant, timeout)
|
||||
c.beiClient = beiClient
|
||||
c.connecting = true
|
||||
go c.handleEvents()
|
||||
go c.connectTCP(conn)
|
||||
return c
|
||||
}
|
||||
|
@ -294,7 +293,7 @@ func (c *Client) createMatch() {
|
|||
c.rolled = false
|
||||
}
|
||||
|
||||
func (c *Client) handleTimeout() {
|
||||
func (c *Client) handleTimeout(inactive bool) {
|
||||
t := time.NewTicker(time.Minute)
|
||||
for range t.C {
|
||||
if !c.rolled {
|
||||
|
@ -310,6 +309,8 @@ func (c *Client) handleTimeout() {
|
|||
c.Out <- []byte("leave")
|
||||
continue
|
||||
}
|
||||
} else if !inactive {
|
||||
continue
|
||||
}
|
||||
|
||||
limit := 5 * time.Minute
|
||||
|
|
4
go.mod
4
go.mod
|
@ -4,8 +4,8 @@ go 1.17
|
|||
|
||||
require (
|
||||
code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240419175805-962ec980f0d0
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240720003230-1e079dcccf22
|
||||
nhooyr.io/websocket v1.8.11
|
||||
)
|
||||
|
||||
require code.rocket9labs.com/tslocum/tabula v0.0.0-20240422202348-09cfc96fcfc9 // indirect
|
||||
require code.rocket9labs.com/tslocum/tabula v0.0.0-20240703054156-ce0b448f0999 // indirect
|
||||
|
|
8
go.sum
8
go.sum
|
@ -1,8 +1,8 @@
|
|||
code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b h1:Y0a14Kf/hSYepSmp4ZfDeE4CZZGBGBS97CNjCbKJm0c=
|
||||
code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b/go.mod h1:tS60/VNAJphKvDBkSLQhKALa15msIAuWWfEKNc4oFZc=
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240419175805-962ec980f0d0 h1:FnvEy3QkAy/8ioIxTyvF2VZnzh+anDN8USKNKhPXj8E=
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240419175805-962ec980f0d0/go.mod h1:NGFAKlapNeIriQfrrayRBAv2jOuxHhhJH3zokKBJ/Gg=
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240422202348-09cfc96fcfc9 h1:9wtELMiDrOEsgRPcumaSkdVOBGxr1/KAcUii/rmpwmU=
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240422202348-09cfc96fcfc9/go.mod h1:WEJXESKXqrMFLAArikQ79lpRibNeeE1C0VruxXYMF5M=
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240720003230-1e079dcccf22 h1:D1nKA9WbDvPXNt00b4TwoTqeCiG1jK2/P41uwjoAmVA=
|
||||
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240720003230-1e079dcccf22/go.mod h1:z9MOUNGBYmJC0XY8Mac40nYbTwzvosmKjpF04Vr8CWo=
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240703054156-ce0b448f0999 h1:PwfoDBtxVT3TwL2KpoijPKi6NQsGu6cXhPVoQeqKJWM=
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240703054156-ce0b448f0999/go.mod h1:WEJXESKXqrMFLAArikQ79lpRibNeeE1C0VruxXYMF5M=
|
||||
nhooyr.io/websocket v1.8.11 h1:f/qXNc2/3DpoSZkHt1DQu6rj4zGC8JmkkLkWss0MgN0=
|
||||
nhooyr.io/websocket v1.8.11/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
|
||||
|
|
4
main.go
4
main.go
|
@ -19,6 +19,7 @@ func main() {
|
|||
password string
|
||||
points int
|
||||
variant int
|
||||
noTimeout bool
|
||||
debug int
|
||||
)
|
||||
flag.StringVar(&serverAddress, "server", "bgammon.org:1337", "Server address (bgammon protocol)")
|
||||
|
@ -27,6 +28,7 @@ func main() {
|
|||
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()
|
||||
|
||||
|
@ -44,7 +46,7 @@ func main() {
|
|||
}()
|
||||
}
|
||||
|
||||
c := bot.NewClient(beiAddress, serverAddress, username, password, points, int8(variant))
|
||||
c := bot.NewClient(beiAddress, serverAddress, username, password, points, int8(variant), !noTimeout)
|
||||
|
||||
go c.Connect()
|
||||
select {}
|
||||
|
|
Loading…
Reference in a new issue