From 2648772e515e79fa5876d6607ee38d58e2a5f579 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 16 Sep 2024 20:16:46 -0700 Subject: [PATCH] Leave local matches immediately when player leaves --- bot/client.go | 13 ++++++++++++- go.mod | 6 ++++-- go.sum | 4 ++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bot/client.go b/bot/client.go index d578ce0..31b6a4c 100644 --- a/bot/client.go +++ b/bot/client.go @@ -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 diff --git a/go.mod b/go.mod index 43a11eb..51f9ae8 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 8134c93..d4cdcb0 100644 --- a/go.sum +++ b/go.sum @@ -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=