dkforest

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

commit 1cff8aca725623d51313a637e518798a58891056
parent 1d4b3b77c3cf6665ca3e865233bab42ec580391d
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 13 Dec 2023 20:09:31 -0500

keep piconero in database

Diffstat:
Acmd/dkf/migrations/149.sql | 5+++++
Mpkg/actions/actions.go | 5++---
Mpkg/database/tablePokerTables.go | 22+++++++++++++++++-----
Mpkg/database/tablePokerXmrTransactions.go | 14+++++++-------
Mpkg/database/tableUsers.go | 15++-------------
Mpkg/template/fn.go | 5++++-
Mpkg/template/tmp.go | 1+
Mpkg/utils/utils.go | 12+++++++++++-
Mpkg/web/handlers/data.go | 5+++--
Mpkg/web/handlers/handlers.go | 39+++++++++++++++++++++++++++------------
Mpkg/web/handlers/poker/events.go | 8++++----
Mpkg/web/handlers/poker/poker.go | 96+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Mpkg/web/public/views/pages/poker.gohtml | 2+-
13 files changed, 136 insertions(+), 93 deletions(-)

diff --git a/cmd/dkf/migrations/149.sql b/cmd/dkf/migrations/149.sql @@ -0,0 +1,5 @@ +-- +migrate Up +ALTER TABLE users ADD COLUMN xmr_balance INTEGER NOT NULL DEFAULT 0; +ALTER TABLE users ADD COLUMN xmr_balance_stagenet INTEGER NOT NULL DEFAULT 0; + +-- +migrate Down diff --git a/pkg/actions/actions.go b/pkg/actions/actions.go @@ -236,15 +236,14 @@ func xmrWatch(db *database.DkfDB) { if pokerTransfer.Processed { continue } - pokerTransfer.Confirmations = int64(transfer.Confirmations) + pokerTransfer.Confirmations = utils.MinInt(transfer.Confirmations, 10) pokerTransfer.DoSave(db) if transfer.Confirmations < 10 { - logrus.Error("payment processing") continue } tx := db.Begin() pokerTransfer.Processed = true - user.ChipsTest += int(pokerTransfer.Amount) / 100_000_000 + user.XmrBalanceStagenet += pokerTransfer.Amount pokerTransfer.DoSave(tx) user.DoSave(tx) tx.Commit() diff --git a/pkg/database/tablePokerTables.go b/pkg/database/tablePokerTables.go @@ -8,9 +8,9 @@ type PokerTable struct { ID int64 Slug string Name string - MinBuyIn int64 - MaxBuyIn int64 - MinBet int64 + MinBuyIn PokerChip + MaxBuyIn PokerChip + MinBet PokerChip IsTest bool } @@ -24,12 +24,24 @@ func (d *DkfDB) GetPokerTableBySlug(slug string) (out PokerTable, err error) { return } +type Piconero uint64 + +func (p Piconero) ToPokerChip() PokerChip { + return PokerChip(p / 10_000_000) +} + +type PokerChip uint64 + +func (p PokerChip) ToPiconero() Piconero { + return Piconero(p * 10_000_000) +} + type PokerTableAccount struct { ID int64 UserID UserID PokerTableID int64 - Amount int64 - AmountBet int64 + Amount PokerChip + AmountBet PokerChip PokerTable PokerTable } diff --git a/pkg/database/tablePokerXmrTransactions.go b/pkg/database/tablePokerXmrTransactions.go @@ -11,9 +11,9 @@ type PokerXmrTransaction struct { TxID string UserID UserID Address string - Amount int64 - Confirmations int64 - Height int64 + Amount Piconero + Confirmations uint64 + Height uint64 IsIn bool Processed bool CreatedAt time.Time @@ -31,9 +31,9 @@ func (d *DkfDB) GetOrCreatePokerXmrTransaction(userID UserID, transfer *wallet.T TxID: transfer.TxID, UserID: userID, Address: transfer.Address, - Height: int64(transfer.Height), - Amount: int64(transfer.Amount), - Confirmations: int64(transfer.Confirmations), + Height: transfer.Height, + Amount: Piconero(transfer.Amount), + Confirmations: transfer.Confirmations, IsIn: true, } err = d.db.Create(&out).Error @@ -42,7 +42,7 @@ func (d *DkfDB) GetOrCreatePokerXmrTransaction(userID UserID, transfer *wallet.T } func (d *DkfDB) CreatePokerXmrTransaction(userID UserID, transfer *wallet.ResponseTransfer) (out PokerXmrTransaction, err error) { - err = d.db.Create(&PokerXmrTransaction{UserID: userID, Amount: int64(transfer.Amount), IsIn: false}).Error + err = d.db.Create(&PokerXmrTransaction{UserID: userID, Amount: Piconero(transfer.Amount), IsIn: false}).Error return } diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go @@ -122,6 +122,8 @@ type User struct { Theme int64 GeneralMessagesCount int64 ChipsTest int + XmrBalanceStagenet Piconero + XmrBalance Piconero AFK bool UseStream bool SyntaxHighlightCode string @@ -655,19 +657,6 @@ 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 - } -} - func (u *User) GetURL() string { return fmt.Sprintf("monero:%s", u.PokerXmrSubAddress) } diff --git a/pkg/template/fn.go b/pkg/template/fn.go @@ -116,9 +116,12 @@ func divide1000(val int64) float64 { func divide100M(val int64) float64 { return float64(val) / 100_000_000 } -func divide1T(val int64) float64 { +func divide1T(val database.Piconero) float64 { return float64(val) / 1_000_000_000_000 } +func fmtPiconero(val database.Piconero) string { + return fmt.Sprintf("%.12f", float64(val)/1_000_000_000_000) +} func int64bytes(val int64) string { return humanize.Bytes(uint64(val)) diff --git a/pkg/template/tmp.go b/pkg/template/tmp.go @@ -43,6 +43,7 @@ func GetRenderer(e *echo.Echo) *Templates { tmplBuilder.AddFn("divide1000", divide1000) tmplBuilder.AddFn("divide100M", divide100M) tmplBuilder.AddFn("divide1T", divide1T) + tmplBuilder.AddFn("fmtPiconero", fmtPiconero) tmplBuilder.AddFn("toString", toString) tmplBuilder.AddFn("toI64", toI64) tmplBuilder.AddFn("formatFloat", formatFloat) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go @@ -144,6 +144,16 @@ func DoParseInt(v string) (out int) { return } +func ParseUint64(v string) (uint64, error) { + p, err := strconv.ParseInt(v, 10, 64) + return uint64(p), err +} + +func DoParseUint64(v string) (out uint64) { + out, _ = ParseUint64(v) + return +} + // ParseF64 ... func ParseF64(v string) (float64, error) { return strconv.ParseFloat(v, 64) @@ -601,7 +611,7 @@ func Shuffle1[T any](r *rand.Rand, s []T) { } type Ints interface { - int | int64 | uint64 + int | int64 | ~uint64 } // Clamp ensure the value is within a range diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go @@ -929,12 +929,13 @@ type chessData struct { } type pokerData struct { - Balance int64 + XmrBalanceStagenet database.Piconero PokerXmrSubAddress string Img string Tables []database.PokerTable Transactions []database.PokerXmrTransaction - WithdrawAmount int + MinWithdrawAmount database.Piconero + WithdrawAmount database.Piconero WithdrawAddress string Error string } diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -771,11 +771,11 @@ func PokerHomeHandler(c echo.Context) error { authUser.DoSave(db) } } - const minWithdrawAmount = 100 + const minWithdrawAmount = 1 var data pokerData data.Transactions, _ = db.GetUserPokerXmrTransactions(authUser.ID) data.PokerXmrSubAddress = authUser.PokerXmrSubAddress - data.Balance = int64(authUser.ChipsTest) + data.XmrBalanceStagenet = authUser.XmrBalanceStagenet data.Tables, _ = db.GetPokerTables() data.WithdrawAmount = minWithdrawAmount if authUser.PokerXmrSubAddress != "" { @@ -784,7 +784,7 @@ func PokerHomeHandler(c echo.Context) error { } if c.Request().Method == http.MethodPost { - data.WithdrawAmount = utils.DoParseInt(c.Request().PostFormValue("withdraw_amount")) + data.WithdrawAmount = database.Piconero(utils.DoParseUint64(c.Request().PostFormValue("withdraw_amount"))) data.WithdrawAddress = c.Request().PostFormValue("withdraw_address") if len(data.WithdrawAddress) != 95 { data.Error = "invalid xmr address" @@ -794,34 +794,49 @@ func PokerHomeHandler(c echo.Context) error { data.Error = "cannot withdraw to the deposit address" return c.Render(http.StatusOK, "poker", data) } - withdrawAmount := data.WithdrawAmount + withdrawAmount := data.WithdrawAmount * 1_000_000_000_000 if withdrawAmount < minWithdrawAmount { - data.Error = "minimum withdraw amount is 100 chips" + data.Error = fmt.Sprintf("minimum withdraw amount is %d", minWithdrawAmount) return c.Render(http.StatusOK, "poker", data) } - userChips := authUser.GetChips(true) + userChips := authUser.XmrBalanceStagenet if withdrawAmount > userChips { data.Error = fmt.Sprintf("maximum withdraw amount is %d chips", userChips) return c.Render(http.StatusOK, "poker", data) } withdrawAmount = utils.Clamp(withdrawAmount, minWithdrawAmount, userChips) - authUser.IncrChips(-withdrawAmount, true) - authUser.DoSave(db) - fee := int(pokerHouseFee * float64(withdrawAmount)) - withdrawAmount -= fee + houseFee := database.Piconero(pokerHouseFee * float64(withdrawAmount)) + withdrawAmount -= houseFee res, err := config.Xmr().Transfer(&wallet1.RequestTransfer{ + DoNotRelay: true, + GetTxMetadata: true, Destinations: []*wallet1.Destination{ {Address: data.WithdrawAddress, - Amount: uint64(chips) * 100_000_000}, + Amount: uint64(withdrawAmount)}, {Address: pokerHouseXmrAddressStag, - Amount: uint64(fee) * 100_000_000}}}) + Amount: uint64(houseFee)}}}) if err != nil { logrus.Error(err) data.Error = err.Error() return c.Render(http.StatusOK, "poker", data) } + + transactionFee := database.Piconero(res.Fee) + authUser.XmrBalanceStagenet -= withdrawAmount + transactionFee + if authUser.XmrBalanceStagenet < 0 { + data.Error = fmt.Sprintf("not enough funds to pay for transaction fee (%d)", transactionFee) + return c.Render(http.StatusOK, "poker", data) + } + authUser.DoSave(db) + + if _, err := config.Xmr().RelayTx(&wallet1.RequestRelayTx{Hex: res.TxMetadata}); err != nil { + logrus.Error(err) + data.Error = err.Error() + return c.Render(http.StatusOK, "poker", data) + } + if _, err := db.CreatePokerXmrTransaction(authUser.ID, res); err != nil { logrus.Error(err) data.Error = err.Error() diff --git a/pkg/web/handlers/poker/events.go b/pkg/web/handlers/poker/events.go @@ -28,9 +28,9 @@ type ResetCardsEvent struct { type PlayerBetEvent struct { PlayerSeatIdx int Player database.Username - Bet int - TotalBet int - Cash int + Bet database.PokerChip + TotalBet database.PokerChip + Cash database.PokerChip } type LogEvent struct { @@ -46,7 +46,7 @@ type PlayerFoldEvent struct { } type PokerMainPotUpdatedEvent struct { - MainPot int + MainPot database.PokerChip } type PokerWaitTurnEvent struct { diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -44,7 +44,7 @@ func NewPoker() *Poker { return p } -func (p *Poker) GetOrCreateGame(roomID string, pokerTableID int64, pokerTableMinBet int) *PokerGame { +func (p *Poker) GetOrCreateGame(roomID string, pokerTableID int64, pokerTableMinBet database.PokerChip) *PokerGame { p.Lock() defer p.Unlock() g, found := p.games[roomID] @@ -79,7 +79,7 @@ type PlayerEvent struct { Fold bool AllIn bool Unsit bool - Bet int + Bet database.PokerChip } var PokerInstance = NewPoker() @@ -94,23 +94,23 @@ type Ongoing struct { CommunityCards []string WaitTurnEvent PokerWaitTurnEvent WaitTurnEventMtx sync.RWMutex - MainPot atomic.Int32 + MainPot atomic.Uint64 CreatedAt time.Time } type PokerStandingPlayer struct { UserID database.UserID Username database.Username - Cash int + Cash database.PokerChip LastActionTS time.Time } // Return either or not a player is eligible to play a game -func (p *PokerStandingPlayer) isEligible(pokerTableMinBet int) bool { +func (p *PokerStandingPlayer) isEligible(pokerTableMinBet database.PokerChip) bool { return p != nil && p.Cash >= pokerTableMinBet } -func (p *PokerStandingPlayer) getDisplayCash(g *PokerGame) int { +func (p *PokerStandingPlayer) getDisplayCash(g *PokerGame) database.PokerChip { if g.Ongoing != nil { if op := g.Ongoing.GetPlayer(p.Username); op != nil && !op.Unsit.Load() { return op.Cash @@ -121,9 +121,9 @@ func (p *PokerStandingPlayer) getDisplayCash(g *PokerGame) int { type PokerPlayer struct { *PokerStandingPlayer - RoundTotalBet int - Bet int - AllInMaxGain int + RoundTotalBet database.PokerChip + Bet database.PokerChip + AllInMaxGain database.PokerChip SeatIdx int // 0 indexed Cards []PlayerCard CardsMtx sync.RWMutex @@ -135,10 +135,10 @@ func (p *PokerPlayer) isAllIn() bool { return p.Cash == 0 } -func (p *PokerPlayer) doBet(db *database.DkfDB, bet int, pokerTableID int64) { +func (p *PokerPlayer) doBet(db *database.DkfDB, bet database.PokerChip, pokerTableID int64) { account, _ := db.GetPokerTableAccount(p.UserID, pokerTableID) - account.Amount -= int64(bet) - account.AmountBet += int64(bet) + account.Amount -= bet + account.AmountBet += bet account.DoSave(db) p.RoundTotalBet += bet p.Bet += bet @@ -153,7 +153,7 @@ type PlayerCard struct { type PokerGame struct { sync.Mutex PokerTableID int64 - PokerTableMinBet int + PokerTableMinBet database.PokerChip PlayersEventCh chan PlayerEvent Players []*PokerStandingPlayer PlayersMtx sync.RWMutex @@ -305,7 +305,7 @@ func (g *Ongoing) GetPlayer(player database.Username) *PokerPlayer { func isRoundSettled(players []*PokerPlayer) bool { type Tmp struct { - Bet int + Bet database.PokerChip AllIn bool Folded bool } @@ -373,7 +373,7 @@ func (g *PokerGame) UnSitPlayer1(db *database.DkfDB, roomID string, player *Poke return err } tx := db.Begin() - user.IncrChips(int(account.Amount), account.PokerTable.IsTest) + user.XmrBalanceStagenet += account.Amount.ToPiconero() account.Amount = 0 account.DoSave(tx) user.DoSave(tx) @@ -404,7 +404,7 @@ func (g *PokerGame) UnSitPlayer1(db *database.DkfDB, roomID string, player *Poke return nil } -func (g *PokerGame) SitPlayer(authUser *database.User, pos int, chips int64) error { +func (g *PokerGame) SitPlayer(authUser *database.User, pos int, chips database.PokerChip) error { g.PlayersMtx.Lock() defer g.PlayersMtx.Unlock() for _, p := range g.Players { @@ -415,7 +415,7 @@ func (g *PokerGame) SitPlayer(authUser *database.User, pos int, chips int64) err if g.Players[pos] != nil { return errors.New("seat already taken") } - g.Players[pos] = &PokerStandingPlayer{UserID: authUser.ID, Username: authUser.Username, Cash: int(chips), LastActionTS: time.Now()} + g.Players[pos] = &PokerStandingPlayer{UserID: authUser.ID, Username: authUser.Username, Cash: chips, LastActionTS: time.Now()} return nil } @@ -438,7 +438,7 @@ func NewOngoing(g *PokerGame) *Ongoing { } g.PlayersMtx.RUnlock() - return &Ongoing{Deck: deck, Players: players, WaitTurnEvent: PokerWaitTurnEvent{Idx: -1}, MainPot: atomic.Int32{}, CreatedAt: time.Now()} + return &Ongoing{Deck: deck, Players: players, WaitTurnEvent: PokerWaitTurnEvent{Idx: -1}, MainPot: atomic.Uint64{}, CreatedAt: time.Now()} } func newLogEvent(g *PokerGame, roomLogsTopic, msg string) { @@ -485,7 +485,7 @@ func setWaitTurn(g *PokerGame, roomTopic string, seatIdx int) { } // Return either or not the game ended because only 1 player left playing (or none) -func waitPlayersActionFn(db *database.DkfDB, g *PokerGame, roomID string, skip, minBet int) bool { +func waitPlayersActionFn(db *database.DkfDB, g *PokerGame, roomID string, skip int, minBet database.PokerChip) bool { roomTopic := "room_" + roomID roomLogsTopic := "room_" + roomID + "_logs" dealerIdx := g.Ongoing.getPlayerIdxBySeatIdx(int(g.DealerSeatIdx.Load())) @@ -602,7 +602,7 @@ OUTER: newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s check", p.Username)) } else if evt.Call { - bet := utils.MinInt(minBet-p.Bet, p.Cash) + bet := database.PokerChip(utils.MinInt(uint64(minBet-p.Bet), uint64(p.Cash))) if bet == 0 { newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s check", p.Username)) } else { @@ -677,11 +677,11 @@ END1: time.Sleep(time.Second) // Calculate what is the max gain all-in players can make - mainPot := int(g.Ongoing.MainPot.Load()) + mainPot := database.PokerChip(g.Ongoing.MainPot.Load()) for _, p := range newlyAllInPlayers { maxGain := mainPot for _, op := range g.Ongoing.Players { - maxGain += utils.MinInt(op.Bet, p.Bet) + maxGain += database.PokerChip(utils.MinInt(uint64(op.Bet), uint64(p.Bet))) } p.AllInMaxGain = maxGain } @@ -693,7 +693,7 @@ END1: } PokerPubSub.Pub(roomTopic, PokerMainPotUpdatedEvent{MainPot: mainPot}) - g.Ongoing.MainPot.Store(int32(mainPot)) + g.Ongoing.MainPot.Store(uint64(mainPot)) return playerAlive <= 1 } @@ -890,7 +890,7 @@ func dealerThread(db *database.DkfDB, g *PokerGame, roomID string) { END: winners := g.Ongoing.computeWinners() - mainPot := int(g.Ongoing.MainPot.Load()) + mainPot := database.PokerChip(g.Ongoing.MainPot.Load()) playersGain := processPot(winners, mainPot) var winnersStr, winnerHand string @@ -904,7 +904,7 @@ END: for _, el := range playersGain { newLogEvent(g, roomLogsTopic, fmt.Sprintf("Winner #%d: %s %s -> %d", el.Group, el.Player.Username, el.HandStr, el.Gain)) account, _ := tx.GetPokerTableAccount(el.Player.UserID, g.PokerTableID) - account.Amount += int64(el.Gain) + account.Amount += el.Gain account.AmountBet = 0 account.DoSave(tx) winnersStr += el.Player.Username.String() + " " @@ -950,13 +950,13 @@ END: type PlayerGain struct { Player *PokerPlayer - Gain int + Gain database.PokerChip Group int HandStr string } -func processPot(winners []GameResult, mainPot int) (res []PlayerGain) { - newPlayerGain := func(player *PokerPlayer, gain, groupIdx int, handStr string) PlayerGain { +func processPot(winners []GameResult, mainPot database.PokerChip) (res []PlayerGain) { + newPlayerGain := func(player *PokerPlayer, gain database.PokerChip, groupIdx int, handStr string) PlayerGain { return PlayerGain{Player: player, Gain: gain, Group: groupIdx, HandStr: handStr} } @@ -993,7 +993,7 @@ func processPot(winners []GameResult, mainPot int) (res []PlayerGain) { } else if len(group.Players) > 1 { // Multiple winners, split pot nbPlayersInGroup := len(group.Players) - expectedSplit := mainPot / nbPlayersInGroup + expectedSplit := mainPot / database.PokerChip(nbPlayersInGroup) allInCount := 0 for _, p := range group.Players { if p.isAllIn() { @@ -1004,7 +1004,7 @@ func processPot(winners []GameResult, mainPot int) (res []PlayerGain) { res = append(res, newPlayerGain(p, piece, groupIdx, handStr)) mainPot -= piece if nbPlayersInGroup-allInCount > 0 { - expectedSplit = mainPot / (nbPlayersInGroup - allInCount) + expectedSplit = mainPot / database.PokerChip(nbPlayersInGroup-allInCount) } else { expectedSplit = mainPot } @@ -1015,7 +1015,7 @@ func processPot(winners []GameResult, mainPot int) (res []PlayerGain) { isDone = false continue } - piece := mainPot / (nbPlayersInGroup - allInCount) + piece := mainPot / database.PokerChip(nbPlayersInGroup-allInCount) for _, p := range group.Players { if p.Cash > 0 { piece = utils.MinInt(piece, mainPot) @@ -1129,9 +1129,9 @@ func PokerBetHandler(c echo.Context) error { if g == nil { return c.NoContent(http.StatusNotFound) } - bet := 100 + bet := database.PokerChip(100) if c.Request().Method == http.MethodPost { - bet, _ = strconv.Atoi(c.Request().PostFormValue("betValue")) + bet = database.PokerChip(utils.DoParseUint64(c.Request().PostFormValue("betValue"))) betBtn := c.Request().PostFormValue("bet") if betBtn == "betAllIn" { select { @@ -1154,7 +1154,7 @@ func PokerBetHandler(c echo.Context) error { } html := hutils.HtmlCssReset + ` <form method="post"> - <input type="number" name="betValue" value="` + itoa(bet) + `" style="width: 90px;" /><button type="submit" name="bet" value="bet">Bet</button><br /> + <input type="number" name="betValue" value="` + itoa2(bet) + `" style="width: 90px;" /><button type="submit" name="bet" value="bet">Bet</button><br /> <button type="submit" name="bet" value="bet50">50</button> <button type="submit" name="bet" value="bet100">100</button> <button type="submit" name="bet" value="bet200">200</button> @@ -1200,7 +1200,7 @@ func Refund(db *database.DkfDB) { tx := db.Begin() for _, account := range accounts { if user, err := tx.GetUserByID(account.UserID); err == nil { - user.IncrChips(int(account.Amount+account.AmountBet), account.PokerTable.IsTest) + user.XmrBalanceStagenet += account.Amount.ToPiconero() + account.AmountBet.ToPiconero() account.Amount = 0 account.AmountBet = 0 account.DoSave(tx) @@ -1276,14 +1276,14 @@ func PokerSitHandler(c echo.Context) error { logrus.Error(err) return c.HTML(http.StatusOK, html) } - userChips := int64(authUser.GetChips(tableAccount.PokerTable.IsTest)) + 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.IncrChips(int(-needed), tableAccount.PokerTable.IsTest) + authUser.XmrBalanceStagenet -= needed.ToPiconero() tableAccount.Amount += needed if err := g.SitPlayer(authUser, pos, tableAccount.Amount); err != nil { PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: err.Error()}) @@ -1551,10 +1551,10 @@ func drawSeatsStyle(authUser *database.User, g *PokerGame) string { html += `#seat` + itoa(i+1) + ` { border: 2px solid #0d1b8f; }` } html += `#seat` + itoa(i+1) + ` .inner:before { content: "` + p.Username.String() + `"; }` - html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa(p.getDisplayCash(g)) + `"; }` + html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa2(p.getDisplayCash(g)) + `"; }` if g.Ongoing != nil { if op := g.Ongoing.GetPlayer(p.Username); op != nil && op.Bet > 0 { - html += `#seat` + itoa(i+1) + `Pot:before { content: "` + itoa(op.Bet) + `"; }` + html += `#seat` + itoa(i+1) + `Pot:before { content: "` + itoa2(op.Bet) + `"; }` } } } else { @@ -1573,8 +1573,8 @@ func drawErrorMsgEvent(evt ErrorMsgEvent) string { func drawPlayerBetEvent(evt PlayerBetEvent) (html string) { html += `<style>` - html += `#seat` + itoa(evt.PlayerSeatIdx+1) + `Pot:before { content: "` + itoa(evt.TotalBet) + `"; }` - html += `#seat` + itoa(evt.PlayerSeatIdx+1) + `_cash:before { content: "` + itoa(evt.Cash) + `"; }` + html += `#seat` + itoa(evt.PlayerSeatIdx+1) + `Pot:before { content: "` + itoa2(evt.TotalBet) + `"; }` + html += `#seat` + itoa(evt.PlayerSeatIdx+1) + `_cash:before { content: "` + itoa2(evt.Cash) + `"; }` html += `</style>` return } @@ -1590,7 +1590,7 @@ func drawGameIsDoneHtml(g *PokerGame, evt GameIsDoneEvent) (html string) { html += `<style>` for i, p := range g.Players { if p != nil { - html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa(p.getDisplayCash(g)) + `"; }` + html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa2(p.getDisplayCash(g)) + `"; }` } } html += `#winner:before { content: "Winner: ` + evt.Winner + ` (` + evt.WinnerHand + `)"; }` @@ -1649,7 +1649,7 @@ func drawCountDownStyle(evt PokerWaitTurnEvent) string { func drawMainPotHtml(evt PokerMainPotUpdatedEvent) (html string) { html += `<style>` html += `#seat1Pot:before, #seat2Pot:before, #seat3Pot:before, #seat4Pot:before, #seat5Pot:before, #seat6Pot:before { content: ""; }` - html += `#mainPot:before { content: "Pot: ` + itoa(evt.MainPot) + `"; }` + html += `#mainPot:before { content: "Pot: ` + itoa2(evt.MainPot) + `"; }` html += `</style>` return } @@ -1678,6 +1678,14 @@ func itoa(i int) string { return strconv.Itoa(i) } +func itoa1(i uint64) string { + return fmt.Sprintf("%d", i) +} + +func itoa2(i database.PokerChip) string { + return fmt.Sprintf("%d", i) +} + var pokerCss = `<style> html, body { height: 100%; width: 100%; } body { @@ -1949,7 +1957,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, int(pokerTable.MinBet)) + g := PokerInstance.GetOrCreateGame(roomID, pokerTable.ID, pokerTable.MinBet) 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 @@ -13,7 +13,7 @@ <img src="data:image/png;base64,{{ .Data.Img }}" class="img-thumbnail" alt="" /> {{ end }} </div> - 0.1xmr == 1000chips<br /> + 0.01xmr == 1000chips<br /> 7% house fee on withdraw.<br /> 10 confirmations needed for deposits (~20min)<br /> <div class="clearfix"></div>