dkforest

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

commit f2711b9e0a308614d8784f130ce20c9f43b8bdc2
parent 3df70838341956976b20253f895e2043226142ee
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 27 Dec 2023 02:08:40 -0500

cleanup

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

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -1448,6 +1448,25 @@ const ( TableType2 ) +// Increase users rake-back and casino rake for paying tables. +func applyRake(g *Game, tx *database.DkfDB, rake database.PokerChip) { + rakeBackMap := make(map[database.UserID]database.PokerChip) + for _, p := range g.ongoing.players { + if p.pokerReferredBy != nil { + rakeBack := database.PokerChip(math.RoundToEven(RakeBackPct * float64(p.rakePaid))) + rakeBackMap[*p.pokerReferredBy] += rakeBack + rake -= rakeBack + } + } + for userID, totalRakeBack := range rakeBackMap { + if err := tx.IncrUserRakeBack(userID, totalRakeBack); err != nil { + logrus.Error(err) + rake += totalRakeBack + } + } + _ = tx.IncrPokerCasinoRake(rake) +} + func applyGains(g *Game, playersGain []PlayerGain, mainPot, rake database.PokerChip) (winnersStr, winnerHand string) { ongoing := g.ongoing pokerTableID := g.pokerTableID @@ -1457,25 +1476,10 @@ func applyGains(g *Game, playersGain []PlayerGain, mainPot, rake database.PokerC winnerHand = utils.Ternary(nbPlayersGain == 1, playersGain[0].HandStr, "Split pot") if g.tableType == TableTypeRake { - rakeOrig := rake if !g.pokerTableIsTest { - rakeBackMap := make(map[database.UserID]database.PokerChip) - for _, p := range g.ongoing.players { - if p.pokerReferredBy != nil { - rakeBack := database.PokerChip(math.RoundToEven(RakeBackPct * float64(p.rakePaid))) - rakeBackMap[*p.pokerReferredBy] += rakeBack - rake -= rakeBack - } - } - for userID, totalRakeBack := range rakeBackMap { - if err := tx.IncrUserRakeBack(userID, totalRakeBack); err != nil { - logrus.Error(err) - rake += totalRakeBack - } - } - _ = tx.IncrPokerCasinoRake(rake) + applyRake(g, tx, rake) } - g.newLogEvent(fmt.Sprintf("Rake %d (%.2f%%)", rakeOrig, (float64(rakeOrig)/float64(mainPot))*100)) + g.newLogEvent(fmt.Sprintf("Rake %d (%.2f%%)", rake, (float64(rake)/float64(mainPot))*100)) } for _, el := range playersGain {