dkforest

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

commit bab9047e776b373d4634efb3fd6d1ddc9cccbec1
parent df117837339c3eb680a36569ab414e3c37abd8fa
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 18 Dec 2023 04:08:38 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 43++++++++++++++++++++-----------------------
1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -413,12 +413,13 @@ func (g *PokerGame) UnSitPlayer(username database.Username) error { g.Players.Lock() defer g.Players.Unlock() if p := g.getPlayer(username); p != nil { - return g.UnSitPlayer1(p) + g.UnSitPlayer1(p) + return nil } return errors.New("player is not sit") } -func (g *PokerGame) UnSitPlayer1(seatedPlayer *SeatedPlayer) error { +func (g *PokerGame) UnSitPlayer1(seatedPlayer *SeatedPlayer) { ongoing := g.Ongoing roomTopic := g.RoomID.Topic() seatedPlayerUsername := seatedPlayer.Username @@ -439,7 +440,6 @@ func (g *PokerGame) UnSitPlayer1(seatedPlayer *SeatedPlayer) error { } } (*g.Players.Val())[seatedPlayer.SeatIdx] = nil - return nil } func generateDeck() []string { @@ -1102,31 +1102,28 @@ func autoUnsitInactivePlayers(g *PokerGame) { ongoing := g.Ongoing pokerTableMinBet := g.PokerTableMinBet roomTopic := g.RoomID.Topic() - g.Players.Lock() - defer g.Players.Unlock() - for _, p := range *g.Players.Val() { - if p != nil { - playerShallBeBooted := false - pIsEligible := p.isEligible(pokerTableMinBet) - if !pIsEligible { - playerShallBeBooted = true - } else if p.LastActionTS.Before(ongoing.CreatedAt) { - // If the player was playing the game, must be booted if he had the chance to make actions and did not. - // If the player was not playing the game, must be booted if he's not eligible to play the next one. - op := ongoing.GetPlayer(p.Username) - playerShallBeBooted = (op != nil && op.countChancesToAction > 0) || - (op == nil && !pIsEligible) - } - if playerShallBeBooted { - if err := g.UnSitPlayer1(p); err == nil { + g.Players.With(func(gPlayers *[]*SeatedPlayer) { + for _, p := range *gPlayers { + if p != nil { + playerShallBeBooted := false + pIsEligible := p.isEligible(pokerTableMinBet) + if !pIsEligible { + playerShallBeBooted = true + } else if p.LastActionTS.Before(ongoing.CreatedAt) { + // If the player was playing the game, must be booted if he had the chance to make actions and did not. + // If the player was not playing the game, must be booted if he's not eligible to play the next one. + op := ongoing.GetPlayer(p.Username) + playerShallBeBooted = (op != nil && op.countChancesToAction > 0) || + (op == nil && !pIsEligible) + } + if playerShallBeBooted { + g.UnSitPlayer1(p) PokerPubSub.Pub(roomTopic, PokerSeatLeftEvent{}) g.newLogEvent(fmt.Sprintf("%s auto un-sit", p.Username)) - } else { - fmt.Println(err) } } } - } + }) } const (