dkforest

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

commit 912a97004b04307701f08bd4c3bdb23fb34dbf51
parent 375a0ccbd2eef6b1672964a7b23ffcbe6671071d
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 19 Dec 2023 01:10:22 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 37++++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -700,14 +700,14 @@ func doCheck(g *PokerGame, p *PokerPlayer, minBet *database.PokerChip) int { return doNothing } -func doCall(g *PokerGame, p *PokerPlayer, db *database.DkfDB, minBet *database.PokerChip, +func doCall(g *PokerGame, p *PokerPlayer, minBet *database.PokerChip, newlyAllInPlayers *[]*PokerPlayer) int { pUsername := p.Username bet := utils.MinInt(*minBet-p.GetBet(), p.GetCash()) if bet == 0 { g.newLogEvent(fmt.Sprintf("%s check", pUsername)) } else { - p.doBetAndNotif(db, g.pokerTableID, bet, g.roomID.Topic()) + p.doBetAndNotif(g.db, g.pokerTableID, bet, g.roomID.Topic()) logMsg := fmt.Sprintf("%s call (%d)", pUsername, bet) if p.isAllIn() { logMsg += " (all-in)" @@ -718,14 +718,14 @@ func doCall(g *PokerGame, p *PokerPlayer, db *database.DkfDB, minBet *database.P return doNothing } -func doAllIn(g *PokerGame, p *PokerPlayer, db *database.DkfDB, minBet *database.PokerChip, +func doAllIn(g *PokerGame, p *PokerPlayer, minBet *database.PokerChip, newlyAllInPlayers *[]*PokerPlayer, lastRaisePlayerIdx *int, playerToPlayIdx int) int { bet := p.GetCash() if (p.GetBet() + bet) > *minBet { *lastRaisePlayerIdx = playerToPlayIdx } *minBet = utils.MaxInt(p.GetBet()+bet, *minBet) - p.doBetAndNotif(db, g.pokerTableID, bet, g.roomID.Topic()) + p.doBetAndNotif(g.db, g.pokerTableID, bet, g.roomID.Topic()) logMsg := fmt.Sprintf("%s all-in (%d)", p.Username, bet) if p.isAllIn() { *newlyAllInPlayers = append(*newlyAllInPlayers, p) @@ -734,7 +734,7 @@ func doAllIn(g *PokerGame, p *PokerPlayer, db *database.DkfDB, minBet *database. return doNothing } -func doBet(g *PokerGame, p *PokerPlayer, db *database.DkfDB, minBet *database.PokerChip, +func doBet(g *PokerGame, p *PokerPlayer, minBet *database.PokerChip, newlyAllInPlayers *[]*PokerPlayer, lastRaisePlayerIdx *int, playerToPlayIdx int, evt PlayerEvent) int { roomTopic := g.roomID.Topic() roomUserTopic := g.roomID.UserTopic(p.UserID) @@ -760,7 +760,7 @@ func doBet(g *PokerGame, p *PokerPlayer, db *database.DkfDB, minBet *database.Po *lastRaisePlayerIdx = playerToPlayIdx } *minBet = utils.MaxInt(p.GetBet()+bet, *minBet) - p.doBetAndNotif(db, g.pokerTableID, bet, roomTopic) + p.doBetAndNotif(g.db, g.pokerTableID, bet, roomTopic) logMsg := fmt.Sprintf("%s bet %d", p.Username, bet) if p.isAllIn() { logMsg += " (all-in)" @@ -789,7 +789,7 @@ func handleAutoActionReceived(g *PokerGame, autoCache map[database.UserID]AutoAc return continueGetPlayerEventLoop } -func applyAutoAction(g *PokerGame, p *PokerPlayer, db *database.DkfDB, minBet *database.PokerChip, +func applyAutoAction(g *PokerGame, p *PokerPlayer, minBet *database.PokerChip, newlyAllInPlayers *[]*PokerPlayer, lastRaisePlayerIdx, playerAlive *int, playerToPlayIdx int, autoAction AutoAction, autoCache map[database.UserID]AutoAction) (actionResult int) { @@ -806,11 +806,11 @@ func applyAutoAction(g *PokerGame, p *PokerPlayer, db *database.DkfDB, minBet *d case CheckAction: actionResult = doCheck(g, p, minBet) case CallAction: - actionResult = doCall(g, p, db, minBet, newlyAllInPlayers) + actionResult = doCall(g, p, minBet, newlyAllInPlayers) case AllInAction: - actionResult = doAllIn(g, p, db, minBet, newlyAllInPlayers, lastRaisePlayerIdx, playerToPlayIdx) + actionResult = doAllIn(g, p, minBet, newlyAllInPlayers, lastRaisePlayerIdx, playerToPlayIdx) case BetAction: - actionResult = doBet(g, p, db, minBet, newlyAllInPlayers, lastRaisePlayerIdx, playerToPlayIdx, autoAction.evt) + actionResult = doBet(g, p, minBet, newlyAllInPlayers, lastRaisePlayerIdx, playerToPlayIdx, autoAction.evt) } } delete(autoCache, pUserID) @@ -818,7 +818,7 @@ func applyAutoAction(g *PokerGame, p *PokerPlayer, db *database.DkfDB, minBet *d return } -func handlePlayerActionEvent(g *PokerGame, p *PokerPlayer, db *database.DkfDB, minBet *database.PokerChip, +func handlePlayerActionEvent(g *PokerGame, p *PokerPlayer, minBet *database.PokerChip, newlyAllInPlayers *[]*PokerPlayer, lastRaisePlayerIdx, playerAlive *int, playerToPlayIdx int, evt PlayerEvent) (actionResult int) { @@ -828,11 +828,11 @@ func handlePlayerActionEvent(g *PokerGame, p *PokerPlayer, db *database.DkfDB, m } else if evt.Check { actionResult = doCheck(g, p, minBet) } else if evt.Call { - actionResult = doCall(g, p, db, minBet, newlyAllInPlayers) + actionResult = doCall(g, p, minBet, newlyAllInPlayers) } else if evt.AllIn { - actionResult = doAllIn(g, p, db, minBet, newlyAllInPlayers, lastRaisePlayerIdx, playerToPlayIdx) + actionResult = doAllIn(g, p, minBet, newlyAllInPlayers, lastRaisePlayerIdx, playerToPlayIdx) } else if evt.Bet > 0 { - actionResult = doBet(g, p, db, minBet, newlyAllInPlayers, lastRaisePlayerIdx, playerToPlayIdx, evt) + actionResult = doBet(g, p, minBet, newlyAllInPlayers, lastRaisePlayerIdx, playerToPlayIdx, evt) } else { actionResult = continueGetPlayerEventLoop } @@ -890,32 +890,27 @@ RoundIsSettledLoop: for { // Repeat until we get an event from the player we're interested in var evt PlayerEvent actionResult := doNothing - // Check for pre-selected action if autoAction, ok := autoCache[pUserID]; ok { - actionResult = applyAutoAction(g, p, db, &minBet, &newlyAllInPlayers, + actionResult = applyAutoAction(g, p, &minBet, &newlyAllInPlayers, &lastRaisePlayerIdx, &playerAlive, playerToPlayIdx, autoAction, autoCache) goto checkActionResult } - select { case evt = <-g.playersEventCh: case <-waitCh: // Waited too long, either auto-check or auto-fold actionResult = doTimeout(g, p, &minBet, &playerAlive) goto checkActionResult } - if evt.Unsit { actionResult = doUnsit(g, p, &playerAlive) goto checkActionResult } - if evt.UserID != pUserID { actionResult = handleAutoActionReceived(g, autoCache, evt) goto checkActionResult } - - actionResult = handlePlayerActionEvent(g, p, db, &minBet, &newlyAllInPlayers, + actionResult = handlePlayerActionEvent(g, p, &minBet, &newlyAllInPlayers, &lastRaisePlayerIdx, &playerAlive, playerToPlayIdx, evt) goto checkActionResult