commit c9eb12b8009c8c3815d59609c2f6cd628266ae23
parent a4a48277daa79181313a818b72fdbe7da9e541f2
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 12 Dec 2023 05:23:25 -0500
cleanup
Diffstat:
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/pkg/database/tablePokerTables.go b/pkg/database/tablePokerTables.go
@@ -24,6 +24,7 @@ type PokerTableAccount struct {
UserID UserID
PokerTableID int64
Amount int64
+ PokerTable PokerTable
}
func (a *PokerTableAccount) Save(db *DkfDB) error {
@@ -37,18 +38,23 @@ func (a *PokerTableAccount) DoSave(db *DkfDB) {
}
func (d *DkfDB) GetPositivePokerTableAccounts() (out []PokerTableAccount, err error) {
- err = d.db.Find(&out, "amount > 0").Error
+ err = d.db.Preload("PokerTable").Find(&out, "amount > 0").Error
return
}
func (d *DkfDB) GetPokerTableAccount(userID UserID, pokerTableID int64) (out PokerTableAccount, err error) {
- if err = d.db.First(&out, "user_id = ? AND poker_table_id = ?", userID, pokerTableID).Error; err != nil {
+ if err = d.db.Preload("PokerTable").First(&out, "user_id = ? AND poker_table_id = ?", userID, pokerTableID).Error; err != nil {
out = PokerTableAccount{UserID: userID, PokerTableID: pokerTableID}
err = d.db.Create(&out).Error
}
return
}
+type PokerTableBet struct {
+ PokerTableAccountID int64
+ Amount int64
+}
+
func (d *DkfDB) GetPokerTableBet(accountID int64) (out PokerTableBet, err error) {
if err = d.db.First(&out, "poker_table_account_id = ?", accountID).Error; err != nil {
out = PokerTableBet{PokerTableAccountID: accountID}
@@ -57,11 +63,6 @@ func (d *DkfDB) GetPokerTableBet(accountID int64) (out PokerTableBet, err error)
return
}
-type PokerTableBet struct {
- PokerTableAccountID int64
- Amount int64
-}
-
func (b *PokerTableBet) UpdateAmount(db *DkfDB, accountID, v int64) {
db.db.Model(b).Where("poker_table_account_id = ?", accountID).Update("amount", v)
}
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -364,7 +364,9 @@ func (g *PokerGame) UnSitPlayer1(db *database.DkfDB, roomID string, player *Poke
return err
}
- user.ChipsTest += int(account.Amount)
+ if account.PokerTable.IsTest {
+ user.ChipsTest += int(account.Amount)
+ }
user.DoSave(db)
account.Amount = 0
account.DoSave(db)
@@ -1172,7 +1174,9 @@ func Refund(db *database.DkfDB) {
if user, err := db.GetUserByID(account.UserID); err == nil {
tableBet, _ := db.GetPokerTableBet(account.ID)
account.Amount += tableBet.Amount
- user.ChipsTest += int(account.Amount)
+ if account.PokerTable.IsTest {
+ user.ChipsTest += int(account.Amount)
+ }
user.DoSave(db)
account.Amount = 0
account.DoSave(db)
@@ -1248,11 +1252,17 @@ func PokerSitHandler(c echo.Context) error {
logrus.Error(err)
return c.HTML(http.StatusOK, html)
}
- if int64(authUser.ChipsTest)+tableAccount.Amount < pokerTable.MinBuyIn {
+ userChips := int64(0)
+ if tableAccount.PokerTable.IsTest {
+ userChips = int64(authUser.ChipsTest)
+ }
+ if userChips+tableAccount.Amount < pokerTable.MinBuyIn {
return c.HTML(http.StatusOK, html)
}
needed := pokerTable.MinBuyIn - tableAccount.Amount
- authUser.ChipsTest -= int(needed)
+ if tableAccount.PokerTable.IsTest {
+ authUser.ChipsTest -= int(needed)
+ }
authUser.DoSave(db)
tableAccount.Amount += needed
tableAccount.DoSave(db)