commit e8179c3dab5667ca4445fc8361f4a05960babcf7
parent 297a5599566ff30e8d0aad3ad3306efd63e10381
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 15 Dec 2023 17:29:43 -0500
do not auto-unsit players who had no opportunities to make an action during the game
Diffstat:
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -114,14 +114,15 @@ func (p *PokerStandingPlayer) isEligible(pokerTableMinBet database.PokerChip) bo
type PokerPlayer struct {
*PokerStandingPlayer
- RoundTotalBet database.PokerChip
- Bet database.PokerChip
- AllInMaxGain database.PokerChip
- SeatIdx int // 0 indexed
- Cards []PlayerCard
- CardsMtx sync.RWMutex
- Folded atomic.Bool
- Unsit atomic.Bool
+ RoundTotalBet database.PokerChip
+ Bet database.PokerChip
+ AllInMaxGain database.PokerChip
+ SeatIdx int // 0 indexed
+ Cards []PlayerCard
+ CardsMtx sync.RWMutex
+ Folded atomic.Bool
+ Unsit atomic.Bool
+ countChancesToAction int
}
func (p *PokerPlayer) isAllIn() bool {
@@ -522,6 +523,7 @@ RoundIsSettledLoop:
for { // Repeat until all players have played
playerToPlayIdx = (playerToPlayIdx + 1) % len(g.Ongoing.Players)
p := g.Ongoing.Players[playerToPlayIdx]
+ p.countChancesToAction++
pUsername := p.Username
roomUserTopic := roomID.UserTopic(pUsername)
@@ -565,6 +567,7 @@ RoundIsSettledLoop:
if evt.Unsit {
playerAlive = g.Ongoing.CountAlivePlayers()
if playerAlive == 1 {
+ p.countChancesToAction--
break RoundIsSettledLoop
}
continue GetPlayerEventLoop
@@ -960,7 +963,17 @@ END:
// Auto unsit inactive players
for idx, p := range g.Players {
+ playerShallBeBooted := false
if p != nil && p.LastActionTS.Before(g.Ongoing.CreatedAt) {
+ if op := g.Ongoing.GetPlayer(p.Username); op != nil {
+ if op.countChancesToAction > 0 {
+ playerShallBeBooted = true
+ }
+ } else {
+ playerShallBeBooted = true
+ }
+ }
+ if playerShallBeBooted {
if err := g.UnSitPlayer1(db, roomID, p, idx); err == nil {
PokerPubSub.Pub(roomTopic, PokerSeatLeftEvent{})
newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s auto un-sit", p.Username))