dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit c9705550b8d7268853297144a292104e70a2820a
parent b3a50f6eb49e50001c6db77d441ff7710351ec27
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon,  4 Dec 2023 18:05:21 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker.go | 28++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -15,6 +15,8 @@ import ( "time" ) +const NbPlayers = 10 + type Poker struct { sync.Mutex Games map[string]*PokerGame @@ -32,7 +34,7 @@ func (p *Poker) GetOrCreateGame(roomID string) *PokerGame { g, found := p.Games[roomID] if !found { g = &PokerGame{ - Players: make([]string, 10), + Players: make([]string, NbPlayers), } p.Games[roomID] = g } @@ -69,7 +71,7 @@ func (g *PokerGame) Deal(roomID string) { } utils.Shuffle(deck) - players := make([]string, 10) + players := make([]string, NbPlayers) for idx := range g.Players { players[idx] = g.Players[idx] } @@ -489,7 +491,7 @@ Loop: continue } - if _, ok := payload.(PokerSeatLeftEvent); ok { + drawSeats := func() { seated, _ := g.IsSeated(authUser.Username.String()) for i, p := range g.Players { if p != "" || seated { @@ -503,25 +505,15 @@ Loop: send(`<style>#seat` + strconv.Itoa(i+1) + `:before { content: ""; }</style>`) } } + } + + if _, ok := payload.(PokerSeatLeftEvent); ok { + drawSeats() c.Response().Flush() continue } else if _, ok := payload.(PokerSeatTakenEvent); ok { - - seated, _ := g.IsSeated(authUser.Username.String()) - - for i, p := range g.Players { - if p != "" || seated { - send(`<style>.takeSeat` + strconv.Itoa(i+1) + ` { display: none; }</style>`) - } else { - send(`<style>.takeSeat` + strconv.Itoa(i+1) + ` { display: block; }</style>`) - } - if p != "" { - send(`<style>#seat` + strconv.Itoa(i+1) + `:before { content: "` + p + `"; }</style>`) - } else { - send(`<style>#seat` + strconv.Itoa(i+1) + `:before { content: ""; }</style>`) - } - } + drawSeats() c.Response().Flush() continue