commit 6cfc7b50ca4d18c97fec00570942734d1707481c
parent a021cbb3f10f6e0a987a9c5e67bb26beb7b4d618
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 14 Dec 2023 14:11:57 -0500
bring back free tables
Diffstat:
4 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go
@@ -933,6 +933,7 @@ type pokerData struct {
XmrBalanceStagenet database.Piconero
PokerXmrSubAddress string
Img string
+ ChipsTest int
Tables []database.PokerTable
Transactions []database.PokerXmrTransaction
MinWithdrawAmount database.Piconero
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -774,6 +774,7 @@ func PokerHomeHandler(c echo.Context) error {
var data pokerData
data.Transactions, _ = db.GetUserPokerXmrTransactions(authUser.ID)
data.PokerXmrSubAddress = authUser.PokerXmrSubAddress
+ data.ChipsTest = authUser.ChipsTest
data.XmrBalanceStagenet = authUser.XmrBalanceStagenet
withdrawUnique := rand.Int63()
data.WithdrawUnique = withdrawUnique
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -45,7 +45,7 @@ func NewPoker() *Poker {
return p
}
-func (p *Poker) GetOrCreateGame(roomID string, pokerTableID int64, pokerTableMinBet database.PokerChip) *PokerGame {
+func (p *Poker) GetOrCreateGame(roomID string, pokerTableID int64, pokerTableMinBet database.PokerChip, pokerTableIsTest bool) *PokerGame {
p.Lock()
defer p.Unlock()
g, found := p.games[roomID]
@@ -53,6 +53,7 @@ func (p *Poker) GetOrCreateGame(roomID string, pokerTableID int64, pokerTableMin
g = &PokerGame{
PokerTableID: pokerTableID,
PokerTableMinBet: pokerTableMinBet,
+ PokerTableIsTest: pokerTableIsTest,
PlayersEventCh: make(chan PlayerEvent),
Players: make([]*PokerStandingPlayer, NbPlayers),
DealerSeatIdx: atomic.Int32{},
@@ -155,6 +156,7 @@ type PokerGame struct {
sync.Mutex
PokerTableID int64
PokerTableMinBet database.PokerChip
+ PokerTableIsTest bool
PlayersEventCh chan PlayerEvent
Players []*PokerStandingPlayer
PlayersMtx sync.RWMutex
@@ -374,7 +376,11 @@ func (g *PokerGame) UnSitPlayer1(db *database.DkfDB, roomID string, player *Poke
return err
}
tx := db.Begin()
- user.XmrBalanceStagenet += account.Amount.ToPiconero()
+ if g.PokerTableIsTest {
+ user.ChipsTest += int(account.Amount)
+ } else {
+ user.XmrBalanceStagenet += account.Amount.ToPiconero()
+ }
account.Amount = 0
account.DoSave(tx)
user.DoSave(tx)
@@ -1214,7 +1220,11 @@ func Refund(db *database.DkfDB) {
tx := db.Begin()
for _, account := range accounts {
if user, err := tx.GetUserByID(account.UserID); err == nil {
- user.XmrBalanceStagenet += account.Amount.ToPiconero() + account.AmountBet.ToPiconero()
+ if account.PokerTable.IsTest {
+ user.ChipsTest += int(account.Amount.ToPiconero() + account.AmountBet.ToPiconero())
+ } else {
+ user.XmrBalanceStagenet += account.Amount.ToPiconero() + account.AmountBet.ToPiconero()
+ }
account.Amount = 0
account.AmountBet = 0
account.DoSave(tx)
@@ -1290,14 +1300,23 @@ func PokerSitHandler(c echo.Context) error {
logrus.Error(err)
return c.HTML(http.StatusOK, html)
}
- userChips := authUser.XmrBalanceStagenet.ToPokerChip()
+ var userChips database.PokerChip
+ if pokerTable.IsTest {
+ userChips = database.PokerChip(authUser.ChipsTest)
+ } else {
+ userChips = authUser.XmrBalanceStagenet.ToPokerChip()
+ }
totalChips := userChips + tableAccount.Amount
if totalChips < tableMinBuyIn {
PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: fmt.Sprintf("Not enough chips to sit; have: %d; needs: %d", totalChips, tableMinBuyIn)})
return c.HTML(http.StatusOK, html)
}
needed := tableMinBuyIn - tableAccount.Amount
- authUser.XmrBalanceStagenet -= needed.ToPiconero()
+ if pokerTable.IsTest {
+ authUser.ChipsTest -= int(needed)
+ } else {
+ authUser.XmrBalanceStagenet -= needed.ToPiconero()
+ }
tableAccount.Amount += needed
if err := g.SitPlayer(authUser, pos, tableAccount.Amount); err != nil {
PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: err.Error()})
@@ -1978,7 +1997,7 @@ func PokerHandler(c echo.Context) error {
roomUserTopic := "room_" + roomID + "_" + authUser.Username.String()
send := func(s string) { _, _ = c.Response().Write([]byte(s)) }
- g := PokerInstance.GetOrCreateGame(roomID, pokerTable.ID, pokerTable.MinBet)
+ g := PokerInstance.GetOrCreateGame(roomID, pokerTable.ID, pokerTable.MinBet, pokerTable.IsTest)
quit := hutils.CloseSignalChan(c)
hutils.SetStreamingHeaders(c)
diff --git a/pkg/web/public/views/pages/poker.gohtml b/pkg/web/public/views/pages/poker.gohtml
@@ -20,7 +20,9 @@
</div>
<div class="mb-3">
Balance (stagenet): {{ .Data.XmrBalanceStagenet }}<br />
- <small>({{ .Data.XmrBalanceStagenet | fmtPiconero }} XMR)</small>
+ <small>({{ .Data.XmrBalanceStagenet | fmtPiconero }} XMR)</small><br />
+ <br />
+ Free tables balance: {{ .Data.ChipsTest }}
</div>
<div class="mb-3">
<hr />
@@ -41,14 +43,16 @@
<tr>
<th>Table</th>
<th>Min/max buy-in</th>
+ <th>Type</th>
</tr>
{{ range .Data.Tables }}
<tr>
<td><a href="/poker/{{ .Slug }}">{{ .Name }}</a></td>
<td>{{ .MinBuyIn }} - {{ .MaxBuyIn }}</td>
+ <td>{{ if .IsTest }}FREE{{ else }}XMR{{ end }}</td>
</tr>
{{ else }}
- <tr><td colspan="2"><em>No table to show</em></td></tr>
+ <tr><td colspan="3"><em>No table to show</em></td></tr>
{{ end }}
</table>