dkforest

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

commit ebc3bbced1fa3fc482ea94f25f5527fc21cd8060
parent c140936700b66e008b2fc6aeae6378c4c2ea327f
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 17 Dec 2023 08:48:48 -0500

db with

Diffstat:
Mpkg/database/database.go | 9++++++++-
Mpkg/web/handlers/poker/poker.go | 12++++--------
2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/pkg/database/database.go b/pkg/database/database.go @@ -336,7 +336,14 @@ func Backup() error { return bk.Finish() } -func (d *DkfDB) With(clb func(tx *DkfDB) error) { +func (d *DkfDB) With(clb func(tx *DkfDB)) { + d.WithE(func(tx *DkfDB) error { + clb(tx) + return nil + }) +} + +func (d *DkfDB) WithE(clb func(tx *DkfDB) error) { tx := d.Begin() err := clb(tx) if err != nil { diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -426,12 +426,11 @@ func (g *PokerGame) UnSitPlayer1(seatedPlayer *SeatedPlayer) error { if err != nil { return err } - db.With(func(tx *database.DkfDB) error { + db.With(func(tx *database.DkfDB) { incrUserChips(&user, g.PokerTableIsTest, account.Amount, false) account.Amount = 0 account.DoSave(tx) user.DoSave(tx) - return nil }) if ongoing != nil { if player := ongoing.GetPlayer(seatedPlayerUsername); player != nil { @@ -1154,7 +1153,7 @@ func applyGains(g *PokerGame, playersGain []PlayerGain, mainPot, rake database.P ongoing := g.Ongoing pokerTableID := g.PokerTableID nbPlayersGain := len(playersGain) - g.DB.With(func(tx *database.DkfDB) error { + g.DB.With(func(tx *database.DkfDB) { if nbPlayersGain >= 1 { winnerHand = utils.Ternary(nbPlayersGain == 1, playersGain[0].HandStr, "Split pot") @@ -1178,7 +1177,6 @@ func applyGains(g *PokerGame, playersGain []PlayerGain, mainPot, rake database.P op.refundBet(tx, pokerTableID) } } - return nil }) return } @@ -1433,7 +1431,7 @@ func PokerFoldHandler(c echo.Context) error { func Refund(db *database.DkfDB) { accounts, _ := db.GetPositivePokerTableAccounts() - db.With(func(tx *database.DkfDB) error { + db.With(func(tx *database.DkfDB) { for _, account := range accounts { if user, err := tx.GetUserByID(account.UserID); err == nil { incrUserChips(&user, account.PokerTable.IsTest, account.Amount+account.AmountBet, false) @@ -1443,7 +1441,6 @@ func Refund(db *database.DkfDB) { user.DoSave(tx) } } - return nil }) } @@ -1566,10 +1563,9 @@ func PokerSitHandler(c echo.Context) error { PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: err.Error()}) return c.HTML(http.StatusOK, html) } - db.With(func(tx *database.DkfDB) error { + db.With(func(tx *database.DkfDB) { authUser.DoSave(tx) tableAccount.DoSave(tx) - return nil }) PokerPubSub.Pub(roomTopic, PokerSeatTakenEvent{}) g.newLogEvent(fmt.Sprintf("%s sit", authUser.Username.String()))