dkforest

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

commit c3a71b8f6bee30da28e74a6ef716e09b5ecc096e
parent 6e911280413d35265853c8976283754530421e54
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 12 Dec 2023 17:39:04 -0500

cleanup

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

diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go @@ -644,3 +644,16 @@ func (u *User) CanSendPM() bool { } return u.GeneralMessagesCount >= 20 } + +func (u *User) GetChips(isTest bool) int { + if isTest { + return u.ChipsTest + } + return 0 +} + +func (u *User) IncrChips(chips int, isTest bool) { + if isTest { + u.ChipsTest += chips + } +} diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -370,9 +370,7 @@ func (g *PokerGame) UnSitPlayer1(db *database.DkfDB, roomID string, player *Poke return err } tx := db.Begin() - if account.PokerTable.IsTest { - user.ChipsTest += int(account.Amount) - } + user.IncrChips(int(account.Amount), account.PokerTable.IsTest) account.Amount = 0 account.DoSave(tx) user.DoSave(tx) @@ -1190,9 +1188,7 @@ func Refund(db *database.DkfDB) { tx := db.Begin() for _, account := range accounts { if user, err := tx.GetUserByID(account.UserID); err == nil { - if account.PokerTable.IsTest { - user.ChipsTest += int(account.Amount + account.AmountBet) - } + user.IncrChips(int(account.Amount+account.AmountBet), account.PokerTable.IsTest) account.Amount = 0 account.AmountBet = 0 account.DoSave(tx) @@ -1266,19 +1262,14 @@ func PokerSitHandler(c echo.Context) error { logrus.Error(err) return c.HTML(http.StatusOK, html) } - userChips := int64(0) - if tableAccount.PokerTable.IsTest { - userChips = int64(authUser.ChipsTest) - } + userChips := int64(authUser.GetChips(tableAccount.PokerTable.IsTest)) totalChips := userChips + tableAccount.Amount if totalChips < pokerTable.MinBuyIn { PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: fmt.Sprintf("Not enough chips to sit; have: %d; needs: %d", totalChips, pokerTable.MinBuyIn)}) return c.HTML(http.StatusOK, html) } needed := pokerTable.MinBuyIn - tableAccount.Amount - if tableAccount.PokerTable.IsTest { - authUser.ChipsTest -= int(needed) - } + authUser.IncrChips(int(-needed), tableAccount.PokerTable.IsTest) tableAccount.Amount += needed if err := g.SitPlayer(authUser, pos, tableAccount.Amount); err != nil { PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: err.Error()})