dkforest

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

commit d97ca0373f004c5adebc654a5ae9d245b0b130c2
parent b7ca89f83caa601ad623cb94f9539f44dd033caf
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 19 Dec 2023 00:45:46 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 39++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -1198,28 +1198,33 @@ func autoUnsitInactivePlayers(g *PokerGame) { roomTopic := g.roomID.Topic() 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.UserID) - playerShallBeBooted = (op != nil && op.countChancesToAction > 0) || - (op == nil && !pIsEligible) - } - if playerShallBeBooted { - g.unSitPlayer1(gPlayers, p) - PokerPubSub.Pub(roomTopic, PokerSeatLeftEvent{}) - g.newLogEvent(fmt.Sprintf("%s auto un-sit", p.Username)) - } + if playerShouldBeBooted(p, ongoing, pokerTableMinBet) { + g.unSitPlayer1(gPlayers, p) + PokerPubSub.Pub(roomTopic, PokerSeatLeftEvent{}) + g.newLogEvent(fmt.Sprintf("%s auto un-sit", p.Username)) } } }) } +func playerShouldBeBooted(p *SeatedPlayer, ongoing *Ongoing, pokerTableMinBet database.PokerChip) (playerShallBeBooted bool) { + if p == nil { + return false + } + pIsEligible := p.isEligible(pokerTableMinBet) + if !pIsEligible { + return true + } + 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.UserID) + playerShallBeBooted = (op != nil && op.countChancesToAction > 0) || + (op == nil && !pIsEligible) + } + return playerShallBeBooted +} + const ( TableTypeRake = iota TableType2