Leave local matches immediately when player leaves

This commit is contained in:
Trevor Slocum 2024-09-16 20:16:46 -07:00
parent 92734e0c2a
commit 2648772e51
3 changed files with 18 additions and 5 deletions

View file

@ -55,11 +55,16 @@ func NewClient(beiAddress string, serverAddress string, username string, passwor
Game: bgammon.NewGame(bgammon.VariantBackgammon),
},
}
if beiAddress != "" {
c.beiClient = NewBEIClient(beiAddress, false)
}
go c.handleEvents()
go c.handleTimeout(timeout)
if serverAddress != "" {
go c.handleTimeout(timeout)
}
return c
}
@ -67,7 +72,9 @@ func NewLocalClient(conn net.Conn, serverAddress string, username string, passwo
c := NewClient("", serverAddress, username, password, points, variant, timeout)
c.beiClient = beiClient
c.connecting = true
go c.connectTCP(conn)
return c
}
@ -402,6 +409,10 @@ func (c *Client) handleEvents() {
c.createMatch()
} else {
log.Printf("%s left the match.", ev.Player)
if c.Address == "" {
c.Out <- []byte("leave")
c.createMatch()
}
}
case *bgammon.EventBoard:
*c.game = ev.GameState

6
go.mod
View file

@ -1,10 +1,12 @@
module code.rocket9labs.com/tslocum/bgammon-bei-bot
go 1.17
go 1.23
toolchain go1.23.0
require (
code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240830070609-dc5e2bfea543
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240916195023-c833adb3566e
github.com/coder/websocket v1.8.12
)

4
go.sum
View file

@ -1,7 +1,7 @@
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-20240830070609-dc5e2bfea543 h1:ijyFfRCDXD3wizmLIDEEwmVNebaQl8XRkqYjFuscvUI=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240830070609-dc5e2bfea543/go.mod h1:1wuDH6u2P1SDyyiIDukWOOn0rMcPmsX25a4InIEJYKE=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240916195023-c833adb3566e h1:OnSJcIiARnkoBYsPAjV+wUVqZ5u7POvHFrGtTg4REVw=
code.rocket9labs.com/tslocum/bgammon v0.0.0-20240916195023-c833adb3566e/go.mod h1:fW6aZ6va+Wh8Hw/r7fkIAHUmo/Mwkm0kR2llEX2G3Uc=
code.rocket9labs.com/tslocum/tabula v0.0.0-20240820025521-91065b63f1be h1:awgpl3vS+d7vciw7X5z+joGSPZHB1OOTpkPKW3mPGDs=
code.rocket9labs.com/tslocum/tabula v0.0.0-20240820025521-91065b63f1be/go.mod h1:WEJXESKXqrMFLAArikQ79lpRibNeeE1C0VruxXYMF5M=
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=