dkforest

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

commit 6e3a96166342bddf6f240d9b7ed9405173e5a0fb
parent f2711b9e0a308614d8784f130ce20c9f43b8bdc2
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 27 Dec 2023 11:04:55 -0500

keep track of rake back given

Diffstat:
Acmd/dkf/migrations/158.sql | 4++++
Mpkg/database/tablePokerCasino.go | 11++++++-----
Mpkg/web/handlers/poker/poker.go | 5++++-
3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/cmd/dkf/migrations/158.sql b/cmd/dkf/migrations/158.sql @@ -0,0 +1,4 @@ +-- +migrate Up +ALTER TABLE poker_casino ADD COLUMN total_rake_back INTEGER NOT NULL DEFAULT 0; + +-- +migrate Down diff --git a/pkg/database/tablePokerCasino.go b/pkg/database/tablePokerCasino.go @@ -4,9 +4,10 @@ import "fmt" // PokerCasino table, should always be one row type PokerCasino struct { - ID int64 - Rake PokerChip - HandsPlayed int64 + ID int64 + Rake PokerChip + HandsPlayed int64 + TotalRakeBack int64 } func (PokerCasino) TableName() string { return "poker_casino" } @@ -20,7 +21,7 @@ func (d *DkfDB) GetPokerCasino() (out PokerCasino) { return } -func (d *DkfDB) IncrPokerCasinoRake(rake PokerChip) (err error) { - err = d.db.Exec(`UPDATE poker_casino SET rake = rake + ?, hands_played = hands_played + 1 WHERE id = 1`, rake).Error +func (d *DkfDB) IncrPokerCasinoRake(rake, rakeBack PokerChip) (err error) { + err = d.db.Exec(`UPDATE poker_casino SET rake = rake + ?, total_rake_back = total_rake_back + ?, hands_played = hands_played + 1 WHERE id = 1`, rake, rakeBack).Error return } diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -1458,13 +1458,16 @@ func applyRake(g *Game, tx *database.DkfDB, rake database.PokerChip) { rake -= rakeBack } } + casinoRakeBack := database.PokerChip(0) for userID, totalRakeBack := range rakeBackMap { + casinoRakeBack += totalRakeBack if err := tx.IncrUserRakeBack(userID, totalRakeBack); err != nil { logrus.Error(err) + casinoRakeBack -= totalRakeBack rake += totalRakeBack } } - _ = tx.IncrPokerCasinoRake(rake) + _ = tx.IncrPokerCasinoRake(rake, casinoRakeBack) } func applyGains(g *Game, playersGain []PlayerGain, mainPot, rake database.PokerChip) (winnersStr, winnerHand string) {