Allow players to leave for up to 15 minutes after saying 'brb'

This commit is contained in:
Trevor Slocum 2023-12-18 10:37:02 -08:00
parent bc331bd240
commit 5e4b4e6d97

View file

@ -11,6 +11,7 @@ import (
"math/big"
"net"
"os"
"regexp"
"strconv"
"strings"
"text/tabwriter"
@ -27,6 +28,8 @@ var Game = &bgammon.GameState{
Game: bgammon.NewGame(false),
}
var nonAlpha = regexp.MustCompile(`[^a-zA-Z]+`)
type Client struct {
Address string
Username string
@ -346,6 +349,10 @@ func (c *Client) HandleEvents() {
log.Printf("*** %s", ev.Message)
case *bgammon.EventSay:
log.Printf("<%s> %s", ev.Player, ev.Message)
if nonAlpha.ReplaceAllString(strings.ToLower(ev.Message), "") == "brb" {
c.lastActivity = time.Now().Add(10 * time.Minute)
c.Out <- []byte("say I will wait 15 minutes for your return.")
}
case *bgammon.EventList:
case *bgammon.EventJoined:
if ev.PlayerNumber == 1 {